57842052360601e363a175026cebe991074604b7
[safe/jmp/linux-2.6] / sound / pci / hda / patch_realtek.c
1 /*
2  * Universal Interface for Intel High Definition Audio Codec
3  *
4  * HD audio interface patch for ALC 260/880/882 codecs
5  *
6  * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7  *                    PeiSen Hou <pshou@realtek.com.tw>
8  *                    Takashi Iwai <tiwai@suse.de>
9  *                    Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
10  *
11  *  This driver is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This driver is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
24  */
25
26 #include <linux/init.h>
27 #include <linux/delay.h>
28 #include <linux/slab.h>
29 #include <linux/pci.h>
30 #include <sound/core.h>
31 #include "hda_codec.h"
32 #include "hda_local.h"
33 #include "hda_beep.h"
34
35 #define ALC880_FRONT_EVENT              0x01
36 #define ALC880_DCVOL_EVENT              0x02
37 #define ALC880_HP_EVENT                 0x04
38 #define ALC880_MIC_EVENT                0x08
39
40 /* ALC880 board config type */
41 enum {
42         ALC880_3ST,
43         ALC880_3ST_DIG,
44         ALC880_5ST,
45         ALC880_5ST_DIG,
46         ALC880_W810,
47         ALC880_Z71V,
48         ALC880_6ST,
49         ALC880_6ST_DIG,
50         ALC880_F1734,
51         ALC880_ASUS,
52         ALC880_ASUS_DIG,
53         ALC880_ASUS_W1V,
54         ALC880_ASUS_DIG2,
55         ALC880_FUJITSU,
56         ALC880_UNIWILL_DIG,
57         ALC880_UNIWILL,
58         ALC880_UNIWILL_P53,
59         ALC880_CLEVO,
60         ALC880_TCL_S700,
61         ALC880_LG,
62         ALC880_LG_LW,
63         ALC880_MEDION_RIM,
64 #ifdef CONFIG_SND_DEBUG
65         ALC880_TEST,
66 #endif
67         ALC880_AUTO,
68         ALC880_MODEL_LAST /* last tag */
69 };
70
71 /* ALC260 models */
72 enum {
73         ALC260_BASIC,
74         ALC260_HP,
75         ALC260_HP_DC7600,
76         ALC260_HP_3013,
77         ALC260_FUJITSU_S702X,
78         ALC260_ACER,
79         ALC260_WILL,
80         ALC260_REPLACER_672V,
81         ALC260_FAVORIT100,
82 #ifdef CONFIG_SND_DEBUG
83         ALC260_TEST,
84 #endif
85         ALC260_AUTO,
86         ALC260_MODEL_LAST /* last tag */
87 };
88
89 /* ALC262 models */
90 enum {
91         ALC262_BASIC,
92         ALC262_HIPPO,
93         ALC262_HIPPO_1,
94         ALC262_FUJITSU,
95         ALC262_HP_BPC,
96         ALC262_HP_BPC_D7000_WL,
97         ALC262_HP_BPC_D7000_WF,
98         ALC262_HP_TC_T5735,
99         ALC262_HP_RP5700,
100         ALC262_BENQ_ED8,
101         ALC262_SONY_ASSAMD,
102         ALC262_BENQ_T31,
103         ALC262_ULTRA,
104         ALC262_LENOVO_3000,
105         ALC262_NEC,
106         ALC262_TOSHIBA_S06,
107         ALC262_TOSHIBA_RX1,
108         ALC262_TYAN,
109         ALC262_AUTO,
110         ALC262_MODEL_LAST /* last tag */
111 };
112
113 /* ALC268 models */
114 enum {
115         ALC267_QUANTA_IL1,
116         ALC268_3ST,
117         ALC268_TOSHIBA,
118         ALC268_ACER,
119         ALC268_ACER_DMIC,
120         ALC268_ACER_ASPIRE_ONE,
121         ALC268_DELL,
122         ALC268_ZEPTO,
123 #ifdef CONFIG_SND_DEBUG
124         ALC268_TEST,
125 #endif
126         ALC268_AUTO,
127         ALC268_MODEL_LAST /* last tag */
128 };
129
130 /* ALC269 models */
131 enum {
132         ALC269_BASIC,
133         ALC269_QUANTA_FL1,
134         ALC269_ASUS_EEEPC_P703,
135         ALC269_ASUS_EEEPC_P901,
136         ALC269_FUJITSU,
137         ALC269_LIFEBOOK,
138         ALC269_AUTO,
139         ALC269_MODEL_LAST /* last tag */
140 };
141
142 /* ALC861 models */
143 enum {
144         ALC861_3ST,
145         ALC660_3ST,
146         ALC861_3ST_DIG,
147         ALC861_6ST_DIG,
148         ALC861_UNIWILL_M31,
149         ALC861_TOSHIBA,
150         ALC861_ASUS,
151         ALC861_ASUS_LAPTOP,
152         ALC861_AUTO,
153         ALC861_MODEL_LAST,
154 };
155
156 /* ALC861-VD models */
157 enum {
158         ALC660VD_3ST,
159         ALC660VD_3ST_DIG,
160         ALC660VD_ASUS_V1S,
161         ALC861VD_3ST,
162         ALC861VD_3ST_DIG,
163         ALC861VD_6ST_DIG,
164         ALC861VD_LENOVO,
165         ALC861VD_DALLAS,
166         ALC861VD_HP,
167         ALC861VD_AUTO,
168         ALC861VD_MODEL_LAST,
169 };
170
171 /* ALC662 models */
172 enum {
173         ALC662_3ST_2ch_DIG,
174         ALC662_3ST_6ch_DIG,
175         ALC662_3ST_6ch,
176         ALC662_5ST_DIG,
177         ALC662_LENOVO_101E,
178         ALC662_ASUS_EEEPC_P701,
179         ALC662_ASUS_EEEPC_EP20,
180         ALC663_ASUS_M51VA,
181         ALC663_ASUS_G71V,
182         ALC663_ASUS_H13,
183         ALC663_ASUS_G50V,
184         ALC662_ECS,
185         ALC663_ASUS_MODE1,
186         ALC662_ASUS_MODE2,
187         ALC663_ASUS_MODE3,
188         ALC663_ASUS_MODE4,
189         ALC663_ASUS_MODE5,
190         ALC663_ASUS_MODE6,
191         ALC272_DELL,
192         ALC272_DELL_ZM1,
193         ALC272_SAMSUNG_NC10,
194         ALC662_AUTO,
195         ALC662_MODEL_LAST,
196 };
197
198 /* ALC882 models */
199 enum {
200         ALC882_3ST_DIG,
201         ALC882_6ST_DIG,
202         ALC882_ARIMA,
203         ALC882_W2JC,
204         ALC882_TARGA,
205         ALC882_ASUS_A7J,
206         ALC882_ASUS_A7M,
207         ALC885_MACPRO,
208         ALC885_MBP3,
209         ALC885_MB5,
210         ALC885_IMAC24,
211         ALC883_3ST_2ch_DIG,
212         ALC883_3ST_6ch_DIG,
213         ALC883_3ST_6ch,
214         ALC883_6ST_DIG,
215         ALC883_TARGA_DIG,
216         ALC883_TARGA_2ch_DIG,
217         ALC883_TARGA_8ch_DIG,
218         ALC883_ACER,
219         ALC883_ACER_ASPIRE,
220         ALC888_ACER_ASPIRE_4930G,
221         ALC888_ACER_ASPIRE_6530G,
222         ALC888_ACER_ASPIRE_8930G,
223         ALC888_ACER_ASPIRE_7730G,
224         ALC883_MEDION,
225         ALC883_MEDION_MD2,
226         ALC883_LAPTOP_EAPD,
227         ALC883_LENOVO_101E_2ch,
228         ALC883_LENOVO_NB0763,
229         ALC888_LENOVO_MS7195_DIG,
230         ALC888_LENOVO_SKY,
231         ALC883_HAIER_W66,
232         ALC888_3ST_HP,
233         ALC888_6ST_DELL,
234         ALC883_MITAC,
235         ALC883_CLEVO_M540R,
236         ALC883_CLEVO_M720,
237         ALC883_FUJITSU_PI2515,
238         ALC888_FUJITSU_XA3530,
239         ALC883_3ST_6ch_INTEL,
240         ALC889A_INTEL,
241         ALC889_INTEL,
242         ALC888_ASUS_M90V,
243         ALC888_ASUS_EEE1601,
244         ALC889A_MB31,
245         ALC1200_ASUS_P5Q,
246         ALC883_SONY_VAIO_TT,
247         ALC882_AUTO,
248         ALC882_MODEL_LAST,
249 };
250
251 /* for GPIO Poll */
252 #define GPIO_MASK       0x03
253
254 /* extra amp-initialization sequence types */
255 enum {
256         ALC_INIT_NONE,
257         ALC_INIT_DEFAULT,
258         ALC_INIT_GPIO1,
259         ALC_INIT_GPIO2,
260         ALC_INIT_GPIO3,
261 };
262
263 struct alc_mic_route {
264         hda_nid_t pin;
265         unsigned char mux_idx;
266         unsigned char amix_idx;
267 };
268
269 #define MUX_IDX_UNDEF   ((unsigned char)-1)
270
271 struct alc_spec {
272         /* codec parameterization */
273         struct snd_kcontrol_new *mixers[5];     /* mixer arrays */
274         unsigned int num_mixers;
275         struct snd_kcontrol_new *cap_mixer;     /* capture mixer */
276         unsigned int beep_amp;  /* beep amp value, set via set_beep_amp() */
277
278         const struct hda_verb *init_verbs[10];  /* initialization verbs
279                                                  * don't forget NULL
280                                                  * termination!
281                                                  */
282         unsigned int num_init_verbs;
283
284         char stream_name_analog[32];    /* analog PCM stream */
285         struct hda_pcm_stream *stream_analog_playback;
286         struct hda_pcm_stream *stream_analog_capture;
287         struct hda_pcm_stream *stream_analog_alt_playback;
288         struct hda_pcm_stream *stream_analog_alt_capture;
289
290         char stream_name_digital[32];   /* digital PCM stream */
291         struct hda_pcm_stream *stream_digital_playback;
292         struct hda_pcm_stream *stream_digital_capture;
293
294         /* playback */
295         struct hda_multi_out multiout;  /* playback set-up
296                                          * max_channels, dacs must be set
297                                          * dig_out_nid and hp_nid are optional
298                                          */
299         hda_nid_t alt_dac_nid;
300         hda_nid_t slave_dig_outs[3];    /* optional - for auto-parsing */
301         int dig_out_type;
302
303         /* capture */
304         unsigned int num_adc_nids;
305         hda_nid_t *adc_nids;
306         hda_nid_t *capsrc_nids;
307         hda_nid_t dig_in_nid;           /* digital-in NID; optional */
308
309         /* capture source */
310         unsigned int num_mux_defs;
311         const struct hda_input_mux *input_mux;
312         unsigned int cur_mux[3];
313         struct alc_mic_route ext_mic;
314         struct alc_mic_route int_mic;
315
316         /* channel model */
317         const struct hda_channel_mode *channel_mode;
318         int num_channel_mode;
319         int need_dac_fix;
320         int const_channel_count;
321         int ext_channel_count;
322
323         /* PCM information */
324         struct hda_pcm pcm_rec[3];      /* used in alc_build_pcms() */
325
326         /* dynamic controls, init_verbs and input_mux */
327         struct auto_pin_cfg autocfg;
328         struct snd_array kctls;
329         struct hda_input_mux private_imux[3];
330         hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
331         hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
332         hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
333
334         /* hooks */
335         void (*init_hook)(struct hda_codec *codec);
336         void (*unsol_event)(struct hda_codec *codec, unsigned int res);
337
338         /* for pin sensing */
339         unsigned int sense_updated: 1;
340         unsigned int jack_present: 1;
341         unsigned int master_sw: 1;
342         unsigned int auto_mic:1;
343
344         /* other flags */
345         unsigned int no_analog :1; /* digital I/O only */
346         int init_amp;
347
348         /* for virtual master */
349         hda_nid_t vmaster_nid;
350 #ifdef CONFIG_SND_HDA_POWER_SAVE
351         struct hda_loopback_check loopback;
352 #endif
353
354         /* for PLL fix */
355         hda_nid_t pll_nid;
356         unsigned int pll_coef_idx, pll_coef_bit;
357 };
358
359 /*
360  * configuration template - to be copied to the spec instance
361  */
362 struct alc_config_preset {
363         struct snd_kcontrol_new *mixers[5]; /* should be identical size
364                                              * with spec
365                                              */
366         struct snd_kcontrol_new *cap_mixer; /* capture mixer */
367         const struct hda_verb *init_verbs[5];
368         unsigned int num_dacs;
369         hda_nid_t *dac_nids;
370         hda_nid_t dig_out_nid;          /* optional */
371         hda_nid_t hp_nid;               /* optional */
372         hda_nid_t *slave_dig_outs;
373         unsigned int num_adc_nids;
374         hda_nid_t *adc_nids;
375         hda_nid_t *capsrc_nids;
376         hda_nid_t dig_in_nid;
377         unsigned int num_channel_mode;
378         const struct hda_channel_mode *channel_mode;
379         int need_dac_fix;
380         int const_channel_count;
381         unsigned int num_mux_defs;
382         const struct hda_input_mux *input_mux;
383         void (*unsol_event)(struct hda_codec *, unsigned int);
384         void (*setup)(struct hda_codec *);
385         void (*init_hook)(struct hda_codec *);
386 #ifdef CONFIG_SND_HDA_POWER_SAVE
387         struct hda_amp_list *loopbacks;
388 #endif
389 };
390
391
392 /*
393  * input MUX handling
394  */
395 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
396                              struct snd_ctl_elem_info *uinfo)
397 {
398         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
399         struct alc_spec *spec = codec->spec;
400         unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
401         if (mux_idx >= spec->num_mux_defs)
402                 mux_idx = 0;
403         return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
404 }
405
406 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
407                             struct snd_ctl_elem_value *ucontrol)
408 {
409         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
410         struct alc_spec *spec = codec->spec;
411         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
412
413         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
414         return 0;
415 }
416
417 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
418                             struct snd_ctl_elem_value *ucontrol)
419 {
420         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
421         struct alc_spec *spec = codec->spec;
422         const struct hda_input_mux *imux;
423         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
424         unsigned int mux_idx;
425         hda_nid_t nid = spec->capsrc_nids ?
426                 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
427         unsigned int type;
428
429         mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
430         imux = &spec->input_mux[mux_idx];
431
432         type = get_wcaps_type(get_wcaps(codec, nid));
433         if (type == AC_WID_AUD_MIX) {
434                 /* Matrix-mixer style (e.g. ALC882) */
435                 unsigned int *cur_val = &spec->cur_mux[adc_idx];
436                 unsigned int i, idx;
437
438                 idx = ucontrol->value.enumerated.item[0];
439                 if (idx >= imux->num_items)
440                         idx = imux->num_items - 1;
441                 if (*cur_val == idx)
442                         return 0;
443                 for (i = 0; i < imux->num_items; i++) {
444                         unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
445                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
446                                                  imux->items[i].index,
447                                                  HDA_AMP_MUTE, v);
448                 }
449                 *cur_val = idx;
450                 return 1;
451         } else {
452                 /* MUX style (e.g. ALC880) */
453                 return snd_hda_input_mux_put(codec, imux, ucontrol, nid,
454                                              &spec->cur_mux[adc_idx]);
455         }
456 }
457
458 /*
459  * channel mode setting
460  */
461 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
462                             struct snd_ctl_elem_info *uinfo)
463 {
464         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
465         struct alc_spec *spec = codec->spec;
466         return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
467                                     spec->num_channel_mode);
468 }
469
470 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
471                            struct snd_ctl_elem_value *ucontrol)
472 {
473         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
474         struct alc_spec *spec = codec->spec;
475         return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
476                                    spec->num_channel_mode,
477                                    spec->ext_channel_count);
478 }
479
480 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
481                            struct snd_ctl_elem_value *ucontrol)
482 {
483         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
484         struct alc_spec *spec = codec->spec;
485         int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
486                                       spec->num_channel_mode,
487                                       &spec->ext_channel_count);
488         if (err >= 0 && !spec->const_channel_count) {
489                 spec->multiout.max_channels = spec->ext_channel_count;
490                 if (spec->need_dac_fix)
491                         spec->multiout.num_dacs = spec->multiout.max_channels / 2;
492         }
493         return err;
494 }
495
496 /*
497  * Control the mode of pin widget settings via the mixer.  "pc" is used
498  * instead of "%" to avoid consequences of accidently treating the % as
499  * being part of a format specifier.  Maximum allowed length of a value is
500  * 63 characters plus NULL terminator.
501  *
502  * Note: some retasking pin complexes seem to ignore requests for input
503  * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
504  * are requested.  Therefore order this list so that this behaviour will not
505  * cause problems when mixer clients move through the enum sequentially.
506  * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
507  * March 2006.
508  */
509 static char *alc_pin_mode_names[] = {
510         "Mic 50pc bias", "Mic 80pc bias",
511         "Line in", "Line out", "Headphone out",
512 };
513 static unsigned char alc_pin_mode_values[] = {
514         PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
515 };
516 /* The control can present all 5 options, or it can limit the options based
517  * in the pin being assumed to be exclusively an input or an output pin.  In
518  * addition, "input" pins may or may not process the mic bias option
519  * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
520  * accept requests for bias as of chip versions up to March 2006) and/or
521  * wiring in the computer.
522  */
523 #define ALC_PIN_DIR_IN              0x00
524 #define ALC_PIN_DIR_OUT             0x01
525 #define ALC_PIN_DIR_INOUT           0x02
526 #define ALC_PIN_DIR_IN_NOMICBIAS    0x03
527 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
528
529 /* Info about the pin modes supported by the different pin direction modes.
530  * For each direction the minimum and maximum values are given.
531  */
532 static signed char alc_pin_mode_dir_info[5][2] = {
533         { 0, 2 },    /* ALC_PIN_DIR_IN */
534         { 3, 4 },    /* ALC_PIN_DIR_OUT */
535         { 0, 4 },    /* ALC_PIN_DIR_INOUT */
536         { 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
537         { 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
538 };
539 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
540 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
541 #define alc_pin_mode_n_items(_dir) \
542         (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
543
544 static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
545                              struct snd_ctl_elem_info *uinfo)
546 {
547         unsigned int item_num = uinfo->value.enumerated.item;
548         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
549
550         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
551         uinfo->count = 1;
552         uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
553
554         if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
555                 item_num = alc_pin_mode_min(dir);
556         strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
557         return 0;
558 }
559
560 static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
561                             struct snd_ctl_elem_value *ucontrol)
562 {
563         unsigned int i;
564         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
565         hda_nid_t nid = kcontrol->private_value & 0xffff;
566         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
567         long *valp = ucontrol->value.integer.value;
568         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
569                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
570                                                  0x00);
571
572         /* Find enumerated value for current pinctl setting */
573         i = alc_pin_mode_min(dir);
574         while (i <= alc_pin_mode_max(dir) && alc_pin_mode_values[i] != pinctl)
575                 i++;
576         *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
577         return 0;
578 }
579
580 static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
581                             struct snd_ctl_elem_value *ucontrol)
582 {
583         signed int change;
584         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
585         hda_nid_t nid = kcontrol->private_value & 0xffff;
586         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
587         long val = *ucontrol->value.integer.value;
588         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
589                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
590                                                  0x00);
591
592         if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
593                 val = alc_pin_mode_min(dir);
594
595         change = pinctl != alc_pin_mode_values[val];
596         if (change) {
597                 /* Set pin mode to that requested */
598                 snd_hda_codec_write_cache(codec, nid, 0,
599                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
600                                           alc_pin_mode_values[val]);
601
602                 /* Also enable the retasking pin's input/output as required
603                  * for the requested pin mode.  Enum values of 2 or less are
604                  * input modes.
605                  *
606                  * Dynamically switching the input/output buffers probably
607                  * reduces noise slightly (particularly on input) so we'll
608                  * do it.  However, having both input and output buffers
609                  * enabled simultaneously doesn't seem to be problematic if
610                  * this turns out to be necessary in the future.
611                  */
612                 if (val <= 2) {
613                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
614                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
615                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
616                                                  HDA_AMP_MUTE, 0);
617                 } else {
618                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
619                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
620                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
621                                                  HDA_AMP_MUTE, 0);
622                 }
623         }
624         return change;
625 }
626
627 #define ALC_PIN_MODE(xname, nid, dir) \
628         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
629           .info = alc_pin_mode_info, \
630           .get = alc_pin_mode_get, \
631           .put = alc_pin_mode_put, \
632           .private_value = nid | (dir<<16) }
633
634 /* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
635  * together using a mask with more than one bit set.  This control is
636  * currently used only by the ALC260 test model.  At this stage they are not
637  * needed for any "production" models.
638  */
639 #ifdef CONFIG_SND_DEBUG
640 #define alc_gpio_data_info      snd_ctl_boolean_mono_info
641
642 static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
643                              struct snd_ctl_elem_value *ucontrol)
644 {
645         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
646         hda_nid_t nid = kcontrol->private_value & 0xffff;
647         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
648         long *valp = ucontrol->value.integer.value;
649         unsigned int val = snd_hda_codec_read(codec, nid, 0,
650                                               AC_VERB_GET_GPIO_DATA, 0x00);
651
652         *valp = (val & mask) != 0;
653         return 0;
654 }
655 static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
656                              struct snd_ctl_elem_value *ucontrol)
657 {
658         signed int change;
659         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
660         hda_nid_t nid = kcontrol->private_value & 0xffff;
661         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
662         long val = *ucontrol->value.integer.value;
663         unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
664                                                     AC_VERB_GET_GPIO_DATA,
665                                                     0x00);
666
667         /* Set/unset the masked GPIO bit(s) as needed */
668         change = (val == 0 ? 0 : mask) != (gpio_data & mask);
669         if (val == 0)
670                 gpio_data &= ~mask;
671         else
672                 gpio_data |= mask;
673         snd_hda_codec_write_cache(codec, nid, 0,
674                                   AC_VERB_SET_GPIO_DATA, gpio_data);
675
676         return change;
677 }
678 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
679         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
680           .info = alc_gpio_data_info, \
681           .get = alc_gpio_data_get, \
682           .put = alc_gpio_data_put, \
683           .private_value = nid | (mask<<16) }
684 #endif   /* CONFIG_SND_DEBUG */
685
686 /* A switch control to allow the enabling of the digital IO pins on the
687  * ALC260.  This is incredibly simplistic; the intention of this control is
688  * to provide something in the test model allowing digital outputs to be
689  * identified if present.  If models are found which can utilise these
690  * outputs a more complete mixer control can be devised for those models if
691  * necessary.
692  */
693 #ifdef CONFIG_SND_DEBUG
694 #define alc_spdif_ctrl_info     snd_ctl_boolean_mono_info
695
696 static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
697                               struct snd_ctl_elem_value *ucontrol)
698 {
699         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
700         hda_nid_t nid = kcontrol->private_value & 0xffff;
701         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
702         long *valp = ucontrol->value.integer.value;
703         unsigned int val = snd_hda_codec_read(codec, nid, 0,
704                                               AC_VERB_GET_DIGI_CONVERT_1, 0x00);
705
706         *valp = (val & mask) != 0;
707         return 0;
708 }
709 static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
710                               struct snd_ctl_elem_value *ucontrol)
711 {
712         signed int change;
713         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
714         hda_nid_t nid = kcontrol->private_value & 0xffff;
715         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
716         long val = *ucontrol->value.integer.value;
717         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
718                                                     AC_VERB_GET_DIGI_CONVERT_1,
719                                                     0x00);
720
721         /* Set/unset the masked control bit(s) as needed */
722         change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
723         if (val==0)
724                 ctrl_data &= ~mask;
725         else
726                 ctrl_data |= mask;
727         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
728                                   ctrl_data);
729
730         return change;
731 }
732 #define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
733         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
734           .info = alc_spdif_ctrl_info, \
735           .get = alc_spdif_ctrl_get, \
736           .put = alc_spdif_ctrl_put, \
737           .private_value = nid | (mask<<16) }
738 #endif   /* CONFIG_SND_DEBUG */
739
740 /* A switch control to allow the enabling EAPD digital outputs on the ALC26x.
741  * Again, this is only used in the ALC26x test models to help identify when
742  * the EAPD line must be asserted for features to work.
743  */
744 #ifdef CONFIG_SND_DEBUG
745 #define alc_eapd_ctrl_info      snd_ctl_boolean_mono_info
746
747 static int alc_eapd_ctrl_get(struct snd_kcontrol *kcontrol,
748                               struct snd_ctl_elem_value *ucontrol)
749 {
750         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
751         hda_nid_t nid = kcontrol->private_value & 0xffff;
752         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
753         long *valp = ucontrol->value.integer.value;
754         unsigned int val = snd_hda_codec_read(codec, nid, 0,
755                                               AC_VERB_GET_EAPD_BTLENABLE, 0x00);
756
757         *valp = (val & mask) != 0;
758         return 0;
759 }
760
761 static int alc_eapd_ctrl_put(struct snd_kcontrol *kcontrol,
762                               struct snd_ctl_elem_value *ucontrol)
763 {
764         int change;
765         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
766         hda_nid_t nid = kcontrol->private_value & 0xffff;
767         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
768         long val = *ucontrol->value.integer.value;
769         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
770                                                     AC_VERB_GET_EAPD_BTLENABLE,
771                                                     0x00);
772
773         /* Set/unset the masked control bit(s) as needed */
774         change = (!val ? 0 : mask) != (ctrl_data & mask);
775         if (!val)
776                 ctrl_data &= ~mask;
777         else
778                 ctrl_data |= mask;
779         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
780                                   ctrl_data);
781
782         return change;
783 }
784
785 #define ALC_EAPD_CTRL_SWITCH(xname, nid, mask) \
786         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
787           .info = alc_eapd_ctrl_info, \
788           .get = alc_eapd_ctrl_get, \
789           .put = alc_eapd_ctrl_put, \
790           .private_value = nid | (mask<<16) }
791 #endif   /* CONFIG_SND_DEBUG */
792
793 /*
794  * set up the input pin config (depending on the given auto-pin type)
795  */
796 static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
797                               int auto_pin_type)
798 {
799         unsigned int val = PIN_IN;
800
801         if (auto_pin_type <= AUTO_PIN_FRONT_MIC) {
802                 unsigned int pincap;
803                 pincap = snd_hda_query_pin_caps(codec, nid);
804                 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
805                 if (pincap & AC_PINCAP_VREF_80)
806                         val = PIN_VREF80;
807                 else if (pincap & AC_PINCAP_VREF_50)
808                         val = PIN_VREF50;
809                 else if (pincap & AC_PINCAP_VREF_100)
810                         val = PIN_VREF100;
811                 else if (pincap & AC_PINCAP_VREF_GRD)
812                         val = PIN_VREFGRD;
813         }
814         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
815 }
816
817 /*
818  */
819 static void add_mixer(struct alc_spec *spec, struct snd_kcontrol_new *mix)
820 {
821         if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
822                 return;
823         spec->mixers[spec->num_mixers++] = mix;
824 }
825
826 static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
827 {
828         if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
829                 return;
830         spec->init_verbs[spec->num_init_verbs++] = verb;
831 }
832
833 #ifdef CONFIG_PROC_FS
834 /*
835  * hook for proc
836  */
837 static void print_realtek_coef(struct snd_info_buffer *buffer,
838                                struct hda_codec *codec, hda_nid_t nid)
839 {
840         int coeff;
841
842         if (nid != 0x20)
843                 return;
844         coeff = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PROC_COEF, 0);
845         snd_iprintf(buffer, "  Processing Coefficient: 0x%02x\n", coeff);
846         coeff = snd_hda_codec_read(codec, nid, 0,
847                                    AC_VERB_GET_COEF_INDEX, 0);
848         snd_iprintf(buffer, "  Coefficient Index: 0x%02x\n", coeff);
849 }
850 #else
851 #define print_realtek_coef      NULL
852 #endif
853
854 /*
855  * set up from the preset table
856  */
857 static void setup_preset(struct hda_codec *codec,
858                          const struct alc_config_preset *preset)
859 {
860         struct alc_spec *spec = codec->spec;
861         int i;
862
863         for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
864                 add_mixer(spec, preset->mixers[i]);
865         spec->cap_mixer = preset->cap_mixer;
866         for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
867              i++)
868                 add_verb(spec, preset->init_verbs[i]);
869
870         spec->channel_mode = preset->channel_mode;
871         spec->num_channel_mode = preset->num_channel_mode;
872         spec->need_dac_fix = preset->need_dac_fix;
873         spec->const_channel_count = preset->const_channel_count;
874
875         if (preset->const_channel_count)
876                 spec->multiout.max_channels = preset->const_channel_count;
877         else
878                 spec->multiout.max_channels = spec->channel_mode[0].channels;
879         spec->ext_channel_count = spec->channel_mode[0].channels;
880
881         spec->multiout.num_dacs = preset->num_dacs;
882         spec->multiout.dac_nids = preset->dac_nids;
883         spec->multiout.dig_out_nid = preset->dig_out_nid;
884         spec->multiout.slave_dig_outs = preset->slave_dig_outs;
885         spec->multiout.hp_nid = preset->hp_nid;
886
887         spec->num_mux_defs = preset->num_mux_defs;
888         if (!spec->num_mux_defs)
889                 spec->num_mux_defs = 1;
890         spec->input_mux = preset->input_mux;
891
892         spec->num_adc_nids = preset->num_adc_nids;
893         spec->adc_nids = preset->adc_nids;
894         spec->capsrc_nids = preset->capsrc_nids;
895         spec->dig_in_nid = preset->dig_in_nid;
896
897         spec->unsol_event = preset->unsol_event;
898         spec->init_hook = preset->init_hook;
899 #ifdef CONFIG_SND_HDA_POWER_SAVE
900         spec->loopback.amplist = preset->loopbacks;
901 #endif
902
903         if (preset->setup)
904                 preset->setup(codec);
905 }
906
907 /* Enable GPIO mask and set output */
908 static struct hda_verb alc_gpio1_init_verbs[] = {
909         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
910         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
911         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
912         { }
913 };
914
915 static struct hda_verb alc_gpio2_init_verbs[] = {
916         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
917         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
918         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
919         { }
920 };
921
922 static struct hda_verb alc_gpio3_init_verbs[] = {
923         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
924         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
925         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
926         { }
927 };
928
929 /*
930  * Fix hardware PLL issue
931  * On some codecs, the analog PLL gating control must be off while
932  * the default value is 1.
933  */
934 static void alc_fix_pll(struct hda_codec *codec)
935 {
936         struct alc_spec *spec = codec->spec;
937         unsigned int val;
938
939         if (!spec->pll_nid)
940                 return;
941         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
942                             spec->pll_coef_idx);
943         val = snd_hda_codec_read(codec, spec->pll_nid, 0,
944                                  AC_VERB_GET_PROC_COEF, 0);
945         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
946                             spec->pll_coef_idx);
947         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
948                             val & ~(1 << spec->pll_coef_bit));
949 }
950
951 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
952                              unsigned int coef_idx, unsigned int coef_bit)
953 {
954         struct alc_spec *spec = codec->spec;
955         spec->pll_nid = nid;
956         spec->pll_coef_idx = coef_idx;
957         spec->pll_coef_bit = coef_bit;
958         alc_fix_pll(codec);
959 }
960
961 static void alc_automute_pin(struct hda_codec *codec)
962 {
963         struct alc_spec *spec = codec->spec;
964         unsigned int present, pincap;
965         unsigned int nid = spec->autocfg.hp_pins[0];
966         int i;
967
968         if (!nid)
969                 return;
970         pincap = snd_hda_query_pin_caps(codec, nid);
971         if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */
972                 snd_hda_codec_read(codec, nid, 0, AC_VERB_SET_PIN_SENSE, 0);
973         present = snd_hda_codec_read(codec, nid, 0,
974                                      AC_VERB_GET_PIN_SENSE, 0);
975         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
976         for (i = 0; i < ARRAY_SIZE(spec->autocfg.speaker_pins); i++) {
977                 nid = spec->autocfg.speaker_pins[i];
978                 if (!nid)
979                         break;
980                 snd_hda_codec_write(codec, nid, 0,
981                                     AC_VERB_SET_PIN_WIDGET_CONTROL,
982                                     spec->jack_present ? 0 : PIN_OUT);
983         }
984 }
985
986 static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
987                                 hda_nid_t nid)
988 {
989         hda_nid_t conn[HDA_MAX_NUM_INPUTS];
990         int i, nums;
991
992         nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
993         for (i = 0; i < nums; i++)
994                 if (conn[i] == nid)
995                         return i;
996         return -1;
997 }
998
999 static void alc_mic_automute(struct hda_codec *codec)
1000 {
1001         struct alc_spec *spec = codec->spec;
1002         struct alc_mic_route *dead, *alive;
1003         unsigned int present, type;
1004         hda_nid_t cap_nid;
1005
1006         if (!spec->auto_mic)
1007                 return;
1008         if (!spec->int_mic.pin || !spec->ext_mic.pin)
1009                 return;
1010         if (snd_BUG_ON(!spec->adc_nids))
1011                 return;
1012
1013         cap_nid = spec->capsrc_nids ? spec->capsrc_nids[0] : spec->adc_nids[0];
1014
1015         present = snd_hda_codec_read(codec, spec->ext_mic.pin, 0,
1016                                      AC_VERB_GET_PIN_SENSE, 0);
1017         present &= AC_PINSENSE_PRESENCE;
1018         if (present) {
1019                 alive = &spec->ext_mic;
1020                 dead = &spec->int_mic;
1021         } else {
1022                 alive = &spec->int_mic;
1023                 dead = &spec->ext_mic;
1024         }
1025
1026         type = get_wcaps_type(get_wcaps(codec, cap_nid));
1027         if (type == AC_WID_AUD_MIX) {
1028                 /* Matrix-mixer style (e.g. ALC882) */
1029                 snd_hda_codec_amp_stereo(codec, cap_nid, HDA_INPUT,
1030                                          alive->mux_idx,
1031                                          HDA_AMP_MUTE, 0);
1032                 snd_hda_codec_amp_stereo(codec, cap_nid, HDA_INPUT,
1033                                          dead->mux_idx,
1034                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
1035         } else {
1036                 /* MUX style (e.g. ALC880) */
1037                 snd_hda_codec_write_cache(codec, cap_nid, 0,
1038                                           AC_VERB_SET_CONNECT_SEL,
1039                                           alive->mux_idx);
1040         }
1041
1042         /* FIXME: analog mixer */
1043 }
1044
1045 /* unsolicited event for HP jack sensing */
1046 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
1047 {
1048         if (codec->vendor_id == 0x10ec0880)
1049                 res >>= 28;
1050         else
1051                 res >>= 26;
1052         switch (res) {
1053         case ALC880_HP_EVENT:
1054                 alc_automute_pin(codec);
1055                 break;
1056         case ALC880_MIC_EVENT:
1057                 alc_mic_automute(codec);
1058                 break;
1059         }
1060 }
1061
1062 static void alc_inithook(struct hda_codec *codec)
1063 {
1064         alc_automute_pin(codec);
1065         alc_mic_automute(codec);
1066 }
1067
1068 /* additional initialization for ALC888 variants */
1069 static void alc888_coef_init(struct hda_codec *codec)
1070 {
1071         unsigned int tmp;
1072
1073         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
1074         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
1075         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
1076         if ((tmp & 0xf0) == 0x20)
1077                 /* alc888S-VC */
1078                 snd_hda_codec_read(codec, 0x20, 0,
1079                                    AC_VERB_SET_PROC_COEF, 0x830);
1080          else
1081                  /* alc888-VB */
1082                  snd_hda_codec_read(codec, 0x20, 0,
1083                                     AC_VERB_SET_PROC_COEF, 0x3030);
1084 }
1085
1086 static void alc889_coef_init(struct hda_codec *codec)
1087 {
1088         unsigned int tmp;
1089
1090         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
1091         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
1092         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
1093         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
1094 }
1095
1096 static void alc_auto_init_amp(struct hda_codec *codec, int type)
1097 {
1098         unsigned int tmp;
1099
1100         switch (type) {
1101         case ALC_INIT_GPIO1:
1102                 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
1103                 break;
1104         case ALC_INIT_GPIO2:
1105                 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
1106                 break;
1107         case ALC_INIT_GPIO3:
1108                 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
1109                 break;
1110         case ALC_INIT_DEFAULT:
1111                 switch (codec->vendor_id) {
1112                 case 0x10ec0260:
1113                         snd_hda_codec_write(codec, 0x0f, 0,
1114                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1115                         snd_hda_codec_write(codec, 0x10, 0,
1116                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1117                         break;
1118                 case 0x10ec0262:
1119                 case 0x10ec0267:
1120                 case 0x10ec0268:
1121                 case 0x10ec0269:
1122                 case 0x10ec0272:
1123                 case 0x10ec0660:
1124                 case 0x10ec0662:
1125                 case 0x10ec0663:
1126                 case 0x10ec0862:
1127                 case 0x10ec0889:
1128                         snd_hda_codec_write(codec, 0x14, 0,
1129                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1130                         snd_hda_codec_write(codec, 0x15, 0,
1131                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1132                         break;
1133                 }
1134                 switch (codec->vendor_id) {
1135                 case 0x10ec0260:
1136                         snd_hda_codec_write(codec, 0x1a, 0,
1137                                             AC_VERB_SET_COEF_INDEX, 7);
1138                         tmp = snd_hda_codec_read(codec, 0x1a, 0,
1139                                                  AC_VERB_GET_PROC_COEF, 0);
1140                         snd_hda_codec_write(codec, 0x1a, 0,
1141                                             AC_VERB_SET_COEF_INDEX, 7);
1142                         snd_hda_codec_write(codec, 0x1a, 0,
1143                                             AC_VERB_SET_PROC_COEF,
1144                                             tmp | 0x2010);
1145                         break;
1146                 case 0x10ec0262:
1147                 case 0x10ec0880:
1148                 case 0x10ec0882:
1149                 case 0x10ec0883:
1150                 case 0x10ec0885:
1151                 case 0x10ec0887:
1152                 case 0x10ec0889:
1153                         alc889_coef_init(codec);
1154                         break;
1155                 case 0x10ec0888:
1156                         alc888_coef_init(codec);
1157                         break;
1158                 case 0x10ec0267:
1159                 case 0x10ec0268:
1160                         snd_hda_codec_write(codec, 0x20, 0,
1161                                             AC_VERB_SET_COEF_INDEX, 7);
1162                         tmp = snd_hda_codec_read(codec, 0x20, 0,
1163                                                  AC_VERB_GET_PROC_COEF, 0);
1164                         snd_hda_codec_write(codec, 0x20, 0,
1165                                             AC_VERB_SET_COEF_INDEX, 7);
1166                         snd_hda_codec_write(codec, 0x20, 0,
1167                                             AC_VERB_SET_PROC_COEF,
1168                                             tmp | 0x3000);
1169                         break;
1170                 }
1171                 break;
1172         }
1173 }
1174
1175 static void alc_init_auto_hp(struct hda_codec *codec)
1176 {
1177         struct alc_spec *spec = codec->spec;
1178
1179         if (!spec->autocfg.hp_pins[0])
1180                 return;
1181
1182         if (!spec->autocfg.speaker_pins[0]) {
1183                 if (spec->autocfg.line_out_pins[0] &&
1184                     spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
1185                         spec->autocfg.speaker_pins[0] =
1186                                 spec->autocfg.line_out_pins[0];
1187                 else
1188                         return;
1189         }
1190
1191         snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
1192                     spec->autocfg.hp_pins[0]);
1193         snd_hda_codec_write_cache(codec, spec->autocfg.hp_pins[0], 0,
1194                                   AC_VERB_SET_UNSOLICITED_ENABLE,
1195                                   AC_USRSP_EN | ALC880_HP_EVENT);
1196         spec->unsol_event = alc_sku_unsol_event;
1197 }
1198
1199 static void alc_init_auto_mic(struct hda_codec *codec)
1200 {
1201         struct alc_spec *spec = codec->spec;
1202         struct auto_pin_cfg *cfg = &spec->autocfg;
1203         hda_nid_t fixed, ext;
1204         int i;
1205
1206         /* there must be only two mic inputs exclusively */
1207         for (i = AUTO_PIN_LINE; i < AUTO_PIN_LAST; i++)
1208                 if (cfg->input_pins[i])
1209                         return;
1210
1211         fixed = ext = 0;
1212         for (i = AUTO_PIN_MIC; i <= AUTO_PIN_FRONT_MIC; i++) {
1213                 hda_nid_t nid = cfg->input_pins[i];
1214                 unsigned int defcfg;
1215                 if (!nid)
1216                         return;
1217                 defcfg = snd_hda_codec_get_pincfg(codec, nid);
1218                 switch (get_defcfg_connect(defcfg)) {
1219                 case AC_JACK_PORT_FIXED:
1220                         if (fixed)
1221                                 return; /* already occupied */
1222                         fixed = nid;
1223                         break;
1224                 case AC_JACK_PORT_COMPLEX:
1225                         if (ext)
1226                                 return; /* already occupied */
1227                         ext = nid;
1228                         break;
1229                 default:
1230                         return; /* invalid entry */
1231                 }
1232         }
1233         if (!(get_wcaps(codec, ext) & AC_WCAP_UNSOL_CAP))
1234                 return; /* no unsol support */
1235         snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x\n",
1236                     ext, fixed);
1237         spec->ext_mic.pin = ext;
1238         spec->int_mic.pin = fixed;
1239         spec->ext_mic.mux_idx = MUX_IDX_UNDEF; /* set later */
1240         spec->int_mic.mux_idx = MUX_IDX_UNDEF; /* set later */
1241         spec->auto_mic = 1;
1242         snd_hda_codec_write_cache(codec, spec->ext_mic.pin, 0,
1243                                   AC_VERB_SET_UNSOLICITED_ENABLE,
1244                                   AC_USRSP_EN | ALC880_MIC_EVENT);
1245         spec->unsol_event = alc_sku_unsol_event;
1246 }
1247
1248 /* check subsystem ID and set up device-specific initialization;
1249  * return 1 if initialized, 0 if invalid SSID
1250  */
1251 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1252  *      31 ~ 16 :       Manufacture ID
1253  *      15 ~ 8  :       SKU ID
1254  *      7  ~ 0  :       Assembly ID
1255  *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1256  */
1257 static int alc_subsystem_id(struct hda_codec *codec,
1258                             hda_nid_t porta, hda_nid_t porte,
1259                             hda_nid_t portd)
1260 {
1261         unsigned int ass, tmp, i;
1262         unsigned nid;
1263         struct alc_spec *spec = codec->spec;
1264
1265         ass = codec->subsystem_id & 0xffff;
1266         if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1267                 goto do_sku;
1268
1269         /* invalid SSID, check the special NID pin defcfg instead */
1270         /*
1271          * 31~30        : port connectivity
1272          * 29~21        : reserve
1273          * 20           : PCBEEP input
1274          * 19~16        : Check sum (15:1)
1275          * 15~1         : Custom
1276          * 0            : override
1277         */
1278         nid = 0x1d;
1279         if (codec->vendor_id == 0x10ec0260)
1280                 nid = 0x17;
1281         ass = snd_hda_codec_get_pincfg(codec, nid);
1282         snd_printd("realtek: No valid SSID, "
1283                    "checking pincfg 0x%08x for NID 0x%x\n",
1284                    ass, nid);
1285         if (!(ass & 1) && !(ass & 0x100000))
1286                 return 0;
1287         if ((ass >> 30) != 1)   /* no physical connection */
1288                 return 0;
1289
1290         /* check sum */
1291         tmp = 0;
1292         for (i = 1; i < 16; i++) {
1293                 if ((ass >> i) & 1)
1294                         tmp++;
1295         }
1296         if (((ass >> 16) & 0xf) != tmp)
1297                 return 0;
1298 do_sku:
1299         snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1300                    ass & 0xffff, codec->vendor_id);
1301         /*
1302          * 0 : override
1303          * 1 :  Swap Jack
1304          * 2 : 0 --> Desktop, 1 --> Laptop
1305          * 3~5 : External Amplifier control
1306          * 7~6 : Reserved
1307         */
1308         tmp = (ass & 0x38) >> 3;        /* external Amp control */
1309         switch (tmp) {
1310         case 1:
1311                 spec->init_amp = ALC_INIT_GPIO1;
1312                 break;
1313         case 3:
1314                 spec->init_amp = ALC_INIT_GPIO2;
1315                 break;
1316         case 7:
1317                 spec->init_amp = ALC_INIT_GPIO3;
1318                 break;
1319         case 5:
1320                 spec->init_amp = ALC_INIT_DEFAULT;
1321                 break;
1322         }
1323
1324         /* is laptop or Desktop and enable the function "Mute internal speaker
1325          * when the external headphone out jack is plugged"
1326          */
1327         if (!(ass & 0x8000))
1328                 return 1;
1329         /*
1330          * 10~8 : Jack location
1331          * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1332          * 14~13: Resvered
1333          * 15   : 1 --> enable the function "Mute internal speaker
1334          *              when the external headphone out jack is plugged"
1335          */
1336         if (!spec->autocfg.hp_pins[0]) {
1337                 hda_nid_t nid;
1338                 tmp = (ass >> 11) & 0x3;        /* HP to chassis */
1339                 if (tmp == 0)
1340                         nid = porta;
1341                 else if (tmp == 1)
1342                         nid = porte;
1343                 else if (tmp == 2)
1344                         nid = portd;
1345                 else
1346                         return 1;
1347                 for (i = 0; i < spec->autocfg.line_outs; i++)
1348                         if (spec->autocfg.line_out_pins[i] == nid)
1349                                 return 1;
1350                 spec->autocfg.hp_pins[0] = nid;
1351         }
1352
1353         alc_init_auto_hp(codec);
1354         alc_init_auto_mic(codec);
1355         return 1;
1356 }
1357
1358 static void alc_ssid_check(struct hda_codec *codec,
1359                            hda_nid_t porta, hda_nid_t porte, hda_nid_t portd)
1360 {
1361         if (!alc_subsystem_id(codec, porta, porte, portd)) {
1362                 struct alc_spec *spec = codec->spec;
1363                 snd_printd("realtek: "
1364                            "Enable default setup for auto mode as fallback\n");
1365                 spec->init_amp = ALC_INIT_DEFAULT;
1366                 alc_init_auto_hp(codec);
1367                 alc_init_auto_mic(codec);
1368         }
1369 }
1370
1371 /*
1372  * Fix-up pin default configurations and add default verbs
1373  */
1374
1375 struct alc_pincfg {
1376         hda_nid_t nid;
1377         u32 val;
1378 };
1379
1380 struct alc_fixup {
1381         const struct alc_pincfg *pins;
1382         const struct hda_verb *verbs;
1383 };
1384
1385 static void alc_pick_fixup(struct hda_codec *codec,
1386                            const struct snd_pci_quirk *quirk,
1387                            const struct alc_fixup *fix)
1388 {
1389         const struct alc_pincfg *cfg;
1390
1391         quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1392         if (!quirk)
1393                 return;
1394
1395         fix += quirk->value;
1396         cfg = fix->pins;
1397         if (cfg) {
1398                 for (; cfg->nid; cfg++)
1399                         snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val);
1400         }
1401         if (fix->verbs)
1402                 add_verb(codec->spec, fix->verbs);
1403 }
1404
1405 /*
1406  * ALC888
1407  */
1408
1409 /*
1410  * 2ch mode
1411  */
1412 static struct hda_verb alc888_4ST_ch2_intel_init[] = {
1413 /* Mic-in jack as mic in */
1414         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1415         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1416 /* Line-in jack as Line in */
1417         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1418         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1419 /* Line-Out as Front */
1420         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1421         { } /* end */
1422 };
1423
1424 /*
1425  * 4ch mode
1426  */
1427 static struct hda_verb alc888_4ST_ch4_intel_init[] = {
1428 /* Mic-in jack as mic in */
1429         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1430         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1431 /* Line-in jack as Surround */
1432         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1433         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1434 /* Line-Out as Front */
1435         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1436         { } /* end */
1437 };
1438
1439 /*
1440  * 6ch mode
1441  */
1442 static struct hda_verb alc888_4ST_ch6_intel_init[] = {
1443 /* Mic-in jack as CLFE */
1444         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1445         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1446 /* Line-in jack as Surround */
1447         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1448         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1449 /* Line-Out as CLFE (workaround because Mic-in is not loud enough) */
1450         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1451         { } /* end */
1452 };
1453
1454 /*
1455  * 8ch mode
1456  */
1457 static struct hda_verb alc888_4ST_ch8_intel_init[] = {
1458 /* Mic-in jack as CLFE */
1459         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1460         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1461 /* Line-in jack as Surround */
1462         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1463         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1464 /* Line-Out as Side */
1465         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1466         { } /* end */
1467 };
1468
1469 static struct hda_channel_mode alc888_4ST_8ch_intel_modes[4] = {
1470         { 2, alc888_4ST_ch2_intel_init },
1471         { 4, alc888_4ST_ch4_intel_init },
1472         { 6, alc888_4ST_ch6_intel_init },
1473         { 8, alc888_4ST_ch8_intel_init },
1474 };
1475
1476 /*
1477  * ALC888 Fujitsu Siemens Amillo xa3530
1478  */
1479
1480 static struct hda_verb alc888_fujitsu_xa3530_verbs[] = {
1481 /* Front Mic: set to PIN_IN (empty by default) */
1482         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1483 /* Connect Internal HP to Front */
1484         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1485         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1486         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1487 /* Connect Bass HP to Front */
1488         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1489         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1490         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1491 /* Connect Line-Out side jack (SPDIF) to Side */
1492         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1493         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1494         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1495 /* Connect Mic jack to CLFE */
1496         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1497         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1498         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},
1499 /* Connect Line-in jack to Surround */
1500         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1501         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1502         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
1503 /* Connect HP out jack to Front */
1504         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1505         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1506         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1507 /* Enable unsolicited event for HP jack and Line-out jack */
1508         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1509         {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1510         {}
1511 };
1512
1513 static void alc_automute_amp(struct hda_codec *codec)
1514 {
1515         struct alc_spec *spec = codec->spec;
1516         unsigned int val, mute, pincap;
1517         hda_nid_t nid;
1518         int i;
1519
1520         spec->jack_present = 0;
1521         for (i = 0; i < ARRAY_SIZE(spec->autocfg.hp_pins); i++) {
1522                 nid = spec->autocfg.hp_pins[i];
1523                 if (!nid)
1524                         break;
1525                 pincap = snd_hda_query_pin_caps(codec, nid);
1526                 if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */
1527                         snd_hda_codec_read(codec, nid, 0,
1528                                            AC_VERB_SET_PIN_SENSE, 0);
1529                 val = snd_hda_codec_read(codec, nid, 0,
1530                                          AC_VERB_GET_PIN_SENSE, 0);
1531                 if (val & AC_PINSENSE_PRESENCE) {
1532                         spec->jack_present = 1;
1533                         break;
1534                 }
1535         }
1536
1537         mute = spec->jack_present ? HDA_AMP_MUTE : 0;
1538         /* Toggle internal speakers muting */
1539         for (i = 0; i < ARRAY_SIZE(spec->autocfg.speaker_pins); i++) {
1540                 nid = spec->autocfg.speaker_pins[i];
1541                 if (!nid)
1542                         break;
1543                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
1544                                          HDA_AMP_MUTE, mute);
1545         }
1546 }
1547
1548 static void alc_automute_amp_unsol_event(struct hda_codec *codec,
1549                                          unsigned int res)
1550 {
1551         if (codec->vendor_id == 0x10ec0880)
1552                 res >>= 28;
1553         else
1554                 res >>= 26;
1555         if (res == ALC880_HP_EVENT)
1556                 alc_automute_amp(codec);
1557 }
1558
1559 static void alc889_automute_setup(struct hda_codec *codec)
1560 {
1561         struct alc_spec *spec = codec->spec;
1562
1563         spec->autocfg.hp_pins[0] = 0x15;
1564         spec->autocfg.speaker_pins[0] = 0x14;
1565         spec->autocfg.speaker_pins[1] = 0x16;
1566         spec->autocfg.speaker_pins[2] = 0x17;
1567         spec->autocfg.speaker_pins[3] = 0x19;
1568         spec->autocfg.speaker_pins[4] = 0x1a;
1569 }
1570
1571 static void alc889_intel_init_hook(struct hda_codec *codec)
1572 {
1573         alc889_coef_init(codec);
1574         alc_automute_amp(codec);
1575 }
1576
1577 static void alc888_fujitsu_xa3530_setup(struct hda_codec *codec)
1578 {
1579         struct alc_spec *spec = codec->spec;
1580
1581         spec->autocfg.hp_pins[0] = 0x17; /* line-out */
1582         spec->autocfg.hp_pins[1] = 0x1b; /* hp */
1583         spec->autocfg.speaker_pins[0] = 0x14; /* speaker */
1584         spec->autocfg.speaker_pins[1] = 0x15; /* bass */
1585 }
1586
1587 /*
1588  * ALC888 Acer Aspire 4930G model
1589  */
1590
1591 static struct hda_verb alc888_acer_aspire_4930g_verbs[] = {
1592 /* Front Mic: set to PIN_IN (empty by default) */
1593         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1594 /* Unselect Front Mic by default in input mixer 3 */
1595         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1596 /* Enable unsolicited event for HP jack */
1597         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1598 /* Connect Internal HP to front */
1599         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1600         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1601         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1602 /* Connect HP out to front */
1603         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1604         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1605         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1606         { }
1607 };
1608
1609 /*
1610  * ALC888 Acer Aspire 6530G model
1611  */
1612
1613 static struct hda_verb alc888_acer_aspire_6530g_verbs[] = {
1614 /* Bias voltage on for external mic port */
1615         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN | PIN_VREF80},
1616 /* Front Mic: set to PIN_IN (empty by default) */
1617         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1618 /* Unselect Front Mic by default in input mixer 3 */
1619         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1620 /* Enable unsolicited event for HP jack */
1621         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1622 /* Enable speaker output */
1623         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1624         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1625 /* Enable headphone output */
1626         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | PIN_HP},
1627         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1628         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1629         { }
1630 };
1631
1632 /*
1633  * ALC889 Acer Aspire 8930G model
1634  */
1635
1636 static struct hda_verb alc889_acer_aspire_8930g_verbs[] = {
1637 /* Front Mic: set to PIN_IN (empty by default) */
1638         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1639 /* Unselect Front Mic by default in input mixer 3 */
1640         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1641 /* Enable unsolicited event for HP jack */
1642         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1643 /* Connect Internal Front to Front */
1644         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1645         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1646         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1647 /* Connect Internal Rear to Rear */
1648         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1649         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1650         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},
1651 /* Connect Internal CLFE to CLFE */
1652         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1653         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1654         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
1655 /* Connect HP out to Front */
1656         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | PIN_HP},
1657         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1658         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1659 /* Enable all DACs */
1660 /*  DAC DISABLE/MUTE 1? */
1661 /*  setting bits 1-5 disables DAC nids 0x02-0x06 apparently. Init=0x38 */
1662         {0x20, AC_VERB_SET_COEF_INDEX, 0x03},
1663         {0x20, AC_VERB_SET_PROC_COEF, 0x0000},
1664 /*  DAC DISABLE/MUTE 2? */
1665 /*  some bit here disables the other DACs. Init=0x4900 */
1666         {0x20, AC_VERB_SET_COEF_INDEX, 0x08},
1667         {0x20, AC_VERB_SET_PROC_COEF, 0x0000},
1668 /* Enable amplifiers */
1669         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
1670         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
1671 /* DMIC fix
1672  * This laptop has a stereo digital microphone. The mics are only 1cm apart
1673  * which makes the stereo useless. However, either the mic or the ALC889
1674  * makes the signal become a difference/sum signal instead of standard
1675  * stereo, which is annoying. So instead we flip this bit which makes the
1676  * codec replicate the sum signal to both channels, turning it into a
1677  * normal mono mic.
1678  */
1679 /*  DMIC_CONTROL? Init value = 0x0001 */
1680         {0x20, AC_VERB_SET_COEF_INDEX, 0x0b},
1681         {0x20, AC_VERB_SET_PROC_COEF, 0x0003},
1682         { }
1683 };
1684
1685 static struct hda_input_mux alc888_2_capture_sources[2] = {
1686         /* Front mic only available on one ADC */
1687         {
1688                 .num_items = 4,
1689                 .items = {
1690                         { "Mic", 0x0 },
1691                         { "Line", 0x2 },
1692                         { "CD", 0x4 },
1693                         { "Front Mic", 0xb },
1694                 },
1695         },
1696         {
1697                 .num_items = 3,
1698                 .items = {
1699                         { "Mic", 0x0 },
1700                         { "Line", 0x2 },
1701                         { "CD", 0x4 },
1702                 },
1703         }
1704 };
1705
1706 static struct hda_input_mux alc888_acer_aspire_6530_sources[2] = {
1707         /* Interal mic only available on one ADC */
1708         {
1709                 .num_items = 5,
1710                 .items = {
1711                         { "Ext Mic", 0x0 },
1712                         { "Line In", 0x2 },
1713                         { "CD", 0x4 },
1714                         { "Input Mix", 0xa },
1715                         { "Int Mic", 0xb },
1716                 },
1717         },
1718         {
1719                 .num_items = 4,
1720                 .items = {
1721                         { "Ext Mic", 0x0 },
1722                         { "Line In", 0x2 },
1723                         { "CD", 0x4 },
1724                         { "Input Mix", 0xa },
1725                 },
1726         }
1727 };
1728
1729 static struct hda_input_mux alc889_capture_sources[3] = {
1730         /* Digital mic only available on first "ADC" */
1731         {
1732                 .num_items = 5,
1733                 .items = {
1734                         { "Mic", 0x0 },
1735                         { "Line", 0x2 },
1736                         { "CD", 0x4 },
1737                         { "Front Mic", 0xb },
1738                         { "Input Mix", 0xa },
1739                 },
1740         },
1741         {
1742                 .num_items = 4,
1743                 .items = {
1744                         { "Mic", 0x0 },
1745                         { "Line", 0x2 },
1746                         { "CD", 0x4 },
1747                         { "Input Mix", 0xa },
1748                 },
1749         },
1750         {
1751                 .num_items = 4,
1752                 .items = {
1753                         { "Mic", 0x0 },
1754                         { "Line", 0x2 },
1755                         { "CD", 0x4 },
1756                         { "Input Mix", 0xa },
1757                 },
1758         }
1759 };
1760
1761 static struct snd_kcontrol_new alc888_base_mixer[] = {
1762         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1763         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1764         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1765         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1766         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
1767                 HDA_OUTPUT),
1768         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1769         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1770         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1771         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1772         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1773         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1774         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1775         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1776         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1777         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1778         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
1779         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1780         { } /* end */
1781 };
1782
1783 static void alc888_acer_aspire_4930g_setup(struct hda_codec *codec)
1784 {
1785         struct alc_spec *spec = codec->spec;
1786
1787         spec->autocfg.hp_pins[0] = 0x15;
1788         spec->autocfg.speaker_pins[0] = 0x14;
1789 }
1790
1791 static void alc888_acer_aspire_6530g_setup(struct hda_codec *codec)
1792 {
1793         struct alc_spec *spec = codec->spec;
1794
1795         spec->autocfg.hp_pins[0] = 0x15;
1796         spec->autocfg.speaker_pins[0] = 0x14;
1797         spec->autocfg.speaker_pins[1] = 0x16;
1798         spec->autocfg.speaker_pins[2] = 0x17;
1799 }
1800
1801 static void alc889_acer_aspire_8930g_setup(struct hda_codec *codec)
1802 {
1803         struct alc_spec *spec = codec->spec;
1804
1805         spec->autocfg.hp_pins[0] = 0x15;
1806         spec->autocfg.speaker_pins[0] = 0x14;
1807         spec->autocfg.speaker_pins[1] = 0x16;
1808         spec->autocfg.speaker_pins[2] = 0x1b;
1809 }
1810
1811 /*
1812  * ALC880 3-stack model
1813  *
1814  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
1815  * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
1816  *                 F-Mic = 0x1b, HP = 0x19
1817  */
1818
1819 static hda_nid_t alc880_dac_nids[4] = {
1820         /* front, rear, clfe, rear_surr */
1821         0x02, 0x05, 0x04, 0x03
1822 };
1823
1824 static hda_nid_t alc880_adc_nids[3] = {
1825         /* ADC0-2 */
1826         0x07, 0x08, 0x09,
1827 };
1828
1829 /* The datasheet says the node 0x07 is connected from inputs,
1830  * but it shows zero connection in the real implementation on some devices.
1831  * Note: this is a 915GAV bug, fixed on 915GLV
1832  */
1833 static hda_nid_t alc880_adc_nids_alt[2] = {
1834         /* ADC1-2 */
1835         0x08, 0x09,
1836 };
1837
1838 #define ALC880_DIGOUT_NID       0x06
1839 #define ALC880_DIGIN_NID        0x0a
1840
1841 static struct hda_input_mux alc880_capture_source = {
1842         .num_items = 4,
1843         .items = {
1844                 { "Mic", 0x0 },
1845                 { "Front Mic", 0x3 },
1846                 { "Line", 0x2 },
1847                 { "CD", 0x4 },
1848         },
1849 };
1850
1851 /* channel source setting (2/6 channel selection for 3-stack) */
1852 /* 2ch mode */
1853 static struct hda_verb alc880_threestack_ch2_init[] = {
1854         /* set line-in to input, mute it */
1855         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1856         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1857         /* set mic-in to input vref 80%, mute it */
1858         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1859         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1860         { } /* end */
1861 };
1862
1863 /* 6ch mode */
1864 static struct hda_verb alc880_threestack_ch6_init[] = {
1865         /* set line-in to output, unmute it */
1866         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1867         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1868         /* set mic-in to output, unmute it */
1869         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1870         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1871         { } /* end */
1872 };
1873
1874 static struct hda_channel_mode alc880_threestack_modes[2] = {
1875         { 2, alc880_threestack_ch2_init },
1876         { 6, alc880_threestack_ch6_init },
1877 };
1878
1879 static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
1880         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1881         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1882         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1883         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
1884         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1885         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1886         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1887         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1888         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1889         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1890         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1891         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1892         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1893         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1894         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
1895         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
1896         HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
1897         {
1898                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1899                 .name = "Channel Mode",
1900                 .info = alc_ch_mode_info,
1901                 .get = alc_ch_mode_get,
1902                 .put = alc_ch_mode_put,
1903         },
1904         { } /* end */
1905 };
1906
1907 /* capture mixer elements */
1908 static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1909                             struct snd_ctl_elem_info *uinfo)
1910 {
1911         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1912         struct alc_spec *spec = codec->spec;
1913         int err;
1914
1915         mutex_lock(&codec->control_mutex);
1916         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1917                                                       HDA_INPUT);
1918         err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
1919         mutex_unlock(&codec->control_mutex);
1920         return err;
1921 }
1922
1923 static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1924                            unsigned int size, unsigned int __user *tlv)
1925 {
1926         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1927         struct alc_spec *spec = codec->spec;
1928         int err;
1929
1930         mutex_lock(&codec->control_mutex);
1931         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1932                                                       HDA_INPUT);
1933         err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
1934         mutex_unlock(&codec->control_mutex);
1935         return err;
1936 }
1937
1938 typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1939                              struct snd_ctl_elem_value *ucontrol);
1940
1941 static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1942                                  struct snd_ctl_elem_value *ucontrol,
1943                                  getput_call_t func)
1944 {
1945         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1946         struct alc_spec *spec = codec->spec;
1947         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1948         int err;
1949
1950         mutex_lock(&codec->control_mutex);
1951         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[adc_idx],
1952                                                       3, 0, HDA_INPUT);
1953         err = func(kcontrol, ucontrol);
1954         mutex_unlock(&codec->control_mutex);
1955         return err;
1956 }
1957
1958 static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1959                            struct snd_ctl_elem_value *ucontrol)
1960 {
1961         return alc_cap_getput_caller(kcontrol, ucontrol,
1962                                      snd_hda_mixer_amp_volume_get);
1963 }
1964
1965 static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1966                            struct snd_ctl_elem_value *ucontrol)
1967 {
1968         return alc_cap_getput_caller(kcontrol, ucontrol,
1969                                      snd_hda_mixer_amp_volume_put);
1970 }
1971
1972 /* capture mixer elements */
1973 #define alc_cap_sw_info         snd_ctl_boolean_stereo_info
1974
1975 static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1976                           struct snd_ctl_elem_value *ucontrol)
1977 {
1978         return alc_cap_getput_caller(kcontrol, ucontrol,
1979                                      snd_hda_mixer_amp_switch_get);
1980 }
1981
1982 static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1983                           struct snd_ctl_elem_value *ucontrol)
1984 {
1985         return alc_cap_getput_caller(kcontrol, ucontrol,
1986                                      snd_hda_mixer_amp_switch_put);
1987 }
1988
1989 #define _DEFINE_CAPMIX(num) \
1990         { \
1991                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1992                 .name = "Capture Switch", \
1993                 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1994                 .count = num, \
1995                 .info = alc_cap_sw_info, \
1996                 .get = alc_cap_sw_get, \
1997                 .put = alc_cap_sw_put, \
1998         }, \
1999         { \
2000                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2001                 .name = "Capture Volume", \
2002                 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
2003                            SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
2004                            SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
2005                 .count = num, \
2006                 .info = alc_cap_vol_info, \
2007                 .get = alc_cap_vol_get, \
2008                 .put = alc_cap_vol_put, \
2009                 .tlv = { .c = alc_cap_vol_tlv }, \
2010         }
2011
2012 #define _DEFINE_CAPSRC(num) \
2013         { \
2014                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2015                 /* .name = "Capture Source", */ \
2016                 .name = "Input Source", \
2017                 .count = num, \
2018                 .info = alc_mux_enum_info, \
2019                 .get = alc_mux_enum_get, \
2020                 .put = alc_mux_enum_put, \
2021         }
2022
2023 #define DEFINE_CAPMIX(num) \
2024 static struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
2025         _DEFINE_CAPMIX(num),                                  \
2026         _DEFINE_CAPSRC(num),                                  \
2027         { } /* end */                                         \
2028 }
2029
2030 #define DEFINE_CAPMIX_NOSRC(num) \
2031 static struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
2032         _DEFINE_CAPMIX(num),                                        \
2033         { } /* end */                                               \
2034 }
2035
2036 /* up to three ADCs */
2037 DEFINE_CAPMIX(1);
2038 DEFINE_CAPMIX(2);
2039 DEFINE_CAPMIX(3);
2040 DEFINE_CAPMIX_NOSRC(1);
2041 DEFINE_CAPMIX_NOSRC(2);
2042 DEFINE_CAPMIX_NOSRC(3);
2043
2044 /*
2045  * ALC880 5-stack model
2046  *
2047  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
2048  *      Side = 0x02 (0xd)
2049  * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
2050  *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
2051  */
2052
2053 /* additional mixers to alc880_three_stack_mixer */
2054 static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
2055         HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2056         HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
2057         { } /* end */
2058 };
2059
2060 /* channel source setting (6/8 channel selection for 5-stack) */
2061 /* 6ch mode */
2062 static struct hda_verb alc880_fivestack_ch6_init[] = {
2063         /* set line-in to input, mute it */
2064         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2065         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2066         { } /* end */
2067 };
2068
2069 /* 8ch mode */
2070 static struct hda_verb alc880_fivestack_ch8_init[] = {
2071         /* set line-in to output, unmute it */
2072         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2073         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2074         { } /* end */
2075 };
2076
2077 static struct hda_channel_mode alc880_fivestack_modes[2] = {
2078         { 6, alc880_fivestack_ch6_init },
2079         { 8, alc880_fivestack_ch8_init },
2080 };
2081
2082
2083 /*
2084  * ALC880 6-stack model
2085  *
2086  * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
2087  *      Side = 0x05 (0x0f)
2088  * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
2089  *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
2090  */
2091
2092 static hda_nid_t alc880_6st_dac_nids[4] = {
2093         /* front, rear, clfe, rear_surr */
2094         0x02, 0x03, 0x04, 0x05
2095 };
2096
2097 static struct hda_input_mux alc880_6stack_capture_source = {
2098         .num_items = 4,
2099         .items = {
2100                 { "Mic", 0x0 },
2101                 { "Front Mic", 0x1 },
2102                 { "Line", 0x2 },
2103                 { "CD", 0x4 },
2104         },
2105 };
2106
2107 /* fixed 8-channels */
2108 static struct hda_channel_mode alc880_sixstack_modes[1] = {
2109         { 8, NULL },
2110 };
2111
2112 static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
2113         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2114         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2115         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2116         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2117         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2118         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2119         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2120         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2121         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2122         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
2123         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2124         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2125         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2126         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2127         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2128         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2129         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2130         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2131         {
2132                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2133                 .name = "Channel Mode",
2134                 .info = alc_ch_mode_info,
2135                 .get = alc_ch_mode_get,
2136                 .put = alc_ch_mode_put,
2137         },
2138         { } /* end */
2139 };
2140
2141
2142 /*
2143  * ALC880 W810 model
2144  *
2145  * W810 has rear IO for:
2146  * Front (DAC 02)
2147  * Surround (DAC 03)
2148  * Center/LFE (DAC 04)
2149  * Digital out (06)
2150  *
2151  * The system also has a pair of internal speakers, and a headphone jack.
2152  * These are both connected to Line2 on the codec, hence to DAC 02.
2153  *
2154  * There is a variable resistor to control the speaker or headphone
2155  * volume. This is a hardware-only device without a software API.
2156  *
2157  * Plugging headphones in will disable the internal speakers. This is
2158  * implemented in hardware, not via the driver using jack sense. In
2159  * a similar fashion, plugging into the rear socket marked "front" will
2160  * disable both the speakers and headphones.
2161  *
2162  * For input, there's a microphone jack, and an "audio in" jack.
2163  * These may not do anything useful with this driver yet, because I
2164  * haven't setup any initialization verbs for these yet...
2165  */
2166
2167 static hda_nid_t alc880_w810_dac_nids[3] = {
2168         /* front, rear/surround, clfe */
2169         0x02, 0x03, 0x04
2170 };
2171
2172 /* fixed 6 channels */
2173 static struct hda_channel_mode alc880_w810_modes[1] = {
2174         { 6, NULL }
2175 };
2176
2177 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
2178 static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
2179         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2180         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2181         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2182         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2183         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2184         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2185         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2186         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2187         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
2188         { } /* end */
2189 };
2190
2191
2192 /*
2193  * Z710V model
2194  *
2195  * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
2196  * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
2197  *                 Line = 0x1a
2198  */
2199
2200 static hda_nid_t alc880_z71v_dac_nids[1] = {
2201         0x02
2202 };
2203 #define ALC880_Z71V_HP_DAC      0x03
2204
2205 /* fixed 2 channels */
2206 static struct hda_channel_mode alc880_2_jack_modes[1] = {
2207         { 2, NULL }
2208 };
2209
2210 static struct snd_kcontrol_new alc880_z71v_mixer[] = {
2211         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2212         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2213         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2214         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
2215         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2216         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2217         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2218         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2219         { } /* end */
2220 };
2221
2222
2223 /*
2224  * ALC880 F1734 model
2225  *
2226  * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
2227  * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
2228  */
2229
2230 static hda_nid_t alc880_f1734_dac_nids[1] = {
2231         0x03
2232 };
2233 #define ALC880_F1734_HP_DAC     0x02
2234
2235 static struct snd_kcontrol_new alc880_f1734_mixer[] = {
2236         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2237         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2238         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2239         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2240         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2241         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2242         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2243         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2244         { } /* end */
2245 };
2246
2247 static struct hda_input_mux alc880_f1734_capture_source = {
2248         .num_items = 2,
2249         .items = {
2250                 { "Mic", 0x1 },
2251                 { "CD", 0x4 },
2252         },
2253 };
2254
2255
2256 /*
2257  * ALC880 ASUS model
2258  *
2259  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
2260  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
2261  *  Mic = 0x18, Line = 0x1a
2262  */
2263
2264 #define alc880_asus_dac_nids    alc880_w810_dac_nids    /* identical with w810 */
2265 #define alc880_asus_modes       alc880_threestack_modes /* 2/6 channel mode */
2266
2267 static struct snd_kcontrol_new alc880_asus_mixer[] = {
2268         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2269         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2270         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2271         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2272         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2273         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2274         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2275         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2276         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2277         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2278         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2279         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2280         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2281         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2282         {
2283                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2284                 .name = "Channel Mode",
2285                 .info = alc_ch_mode_info,
2286                 .get = alc_ch_mode_get,
2287                 .put = alc_ch_mode_put,
2288         },
2289         { } /* end */
2290 };
2291
2292 /*
2293  * ALC880 ASUS W1V model
2294  *
2295  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
2296  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
2297  *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
2298  */
2299
2300 /* additional mixers to alc880_asus_mixer */
2301 static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
2302         HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
2303         HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
2304         { } /* end */
2305 };
2306
2307 /* TCL S700 */
2308 static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
2309         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2310         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
2311         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
2312         HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
2313         HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
2314         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
2315         HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
2316         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
2317         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
2318         { } /* end */
2319 };
2320
2321 /* Uniwill */
2322 static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
2323         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2324         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2325         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2326         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2327         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2328         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2329         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2330         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2331         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2332         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2333         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2334         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2335         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2336         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2337         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2338         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2339         {
2340                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2341                 .name = "Channel Mode",
2342                 .info = alc_ch_mode_info,
2343                 .get = alc_ch_mode_get,
2344                 .put = alc_ch_mode_put,
2345         },
2346         { } /* end */
2347 };
2348
2349 static struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
2350         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2351         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2352         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2353         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2354         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2355         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2356         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2357         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2358         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2359         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2360         { } /* end */
2361 };
2362
2363 static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
2364         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2365         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2366         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2367         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2368         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2369         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2370         { } /* end */
2371 };
2372
2373 /*
2374  * virtual master controls
2375  */
2376
2377 /*
2378  * slave controls for virtual master
2379  */
2380 static const char *alc_slave_vols[] = {
2381         "Front Playback Volume",
2382         "Surround Playback Volume",
2383         "Center Playback Volume",
2384         "LFE Playback Volume",
2385         "Side Playback Volume",
2386         "Headphone Playback Volume",
2387         "Speaker Playback Volume",
2388         "Mono Playback Volume",
2389         "Line-Out Playback Volume",
2390         "PCM Playback Volume",
2391         NULL,
2392 };
2393
2394 static const char *alc_slave_sws[] = {
2395         "Front Playback Switch",
2396         "Surround Playback Switch",
2397         "Center Playback Switch",
2398         "LFE Playback Switch",
2399         "Side Playback Switch",
2400         "Headphone Playback Switch",
2401         "Speaker Playback Switch",
2402         "Mono Playback Switch",
2403         "IEC958 Playback Switch",
2404         NULL,
2405 };
2406
2407 /*
2408  * build control elements
2409  */
2410
2411 static void alc_free_kctls(struct hda_codec *codec);
2412
2413 #ifdef CONFIG_SND_HDA_INPUT_BEEP
2414 /* additional beep mixers; the actual parameters are overwritten at build */
2415 static struct snd_kcontrol_new alc_beep_mixer[] = {
2416         HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
2417         HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
2418         { } /* end */
2419 };
2420 #endif
2421
2422 static int alc_build_controls(struct hda_codec *codec)
2423 {
2424         struct alc_spec *spec = codec->spec;
2425         int err;
2426         int i;
2427
2428         for (i = 0; i < spec->num_mixers; i++) {
2429                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
2430                 if (err < 0)
2431                         return err;
2432         }
2433         if (spec->cap_mixer) {
2434                 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
2435                 if (err < 0)
2436                         return err;
2437         }
2438         if (spec->multiout.dig_out_nid) {
2439                 err = snd_hda_create_spdif_out_ctls(codec,
2440                                                     spec->multiout.dig_out_nid);
2441                 if (err < 0)
2442                         return err;
2443                 if (!spec->no_analog) {
2444                         err = snd_hda_create_spdif_share_sw(codec,
2445                                                             &spec->multiout);
2446                         if (err < 0)
2447                                 return err;
2448                         spec->multiout.share_spdif = 1;
2449                 }
2450         }
2451         if (spec->dig_in_nid) {
2452                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
2453                 if (err < 0)
2454                         return err;
2455         }
2456
2457 #ifdef CONFIG_SND_HDA_INPUT_BEEP
2458         /* create beep controls if needed */
2459         if (spec->beep_amp) {
2460                 struct snd_kcontrol_new *knew;
2461                 for (knew = alc_beep_mixer; knew->name; knew++) {
2462                         struct snd_kcontrol *kctl;
2463                         kctl = snd_ctl_new1(knew, codec);
2464                         if (!kctl)
2465                                 return -ENOMEM;
2466                         kctl->private_value = spec->beep_amp;
2467                         err = snd_hda_ctl_add(codec,
2468                                         get_amp_nid_(spec->beep_amp), kctl);
2469                         if (err < 0)
2470                                 return err;
2471                 }
2472         }
2473 #endif
2474
2475         /* if we have no master control, let's create it */
2476         if (!spec->no_analog &&
2477             !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
2478                 unsigned int vmaster_tlv[4];
2479                 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
2480                                         HDA_OUTPUT, vmaster_tlv);
2481                 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
2482                                           vmaster_tlv, alc_slave_vols);
2483                 if (err < 0)
2484                         return err;
2485         }
2486         if (!spec->no_analog &&
2487             !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
2488                 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
2489                                           NULL, alc_slave_sws);
2490                 if (err < 0)
2491                         return err;
2492         }
2493
2494         alc_free_kctls(codec); /* no longer needed */
2495         return 0;
2496 }
2497
2498
2499 /*
2500  * initialize the codec volumes, etc
2501  */
2502
2503 /*
2504  * generic initialization of ADC, input mixers and output mixers
2505  */
2506 static struct hda_verb alc880_volume_init_verbs[] = {
2507         /*
2508          * Unmute ADC0-2 and set the default input to mic-in
2509          */
2510         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
2511         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2512         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
2513         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2514         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
2515         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2516
2517         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2518          * mixer widget
2519          * Note: PASD motherboards uses the Line In 2 as the input for front
2520          * panel mic (mic 2)
2521          */
2522         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
2523         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2524         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2525         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2526         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2527         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2528         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2529         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2530
2531         /*
2532          * Set up output mixers (0x0c - 0x0f)
2533          */
2534         /* set vol=0 to output mixers */
2535         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2536         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2537         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2538         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2539         /* set up input amps for analog loopback */
2540         /* Amp Indices: DAC = 0, mixer = 1 */
2541         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2542         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2543         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2544         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2545         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2546         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2547         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2548         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2549
2550         { }
2551 };
2552
2553 /*
2554  * 3-stack pin configuration:
2555  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
2556  */
2557 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
2558         /*
2559          * preset connection lists of input pins
2560          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2561          */
2562         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2563         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2564         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2565
2566         /*
2567          * Set pin mode and muting
2568          */
2569         /* set front pin widgets 0x14 for output */
2570         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2571         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2572         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2573         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2574         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2575         /* Mic2 (as headphone out) for HP output */
2576         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2577         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2578         /* Line In pin widget for input */
2579         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2580         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2581         /* Line2 (as front mic) pin widget for input and vref at 80% */
2582         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2583         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2584         /* CD pin widget for input */
2585         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2586
2587         { }
2588 };
2589
2590 /*
2591  * 5-stack pin configuration:
2592  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
2593  * line-in/side = 0x1a, f-mic = 0x1b
2594  */
2595 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
2596         /*
2597          * preset connection lists of input pins
2598          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2599          */
2600         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2601         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
2602
2603         /*
2604          * Set pin mode and muting
2605          */
2606         /* set pin widgets 0x14-0x17 for output */
2607         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2608         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2609         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2610         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2611         /* unmute pins for output (no gain on this amp) */
2612         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2613         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2614         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2615         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2616
2617         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2618         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2619         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2620         /* Mic2 (as headphone out) for HP output */
2621         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2622         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2623         /* Line In pin widget for input */
2624         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2625         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2626         /* Line2 (as front mic) pin widget for input and vref at 80% */
2627         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2628         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2629         /* CD pin widget for input */
2630         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2631
2632         { }
2633 };
2634
2635 /*
2636  * W810 pin configuration:
2637  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
2638  */
2639 static struct hda_verb alc880_pin_w810_init_verbs[] = {
2640         /* hphone/speaker input selector: front DAC */
2641         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
2642
2643         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2644         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2645         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2646         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2647         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2648         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2649
2650         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2651         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2652
2653         { }
2654 };
2655
2656 /*
2657  * Z71V pin configuration:
2658  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
2659  */
2660 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
2661         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2662         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2663         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2664         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2665
2666         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2667         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2668         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2669         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2670
2671         { }
2672 };
2673
2674 /*
2675  * 6-stack pin configuration:
2676  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
2677  * f-mic = 0x19, line = 0x1a, HP = 0x1b
2678  */
2679 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
2680         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2681
2682         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2683         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2684         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2685         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2686         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2687         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2688         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2689         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2690
2691         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2692         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2693         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2694         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2695         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2696         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2697         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2698         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2699         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2700
2701         { }
2702 };
2703
2704 /*
2705  * Uniwill pin configuration:
2706  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
2707  * line = 0x1a
2708  */
2709 static struct hda_verb alc880_uniwill_init_verbs[] = {
2710         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2711
2712         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2713         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2714         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2715         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2716         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2717         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2718         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2719         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2720         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2721         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2722         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2723         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2724         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2725         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2726
2727         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2728         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2729         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2730         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2731         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2732         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2733         /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
2734         /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
2735         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2736
2737         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2738         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
2739
2740         { }
2741 };
2742
2743 /*
2744 * Uniwill P53
2745 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19,
2746  */
2747 static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
2748         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2749
2750         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2751         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2752         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2753         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2754         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2755         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2756         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2757         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2758         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2759         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2760         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2761         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2762
2763         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2764         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2765         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2766         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2767         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2768         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2769
2770         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2771         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
2772
2773         { }
2774 };
2775
2776 static struct hda_verb alc880_beep_init_verbs[] = {
2777         { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
2778         { }
2779 };
2780
2781 /* auto-toggle front mic */
2782 static void alc880_uniwill_mic_automute(struct hda_codec *codec)
2783 {
2784         unsigned int present;
2785         unsigned char bits;
2786
2787         present = snd_hda_codec_read(codec, 0x18, 0,
2788                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2789         bits = present ? HDA_AMP_MUTE : 0;
2790         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
2791 }
2792
2793 static void alc880_uniwill_setup(struct hda_codec *codec)
2794 {
2795         struct alc_spec *spec = codec->spec;
2796
2797         spec->autocfg.hp_pins[0] = 0x14;
2798         spec->autocfg.speaker_pins[0] = 0x15;
2799         spec->autocfg.speaker_pins[0] = 0x16;
2800 }
2801
2802 static void alc880_uniwill_init_hook(struct hda_codec *codec)
2803 {
2804         alc_automute_amp(codec);
2805         alc880_uniwill_mic_automute(codec);
2806 }
2807
2808 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
2809                                        unsigned int res)
2810 {
2811         /* Looks like the unsol event is incompatible with the standard
2812          * definition.  4bit tag is placed at 28 bit!
2813          */
2814         switch (res >> 28) {
2815         case ALC880_MIC_EVENT:
2816                 alc880_uniwill_mic_automute(codec);
2817                 break;
2818         default:
2819                 alc_automute_amp_unsol_event(codec, res);
2820                 break;
2821         }
2822 }
2823
2824 static void alc880_uniwill_p53_setup(struct hda_codec *codec)
2825 {
2826         struct alc_spec *spec = codec->spec;
2827
2828         spec->autocfg.hp_pins[0] = 0x14;
2829         spec->autocfg.speaker_pins[0] = 0x15;
2830 }
2831
2832 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
2833 {
2834         unsigned int present;
2835
2836         present = snd_hda_codec_read(codec, 0x21, 0,
2837                                      AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
2838         present &= HDA_AMP_VOLMASK;
2839         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
2840                                  HDA_AMP_VOLMASK, present);
2841         snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
2842                                  HDA_AMP_VOLMASK, present);
2843 }
2844
2845 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
2846                                            unsigned int res)
2847 {
2848         /* Looks like the unsol event is incompatible with the standard
2849          * definition.  4bit tag is placed at 28 bit!
2850          */
2851         if ((res >> 28) == ALC880_DCVOL_EVENT)
2852                 alc880_uniwill_p53_dcvol_automute(codec);
2853         else
2854                 alc_automute_amp_unsol_event(codec, res);
2855 }
2856
2857 /*
2858  * F1734 pin configuration:
2859  * HP = 0x14, speaker-out = 0x15, mic = 0x18
2860  */
2861 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
2862         {0x07, AC_VERB_SET_CONNECT_SEL, 0x01},
2863         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2864         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2865         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2866         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2867
2868         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2869         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2870         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2871         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2872
2873         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2874         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2875         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
2876         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2877         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2878         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2879         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2880         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2881         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2882
2883         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
2884         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_DCVOL_EVENT},
2885
2886         { }
2887 };
2888
2889 /*
2890  * ASUS pin configuration:
2891  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
2892  */
2893 static struct hda_verb alc880_pin_asus_init_verbs[] = {
2894         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2895         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2896         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2897         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2898
2899         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2900         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2901         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2902         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2903         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2904         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2905         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2906         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2907
2908         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2909         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2910         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2911         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2912         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2913         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2914         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2915         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2916         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2917
2918         { }
2919 };
2920
2921 /* Enable GPIO mask and set output */
2922 #define alc880_gpio1_init_verbs alc_gpio1_init_verbs
2923 #define alc880_gpio2_init_verbs alc_gpio2_init_verbs
2924 #define alc880_gpio3_init_verbs alc_gpio3_init_verbs
2925
2926 /* Clevo m520g init */
2927 static struct hda_verb alc880_pin_clevo_init_verbs[] = {
2928         /* headphone output */
2929         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2930         /* line-out */
2931         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2932         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2933         /* Line-in */
2934         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2935         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2936         /* CD */
2937         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2938         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2939         /* Mic1 (rear panel) */
2940         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2941         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2942         /* Mic2 (front panel) */
2943         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2944         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2945         /* headphone */
2946         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2947         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2948         /* change to EAPD mode */
2949         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2950         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2951
2952         { }
2953 };
2954
2955 static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
2956         /* change to EAPD mode */
2957         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2958         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2959
2960         /* Headphone output */
2961         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2962         /* Front output*/
2963         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2964         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
2965
2966         /* Line In pin widget for input */
2967         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2968         /* CD pin widget for input */
2969         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2970         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2971         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2972
2973         /* change to EAPD mode */
2974         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2975         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
2976
2977         { }
2978 };
2979
2980 /*
2981  * LG m1 express dual
2982  *
2983  * Pin assignment:
2984  *   Rear Line-In/Out (blue): 0x14
2985  *   Build-in Mic-In: 0x15
2986  *   Speaker-out: 0x17
2987  *   HP-Out (green): 0x1b
2988  *   Mic-In/Out (red): 0x19
2989  *   SPDIF-Out: 0x1e
2990  */
2991
2992 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
2993 static hda_nid_t alc880_lg_dac_nids[3] = {
2994         0x05, 0x02, 0x03
2995 };
2996
2997 /* seems analog CD is not working */
2998 static struct hda_input_mux alc880_lg_capture_source = {
2999         .num_items = 3,
3000         .items = {
3001                 { "Mic", 0x1 },
3002                 { "Line", 0x5 },
3003                 { "Internal Mic", 0x6 },
3004         },
3005 };
3006
3007 /* 2,4,6 channel modes */
3008 static struct hda_verb alc880_lg_ch2_init[] = {
3009         /* set line-in and mic-in to input */
3010         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
3011         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
3012         { }
3013 };
3014
3015 static struct hda_verb alc880_lg_ch4_init[] = {
3016         /* set line-in to out and mic-in to input */
3017         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
3018         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
3019         { }
3020 };
3021
3022 static struct hda_verb alc880_lg_ch6_init[] = {
3023         /* set line-in and mic-in to output */
3024         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
3025         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
3026         { }
3027 };
3028
3029 static struct hda_channel_mode alc880_lg_ch_modes[3] = {
3030         { 2, alc880_lg_ch2_init },
3031         { 4, alc880_lg_ch4_init },
3032         { 6, alc880_lg_ch6_init },
3033 };
3034
3035 static struct snd_kcontrol_new alc880_lg_mixer[] = {
3036         HDA_CODEC_VOLUME("Front Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3037         HDA_BIND_MUTE("Front Playback Switch", 0x0f, 2, HDA_INPUT),
3038         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3039         HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
3040         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
3041         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
3042         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
3043         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
3044         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
3045         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
3046         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
3047         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
3048         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
3049         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
3050         {
3051                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3052                 .name = "Channel Mode",
3053                 .info = alc_ch_mode_info,
3054                 .get = alc_ch_mode_get,
3055                 .put = alc_ch_mode_put,
3056         },
3057         { } /* end */
3058 };
3059
3060 static struct hda_verb alc880_lg_init_verbs[] = {
3061         /* set capture source to mic-in */
3062         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3063         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3064         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3065         /* mute all amp mixer inputs */
3066         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
3067         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
3068         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
3069         /* line-in to input */
3070         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3071         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3072         /* built-in mic */
3073         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3074         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3075         /* speaker-out */
3076         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3077         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3078         /* mic-in to input */
3079         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
3080         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3081         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3082         /* HP-out */
3083         {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
3084         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3085         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3086         /* jack sense */
3087         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3088         { }
3089 };
3090
3091 /* toggle speaker-output according to the hp-jack state */
3092 static void alc880_lg_setup(struct hda_codec *codec)
3093 {
3094         struct alc_spec *spec = codec->spec;
3095
3096         spec->autocfg.hp_pins[0] = 0x1b;
3097         spec->autocfg.speaker_pins[0] = 0x17;
3098 }
3099
3100 /*
3101  * LG LW20
3102  *
3103  * Pin assignment:
3104  *   Speaker-out: 0x14
3105  *   Mic-In: 0x18
3106  *   Built-in Mic-In: 0x19
3107  *   Line-In: 0x1b
3108  *   HP-Out: 0x1a
3109  *   SPDIF-Out: 0x1e
3110  */
3111
3112 static struct hda_input_mux alc880_lg_lw_capture_source = {
3113         .num_items = 3,
3114         .items = {
3115                 { "Mic", 0x0 },
3116                 { "Internal Mic", 0x1 },
3117                 { "Line In", 0x2 },
3118         },
3119 };
3120
3121 #define alc880_lg_lw_modes alc880_threestack_modes
3122
3123 static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
3124         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3125         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
3126         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3127         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
3128         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
3129         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
3130         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
3131         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
3132         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
3133         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
3134         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
3135         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
3136         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
3137         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
3138         {
3139                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3140                 .name = "Channel Mode",
3141                 .info = alc_ch_mode_info,
3142                 .get = alc_ch_mode_get,
3143                 .put = alc_ch_mode_put,
3144         },
3145         { } /* end */
3146 };
3147
3148 static struct hda_verb alc880_lg_lw_init_verbs[] = {
3149         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3150         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
3151         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
3152
3153         /* set capture source to mic-in */
3154         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3155         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3156         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3157         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
3158         /* speaker-out */
3159         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3160         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3161         /* HP-out */
3162         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3163         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3164         /* mic-in to input */
3165         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3166         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3167         /* built-in mic */
3168         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3169         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3170         /* jack sense */
3171         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3172         { }
3173 };
3174
3175 /* toggle speaker-output according to the hp-jack state */
3176 static void alc880_lg_lw_setup(struct hda_codec *codec)
3177 {
3178         struct alc_spec *spec = codec->spec;
3179
3180         spec->autocfg.hp_pins[0] = 0x1b;
3181         spec->autocfg.speaker_pins[0] = 0x14;
3182 }
3183
3184 static struct snd_kcontrol_new alc880_medion_rim_mixer[] = {
3185         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3186         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
3187         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
3188         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
3189         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
3190         HDA_CODEC_MUTE("Internal Playback Switch", 0x0b, 0x1, HDA_INPUT),
3191         { } /* end */
3192 };
3193
3194 static struct hda_input_mux alc880_medion_rim_capture_source = {
3195         .num_items = 2,
3196         .items = {
3197                 { "Mic", 0x0 },
3198                 { "Internal Mic", 0x1 },
3199         },
3200 };
3201
3202 static struct hda_verb alc880_medion_rim_init_verbs[] = {
3203         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3204
3205         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3206         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3207
3208         /* Mic1 (rear panel) pin widget for input and vref at 80% */
3209         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3210         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3211         /* Mic2 (as headphone out) for HP output */
3212         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3213         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3214         /* Internal Speaker */
3215         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3216         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3217
3218         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
3219         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
3220
3221         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3222         { }
3223 };
3224
3225 /* toggle speaker-output according to the hp-jack state */
3226 static void alc880_medion_rim_automute(struct hda_codec *codec)
3227 {
3228         struct alc_spec *spec = codec->spec;
3229         alc_automute_amp(codec);
3230         /* toggle EAPD */
3231         if (spec->jack_present)
3232                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0);
3233         else
3234                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 2);
3235 }
3236
3237 static void alc880_medion_rim_unsol_event(struct hda_codec *codec,
3238                                           unsigned int res)
3239 {
3240         /* Looks like the unsol event is incompatible with the standard
3241          * definition.  4bit tag is placed at 28 bit!
3242          */
3243         if ((res >> 28) == ALC880_HP_EVENT)
3244                 alc880_medion_rim_automute(codec);
3245 }
3246
3247 static void alc880_medion_rim_setup(struct hda_codec *codec)
3248 {
3249         struct alc_spec *spec = codec->spec;
3250
3251         spec->autocfg.hp_pins[0] = 0x14;
3252         spec->autocfg.speaker_pins[0] = 0x1b;
3253 }
3254
3255 #ifdef CONFIG_SND_HDA_POWER_SAVE
3256 static struct hda_amp_list alc880_loopbacks[] = {
3257         { 0x0b, HDA_INPUT, 0 },
3258         { 0x0b, HDA_INPUT, 1 },
3259         { 0x0b, HDA_INPUT, 2 },
3260         { 0x0b, HDA_INPUT, 3 },
3261         { 0x0b, HDA_INPUT, 4 },
3262         { } /* end */
3263 };
3264
3265 static struct hda_amp_list alc880_lg_loopbacks[] = {
3266         { 0x0b, HDA_INPUT, 1 },
3267         { 0x0b, HDA_INPUT, 6 },
3268         { 0x0b, HDA_INPUT, 7 },
3269         { } /* end */
3270 };
3271 #endif
3272
3273 /*
3274  * Common callbacks
3275  */
3276
3277 static int alc_init(struct hda_codec *codec)
3278 {
3279         struct alc_spec *spec = codec->spec;
3280         unsigned int i;
3281
3282         alc_fix_pll(codec);
3283         alc_auto_init_amp(codec, spec->init_amp);
3284
3285         for (i = 0; i < spec->num_init_verbs; i++)
3286                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
3287
3288         if (spec->init_hook)
3289                 spec->init_hook(codec);
3290
3291         return 0;
3292 }
3293
3294 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
3295 {
3296         struct alc_spec *spec = codec->spec;
3297
3298         if (spec->unsol_event)
3299                 spec->unsol_event(codec, res);
3300 }
3301
3302 #ifdef CONFIG_SND_HDA_POWER_SAVE
3303 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
3304 {
3305         struct alc_spec *spec = codec->spec;
3306         return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
3307 }
3308 #endif
3309
3310 /*
3311  * Analog playback callbacks
3312  */
3313 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
3314                                     struct hda_codec *codec,
3315                                     struct snd_pcm_substream *substream)
3316 {
3317         struct alc_spec *spec = codec->spec;
3318         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
3319                                              hinfo);
3320 }
3321
3322 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3323                                        struct hda_codec *codec,
3324                                        unsigned int stream_tag,
3325                                        unsigned int format,
3326                                        struct snd_pcm_substream *substream)
3327 {
3328         struct alc_spec *spec = codec->spec;
3329         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
3330                                                 stream_tag, format, substream);
3331 }
3332
3333 static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
3334                                        struct hda_codec *codec,
3335                                        struct snd_pcm_substream *substream)
3336 {
3337         struct alc_spec *spec = codec->spec;
3338         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
3339 }
3340
3341 /*
3342  * Digital out
3343  */
3344 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
3345                                         struct hda_codec *codec,
3346                                         struct snd_pcm_substream *substream)
3347 {
3348         struct alc_spec *spec = codec->spec;
3349         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
3350 }
3351
3352 static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3353                                            struct hda_codec *codec,
3354                                            unsigned int stream_tag,
3355                                            unsigned int format,
3356                                            struct snd_pcm_substream *substream)
3357 {
3358         struct alc_spec *spec = codec->spec;
3359         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
3360                                              stream_tag, format, substream);
3361 }
3362
3363 static int alc880_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
3364                                            struct hda_codec *codec,
3365                                            struct snd_pcm_substream *substream)
3366 {
3367         struct alc_spec *spec = codec->spec;
3368         return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
3369 }
3370
3371 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
3372                                          struct hda_codec *codec,
3373                                          struct snd_pcm_substream *substream)
3374 {
3375         struct alc_spec *spec = codec->spec;
3376         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
3377 }
3378
3379 /*
3380  * Analog capture
3381  */
3382 static int alc880_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3383                                       struct hda_codec *codec,
3384                                       unsigned int stream_tag,
3385                                       unsigned int format,
3386                                       struct snd_pcm_substream *substream)
3387 {
3388         struct alc_spec *spec = codec->spec;
3389
3390         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
3391                                    stream_tag, 0, format);
3392         return 0;
3393 }
3394
3395 static int alc880_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3396                                       struct hda_codec *codec,
3397                                       struct snd_pcm_substream *substream)
3398 {
3399         struct alc_spec *spec = codec->spec;
3400
3401         snd_hda_codec_cleanup_stream(codec,
3402                                      spec->adc_nids[substream->number + 1]);
3403         return 0;
3404 }
3405
3406
3407 /*
3408  */
3409 static struct hda_pcm_stream alc880_pcm_analog_playback = {
3410         .substreams = 1,
3411         .channels_min = 2,
3412         .channels_max = 8,
3413         /* NID is set in alc_build_pcms */
3414         .ops = {
3415                 .open = alc880_playback_pcm_open,
3416                 .prepare = alc880_playback_pcm_prepare,
3417                 .cleanup = alc880_playback_pcm_cleanup
3418         },
3419 };
3420
3421 static struct hda_pcm_stream alc880_pcm_analog_capture = {
3422         .substreams = 1,
3423         .channels_min = 2,
3424         .channels_max = 2,
3425         /* NID is set in alc_build_pcms */
3426 };
3427
3428 static struct hda_pcm_stream alc880_pcm_analog_alt_playback = {
3429         .substreams = 1,
3430         .channels_min = 2,
3431         .channels_max = 2,
3432         /* NID is set in alc_build_pcms */
3433 };
3434
3435 static struct hda_pcm_stream alc880_pcm_analog_alt_capture = {
3436         .substreams = 2, /* can be overridden */
3437         .channels_min = 2,
3438         .channels_max = 2,
3439         /* NID is set in alc_build_pcms */
3440         .ops = {
3441                 .prepare = alc880_alt_capture_pcm_prepare,
3442                 .cleanup = alc880_alt_capture_pcm_cleanup
3443         },
3444 };
3445
3446 static struct hda_pcm_stream alc880_pcm_digital_playback = {
3447         .substreams = 1,
3448         .channels_min = 2,
3449         .channels_max = 2,
3450         /* NID is set in alc_build_pcms */
3451         .ops = {
3452                 .open = alc880_dig_playback_pcm_open,
3453                 .close = alc880_dig_playback_pcm_close,
3454                 .prepare = alc880_dig_playback_pcm_prepare,
3455                 .cleanup = alc880_dig_playback_pcm_cleanup
3456         },
3457 };
3458
3459 static struct hda_pcm_stream alc880_pcm_digital_capture = {
3460         .substreams = 1,
3461         .channels_min = 2,
3462         .channels_max = 2,
3463         /* NID is set in alc_build_pcms */
3464 };
3465
3466 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
3467 static struct hda_pcm_stream alc_pcm_null_stream = {
3468         .substreams = 0,
3469         .channels_min = 0,
3470         .channels_max = 0,
3471 };
3472
3473 static int alc_build_pcms(struct hda_codec *codec)
3474 {
3475         struct alc_spec *spec = codec->spec;
3476         struct hda_pcm *info = spec->pcm_rec;
3477         int i;
3478
3479         codec->num_pcms = 1;
3480         codec->pcm_info = info;
3481
3482         if (spec->no_analog)
3483                 goto skip_analog;
3484
3485         snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
3486                  "%s Analog", codec->chip_name);
3487         info->name = spec->stream_name_analog;
3488         
3489         if (spec->stream_analog_playback) {
3490                 if (snd_BUG_ON(!spec->multiout.dac_nids))
3491                         return -EINVAL;
3492                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
3493                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
3494         }
3495         if (spec->stream_analog_capture) {
3496                 if (snd_BUG_ON(!spec->adc_nids))
3497                         return -EINVAL;
3498                 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
3499                 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
3500         }
3501
3502         if (spec->channel_mode) {
3503                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
3504                 for (i = 0; i < spec->num_channel_mode; i++) {
3505                         if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
3506                                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
3507                         }
3508                 }
3509         }
3510
3511  skip_analog:
3512         /* SPDIF for stream index #1 */
3513         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
3514                 snprintf(spec->stream_name_digital,
3515                          sizeof(spec->stream_name_digital),
3516                          "%s Digital", codec->chip_name);
3517                 codec->num_pcms = 2;
3518                 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
3519                 info = spec->pcm_rec + 1;
3520                 info->name = spec->stream_name_digital;
3521                 if (spec->dig_out_type)
3522                         info->pcm_type = spec->dig_out_type;
3523                 else
3524                         info->pcm_type = HDA_PCM_TYPE_SPDIF;
3525                 if (spec->multiout.dig_out_nid &&
3526                     spec->stream_digital_playback) {
3527                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
3528                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
3529                 }
3530                 if (spec->dig_in_nid &&
3531                     spec->stream_digital_capture) {
3532                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
3533                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
3534                 }
3535                 /* FIXME: do we need this for all Realtek codec models? */
3536                 codec->spdif_status_reset = 1;
3537         }
3538
3539         if (spec->no_analog)
3540                 return 0;
3541
3542         /* If the use of more than one ADC is requested for the current
3543          * model, configure a second analog capture-only PCM.
3544          */
3545         /* Additional Analaog capture for index #2 */
3546         if ((spec->alt_dac_nid && spec->stream_analog_alt_playback) ||
3547             (spec->num_adc_nids > 1 && spec->stream_analog_alt_capture)) {
3548                 codec->num_pcms = 3;
3549                 info = spec->pcm_rec + 2;
3550                 info->name = spec->stream_name_analog;
3551                 if (spec->alt_dac_nid) {
3552                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
3553                                 *spec->stream_analog_alt_playback;
3554                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
3555                                 spec->alt_dac_nid;
3556                 } else {
3557                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
3558                                 alc_pcm_null_stream;
3559                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
3560                 }
3561                 if (spec->num_adc_nids > 1) {
3562                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
3563                                 *spec->stream_analog_alt_capture;
3564                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
3565                                 spec->adc_nids[1];
3566                         info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
3567                                 spec->num_adc_nids - 1;
3568                 } else {
3569                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
3570                                 alc_pcm_null_stream;
3571                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
3572                 }
3573         }
3574
3575         return 0;
3576 }
3577
3578 static void alc_free_kctls(struct hda_codec *codec)
3579 {
3580         struct alc_spec *spec = codec->spec;
3581
3582         if (spec->kctls.list) {
3583                 struct snd_kcontrol_new *kctl = spec->kctls.list;
3584                 int i;
3585                 for (i = 0; i < spec->kctls.used; i++)
3586                         kfree(kctl[i].name);
3587         }
3588         snd_array_free(&spec->kctls);
3589 }
3590
3591 static void alc_free(struct hda_codec *codec)
3592 {
3593         struct alc_spec *spec = codec->spec;
3594
3595         if (!spec)
3596                 return;
3597
3598         alc_free_kctls(codec);
3599         kfree(spec);
3600         snd_hda_detach_beep_device(codec);
3601 }
3602
3603 #ifdef SND_HDA_NEEDS_RESUME
3604 static int alc_resume(struct hda_codec *codec)
3605 {
3606         codec->patch_ops.init(codec);
3607         snd_hda_codec_resume_amp(codec);
3608         snd_hda_codec_resume_cache(codec);
3609         return 0;
3610 }
3611 #endif
3612
3613 /*
3614  */
3615 static struct hda_codec_ops alc_patch_ops = {
3616         .build_controls = alc_build_controls,
3617         .build_pcms = alc_build_pcms,
3618         .init = alc_init,
3619         .free = alc_free,
3620         .unsol_event = alc_unsol_event,
3621 #ifdef SND_HDA_NEEDS_RESUME
3622         .resume = alc_resume,
3623 #endif
3624 #ifdef CONFIG_SND_HDA_POWER_SAVE
3625         .check_power_status = alc_check_power_status,
3626 #endif
3627 };
3628
3629
3630 /*
3631  * Test configuration for debugging
3632  *
3633  * Almost all inputs/outputs are enabled.  I/O pins can be configured via
3634  * enum controls.
3635  */
3636 #ifdef CONFIG_SND_DEBUG
3637 static hda_nid_t alc880_test_dac_nids[4] = {
3638         0x02, 0x03, 0x04, 0x05
3639 };
3640
3641 static struct hda_input_mux alc880_test_capture_source = {
3642         .num_items = 7,
3643         .items = {
3644                 { "In-1", 0x0 },
3645                 { "In-2", 0x1 },
3646                 { "In-3", 0x2 },
3647                 { "In-4", 0x3 },
3648                 { "CD", 0x4 },
3649                 { "Front", 0x5 },
3650                 { "Surround", 0x6 },
3651         },
3652 };
3653
3654 static struct hda_channel_mode alc880_test_modes[4] = {
3655         { 2, NULL },
3656         { 4, NULL },
3657         { 6, NULL },
3658         { 8, NULL },
3659 };
3660
3661 static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
3662                                  struct snd_ctl_elem_info *uinfo)
3663 {
3664         static char *texts[] = {
3665                 "N/A", "Line Out", "HP Out",
3666                 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
3667         };
3668         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3669         uinfo->count = 1;
3670         uinfo->value.enumerated.items = 8;
3671         if (uinfo->value.enumerated.item >= 8)
3672                 uinfo->value.enumerated.item = 7;
3673         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3674         return 0;
3675 }
3676
3677 static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
3678                                 struct snd_ctl_elem_value *ucontrol)
3679 {
3680         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3681         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3682         unsigned int pin_ctl, item = 0;
3683
3684         pin_ctl = snd_hda_codec_read(codec, nid, 0,
3685                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3686         if (pin_ctl & AC_PINCTL_OUT_EN) {
3687                 if (pin_ctl & AC_PINCTL_HP_EN)
3688                         item = 2;
3689                 else
3690                         item = 1;
3691         } else if (pin_ctl & AC_PINCTL_IN_EN) {
3692                 switch (pin_ctl & AC_PINCTL_VREFEN) {
3693                 case AC_PINCTL_VREF_HIZ: item = 3; break;
3694                 case AC_PINCTL_VREF_50:  item = 4; break;
3695                 case AC_PINCTL_VREF_GRD: item = 5; break;
3696                 case AC_PINCTL_VREF_80:  item = 6; break;
3697                 case AC_PINCTL_VREF_100: item = 7; break;
3698                 }
3699         }
3700         ucontrol->value.enumerated.item[0] = item;
3701         return 0;
3702 }
3703
3704 static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
3705                                 struct snd_ctl_elem_value *ucontrol)
3706 {
3707         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3708         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3709         static unsigned int ctls[] = {
3710                 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
3711                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
3712                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
3713                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
3714                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
3715                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
3716         };
3717         unsigned int old_ctl, new_ctl;
3718
3719         old_ctl = snd_hda_codec_read(codec, nid, 0,
3720                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3721         new_ctl = ctls[ucontrol->value.enumerated.item[0]];
3722         if (old_ctl != new_ctl) {
3723                 int val;
3724                 snd_hda_codec_write_cache(codec, nid, 0,
3725                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
3726                                           new_ctl);
3727                 val = ucontrol->value.enumerated.item[0] >= 3 ?
3728                         HDA_AMP_MUTE : 0;
3729                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3730                                          HDA_AMP_MUTE, val);
3731                 return 1;
3732         }
3733         return 0;
3734 }
3735
3736 static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
3737                                  struct snd_ctl_elem_info *uinfo)
3738 {
3739         static char *texts[] = {
3740                 "Front", "Surround", "CLFE", "Side"
3741         };
3742         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3743         uinfo->count = 1;
3744         uinfo->value.enumerated.items = 4;
3745         if (uinfo->value.enumerated.item >= 4)
3746                 uinfo->value.enumerated.item = 3;
3747         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3748         return 0;
3749 }
3750
3751 static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
3752                                 struct snd_ctl_elem_value *ucontrol)
3753 {
3754         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3755         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3756         unsigned int sel;
3757
3758         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
3759         ucontrol->value.enumerated.item[0] = sel & 3;
3760         return 0;
3761 }
3762
3763 static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
3764                                 struct snd_ctl_elem_value *ucontrol)
3765 {
3766         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3767         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3768         unsigned int sel;
3769
3770         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
3771         if (ucontrol->value.enumerated.item[0] != sel) {
3772                 sel = ucontrol->value.enumerated.item[0] & 3;
3773                 snd_hda_codec_write_cache(codec, nid, 0,
3774                                           AC_VERB_SET_CONNECT_SEL, sel);
3775                 return 1;
3776         }
3777         return 0;
3778 }
3779
3780 #define PIN_CTL_TEST(xname,nid) {                       \
3781                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3782                         .name = xname,                 \
3783                         .info = alc_test_pin_ctl_info, \
3784                         .get = alc_test_pin_ctl_get,   \
3785                         .put = alc_test_pin_ctl_put,   \
3786                         .private_value = nid           \
3787                         }
3788
3789 #define PIN_SRC_TEST(xname,nid) {                       \
3790                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3791                         .name = xname,                 \
3792                         .info = alc_test_pin_src_info, \
3793                         .get = alc_test_pin_src_get,   \
3794                         .put = alc_test_pin_src_put,   \
3795                         .private_value = nid           \
3796                         }
3797
3798 static struct snd_kcontrol_new alc880_test_mixer[] = {
3799         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3800         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
3801         HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
3802         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3803         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
3804         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
3805         HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
3806         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
3807         PIN_CTL_TEST("Front Pin Mode", 0x14),
3808         PIN_CTL_TEST("Surround Pin Mode", 0x15),
3809         PIN_CTL_TEST("CLFE Pin Mode", 0x16),
3810         PIN_CTL_TEST("Side Pin Mode", 0x17),
3811         PIN_CTL_TEST("In-1 Pin Mode", 0x18),
3812         PIN_CTL_TEST("In-2 Pin Mode", 0x19),
3813         PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
3814         PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
3815         PIN_SRC_TEST("In-1 Pin Source", 0x18),
3816         PIN_SRC_TEST("In-2 Pin Source", 0x19),
3817         PIN_SRC_TEST("In-3 Pin Source", 0x1a),
3818         PIN_SRC_TEST("In-4 Pin Source", 0x1b),
3819         HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
3820         HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
3821         HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
3822         HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
3823         HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
3824         HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
3825         HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
3826         HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
3827         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
3828         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
3829         {
3830                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3831                 .name = "Channel Mode",
3832                 .info = alc_ch_mode_info,
3833                 .get = alc_ch_mode_get,
3834                 .put = alc_ch_mode_put,
3835         },
3836         { } /* end */
3837 };
3838
3839 static struct hda_verb alc880_test_init_verbs[] = {
3840         /* Unmute inputs of 0x0c - 0x0f */
3841         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3842         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3843         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3844         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3845         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3846         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3847         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3848         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3849         /* Vol output for 0x0c-0x0f */
3850         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3851         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3852         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3853         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3854         /* Set output pins 0x14-0x17 */
3855         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3856         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3857         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3858         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3859         /* Unmute output pins 0x14-0x17 */
3860         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3861         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3862         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3863         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3864         /* Set input pins 0x18-0x1c */
3865         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3866         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3867         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3868         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3869         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3870         /* Mute input pins 0x18-0x1b */
3871         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3872         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3873         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3874         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3875         /* ADC set up */
3876         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3877         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
3878         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3879         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
3880         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3881         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
3882         /* Analog input/passthru */
3883         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3884         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3885         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3886         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3887         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3888         { }
3889 };
3890 #endif
3891
3892 /*
3893  */
3894
3895 static const char *alc880_models[ALC880_MODEL_LAST] = {
3896         [ALC880_3ST]            = "3stack",
3897         [ALC880_TCL_S700]       = "tcl",
3898         [ALC880_3ST_DIG]        = "3stack-digout",
3899         [ALC880_CLEVO]          = "clevo",
3900         [ALC880_5ST]            = "5stack",
3901         [ALC880_5ST_DIG]        = "5stack-digout",
3902         [ALC880_W810]           = "w810",
3903         [ALC880_Z71V]           = "z71v",
3904         [ALC880_6ST]            = "6stack",
3905         [ALC880_6ST_DIG]        = "6stack-digout",
3906         [ALC880_ASUS]           = "asus",
3907         [ALC880_ASUS_W1V]       = "asus-w1v",
3908         [ALC880_ASUS_DIG]       = "asus-dig",
3909         [ALC880_ASUS_DIG2]      = "asus-dig2",
3910         [ALC880_UNIWILL_DIG]    = "uniwill",
3911         [ALC880_UNIWILL_P53]    = "uniwill-p53",
3912         [ALC880_FUJITSU]        = "fujitsu",
3913         [ALC880_F1734]          = "F1734",
3914         [ALC880_LG]             = "lg",
3915         [ALC880_LG_LW]          = "lg-lw",
3916         [ALC880_MEDION_RIM]     = "medion",
3917 #ifdef CONFIG_SND_DEBUG
3918         [ALC880_TEST]           = "test",
3919 #endif
3920         [ALC880_AUTO]           = "auto",
3921 };
3922
3923 static struct snd_pci_quirk alc880_cfg_tbl[] = {
3924         SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
3925         SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
3926         SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
3927         SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
3928         SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
3929         SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
3930         SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
3931         SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
3932         SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
3933         SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
3934         SND_PCI_QUIRK(0x103c, 0x2a09, "HP", ALC880_5ST),
3935         SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
3936         SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
3937         SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
3938         SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
3939         SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
3940         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
3941         SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
3942         /* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
3943         SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
3944         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
3945         SND_PCI_QUIRK(0x1043, 0x814e, "ASUS P5GD1 w/SPDIF", ALC880_6ST_DIG),
3946         SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
3947         SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
3948         SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
3949         SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_ASUS), /* default ASUS */
3950         SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
3951         SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
3952         SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
3953         SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
3954         SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
3955         SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
3956         SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
3957         SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
3958         SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
3959         SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
3960         SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
3961         SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
3962         SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
3963         SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
3964         SND_PCI_QUIRK(0x1584, 0x9054, "Uniwlll", ALC880_F1734),
3965         SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
3966         SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
3967         SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
3968         SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_MEDION_RIM),
3969         SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
3970         SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
3971         SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
3972         SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FUJITSU),
3973         SND_PCI_QUIRK(0x1734, 0x10ac, "FSC", ALC880_UNIWILL),
3974         SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
3975         SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
3976         SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
3977         SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
3978         SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
3979         SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
3980         SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG), /* broken BIOS */
3981         SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
3982         SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
3983         SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
3984         SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
3985         SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
3986         SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
3987         SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
3988         SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
3989         SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
3990         SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
3991         SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
3992         /* default Intel */
3993         SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_3ST),
3994         SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
3995         SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
3996         {}
3997 };
3998
3999 /*
4000  * ALC880 codec presets
4001  */
4002 static struct alc_config_preset alc880_presets[] = {
4003         [ALC880_3ST] = {
4004                 .mixers = { alc880_three_stack_mixer },
4005                 .init_verbs = { alc880_volume_init_verbs,
4006                                 alc880_pin_3stack_init_verbs },
4007                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4008                 .dac_nids = alc880_dac_nids,
4009                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
4010                 .channel_mode = alc880_threestack_modes,
4011                 .need_dac_fix = 1,
4012                 .input_mux = &alc880_capture_source,
4013         },
4014         [ALC880_3ST_DIG] = {
4015                 .mixers = { alc880_three_stack_mixer },
4016                 .init_verbs = { alc880_volume_init_verbs,
4017                                 alc880_pin_3stack_init_verbs },
4018                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4019                 .dac_nids = alc880_dac_nids,
4020                 .dig_out_nid = ALC880_DIGOUT_NID,
4021                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
4022                 .channel_mode = alc880_threestack_modes,
4023                 .need_dac_fix = 1,
4024                 .input_mux = &alc880_capture_source,
4025         },
4026         [ALC880_TCL_S700] = {
4027                 .mixers = { alc880_tcl_s700_mixer },
4028                 .init_verbs = { alc880_volume_init_verbs,
4029                                 alc880_pin_tcl_S700_init_verbs,
4030                                 alc880_gpio2_init_verbs },
4031                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4032                 .dac_nids = alc880_dac_nids,
4033                 .adc_nids = alc880_adc_nids_alt, /* FIXME: correct? */
4034                 .num_adc_nids = 1, /* single ADC */
4035                 .hp_nid = 0x03,
4036                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4037                 .channel_mode = alc880_2_jack_modes,
4038                 .input_mux = &alc880_capture_source,
4039         },
4040         [ALC880_5ST] = {
4041                 .mixers = { alc880_three_stack_mixer,
4042                             alc880_five_stack_mixer},
4043                 .init_verbs = { alc880_volume_init_verbs,
4044                                 alc880_pin_5stack_init_verbs },
4045                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4046                 .dac_nids = alc880_dac_nids,
4047                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
4048                 .channel_mode = alc880_fivestack_modes,
4049                 .input_mux = &alc880_capture_source,
4050         },
4051         [ALC880_5ST_DIG] = {
4052                 .mixers = { alc880_three_stack_mixer,
4053                             alc880_five_stack_mixer },
4054                 .init_verbs = { alc880_volume_init_verbs,
4055                                 alc880_pin_5stack_init_verbs },
4056                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4057                 .dac_nids = alc880_dac_nids,
4058                 .dig_out_nid = ALC880_DIGOUT_NID,
4059                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
4060                 .channel_mode = alc880_fivestack_modes,
4061                 .input_mux = &alc880_capture_source,
4062         },
4063         [ALC880_6ST] = {
4064                 .mixers = { alc880_six_stack_mixer },
4065                 .init_verbs = { alc880_volume_init_verbs,
4066                                 alc880_pin_6stack_init_verbs },
4067                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
4068                 .dac_nids = alc880_6st_dac_nids,
4069                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
4070                 .channel_mode = alc880_sixstack_modes,
4071                 .input_mux = &alc880_6stack_capture_source,
4072         },
4073         [ALC880_6ST_DIG] = {
4074                 .mixers = { alc880_six_stack_mixer },
4075                 .init_verbs = { alc880_volume_init_verbs,
4076                                 alc880_pin_6stack_init_verbs },
4077                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
4078                 .dac_nids = alc880_6st_dac_nids,
4079                 .dig_out_nid = ALC880_DIGOUT_NID,
4080                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
4081                 .channel_mode = alc880_sixstack_modes,
4082                 .input_mux = &alc880_6stack_capture_source,
4083         },
4084         [ALC880_W810] = {
4085                 .mixers = { alc880_w810_base_mixer },
4086                 .init_verbs = { alc880_volume_init_verbs,
4087                                 alc880_pin_w810_init_verbs,
4088                                 alc880_gpio2_init_verbs },
4089                 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
4090                 .dac_nids = alc880_w810_dac_nids,
4091                 .dig_out_nid = ALC880_DIGOUT_NID,
4092                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
4093                 .channel_mode = alc880_w810_modes,
4094                 .input_mux = &alc880_capture_source,
4095         },
4096         [ALC880_Z71V] = {
4097                 .mixers = { alc880_z71v_mixer },
4098                 .init_verbs = { alc880_volume_init_verbs,
4099                                 alc880_pin_z71v_init_verbs },
4100                 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
4101                 .dac_nids = alc880_z71v_dac_nids,
4102                 .dig_out_nid = ALC880_DIGOUT_NID,
4103                 .hp_nid = 0x03,
4104                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4105                 .channel_mode = alc880_2_jack_modes,
4106                 .input_mux = &alc880_capture_source,
4107         },
4108         [ALC880_F1734] = {
4109                 .mixers = { alc880_f1734_mixer },
4110                 .init_verbs = { alc880_volume_init_verbs,
4111                                 alc880_pin_f1734_init_verbs },
4112                 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
4113                 .dac_nids = alc880_f1734_dac_nids,
4114                 .hp_nid = 0x02,
4115                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4116                 .channel_mode = alc880_2_jack_modes,
4117                 .input_mux = &alc880_f1734_capture_source,
4118                 .unsol_event = alc880_uniwill_p53_unsol_event,
4119                 .setup = alc880_uniwill_p53_setup,
4120                 .init_hook = alc_automute_amp,
4121         },
4122         [ALC880_ASUS] = {
4123                 .mixers = { alc880_asus_mixer },
4124                 .init_verbs = { alc880_volume_init_verbs,
4125                                 alc880_pin_asus_init_verbs,
4126                                 alc880_gpio1_init_verbs },
4127                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4128                 .dac_nids = alc880_asus_dac_nids,
4129                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4130                 .channel_mode = alc880_asus_modes,
4131                 .need_dac_fix = 1,
4132                 .input_mux = &alc880_capture_source,
4133         },
4134         [ALC880_ASUS_DIG] = {
4135                 .mixers = { alc880_asus_mixer },
4136                 .init_verbs = { alc880_volume_init_verbs,
4137                                 alc880_pin_asus_init_verbs,
4138                                 alc880_gpio1_init_verbs },
4139                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4140                 .dac_nids = alc880_asus_dac_nids,
4141                 .dig_out_nid = ALC880_DIGOUT_NID,
4142                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4143                 .channel_mode = alc880_asus_modes,
4144                 .need_dac_fix = 1,
4145                 .input_mux = &alc880_capture_source,
4146         },
4147         [ALC880_ASUS_DIG2] = {
4148                 .mixers = { alc880_asus_mixer },
4149                 .init_verbs = { alc880_volume_init_verbs,
4150                                 alc880_pin_asus_init_verbs,
4151                                 alc880_gpio2_init_verbs }, /* use GPIO2 */
4152                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4153                 .dac_nids = alc880_asus_dac_nids,
4154                 .dig_out_nid = ALC880_DIGOUT_NID,
4155                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4156                 .channel_mode = alc880_asus_modes,
4157                 .need_dac_fix = 1,
4158                 .input_mux = &alc880_capture_source,
4159         },
4160         [ALC880_ASUS_W1V] = {
4161                 .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
4162                 .init_verbs = { alc880_volume_init_verbs,
4163                                 alc880_pin_asus_init_verbs,
4164                                 alc880_gpio1_init_verbs },
4165                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4166                 .dac_nids = alc880_asus_dac_nids,
4167                 .dig_out_nid = ALC880_DIGOUT_NID,
4168                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4169                 .channel_mode = alc880_asus_modes,
4170                 .need_dac_fix = 1,
4171                 .input_mux = &alc880_capture_source,
4172         },
4173         [ALC880_UNIWILL_DIG] = {
4174                 .mixers = { alc880_asus_mixer },
4175                 .init_verbs = { alc880_volume_init_verbs,
4176                                 alc880_pin_asus_init_verbs },
4177                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4178                 .dac_nids = alc880_asus_dac_nids,
4179                 .dig_out_nid = ALC880_DIGOUT_NID,
4180                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4181                 .channel_mode = alc880_asus_modes,
4182                 .need_dac_fix = 1,
4183                 .input_mux = &alc880_capture_source,
4184         },
4185         [ALC880_UNIWILL] = {
4186                 .mixers = { alc880_uniwill_mixer },
4187                 .init_verbs = { alc880_volume_init_verbs,
4188                                 alc880_uniwill_init_verbs },
4189                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4190                 .dac_nids = alc880_asus_dac_nids,
4191                 .dig_out_nid = ALC880_DIGOUT_NID,
4192                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
4193                 .channel_mode = alc880_threestack_modes,
4194                 .need_dac_fix = 1,
4195                 .input_mux = &alc880_capture_source,
4196                 .unsol_event = alc880_uniwill_unsol_event,
4197                 .setup = alc880_uniwill_setup,
4198                 .init_hook = alc880_uniwill_init_hook,
4199         },
4200         [ALC880_UNIWILL_P53] = {
4201                 .mixers = { alc880_uniwill_p53_mixer },
4202                 .init_verbs = { alc880_volume_init_verbs,
4203                                 alc880_uniwill_p53_init_verbs },
4204                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4205                 .dac_nids = alc880_asus_dac_nids,
4206                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
4207                 .channel_mode = alc880_threestack_modes,
4208                 .input_mux = &alc880_capture_source,
4209                 .unsol_event = alc880_uniwill_p53_unsol_event,
4210                 .setup = alc880_uniwill_p53_setup,
4211                 .init_hook = alc_automute_amp,
4212         },
4213         [ALC880_FUJITSU] = {
4214                 .mixers = { alc880_fujitsu_mixer },
4215                 .init_verbs = { alc880_volume_init_verbs,
4216                                 alc880_uniwill_p53_init_verbs,
4217                                 alc880_beep_init_verbs },
4218                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4219                 .dac_nids = alc880_dac_nids,
4220                 .dig_out_nid = ALC880_DIGOUT_NID,
4221                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4222                 .channel_mode = alc880_2_jack_modes,
4223                 .input_mux = &alc880_capture_source,
4224                 .unsol_event = alc880_uniwill_p53_unsol_event,
4225                 .setup = alc880_uniwill_p53_setup,
4226                 .init_hook = alc_automute_amp,
4227         },
4228         [ALC880_CLEVO] = {
4229                 .mixers = { alc880_three_stack_mixer },
4230                 .init_verbs = { alc880_volume_init_verbs,
4231                                 alc880_pin_clevo_init_verbs },
4232                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4233                 .dac_nids = alc880_dac_nids,
4234                 .hp_nid = 0x03,
4235                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
4236                 .channel_mode = alc880_threestack_modes,
4237                 .need_dac_fix = 1,
4238                 .input_mux = &alc880_capture_source,
4239         },
4240         [ALC880_LG] = {
4241                 .mixers = { alc880_lg_mixer },
4242                 .init_verbs = { alc880_volume_init_verbs,
4243                                 alc880_lg_init_verbs },
4244                 .num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
4245                 .dac_nids = alc880_lg_dac_nids,
4246                 .dig_out_nid = ALC880_DIGOUT_NID,
4247                 .num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
4248                 .channel_mode = alc880_lg_ch_modes,
4249                 .need_dac_fix = 1,
4250                 .input_mux = &alc880_lg_capture_source,
4251                 .unsol_event = alc_automute_amp_unsol_event,
4252                 .setup = alc880_lg_setup,
4253                 .init_hook = alc_automute_amp,
4254 #ifdef CONFIG_SND_HDA_POWER_SAVE
4255                 .loopbacks = alc880_lg_loopbacks,
4256 #endif
4257         },
4258         [ALC880_LG_LW] = {
4259                 .mixers = { alc880_lg_lw_mixer },
4260                 .init_verbs = { alc880_volume_init_verbs,
4261                                 alc880_lg_lw_init_verbs },
4262                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4263                 .dac_nids = alc880_dac_nids,
4264                 .dig_out_nid = ALC880_DIGOUT_NID,
4265                 .num_channel_mode = ARRAY_SIZE(alc880_lg_lw_modes),
4266                 .channel_mode = alc880_lg_lw_modes,
4267                 .input_mux = &alc880_lg_lw_capture_source,
4268                 .unsol_event = alc_automute_amp_unsol_event,
4269                 .setup = alc880_lg_lw_setup,
4270                 .init_hook = alc_automute_amp,
4271         },
4272         [ALC880_MEDION_RIM] = {
4273                 .mixers = { alc880_medion_rim_mixer },
4274                 .init_verbs = { alc880_volume_init_verbs,
4275                                 alc880_medion_rim_init_verbs,
4276                                 alc_gpio2_init_verbs },
4277                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4278                 .dac_nids = alc880_dac_nids,
4279                 .dig_out_nid = ALC880_DIGOUT_NID,
4280                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4281                 .channel_mode = alc880_2_jack_modes,
4282                 .input_mux = &alc880_medion_rim_capture_source,
4283                 .unsol_event = alc880_medion_rim_unsol_event,
4284                 .setup = alc880_medion_rim_setup,
4285                 .init_hook = alc880_medion_rim_automute,
4286         },
4287 #ifdef CONFIG_SND_DEBUG
4288         [ALC880_TEST] = {
4289                 .mixers = { alc880_test_mixer },
4290                 .init_verbs = { alc880_test_init_verbs },
4291                 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
4292                 .dac_nids = alc880_test_dac_nids,
4293                 .dig_out_nid = ALC880_DIGOUT_NID,
4294                 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
4295                 .channel_mode = alc880_test_modes,
4296                 .input_mux = &alc880_test_capture_source,
4297         },
4298 #endif
4299 };
4300
4301 /*
4302  * Automatic parse of I/O pins from the BIOS configuration
4303  */
4304
4305 enum {
4306         ALC_CTL_WIDGET_VOL,
4307         ALC_CTL_WIDGET_MUTE,
4308         ALC_CTL_BIND_MUTE,
4309 };
4310 static struct snd_kcontrol_new alc880_control_templates[] = {
4311         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
4312         HDA_CODEC_MUTE(NULL, 0, 0, 0),
4313         HDA_BIND_MUTE(NULL, 0, 0, 0),
4314 };
4315
4316 /* add dynamic controls */
4317 static int add_control(struct alc_spec *spec, int type, const char *name,
4318                        unsigned long val)
4319 {
4320         struct snd_kcontrol_new *knew;
4321
4322         snd_array_init(&spec->kctls, sizeof(*knew), 32);
4323         knew = snd_array_new(&spec->kctls);
4324         if (!knew)
4325                 return -ENOMEM;
4326         *knew = alc880_control_templates[type];
4327         knew->name = kstrdup(name, GFP_KERNEL);
4328         if (!knew->name)
4329                 return -ENOMEM;
4330         if (get_amp_nid_(val))
4331                 knew->subdevice = HDA_SUBDEV_NID_FLAG | get_amp_nid_(val);
4332         knew->private_value = val;
4333         return 0;
4334 }
4335
4336 static int add_control_with_pfx(struct alc_spec *spec, int type,
4337                                 const char *pfx, const char *dir,
4338                                 const char *sfx, unsigned long val)
4339 {
4340         char name[32];
4341         snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
4342         return add_control(spec, type, name, val);
4343 }
4344
4345 #define add_pb_vol_ctrl(spec, type, pfx, val) \
4346         add_control_with_pfx(spec, type, pfx, "Playback", "Volume", val)
4347 #define add_pb_sw_ctrl(spec, type, pfx, val) \
4348         add_control_with_pfx(spec, type, pfx, "Playback", "Switch", val)
4349
4350 #define alc880_is_fixed_pin(nid)        ((nid) >= 0x14 && (nid) <= 0x17)
4351 #define alc880_fixed_pin_idx(nid)       ((nid) - 0x14)
4352 #define alc880_is_multi_pin(nid)        ((nid) >= 0x18)
4353 #define alc880_multi_pin_idx(nid)       ((nid) - 0x18)
4354 #define alc880_idx_to_dac(nid)          ((nid) + 0x02)
4355 #define alc880_dac_to_idx(nid)          ((nid) - 0x02)
4356 #define alc880_idx_to_mixer(nid)        ((nid) + 0x0c)
4357 #define alc880_idx_to_selector(nid)     ((nid) + 0x10)
4358 #define ALC880_PIN_CD_NID               0x1c
4359
4360 /* fill in the dac_nids table from the parsed pin configuration */
4361 static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
4362                                      const struct auto_pin_cfg *cfg)
4363 {
4364         hda_nid_t nid;
4365         int assigned[4];
4366         int i, j;
4367
4368         memset(assigned, 0, sizeof(assigned));
4369         spec->multiout.dac_nids = spec->private_dac_nids;
4370
4371         /* check the pins hardwired to audio widget */
4372         for (i = 0; i < cfg->line_outs; i++) {
4373                 nid = cfg->line_out_pins[i];
4374                 if (alc880_is_fixed_pin(nid)) {
4375                         int idx = alc880_fixed_pin_idx(nid);
4376                         spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
4377                         assigned[idx] = 1;
4378                 }
4379         }
4380         /* left pins can be connect to any audio widget */
4381         for (i = 0; i < cfg->line_outs; i++) {
4382                 nid = cfg->line_out_pins[i];
4383                 if (alc880_is_fixed_pin(nid))
4384                         continue;
4385                 /* search for an empty channel */
4386                 for (j = 0; j < cfg->line_outs; j++) {
4387                         if (!assigned[j]) {
4388                                 spec->multiout.dac_nids[i] =
4389                                         alc880_idx_to_dac(j);
4390                                 assigned[j] = 1;
4391                                 break;
4392                         }
4393                 }
4394         }
4395         spec->multiout.num_dacs = cfg->line_outs;
4396         return 0;
4397 }
4398
4399 /* add playback controls from the parsed DAC table */
4400 static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
4401                                              const struct auto_pin_cfg *cfg)
4402 {
4403         static const char *chname[4] = {
4404                 "Front", "Surround", NULL /*CLFE*/, "Side"
4405         };
4406         hda_nid_t nid;
4407         int i, err;
4408
4409         for (i = 0; i < cfg->line_outs; i++) {
4410                 if (!spec->multiout.dac_nids[i])
4411                         continue;
4412                 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
4413                 if (i == 2) {
4414                         /* Center/LFE */
4415                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
4416                                               "Center",
4417                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
4418                                                               HDA_OUTPUT));
4419                         if (err < 0)
4420                                 return err;
4421                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
4422                                               "LFE",
4423                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
4424                                                               HDA_OUTPUT));
4425                         if (err < 0)
4426                                 return err;
4427                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
4428                                              "Center",
4429                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
4430                                                               HDA_INPUT));
4431                         if (err < 0)
4432                                 return err;
4433                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
4434                                              "LFE",
4435                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
4436                                                               HDA_INPUT));
4437                         if (err < 0)
4438                                 return err;
4439                 } else {
4440                         const char *pfx;
4441                         if (cfg->line_outs == 1 &&
4442                             cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
4443                                 pfx = "Speaker";
4444                         else
4445                                 pfx = chname[i];
4446                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
4447                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
4448                                                               HDA_OUTPUT));
4449                         if (err < 0)
4450                                 return err;
4451                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE, pfx,
4452                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
4453                                                               HDA_INPUT));
4454                         if (err < 0)
4455                                 return err;
4456                 }
4457         }
4458         return 0;
4459 }
4460
4461 /* add playback controls for speaker and HP outputs */
4462 static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
4463                                         const char *pfx)
4464 {
4465         hda_nid_t nid;
4466         int err;
4467
4468         if (!pin)
4469                 return 0;
4470
4471         if (alc880_is_fixed_pin(pin)) {
4472                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
4473                 /* specify the DAC as the extra output */
4474                 if (!spec->multiout.hp_nid)
4475                         spec->multiout.hp_nid = nid;
4476                 else
4477                         spec->multiout.extra_out_nid[0] = nid;
4478                 /* control HP volume/switch on the output mixer amp */
4479                 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
4480                 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
4481                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
4482                 if (err < 0)
4483                         return err;
4484                 err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE, pfx,
4485                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
4486                 if (err < 0)
4487                         return err;
4488         } else if (alc880_is_multi_pin(pin)) {
4489                 /* set manual connection */
4490                 /* we have only a switch on HP-out PIN */
4491                 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
4492                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4493                 if (err < 0)
4494                         return err;
4495         }
4496         return 0;
4497 }
4498
4499 /* create input playback/capture controls for the given pin */
4500 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
4501                             const char *ctlname,
4502                             int idx, hda_nid_t mix_nid)
4503 {
4504         int err;
4505
4506         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname,
4507                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
4508         if (err < 0)
4509                 return err;
4510         err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname,
4511                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
4512         if (err < 0)
4513                 return err;
4514         return 0;
4515 }
4516
4517 static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
4518 {
4519         unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
4520         return (pincap & AC_PINCAP_IN) != 0;
4521 }
4522
4523 /* create playback/capture controls for input pins */
4524 static int alc_auto_create_input_ctls(struct hda_codec *codec,
4525                                       const struct auto_pin_cfg *cfg,
4526                                       hda_nid_t mixer,
4527                                       hda_nid_t cap1, hda_nid_t cap2)
4528 {
4529         struct alc_spec *spec = codec->spec;
4530         struct hda_input_mux *imux = &spec->private_imux[0];
4531         int i, err, idx;
4532
4533         for (i = 0; i < AUTO_PIN_LAST; i++) {
4534                 hda_nid_t pin;
4535
4536                 pin = cfg->input_pins[i];
4537                 if (!alc_is_input_pin(codec, pin))
4538                         continue;
4539
4540                 if (mixer) {
4541                         idx = get_connection_index(codec, mixer, pin);
4542                         if (idx >= 0) {
4543                                 err = new_analog_input(spec, pin,
4544                                                        auto_pin_cfg_labels[i],
4545                                                        idx, mixer);
4546                                 if (err < 0)
4547                                         return err;
4548                         }
4549                 }
4550
4551                 if (!cap1)
4552                         continue;
4553                 idx = get_connection_index(codec, cap1, pin);
4554                 if (idx < 0 && cap2)
4555                         idx = get_connection_index(codec, cap2, pin);
4556                 if (idx >= 0) {
4557                         imux->items[imux->num_items].label =
4558                                 auto_pin_cfg_labels[i];
4559                         imux->items[imux->num_items].index = idx;
4560                         imux->num_items++;
4561                 }
4562         }
4563         return 0;
4564 }
4565
4566 static int alc880_auto_create_input_ctls(struct hda_codec *codec,
4567                                                 const struct auto_pin_cfg *cfg)
4568 {
4569         return alc_auto_create_input_ctls(codec, cfg, 0x0b, 0x08, 0x09);
4570 }
4571
4572 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
4573                                unsigned int pin_type)
4574 {
4575         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4576                             pin_type);
4577         /* unmute pin */
4578         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4579                             AMP_OUT_UNMUTE);
4580 }
4581
4582 static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
4583                                               hda_nid_t nid, int pin_type,
4584                                               int dac_idx)
4585 {
4586         alc_set_pin_output(codec, nid, pin_type);
4587         /* need the manual connection? */
4588         if (alc880_is_multi_pin(nid)) {
4589                 struct alc_spec *spec = codec->spec;
4590                 int idx = alc880_multi_pin_idx(nid);
4591                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
4592                                     AC_VERB_SET_CONNECT_SEL,
4593                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
4594         }
4595 }
4596
4597 static int get_pin_type(int line_out_type)
4598 {
4599         if (line_out_type == AUTO_PIN_HP_OUT)
4600                 return PIN_HP;
4601         else
4602                 return PIN_OUT;
4603 }
4604
4605 static void alc880_auto_init_multi_out(struct hda_codec *codec)
4606 {
4607         struct alc_spec *spec = codec->spec;
4608         int i;
4609
4610         for (i = 0; i < spec->autocfg.line_outs; i++) {
4611                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
4612                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
4613                 alc880_auto_set_output_and_unmute(codec, nid, pin_type, i);
4614         }
4615 }
4616
4617 static void alc880_auto_init_extra_out(struct hda_codec *codec)
4618 {
4619         struct alc_spec *spec = codec->spec;
4620         hda_nid_t pin;
4621
4622         pin = spec->autocfg.speaker_pins[0];
4623         if (pin) /* connect to front */
4624                 alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
4625         pin = spec->autocfg.hp_pins[0];
4626         if (pin) /* connect to front */
4627                 alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
4628 }
4629
4630 static void alc880_auto_init_analog_input(struct hda_codec *codec)
4631 {
4632         struct alc_spec *spec = codec->spec;
4633         int i;
4634
4635         for (i = 0; i < AUTO_PIN_LAST; i++) {
4636                 hda_nid_t nid = spec->autocfg.input_pins[i];
4637                 if (alc_is_input_pin(codec, nid)) {
4638                         alc_set_input_pin(codec, nid, i);
4639                         if (nid != ALC880_PIN_CD_NID &&
4640                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
4641                                 snd_hda_codec_write(codec, nid, 0,
4642                                                     AC_VERB_SET_AMP_GAIN_MUTE,
4643                                                     AMP_OUT_MUTE);
4644                 }
4645         }
4646 }
4647
4648 /* parse the BIOS configuration and set up the alc_spec */
4649 /* return 1 if successful, 0 if the proper config is not found,
4650  * or a negative error code
4651  */
4652 static int alc880_parse_auto_config(struct hda_codec *codec)
4653 {
4654         struct alc_spec *spec = codec->spec;
4655         int i, err;
4656         static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4657
4658         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
4659                                            alc880_ignore);
4660         if (err < 0)
4661                 return err;
4662         if (!spec->autocfg.line_outs)
4663                 return 0; /* can't find valid BIOS pin config */
4664
4665         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
4666         if (err < 0)
4667                 return err;
4668         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
4669         if (err < 0)
4670                 return err;
4671         err = alc880_auto_create_extra_out(spec,
4672                                            spec->autocfg.speaker_pins[0],
4673                                            "Speaker");
4674         if (err < 0)
4675                 return err;
4676         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
4677                                            "Headphone");
4678         if (err < 0)
4679                 return err;
4680         err = alc880_auto_create_input_ctls(codec, &spec->autocfg);
4681         if (err < 0)
4682                 return err;
4683
4684         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4685
4686         /* check multiple SPDIF-out (for recent codecs) */
4687         for (i = 0; i < spec->autocfg.dig_outs; i++) {
4688                 hda_nid_t dig_nid;
4689                 err = snd_hda_get_connections(codec,
4690                                               spec->autocfg.dig_out_pins[i],
4691                                               &dig_nid, 1);
4692                 if (err < 0)
4693                         continue;
4694                 if (!i)
4695                         spec->multiout.dig_out_nid = dig_nid;
4696                 else {
4697                         spec->multiout.slave_dig_outs = spec->slave_dig_outs;
4698                         if (i >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
4699                                 break;
4700                         spec->slave_dig_outs[i - 1] = dig_nid;
4701                 }
4702         }
4703         if (spec->autocfg.dig_in_pin)
4704                 spec->dig_in_nid = ALC880_DIGIN_NID;
4705
4706         if (spec->kctls.list)
4707                 add_mixer(spec, spec->kctls.list);
4708
4709         add_verb(spec, alc880_volume_init_verbs);
4710
4711         spec->num_mux_defs = 1;
4712         spec->input_mux = &spec->private_imux[0];
4713
4714         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
4715
4716         return 1;
4717 }
4718
4719 /* additional initialization for auto-configuration model */
4720 static void alc880_auto_init(struct hda_codec *codec)
4721 {
4722         struct alc_spec *spec = codec->spec;
4723         alc880_auto_init_multi_out(codec);
4724         alc880_auto_init_extra_out(codec);
4725         alc880_auto_init_analog_input(codec);
4726         if (spec->unsol_event)
4727                 alc_inithook(codec);
4728 }
4729
4730 /* check the ADC/MUX contains all input pins; some ADC/MUX contains only
4731  * one of two digital mic pins, e.g. on ALC272
4732  */
4733 static void fixup_automic_adc(struct hda_codec *codec)
4734 {
4735         struct alc_spec *spec = codec->spec;
4736         int i;
4737
4738         for (i = 0; i < spec->num_adc_nids; i++) {
4739                 hda_nid_t cap = spec->capsrc_nids ?
4740                         spec->capsrc_nids[i] : spec->adc_nids[i];
4741                 int iidx, eidx;
4742
4743                 iidx = get_connection_index(codec, cap, spec->int_mic.pin);
4744                 if (iidx < 0)
4745                         continue;
4746                 eidx = get_connection_index(codec, cap, spec->ext_mic.pin);
4747                 if (eidx < 0)
4748                         continue;
4749                 spec->int_mic.mux_idx = iidx;
4750                 spec->ext_mic.mux_idx = eidx;
4751                 if (spec->capsrc_nids)
4752                         spec->capsrc_nids += i;
4753                 spec->adc_nids += i;
4754                 spec->num_adc_nids = 1;
4755                 return;
4756         }
4757         snd_printd(KERN_INFO "hda_codec: %s: "
4758                    "No ADC/MUX containing both 0x%x and 0x%x pins\n",
4759                    codec->chip_name, spec->int_mic.pin, spec->ext_mic.pin);
4760         spec->auto_mic = 0; /* disable auto-mic to be sure */
4761 }
4762
4763 static void set_capture_mixer(struct hda_codec *codec)
4764 {
4765         struct alc_spec *spec = codec->spec;
4766         static struct snd_kcontrol_new *caps[2][3] = {
4767                 { alc_capture_mixer_nosrc1,
4768                   alc_capture_mixer_nosrc2,
4769                   alc_capture_mixer_nosrc3 },
4770                 { alc_capture_mixer1,
4771                   alc_capture_mixer2,
4772                   alc_capture_mixer3 },
4773         };
4774         if (spec->num_adc_nids > 0 && spec->num_adc_nids <= 3) {
4775                 int mux;
4776                 if (spec->auto_mic) {
4777                         mux = 0;
4778                         fixup_automic_adc(codec);
4779                 } else if (spec->input_mux && spec->input_mux->num_items > 1)
4780                         mux = 1;
4781                 else
4782                         mux = 0;
4783                 spec->cap_mixer = caps[mux][spec->num_adc_nids - 1];
4784         }
4785 }
4786
4787 #ifdef CONFIG_SND_HDA_INPUT_BEEP
4788 #define set_beep_amp(spec, nid, idx, dir) \
4789         ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4790 #else
4791 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
4792 #endif
4793
4794 /*
4795  * OK, here we have finally the patch for ALC880
4796  */
4797
4798 static int patch_alc880(struct hda_codec *codec)
4799 {
4800         struct alc_spec *spec;
4801         int board_config;
4802         int err;
4803
4804         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4805         if (spec == NULL)
4806                 return -ENOMEM;
4807
4808         codec->spec = spec;
4809
4810         board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
4811                                                   alc880_models,
4812                                                   alc880_cfg_tbl);
4813         if (board_config < 0) {
4814                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4815                        codec->chip_name);
4816                 board_config = ALC880_AUTO;
4817         }
4818
4819         if (board_config == ALC880_AUTO) {
4820                 /* automatic parse from the BIOS config */
4821                 err = alc880_parse_auto_config(codec);
4822                 if (err < 0) {
4823                         alc_free(codec);
4824                         return err;
4825                 } else if (!err) {
4826                         printk(KERN_INFO
4827                                "hda_codec: Cannot set up configuration "
4828                                "from BIOS.  Using 3-stack mode...\n");
4829                         board_config = ALC880_3ST;
4830                 }
4831         }
4832
4833         err = snd_hda_attach_beep_device(codec, 0x1);
4834         if (err < 0) {
4835                 alc_free(codec);
4836                 return err;
4837         }
4838
4839         if (board_config != ALC880_AUTO)
4840                 setup_preset(codec, &alc880_presets[board_config]);
4841
4842         spec->stream_analog_playback = &alc880_pcm_analog_playback;
4843         spec->stream_analog_capture = &alc880_pcm_analog_capture;
4844         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
4845
4846         spec->stream_digital_playback = &alc880_pcm_digital_playback;
4847         spec->stream_digital_capture = &alc880_pcm_digital_capture;
4848
4849         if (!spec->adc_nids && spec->input_mux) {
4850                 /* check whether NID 0x07 is valid */
4851                 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
4852                 /* get type */
4853                 wcap = get_wcaps_type(wcap);
4854                 if (wcap != AC_WID_AUD_IN) {
4855                         spec->adc_nids = alc880_adc_nids_alt;
4856                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
4857                 } else {
4858                         spec->adc_nids = alc880_adc_nids;
4859                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
4860                 }
4861         }
4862         set_capture_mixer(codec);
4863         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4864
4865         spec->vmaster_nid = 0x0c;
4866
4867         codec->patch_ops = alc_patch_ops;
4868         if (board_config == ALC880_AUTO)
4869                 spec->init_hook = alc880_auto_init;
4870 #ifdef CONFIG_SND_HDA_POWER_SAVE
4871         if (!spec->loopback.amplist)
4872                 spec->loopback.amplist = alc880_loopbacks;
4873 #endif
4874         codec->proc_widget_hook = print_realtek_coef;
4875
4876         return 0;
4877 }
4878
4879
4880 /*
4881  * ALC260 support
4882  */
4883
4884 static hda_nid_t alc260_dac_nids[1] = {
4885         /* front */
4886         0x02,
4887 };
4888
4889 static hda_nid_t alc260_adc_nids[1] = {
4890         /* ADC0 */
4891         0x04,
4892 };
4893
4894 static hda_nid_t alc260_adc_nids_alt[1] = {
4895         /* ADC1 */
4896         0x05,
4897 };
4898
4899 /* NIDs used when simultaneous access to both ADCs makes sense.  Note that
4900  * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
4901  */
4902 static hda_nid_t alc260_dual_adc_nids[2] = {
4903         /* ADC0, ADC1 */
4904         0x04, 0x05
4905 };
4906
4907 #define ALC260_DIGOUT_NID       0x03
4908 #define ALC260_DIGIN_NID        0x06
4909
4910 static struct hda_input_mux alc260_capture_source = {
4911         .num_items = 4,
4912         .items = {
4913                 { "Mic", 0x0 },
4914                 { "Front Mic", 0x1 },
4915                 { "Line", 0x2 },
4916                 { "CD", 0x4 },
4917         },
4918 };
4919
4920 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
4921  * headphone jack and the internal CD lines since these are the only pins at
4922  * which audio can appear.  For flexibility, also allow the option of
4923  * recording the mixer output on the second ADC (ADC0 doesn't have a
4924  * connection to the mixer output).
4925  */
4926 static struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
4927         {
4928                 .num_items = 3,
4929                 .items = {
4930                         { "Mic/Line", 0x0 },
4931                         { "CD", 0x4 },
4932                         { "Headphone", 0x2 },
4933                 },
4934         },
4935         {
4936                 .num_items = 4,
4937                 .items = {
4938                         { "Mic/Line", 0x0 },
4939                         { "CD", 0x4 },
4940                         { "Headphone", 0x2 },
4941                         { "Mixer", 0x5 },
4942                 },
4943         },
4944
4945 };
4946
4947 /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
4948  * the Fujitsu S702x, but jacks are marked differently.
4949  */
4950 static struct hda_input_mux alc260_acer_capture_sources[2] = {
4951         {
4952                 .num_items = 4,
4953                 .items = {
4954                         { "Mic", 0x0 },
4955                         { "Line", 0x2 },
4956                         { "CD", 0x4 },
4957                         { "Headphone", 0x5 },
4958                 },
4959         },
4960         {
4961                 .num_items = 5,
4962                 .items = {
4963                         { "Mic", 0x0 },
4964                         { "Line", 0x2 },
4965                         { "CD", 0x4 },
4966                         { "Headphone", 0x6 },
4967                         { "Mixer", 0x5 },
4968                 },
4969         },
4970 };
4971
4972 /* Maxdata Favorit 100XS */
4973 static struct hda_input_mux alc260_favorit100_capture_sources[2] = {
4974         {
4975                 .num_items = 2,
4976                 .items = {
4977                         { "Line/Mic", 0x0 },
4978                         { "CD", 0x4 },
4979                 },
4980         },
4981         {
4982                 .num_items = 3,
4983                 .items = {
4984                         { "Line/Mic", 0x0 },
4985                         { "CD", 0x4 },
4986                         { "Mixer", 0x5 },
4987                 },
4988         },
4989 };
4990
4991 /*
4992  * This is just place-holder, so there's something for alc_build_pcms to look
4993  * at when it calculates the maximum number of channels. ALC260 has no mixer
4994  * element which allows changing the channel mode, so the verb list is
4995  * never used.
4996  */
4997 static struct hda_channel_mode alc260_modes[1] = {
4998         { 2, NULL },
4999 };
5000
5001
5002 /* Mixer combinations
5003  *
5004  * basic: base_output + input + pc_beep + capture
5005  * HP: base_output + input + capture_alt
5006  * HP_3013: hp_3013 + input + capture
5007  * fujitsu: fujitsu + capture
5008  * acer: acer + capture
5009  */
5010
5011 static struct snd_kcontrol_new alc260_base_output_mixer[] = {
5012         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5013         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
5014         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5015         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
5016         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
5017         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
5018         { } /* end */
5019 };
5020
5021 static struct snd_kcontrol_new alc260_input_mixer[] = {
5022         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5023         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5024         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
5025         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
5026         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
5027         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
5028         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
5029         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
5030         { } /* end */
5031 };
5032
5033 /* update HP, line and mono out pins according to the master switch */
5034 static void alc260_hp_master_update(struct hda_codec *codec,
5035                                     hda_nid_t hp, hda_nid_t line,
5036                                     hda_nid_t mono)
5037 {
5038         struct alc_spec *spec = codec->spec;
5039         unsigned int val = spec->master_sw ? PIN_HP : 0;
5040         /* change HP and line-out pins */
5041         snd_hda_codec_write(codec, hp, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5042                             val);
5043         snd_hda_codec_write(codec, line, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5044                             val);
5045         /* mono (speaker) depending on the HP jack sense */
5046         val = (val && !spec->jack_present) ? PIN_OUT : 0;
5047         snd_hda_codec_write(codec, mono, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5048                             val);
5049 }
5050
5051 static int alc260_hp_master_sw_get(struct snd_kcontrol *kcontrol,
5052                                    struct snd_ctl_elem_value *ucontrol)
5053 {
5054         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5055         struct alc_spec *spec = codec->spec;
5056         *ucontrol->value.integer.value = spec->master_sw;
5057         return 0;
5058 }
5059
5060 static int alc260_hp_master_sw_put(struct snd_kcontrol *kcontrol,
5061                                    struct snd_ctl_elem_value *ucontrol)
5062 {
5063         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5064         struct alc_spec *spec = codec->spec;
5065         int val = !!*ucontrol->value.integer.value;
5066         hda_nid_t hp, line, mono;
5067
5068         if (val == spec->master_sw)
5069                 return 0;
5070         spec->master_sw = val;
5071         hp = (kcontrol->private_value >> 16) & 0xff;
5072         line = (kcontrol->private_value >> 8) & 0xff;
5073         mono = kcontrol->private_value & 0xff;
5074         alc260_hp_master_update(codec, hp, line, mono);
5075         return 1;
5076 }
5077
5078 static struct snd_kcontrol_new alc260_hp_output_mixer[] = {
5079         {
5080                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5081                 .name = "Master Playback Switch",
5082                 .info = snd_ctl_boolean_mono_info,
5083                 .get = alc260_hp_master_sw_get,
5084                 .put = alc260_hp_master_sw_put,
5085                 .private_value = (0x0f << 16) | (0x10 << 8) | 0x11
5086         },
5087         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5088         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
5089         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5090         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
5091         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
5092                               HDA_OUTPUT),
5093         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2, HDA_INPUT),
5094         { } /* end */
5095 };
5096
5097 static struct hda_verb alc260_hp_unsol_verbs[] = {
5098         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5099         {},
5100 };
5101
5102 static void alc260_hp_automute(struct hda_codec *codec)
5103 {
5104         struct alc_spec *spec = codec->spec;
5105         unsigned int present;
5106
5107         present = snd_hda_codec_read(codec, 0x10, 0,
5108                                      AC_VERB_GET_PIN_SENSE, 0);
5109         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
5110         alc260_hp_master_update(codec, 0x0f, 0x10, 0x11);
5111 }
5112
5113 static void alc260_hp_unsol_event(struct hda_codec *codec, unsigned int res)
5114 {
5115         if ((res >> 26) == ALC880_HP_EVENT)
5116                 alc260_hp_automute(codec);
5117 }
5118
5119 static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
5120         {
5121                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5122                 .name = "Master Playback Switch",
5123                 .info = snd_ctl_boolean_mono_info,
5124                 .get = alc260_hp_master_sw_get,
5125                 .put = alc260_hp_master_sw_put,
5126                 .private_value = (0x15 << 16) | (0x10 << 8) | 0x11
5127         },
5128         HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5129         HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
5130         HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
5131         HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
5132         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5133         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5134         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
5135         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
5136         { } /* end */
5137 };
5138
5139 static struct hda_bind_ctls alc260_dc7600_bind_master_vol = {
5140         .ops = &snd_hda_bind_vol,
5141         .values = {
5142                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_OUTPUT),
5143                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
5144                 HDA_COMPOSE_AMP_VAL(0x0a, 3, 0, HDA_OUTPUT),
5145                 0
5146         },
5147 };
5148
5149 static struct hda_bind_ctls alc260_dc7600_bind_switch = {
5150         .ops = &snd_hda_bind_sw,
5151         .values = {
5152                 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
5153                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
5154                 0
5155         },
5156 };
5157
5158 static struct snd_kcontrol_new alc260_hp_dc7600_mixer[] = {
5159         HDA_BIND_VOL("Master Playback Volume", &alc260_dc7600_bind_master_vol),
5160         HDA_BIND_SW("LineOut Playback Switch", &alc260_dc7600_bind_switch),
5161         HDA_CODEC_MUTE("Speaker Playback Switch", 0x0f, 0x0, HDA_OUTPUT),
5162         HDA_CODEC_MUTE("Headphone Playback Switch", 0x10, 0x0, HDA_OUTPUT),
5163         { } /* end */
5164 };
5165
5166 static struct hda_verb alc260_hp_3013_unsol_verbs[] = {
5167         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5168         {},
5169 };
5170
5171 static void alc260_hp_3013_automute(struct hda_codec *codec)
5172 {
5173         struct alc_spec *spec = codec->spec;
5174         unsigned int present;
5175
5176         present = snd_hda_codec_read(codec, 0x15, 0,
5177                                      AC_VERB_GET_PIN_SENSE, 0);
5178         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
5179         alc260_hp_master_update(codec, 0x15, 0x10, 0x11);
5180 }
5181
5182 static void alc260_hp_3013_unsol_event(struct hda_codec *codec,
5183                                        unsigned int res)
5184 {
5185         if ((res >> 26) == ALC880_HP_EVENT)
5186                 alc260_hp_3013_automute(codec);
5187 }
5188
5189 static void alc260_hp_3012_automute(struct hda_codec *codec)
5190 {
5191         unsigned int present, bits;
5192
5193         present = snd_hda_codec_read(codec, 0x10, 0,
5194                         AC_VERB_GET_PIN_SENSE, 0) & AC_PINSENSE_PRESENCE;
5195
5196         bits = present ? 0 : PIN_OUT;
5197         snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5198                             bits);
5199         snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5200                             bits);
5201         snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5202                             bits);
5203 }
5204
5205 static void alc260_hp_3012_unsol_event(struct hda_codec *codec,
5206                                        unsigned int res)
5207 {
5208         if ((res >> 26) == ALC880_HP_EVENT)
5209                 alc260_hp_3012_automute(codec);
5210 }
5211
5212 /* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12,
5213  * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
5214  */
5215 static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
5216         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5217         HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
5218         ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
5219         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5220         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5221         HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
5222         HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
5223         ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
5224         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5225         HDA_BIND_MUTE("Speaker Playback Switch", 0x09, 2, HDA_INPUT),
5226         { } /* end */
5227 };
5228
5229 /* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks.  Note that current
5230  * versions of the ALC260 don't act on requests to enable mic bias from NID
5231  * 0x0f (used to drive the headphone jack in these laptops).  The ALC260
5232  * datasheet doesn't mention this restriction.  At this stage it's not clear
5233  * whether this behaviour is intentional or is a hardware bug in chip
5234  * revisions available in early 2006.  Therefore for now allow the
5235  * "Headphone Jack Mode" control to span all choices, but if it turns out
5236  * that the lack of mic bias for this NID is intentional we could change the
5237  * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
5238  *
5239  * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
5240  * don't appear to make the mic bias available from the "line" jack, even
5241  * though the NID used for this jack (0x14) can supply it.  The theory is
5242  * that perhaps Acer have included blocking capacitors between the ALC260
5243  * and the output jack.  If this turns out to be the case for all such
5244  * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
5245  * to ALC_PIN_DIR_INOUT_NOMICBIAS.
5246  *
5247  * The C20x Tablet series have a mono internal speaker which is controlled
5248  * via the chip's Mono sum widget and pin complex, so include the necessary
5249  * controls for such models.  On models without a "mono speaker" the control
5250  * won't do anything.
5251  */
5252 static struct snd_kcontrol_new alc260_acer_mixer[] = {
5253         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5254         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
5255         ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
5256         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
5257                               HDA_OUTPUT),
5258         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2,
5259                            HDA_INPUT),
5260         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5261         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5262         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
5263         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
5264         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
5265         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
5266         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
5267         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
5268         { } /* end */
5269 };
5270
5271 /* Maxdata Favorit 100XS: one output and one input (0x12) jack
5272  */
5273 static struct snd_kcontrol_new alc260_favorit100_mixer[] = {
5274         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5275         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
5276         ALC_PIN_MODE("Output Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
5277         HDA_CODEC_VOLUME("Line/Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
5278         HDA_CODEC_MUTE("Line/Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
5279         ALC_PIN_MODE("Line/Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
5280         { } /* end */
5281 };
5282
5283 /* Packard bell V7900  ALC260 pin usage: HP = 0x0f, Mic jack = 0x12,
5284  * Line In jack = 0x14, CD audio =  0x16, pc beep = 0x17.
5285  */
5286 static struct snd_kcontrol_new alc260_will_mixer[] = {
5287         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5288         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
5289         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
5290         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
5291         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
5292         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
5293         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
5294         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
5295         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5296         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5297         { } /* end */
5298 };
5299
5300 /* Replacer 672V ALC260 pin usage: Mic jack = 0x12,
5301  * Line In jack = 0x14, ATAPI Mic = 0x13, speaker = 0x0f.
5302  */
5303 static struct snd_kcontrol_new alc260_replacer_672v_mixer[] = {
5304         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5305         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
5306         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
5307         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
5308         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
5309         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x07, 0x1, HDA_INPUT),
5310         HDA_CODEC_MUTE("ATATI Mic Playback Switch", 0x07, 0x1, HDA_INPUT),
5311         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
5312         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
5313         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
5314         { } /* end */
5315 };
5316
5317 /*
5318  * initialization verbs
5319  */
5320 static struct hda_verb alc260_init_verbs[] = {
5321         /* Line In pin widget for input */
5322         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5323         /* CD pin widget for input */
5324         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5325         /* Mic1 (rear panel) pin widget for input and vref at 80% */
5326         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5327         /* Mic2 (front panel) pin widget for input and vref at 80% */
5328         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5329         /* LINE-2 is used for line-out in rear */
5330         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5331         /* select line-out */
5332         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
5333         /* LINE-OUT pin */
5334         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5335         /* enable HP */
5336         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5337         /* enable Mono */
5338         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5339         /* mute capture amp left and right */
5340         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5341         /* set connection select to line in (default select for this ADC) */
5342         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
5343         /* mute capture amp left and right */
5344         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5345         /* set connection select to line in (default select for this ADC) */
5346         {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
5347         /* set vol=0 Line-Out mixer amp left and right */
5348         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5349         /* unmute pin widget amp left and right (no gain on this amp) */
5350         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5351         /* set vol=0 HP mixer amp left and right */
5352         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5353         /* unmute pin widget amp left and right (no gain on this amp) */
5354         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5355         /* set vol=0 Mono mixer amp left and right */
5356         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5357         /* unmute pin widget amp left and right (no gain on this amp) */
5358         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5359         /* unmute LINE-2 out pin */
5360         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5361         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
5362          * Line In 2 = 0x03
5363          */
5364         /* mute analog inputs */
5365         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5366         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5367         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5368         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5369         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5370         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
5371         /* mute Front out path */
5372         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5373         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5374         /* mute Headphone out path */
5375         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5376         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5377         /* mute Mono out path */
5378         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5379         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5380         { }
5381 };
5382
5383 #if 0 /* should be identical with alc260_init_verbs? */
5384 static struct hda_verb alc260_hp_init_verbs[] = {
5385         /* Headphone and output */
5386         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
5387         /* mono output */
5388         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5389         /* Mic1 (rear panel) pin widget for input and vref at 80% */
5390         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
5391         /* Mic2 (front panel) pin widget for input and vref at 80% */
5392         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
5393         /* Line In pin widget for input */
5394         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
5395         /* Line-2 pin widget for output */
5396         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5397         /* CD pin widget for input */
5398         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
5399         /* unmute amp left and right */
5400         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
5401         /* set connection select to line in (default select for this ADC) */
5402         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
5403         /* unmute Line-Out mixer amp left and right (volume = 0) */
5404         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5405         /* mute pin widget amp left and right (no gain on this amp) */
5406         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5407         /* unmute HP mixer amp left and right (volume = 0) */
5408         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5409         /* mute pin widget amp left and right (no gain on this amp) */
5410         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5411         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
5412          * Line In 2 = 0x03
5413          */
5414         /* mute analog inputs */
5415         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5416         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5417         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5418         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5419         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5420         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
5421         /* Unmute Front out path */
5422         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5423         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5424         /* Unmute Headphone out path */
5425         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5426         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5427         /* Unmute Mono out path */
5428         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5429         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5430         { }
5431 };
5432 #endif
5433
5434 static struct hda_verb alc260_hp_3013_init_verbs[] = {
5435         /* Line out and output */
5436         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5437         /* mono output */
5438         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5439         /* Mic1 (rear panel) pin widget for input and vref at 80% */
5440         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
5441         /* Mic2 (front panel) pin widget for input and vref at 80% */
5442         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
5443         /* Line In pin widget for input */
5444         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
5445         /* Headphone pin widget for output */
5446         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
5447         /* CD pin widget for input */
5448         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
5449         /* unmute amp left and right */
5450         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
5451         /* set connection select to line in (default select for this ADC) */
5452         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
5453         /* unmute Line-Out mixer amp left and right (volume = 0) */
5454         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5455         /* mute pin widget amp left and right (no gain on this amp) */
5456         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5457         /* unmute HP mixer amp left and right (volume = 0) */
5458         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5459         /* mute pin widget amp left and right (no gain on this amp) */
5460         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5461         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
5462          * Line In 2 = 0x03
5463          */
5464         /* mute analog inputs */
5465         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5466         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5467         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5468         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5469         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5470         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
5471         /* Unmute Front out path */
5472         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5473         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5474         /* Unmute Headphone out path */
5475         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5476         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5477         /* Unmute Mono out path */
5478         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5479         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5480         { }
5481 };
5482
5483 /* Initialisation sequence for ALC260 as configured in Fujitsu S702x
5484  * laptops.  ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
5485  * audio = 0x16, internal speaker = 0x10.
5486  */
5487 static struct hda_verb alc260_fujitsu_init_verbs[] = {
5488         /* Disable all GPIOs */
5489         {0x01, AC_VERB_SET_GPIO_MASK, 0},
5490         /* Internal speaker is connected to headphone pin */
5491         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5492         /* Headphone/Line-out jack connects to Line1 pin; make it an output */
5493         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5494         /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
5495         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5496         /* Ensure all other unused pins are disabled and muted. */
5497         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5498         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5499         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5500         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5501         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5502         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5503         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5504         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5505
5506         /* Disable digital (SPDIF) pins */
5507         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5508         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5509
5510         /* Ensure Line1 pin widget takes its input from the OUT1 sum bus
5511          * when acting as an output.
5512          */
5513         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5514
5515         /* Start with output sum widgets muted and their output gains at min */
5516         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5517         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5518         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5519         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5520         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5521         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5522         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5523         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5524         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5525
5526         /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
5527         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5528         /* Unmute Line1 pin widget output buffer since it starts as an output.
5529          * If the pin mode is changed by the user the pin mode control will
5530          * take care of enabling the pin's input/output buffers as needed.
5531          * Therefore there's no need to enable the input buffer at this
5532          * stage.
5533          */
5534         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5535         /* Unmute input buffer of pin widget used for Line-in (no equiv
5536          * mixer ctrl)
5537          */
5538         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5539
5540         /* Mute capture amp left and right */
5541         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5542         /* Set ADC connection select to match default mixer setting - line
5543          * in (on mic1 pin)
5544          */
5545         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5546
5547         /* Do the same for the second ADC: mute capture input amp and
5548          * set ADC connection to line in (on mic1 pin)
5549          */
5550         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5551         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5552
5553         /* Mute all inputs to mixer widget (even unconnected ones) */
5554         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5555         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5556         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5557         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5558         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5559         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5560         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5561         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5562
5563         { }
5564 };
5565
5566 /* Initialisation sequence for ALC260 as configured in Acer TravelMate and
5567  * similar laptops (adapted from Fujitsu init verbs).
5568  */
5569 static struct hda_verb alc260_acer_init_verbs[] = {
5570         /* On TravelMate laptops, GPIO 0 enables the internal speaker and
5571          * the headphone jack.  Turn this on and rely on the standard mute
5572          * methods whenever the user wants to turn these outputs off.
5573          */
5574         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5575         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5576         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5577         /* Internal speaker/Headphone jack is connected to Line-out pin */
5578         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5579         /* Internal microphone/Mic jack is connected to Mic1 pin */
5580         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
5581         /* Line In jack is connected to Line1 pin */
5582         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5583         /* Some Acers (eg: C20x Tablets) use Mono pin for internal speaker */
5584         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5585         /* Ensure all other unused pins are disabled and muted. */
5586         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5587         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5588         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5589         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5590         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5591         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5592         /* Disable digital (SPDIF) pins */
5593         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5594         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5595
5596         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
5597          * bus when acting as outputs.
5598          */
5599         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5600         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5601
5602         /* Start with output sum widgets muted and their output gains at min */
5603         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5604         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5605         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5606         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5607         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5608         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5609         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5610         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5611         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5612
5613         /* Unmute Line-out pin widget amp left and right
5614          * (no equiv mixer ctrl)
5615          */
5616         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5617         /* Unmute mono pin widget amp output (no equiv mixer ctrl) */
5618         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5619         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
5620          * inputs. If the pin mode is changed by the user the pin mode control
5621          * will take care of enabling the pin's input/output buffers as needed.
5622          * Therefore there's no need to enable the input buffer at this
5623          * stage.
5624          */
5625         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5626         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5627
5628         /* Mute capture amp left and right */
5629         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5630         /* Set ADC connection select to match default mixer setting - mic
5631          * (on mic1 pin)
5632          */
5633         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5634
5635         /* Do similar with the second ADC: mute capture input amp and
5636          * set ADC connection to mic to match ALSA's default state.
5637          */
5638         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5639         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5640
5641         /* Mute all inputs to mixer widget (even unconnected ones) */
5642         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5643         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5644         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5645         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5646         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5647         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5648         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5649         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5650
5651         { }
5652 };
5653
5654 /* Initialisation sequence for Maxdata Favorit 100XS
5655  * (adapted from Acer init verbs).
5656  */
5657 static struct hda_verb alc260_favorit100_init_verbs[] = {
5658         /* GPIO 0 enables the output jack.
5659          * Turn this on and rely on the standard mute
5660          * methods whenever the user wants to turn these outputs off.
5661          */
5662         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5663         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5664         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5665         /* Line/Mic input jack is connected to Mic1 pin */
5666         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
5667         /* Ensure all other unused pins are disabled and muted. */
5668         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5669         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5670         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5671         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5672         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5673         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5674         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5675         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5676         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5677         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5678         /* Disable digital (SPDIF) pins */
5679         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5680         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5681
5682         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
5683          * bus when acting as outputs.
5684          */
5685         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5686         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5687
5688         /* Start with output sum widgets muted and their output gains at min */
5689         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5690         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5691         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5692         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5693         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5694         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5695         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5696         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5697         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5698
5699         /* Unmute Line-out pin widget amp left and right
5700          * (no equiv mixer ctrl)
5701          */
5702         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5703         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
5704          * inputs. If the pin mode is changed by the user the pin mode control
5705          * will take care of enabling the pin's input/output buffers as needed.
5706          * Therefore there's no need to enable the input buffer at this
5707          * stage.
5708          */
5709         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5710
5711         /* Mute capture amp left and right */
5712         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5713         /* Set ADC connection select to match default mixer setting - mic
5714          * (on mic1 pin)
5715          */
5716         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5717
5718         /* Do similar with the second ADC: mute capture input amp and
5719          * set ADC connection to mic to match ALSA's default state.
5720          */
5721         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5722         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5723
5724         /* Mute all inputs to mixer widget (even unconnected ones) */
5725         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5726         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5727         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5728         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5729         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5730         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5731         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5732         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5733
5734         { }
5735 };
5736
5737 static struct hda_verb alc260_will_verbs[] = {
5738         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5739         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x00},
5740         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
5741         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
5742         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
5743         {0x1a, AC_VERB_SET_PROC_COEF, 0x3040},
5744         {}
5745 };
5746
5747 static struct hda_verb alc260_replacer_672v_verbs[] = {
5748         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
5749         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
5750         {0x1a, AC_VERB_SET_PROC_COEF, 0x3050},
5751
5752         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5753         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5754         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5755
5756         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5757         {}
5758 };
5759
5760 /* toggle speaker-output according to the hp-jack state */
5761 static void alc260_replacer_672v_automute(struct hda_codec *codec)
5762 {
5763         unsigned int present;
5764
5765         /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
5766         present = snd_hda_codec_read(codec, 0x0f, 0,
5767                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5768         if (present) {
5769                 snd_hda_codec_write_cache(codec, 0x01, 0,
5770                                           AC_VERB_SET_GPIO_DATA, 1);
5771                 snd_hda_codec_write_cache(codec, 0x0f, 0,
5772                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
5773                                           PIN_HP);
5774         } else {
5775                 snd_hda_codec_write_cache(codec, 0x01, 0,
5776                                           AC_VERB_SET_GPIO_DATA, 0);
5777                 snd_hda_codec_write_cache(codec, 0x0f, 0,
5778                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
5779                                           PIN_OUT);
5780         }
5781 }
5782
5783 static void alc260_replacer_672v_unsol_event(struct hda_codec *codec,
5784                                        unsigned int res)
5785 {
5786         if ((res >> 26) == ALC880_HP_EVENT)
5787                 alc260_replacer_672v_automute(codec);
5788 }
5789
5790 static struct hda_verb alc260_hp_dc7600_verbs[] = {
5791         {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
5792         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
5793         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5794         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5795         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5796         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5797         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5798         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5799         {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5800         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5801         {}
5802 };
5803
5804 /* Test configuration for debugging, modelled after the ALC880 test
5805  * configuration.
5806  */
5807 #ifdef CONFIG_SND_DEBUG
5808 static hda_nid_t alc260_test_dac_nids[1] = {
5809         0x02,
5810 };
5811 static hda_nid_t alc260_test_adc_nids[2] = {
5812         0x04, 0x05,
5813 };
5814 /* For testing the ALC260, each input MUX needs its own definition since
5815  * the signal assignments are different.  This assumes that the first ADC
5816  * is NID 0x04.
5817  */
5818 static struct hda_input_mux alc260_test_capture_sources[2] = {
5819         {
5820                 .num_items = 7,
5821                 .items = {
5822                         { "MIC1 pin", 0x0 },
5823                         { "MIC2 pin", 0x1 },
5824                         { "LINE1 pin", 0x2 },
5825                         { "LINE2 pin", 0x3 },
5826                         { "CD pin", 0x4 },
5827                         { "LINE-OUT pin", 0x5 },
5828                         { "HP-OUT pin", 0x6 },
5829                 },
5830         },
5831         {
5832                 .num_items = 8,
5833                 .items = {
5834                         { "MIC1 pin", 0x0 },
5835                         { "MIC2 pin", 0x1 },
5836                         { "LINE1 pin", 0x2 },
5837                         { "LINE2 pin", 0x3 },
5838                         { "CD pin", 0x4 },
5839                         { "Mixer", 0x5 },
5840                         { "LINE-OUT pin", 0x6 },
5841                         { "HP-OUT pin", 0x7 },
5842                 },
5843         },
5844 };
5845 static struct snd_kcontrol_new alc260_test_mixer[] = {
5846         /* Output driver widgets */
5847         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
5848         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
5849         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5850         HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
5851         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5852         HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),
5853
5854         /* Modes for retasking pin widgets
5855          * Note: the ALC260 doesn't seem to act on requests to enable mic
5856          * bias from NIDs 0x0f and 0x10.  The ALC260 datasheet doesn't
5857          * mention this restriction.  At this stage it's not clear whether
5858          * this behaviour is intentional or is a hardware bug in chip
5859          * revisions available at least up until early 2006.  Therefore for
5860          * now allow the "HP-OUT" and "LINE-OUT" Mode controls to span all
5861          * choices, but if it turns out that the lack of mic bias for these
5862          * NIDs is intentional we could change their modes from
5863          * ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
5864          */
5865         ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
5866         ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
5867         ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
5868         ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
5869         ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
5870         ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),
5871
5872         /* Loopback mixer controls */
5873         HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
5874         HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
5875         HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
5876         HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
5877         HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
5878         HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
5879         HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
5880         HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
5881         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5882         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5883         HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
5884         HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
5885         HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
5886         HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
5887
5888         /* Controls for GPIO pins, assuming they are configured as outputs */
5889         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
5890         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
5891         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
5892         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
5893
5894         /* Switches to allow the digital IO pins to be enabled.  The datasheet
5895          * is ambigious as to which NID is which; testing on laptops which
5896          * make this output available should provide clarification.
5897          */
5898         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
5899         ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),
5900
5901         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
5902          * this output to turn on an external amplifier.
5903          */
5904         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
5905         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
5906
5907         { } /* end */
5908 };
5909 static struct hda_verb alc260_test_init_verbs[] = {
5910         /* Enable all GPIOs as outputs with an initial value of 0 */
5911         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
5912         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5913         {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
5914
5915         /* Enable retasking pins as output, initially without power amp */
5916         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5917         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5918         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5919         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5920         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5921         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5922
5923         /* Disable digital (SPDIF) pins initially, but users can enable
5924          * them via a mixer switch.  In the case of SPDIF-out, this initverb
5925          * payload also sets the generation to 0, output to be in "consumer"
5926          * PCM format, copyright asserted, no pre-emphasis and no validity
5927          * control.
5928          */
5929         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5930         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5931
5932         /* Ensure mic1, mic2, line1 and line2 pin widgets take input from the
5933          * OUT1 sum bus when acting as an output.
5934          */
5935         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5936         {0x0c, AC_VERB_SET_CONNECT_SEL, 0},
5937         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5938         {0x0e, AC_VERB_SET_CONNECT_SEL, 0},
5939
5940         /* Start with output sum widgets muted and their output gains at min */
5941         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5942         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5943         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5944         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5945         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5946         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5947         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5948         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5949         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5950
5951         /* Unmute retasking pin widget output buffers since the default
5952          * state appears to be output.  As the pin mode is changed by the
5953          * user the pin mode control will take care of enabling the pin's
5954          * input/output buffers as needed.
5955          */
5956         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5957         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5958         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5959         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5960         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5961         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5962         /* Also unmute the mono-out pin widget */
5963         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5964
5965         /* Mute capture amp left and right */
5966         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5967         /* Set ADC connection select to match default mixer setting (mic1
5968          * pin)
5969          */
5970         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5971
5972         /* Do the same for the second ADC: mute capture input amp and
5973          * set ADC connection to mic1 pin
5974          */
5975         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5976         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5977
5978         /* Mute all inputs to mixer widget (even unconnected ones) */
5979         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5980         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5981         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5982         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5983         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5984         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5985         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5986         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5987
5988         { }
5989 };
5990 #endif
5991
5992 #define alc260_pcm_analog_playback      alc880_pcm_analog_alt_playback
5993 #define alc260_pcm_analog_capture       alc880_pcm_analog_capture
5994
5995 #define alc260_pcm_digital_playback     alc880_pcm_digital_playback
5996 #define alc260_pcm_digital_capture      alc880_pcm_digital_capture
5997
5998 /*
5999  * for BIOS auto-configuration
6000  */
6001
6002 static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
6003                                         const char *pfx, int *vol_bits)
6004 {
6005         hda_nid_t nid_vol;
6006         unsigned long vol_val, sw_val;
6007         int err;
6008
6009         if (nid >= 0x0f && nid < 0x11) {
6010                 nid_vol = nid - 0x7;
6011                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
6012                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
6013         } else if (nid == 0x11) {
6014                 nid_vol = nid - 0x7;
6015                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT);
6016                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
6017         } else if (nid >= 0x12 && nid <= 0x15) {
6018                 nid_vol = 0x08;
6019                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
6020                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
6021         } else
6022                 return 0; /* N/A */
6023
6024         if (!(*vol_bits & (1 << nid_vol))) {
6025                 /* first control for the volume widget */
6026                 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx, vol_val);
6027                 if (err < 0)
6028                         return err;
6029                 *vol_bits |= (1 << nid_vol);
6030         }
6031         err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, sw_val);
6032         if (err < 0)
6033                 return err;
6034         return 1;
6035 }
6036
6037 /* add playback controls from the parsed DAC table */
6038 static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
6039                                              const struct auto_pin_cfg *cfg)
6040 {
6041         hda_nid_t nid;
6042         int err;
6043         int vols = 0;
6044
6045         spec->multiout.num_dacs = 1;
6046         spec->multiout.dac_nids = spec->private_dac_nids;
6047         spec->multiout.dac_nids[0] = 0x02;
6048
6049         nid = cfg->line_out_pins[0];
6050         if (nid) {
6051                 const char *pfx;
6052                 if (!cfg->speaker_pins[0] && !cfg->hp_pins[0])
6053                         pfx = "Master";
6054                 else if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
6055                         pfx = "Speaker";
6056                 else
6057                         pfx = "Front";
6058                 err = alc260_add_playback_controls(spec, nid, pfx, &vols);
6059                 if (err < 0)
6060                         return err;
6061         }
6062
6063         nid = cfg->speaker_pins[0];
6064         if (nid) {
6065                 err = alc260_add_playback_controls(spec, nid, "Speaker", &vols);
6066                 if (err < 0)
6067                         return err;
6068         }
6069
6070         nid = cfg->hp_pins[0];
6071         if (nid) {
6072                 err = alc260_add_playback_controls(spec, nid, "Headphone",
6073                                                    &vols);
6074                 if (err < 0)
6075                         return err;
6076         }
6077         return 0;
6078 }
6079
6080 /* create playback/capture controls for input pins */
6081 static int alc260_auto_create_input_ctls(struct hda_codec *codec,
6082                                                 const struct auto_pin_cfg *cfg)
6083 {
6084         return alc_auto_create_input_ctls(codec, cfg, 0x07, 0x04, 0x05);
6085 }
6086
6087 static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
6088                                               hda_nid_t nid, int pin_type,
6089                                               int sel_idx)
6090 {
6091         alc_set_pin_output(codec, nid, pin_type);
6092         /* need the manual connection? */
6093         if (nid >= 0x12) {
6094                 int idx = nid - 0x12;
6095                 snd_hda_codec_write(codec, idx + 0x0b, 0,
6096                                     AC_VERB_SET_CONNECT_SEL, sel_idx);
6097         }
6098 }
6099
6100 static void alc260_auto_init_multi_out(struct hda_codec *codec)
6101 {
6102         struct alc_spec *spec = codec->spec;
6103         hda_nid_t nid;
6104
6105         nid = spec->autocfg.line_out_pins[0];
6106         if (nid) {
6107                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
6108                 alc260_auto_set_output_and_unmute(codec, nid, pin_type, 0);
6109         }
6110
6111         nid = spec->autocfg.speaker_pins[0];
6112         if (nid)
6113                 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
6114
6115         nid = spec->autocfg.hp_pins[0];
6116         if (nid)
6117                 alc260_auto_set_output_and_unmute(codec, nid, PIN_HP, 0);
6118 }
6119
6120 #define ALC260_PIN_CD_NID               0x16
6121 static void alc260_auto_init_analog_input(struct hda_codec *codec)
6122 {
6123         struct alc_spec *spec = codec->spec;
6124         int i;
6125
6126         for (i = 0; i < AUTO_PIN_LAST; i++) {
6127                 hda_nid_t nid = spec->autocfg.input_pins[i];
6128                 if (nid >= 0x12) {
6129                         alc_set_input_pin(codec, nid, i);
6130                         if (nid != ALC260_PIN_CD_NID &&
6131                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
6132                                 snd_hda_codec_write(codec, nid, 0,
6133                                                     AC_VERB_SET_AMP_GAIN_MUTE,
6134                                                     AMP_OUT_MUTE);
6135                 }
6136         }
6137 }
6138
6139 /*
6140  * generic initialization of ADC, input mixers and output mixers
6141  */
6142 static struct hda_verb alc260_volume_init_verbs[] = {
6143         /*
6144          * Unmute ADC0-1 and set the default input to mic-in
6145          */
6146         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
6147         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6148         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
6149         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6150
6151         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
6152          * mixer widget
6153          * Note: PASD motherboards uses the Line In 2 as the input for
6154          * front panel mic (mic 2)
6155          */
6156         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
6157         /* mute analog inputs */
6158         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6159         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6160         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6161         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6162         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6163
6164         /*
6165          * Set up output mixers (0x08 - 0x0a)
6166          */
6167         /* set vol=0 to output mixers */
6168         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6169         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6170         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6171         /* set up input amps for analog loopback */
6172         /* Amp Indices: DAC = 0, mixer = 1 */
6173         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6174         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6175         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6176         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6177         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6178         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6179
6180         { }
6181 };
6182
6183 static int alc260_parse_auto_config(struct hda_codec *codec)
6184 {
6185         struct alc_spec *spec = codec->spec;
6186         int err;
6187         static hda_nid_t alc260_ignore[] = { 0x17, 0 };
6188
6189         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
6190                                            alc260_ignore);
6191         if (err < 0)
6192                 return err;
6193         err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg);
6194         if (err < 0)
6195                 return err;
6196         if (!spec->kctls.list)
6197                 return 0; /* can't find valid BIOS pin config */
6198         err = alc260_auto_create_input_ctls(codec, &spec->autocfg);
6199         if (err < 0)
6200                 return err;
6201
6202         spec->multiout.max_channels = 2;
6203
6204         if (spec->autocfg.dig_outs)
6205                 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
6206         if (spec->kctls.list)
6207                 add_mixer(spec, spec->kctls.list);
6208
6209         add_verb(spec, alc260_volume_init_verbs);
6210
6211         spec->num_mux_defs = 1;
6212         spec->input_mux = &spec->private_imux[0];
6213
6214         alc_ssid_check(codec, 0x10, 0x15, 0x0f);
6215
6216         return 1;
6217 }
6218
6219 /* additional initialization for auto-configuration model */
6220 static void alc260_auto_init(struct hda_codec *codec)
6221 {
6222         struct alc_spec *spec = codec->spec;
6223         alc260_auto_init_multi_out(codec);
6224         alc260_auto_init_analog_input(codec);
6225         if (spec->unsol_event)
6226                 alc_inithook(codec);
6227 }
6228
6229 #ifdef CONFIG_SND_HDA_POWER_SAVE
6230 static struct hda_amp_list alc260_loopbacks[] = {
6231         { 0x07, HDA_INPUT, 0 },
6232         { 0x07, HDA_INPUT, 1 },
6233         { 0x07, HDA_INPUT, 2 },
6234         { 0x07, HDA_INPUT, 3 },
6235         { 0x07, HDA_INPUT, 4 },
6236         { } /* end */
6237 };
6238 #endif
6239
6240 /*
6241  * ALC260 configurations
6242  */
6243 static const char *alc260_models[ALC260_MODEL_LAST] = {
6244         [ALC260_BASIC]          = "basic",
6245         [ALC260_HP]             = "hp",
6246         [ALC260_HP_3013]        = "hp-3013",
6247         [ALC260_HP_DC7600]      = "hp-dc7600",
6248         [ALC260_FUJITSU_S702X]  = "fujitsu",
6249         [ALC260_ACER]           = "acer",
6250         [ALC260_WILL]           = "will",
6251         [ALC260_REPLACER_672V]  = "replacer",
6252         [ALC260_FAVORIT100]     = "favorit100",
6253 #ifdef CONFIG_SND_DEBUG
6254         [ALC260_TEST]           = "test",
6255 #endif
6256         [ALC260_AUTO]           = "auto",
6257 };
6258
6259 static struct snd_pci_quirk alc260_cfg_tbl[] = {
6260         SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER),
6261         SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
6262         SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FAVORIT100),
6263         SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
6264         SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_AUTO), /* no quirk */
6265         SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
6266         SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP_3013),
6267         SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_DC7600),
6268         SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
6269         SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
6270         SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP),
6271         SND_PCI_QUIRK(0x103c, 0x3016, "HP", ALC260_HP),
6272         SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_BASIC),
6273         SND_PCI_QUIRK(0x104d, 0x81cc, "Sony VAIO", ALC260_BASIC),
6274         SND_PCI_QUIRK(0x104d, 0x81cd, "Sony VAIO", ALC260_BASIC),
6275         SND_PCI_QUIRK(0x10cf, 0x1326, "Fujitsu S702X", ALC260_FUJITSU_S702X),
6276         SND_PCI_QUIRK(0x152d, 0x0729, "CTL U553W", ALC260_BASIC),
6277         SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_REPLACER_672V),
6278         SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_WILL),
6279         {}
6280 };
6281
6282 static struct alc_config_preset alc260_presets[] = {
6283         [ALC260_BASIC] = {
6284                 .mixers = { alc260_base_output_mixer,
6285                             alc260_input_mixer },
6286                 .init_verbs = { alc260_init_verbs },
6287                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6288                 .dac_nids = alc260_dac_nids,
6289                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
6290                 .adc_nids = alc260_adc_nids,
6291                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6292                 .channel_mode = alc260_modes,
6293                 .input_mux = &alc260_capture_source,
6294         },
6295         [ALC260_HP] = {
6296                 .mixers = { alc260_hp_output_mixer,
6297                             alc260_input_mixer },
6298                 .init_verbs = { alc260_init_verbs,
6299                                 alc260_hp_unsol_verbs },
6300                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6301                 .dac_nids = alc260_dac_nids,
6302                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
6303                 .adc_nids = alc260_adc_nids_alt,
6304                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6305                 .channel_mode = alc260_modes,
6306                 .input_mux = &alc260_capture_source,
6307                 .unsol_event = alc260_hp_unsol_event,
6308                 .init_hook = alc260_hp_automute,
6309         },
6310         [ALC260_HP_DC7600] = {
6311                 .mixers = { alc260_hp_dc7600_mixer,
6312                             alc260_input_mixer },
6313                 .init_verbs = { alc260_init_verbs,
6314                                 alc260_hp_dc7600_verbs },
6315                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6316                 .dac_nids = alc260_dac_nids,
6317                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
6318                 .adc_nids = alc260_adc_nids_alt,
6319                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6320                 .channel_mode = alc260_modes,
6321                 .input_mux = &alc260_capture_source,
6322                 .unsol_event = alc260_hp_3012_unsol_event,
6323                 .init_hook = alc260_hp_3012_automute,
6324         },
6325         [ALC260_HP_3013] = {
6326                 .mixers = { alc260_hp_3013_mixer,
6327                             alc260_input_mixer },
6328                 .init_verbs = { alc260_hp_3013_init_verbs,
6329                                 alc260_hp_3013_unsol_verbs },
6330                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6331                 .dac_nids = alc260_dac_nids,
6332                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
6333                 .adc_nids = alc260_adc_nids_alt,
6334                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6335                 .channel_mode = alc260_modes,
6336                 .input_mux = &alc260_capture_source,
6337                 .unsol_event = alc260_hp_3013_unsol_event,
6338                 .init_hook = alc260_hp_3013_automute,
6339         },
6340         [ALC260_FUJITSU_S702X] = {
6341                 .mixers = { alc260_fujitsu_mixer },
6342                 .init_verbs = { alc260_fujitsu_init_verbs },
6343                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6344                 .dac_nids = alc260_dac_nids,
6345                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
6346                 .adc_nids = alc260_dual_adc_nids,
6347                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6348                 .channel_mode = alc260_modes,
6349                 .num_mux_defs = ARRAY_SIZE(alc260_fujitsu_capture_sources),
6350                 .input_mux = alc260_fujitsu_capture_sources,
6351         },
6352         [ALC260_ACER] = {
6353                 .mixers = { alc260_acer_mixer },
6354                 .init_verbs = { alc260_acer_init_verbs },
6355                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6356                 .dac_nids = alc260_dac_nids,
6357                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
6358                 .adc_nids = alc260_dual_adc_nids,
6359                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6360                 .channel_mode = alc260_modes,
6361                 .num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources),
6362                 .input_mux = alc260_acer_capture_sources,
6363         },
6364         [ALC260_FAVORIT100] = {
6365                 .mixers = { alc260_favorit100_mixer },
6366                 .init_verbs = { alc260_favorit100_init_verbs },
6367                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6368                 .dac_nids = alc260_dac_nids,
6369                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
6370                 .adc_nids = alc260_dual_adc_nids,
6371                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6372                 .channel_mode = alc260_modes,
6373                 .num_mux_defs = ARRAY_SIZE(alc260_favorit100_capture_sources),
6374                 .input_mux = alc260_favorit100_capture_sources,
6375         },
6376         [ALC260_WILL] = {
6377                 .mixers = { alc260_will_mixer },
6378                 .init_verbs = { alc260_init_verbs, alc260_will_verbs },
6379                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6380                 .dac_nids = alc260_dac_nids,
6381                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
6382                 .adc_nids = alc260_adc_nids,
6383                 .dig_out_nid = ALC260_DIGOUT_NID,
6384                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6385                 .channel_mode = alc260_modes,
6386                 .input_mux = &alc260_capture_source,
6387         },
6388         [ALC260_REPLACER_672V] = {
6389                 .mixers = { alc260_replacer_672v_mixer },
6390                 .init_verbs = { alc260_init_verbs, alc260_replacer_672v_verbs },
6391                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6392                 .dac_nids = alc260_dac_nids,
6393                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
6394                 .adc_nids = alc260_adc_nids,
6395                 .dig_out_nid = ALC260_DIGOUT_NID,
6396                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6397                 .channel_mode = alc260_modes,
6398                 .input_mux = &alc260_capture_source,
6399                 .unsol_event = alc260_replacer_672v_unsol_event,
6400                 .init_hook = alc260_replacer_672v_automute,
6401         },
6402 #ifdef CONFIG_SND_DEBUG
6403         [ALC260_TEST] = {
6404                 .mixers = { alc260_test_mixer },
6405                 .init_verbs = { alc260_test_init_verbs },
6406                 .num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
6407                 .dac_nids = alc260_test_dac_nids,
6408                 .num_adc_nids = ARRAY_SIZE(alc260_test_adc_nids),
6409                 .adc_nids = alc260_test_adc_nids,
6410                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6411                 .channel_mode = alc260_modes,
6412                 .num_mux_defs = ARRAY_SIZE(alc260_test_capture_sources),
6413                 .input_mux = alc260_test_capture_sources,
6414         },
6415 #endif
6416 };
6417
6418 static int patch_alc260(struct hda_codec *codec)
6419 {
6420         struct alc_spec *spec;
6421         int err, board_config;
6422
6423         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6424         if (spec == NULL)
6425                 return -ENOMEM;
6426
6427         codec->spec = spec;
6428
6429         board_config = snd_hda_check_board_config(codec, ALC260_MODEL_LAST,
6430                                                   alc260_models,
6431                                                   alc260_cfg_tbl);
6432         if (board_config < 0) {
6433                 snd_printd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6434                            codec->chip_name);
6435                 board_config = ALC260_AUTO;
6436         }
6437
6438         if (board_config == ALC260_AUTO) {
6439                 /* automatic parse from the BIOS config */
6440                 err = alc260_parse_auto_config(codec);
6441                 if (err < 0) {
6442                         alc_free(codec);
6443                         return err;
6444                 } else if (!err) {
6445                         printk(KERN_INFO
6446                                "hda_codec: Cannot set up configuration "
6447                                "from BIOS.  Using base mode...\n");
6448                         board_config = ALC260_BASIC;
6449                 }
6450         }
6451
6452         err = snd_hda_attach_beep_device(codec, 0x1);
6453         if (err < 0) {
6454                 alc_free(codec);
6455                 return err;
6456         }
6457
6458         if (board_config != ALC260_AUTO)
6459                 setup_preset(codec, &alc260_presets[board_config]);
6460
6461         spec->stream_analog_playback = &alc260_pcm_analog_playback;
6462         spec->stream_analog_capture = &alc260_pcm_analog_capture;
6463
6464         spec->stream_digital_playback = &alc260_pcm_digital_playback;
6465         spec->stream_digital_capture = &alc260_pcm_digital_capture;
6466
6467         if (!spec->adc_nids && spec->input_mux) {
6468                 /* check whether NID 0x04 is valid */
6469                 unsigned int wcap = get_wcaps(codec, 0x04);
6470                 wcap = get_wcaps_type(wcap);
6471                 /* get type */
6472                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
6473                         spec->adc_nids = alc260_adc_nids_alt;
6474                         spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
6475                 } else {
6476                         spec->adc_nids = alc260_adc_nids;
6477                         spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
6478                 }
6479         }
6480         set_capture_mixer(codec);
6481         set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
6482
6483         spec->vmaster_nid = 0x08;
6484
6485         codec->patch_ops = alc_patch_ops;
6486         if (board_config == ALC260_AUTO)
6487                 spec->init_hook = alc260_auto_init;
6488 #ifdef CONFIG_SND_HDA_POWER_SAVE
6489         if (!spec->loopback.amplist)
6490                 spec->loopback.amplist = alc260_loopbacks;
6491 #endif
6492         codec->proc_widget_hook = print_realtek_coef;
6493
6494         return 0;
6495 }
6496
6497
6498 /*
6499  * ALC882/883/885/888/889 support
6500  *
6501  * ALC882 is almost identical with ALC880 but has cleaner and more flexible
6502  * configuration.  Each pin widget can choose any input DACs and a mixer.
6503  * Each ADC is connected from a mixer of all inputs.  This makes possible
6504  * 6-channel independent captures.
6505  *
6506  * In addition, an independent DAC for the multi-playback (not used in this
6507  * driver yet).
6508  */
6509 #define ALC882_DIGOUT_NID       0x06
6510 #define ALC882_DIGIN_NID        0x0a
6511 #define ALC883_DIGOUT_NID       ALC882_DIGOUT_NID
6512 #define ALC883_DIGIN_NID        ALC882_DIGIN_NID
6513 #define ALC1200_DIGOUT_NID      0x10
6514
6515
6516 static struct hda_channel_mode alc882_ch_modes[1] = {
6517         { 8, NULL }
6518 };
6519
6520 /* DACs */
6521 static hda_nid_t alc882_dac_nids[4] = {
6522         /* front, rear, clfe, rear_surr */
6523         0x02, 0x03, 0x04, 0x05
6524 };
6525 #define alc883_dac_nids         alc882_dac_nids
6526
6527 /* ADCs */
6528 #define alc882_adc_nids         alc880_adc_nids
6529 #define alc882_adc_nids_alt     alc880_adc_nids_alt
6530 #define alc883_adc_nids         alc882_adc_nids_alt
6531 static hda_nid_t alc883_adc_nids_alt[1] = { 0x08 };
6532 static hda_nid_t alc883_adc_nids_rev[2] = { 0x09, 0x08 };
6533 #define alc889_adc_nids         alc880_adc_nids
6534
6535 static hda_nid_t alc882_capsrc_nids[3] = { 0x24, 0x23, 0x22 };
6536 static hda_nid_t alc882_capsrc_nids_alt[2] = { 0x23, 0x22 };
6537 #define alc883_capsrc_nids      alc882_capsrc_nids_alt
6538 static hda_nid_t alc883_capsrc_nids_rev[2] = { 0x22, 0x23 };
6539 #define alc889_capsrc_nids      alc882_capsrc_nids
6540
6541 /* input MUX */
6542 /* FIXME: should be a matrix-type input source selection */
6543
6544 static struct hda_input_mux alc882_capture_source = {
6545         .num_items = 4,
6546         .items = {
6547                 { "Mic", 0x0 },
6548                 { "Front Mic", 0x1 },
6549                 { "Line", 0x2 },
6550                 { "CD", 0x4 },
6551         },
6552 };
6553
6554 #define alc883_capture_source   alc882_capture_source
6555
6556 static struct hda_input_mux alc889_capture_source = {
6557         .num_items = 3,
6558         .items = {
6559                 { "Front Mic", 0x0 },
6560                 { "Mic", 0x3 },
6561                 { "Line", 0x2 },
6562         },
6563 };
6564
6565 static struct hda_input_mux mb5_capture_source = {
6566         .num_items = 3,
6567         .items = {
6568                 { "Mic", 0x1 },
6569                 { "Line", 0x2 },
6570                 { "CD", 0x4 },
6571         },
6572 };
6573
6574 static struct hda_input_mux alc883_3stack_6ch_intel = {
6575         .num_items = 4,
6576         .items = {
6577                 { "Mic", 0x1 },
6578                 { "Front Mic", 0x0 },
6579                 { "Line", 0x2 },
6580                 { "CD", 0x4 },
6581         },
6582 };
6583
6584 static struct hda_input_mux alc883_lenovo_101e_capture_source = {
6585         .num_items = 2,
6586         .items = {
6587                 { "Mic", 0x1 },
6588                 { "Line", 0x2 },
6589         },
6590 };
6591
6592 static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
6593         .num_items = 4,
6594         .items = {
6595                 { "Mic", 0x0 },
6596                 { "iMic", 0x1 },
6597                 { "Line", 0x2 },
6598                 { "CD", 0x4 },
6599         },
6600 };
6601
6602 static struct hda_input_mux alc883_fujitsu_pi2515_capture_source = {
6603         .num_items = 2,
6604         .items = {
6605                 { "Mic", 0x0 },
6606                 { "Int Mic", 0x1 },
6607         },
6608 };
6609
6610 static struct hda_input_mux alc883_lenovo_sky_capture_source = {
6611         .num_items = 3,
6612         .items = {
6613                 { "Mic", 0x0 },
6614                 { "Front Mic", 0x1 },
6615                 { "Line", 0x4 },
6616         },
6617 };
6618
6619 static struct hda_input_mux alc883_asus_eee1601_capture_source = {
6620         .num_items = 2,
6621         .items = {
6622                 { "Mic", 0x0 },
6623                 { "Line", 0x2 },
6624         },
6625 };
6626
6627 static struct hda_input_mux alc889A_mb31_capture_source = {
6628         .num_items = 2,
6629         .items = {
6630                 { "Mic", 0x0 },
6631                 /* Front Mic (0x01) unused */
6632                 { "Line", 0x2 },
6633                 /* Line 2 (0x03) unused */
6634                 /* CD (0x04) unsused? */
6635         },
6636 };
6637
6638 /*
6639  * 2ch mode
6640  */
6641 static struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
6642         { 2, NULL }
6643 };
6644
6645 /*
6646  * 2ch mode
6647  */
6648 static struct hda_verb alc882_3ST_ch2_init[] = {
6649         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6650         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6651         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6652         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6653         { } /* end */
6654 };
6655
6656 /*
6657  * 4ch mode
6658  */
6659 static struct hda_verb alc882_3ST_ch4_init[] = {
6660         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6661         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6662         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6663         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6664         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6665         { } /* end */
6666 };
6667
6668 /*
6669  * 6ch mode
6670  */
6671 static struct hda_verb alc882_3ST_ch6_init[] = {
6672         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6673         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6674         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6675         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6676         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6677         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6678         { } /* end */
6679 };
6680
6681 static struct hda_channel_mode alc882_3ST_6ch_modes[3] = {
6682         { 2, alc882_3ST_ch2_init },
6683         { 4, alc882_3ST_ch4_init },
6684         { 6, alc882_3ST_ch6_init },
6685 };
6686
6687 #define alc883_3ST_6ch_modes    alc882_3ST_6ch_modes
6688
6689 /*
6690  * 2ch mode
6691  */
6692 static struct hda_verb alc883_3ST_ch2_clevo_init[] = {
6693         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
6694         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6695         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6696         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6697         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6698         { } /* end */
6699 };
6700
6701 /*
6702  * 4ch mode
6703  */
6704 static struct hda_verb alc883_3ST_ch4_clevo_init[] = {
6705         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6706         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6707         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6708         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6709         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6710         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6711         { } /* end */
6712 };
6713
6714 /*
6715  * 6ch mode
6716  */
6717 static struct hda_verb alc883_3ST_ch6_clevo_init[] = {
6718         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6719         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6720         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6721         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6722         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6723         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6724         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6725         { } /* end */
6726 };
6727
6728 static struct hda_channel_mode alc883_3ST_6ch_clevo_modes[3] = {
6729         { 2, alc883_3ST_ch2_clevo_init },
6730         { 4, alc883_3ST_ch4_clevo_init },
6731         { 6, alc883_3ST_ch6_clevo_init },
6732 };
6733
6734
6735 /*
6736  * 6ch mode
6737  */
6738 static struct hda_verb alc882_sixstack_ch6_init[] = {
6739         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
6740         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6741         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6742         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6743         { } /* end */
6744 };
6745
6746 /*
6747  * 8ch mode
6748  */
6749 static struct hda_verb alc882_sixstack_ch8_init[] = {
6750         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6751         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6752         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6753         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6754         { } /* end */
6755 };
6756
6757 static struct hda_channel_mode alc882_sixstack_modes[2] = {
6758         { 6, alc882_sixstack_ch6_init },
6759         { 8, alc882_sixstack_ch8_init },
6760 };
6761
6762 /*
6763  * macbook pro ALC885 can switch LineIn to LineOut without losing Mic
6764  */
6765
6766 /*
6767  * 2ch mode
6768  */
6769 static struct hda_verb alc885_mbp_ch2_init[] = {
6770         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6771         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6772         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6773         { } /* end */
6774 };
6775
6776 /*
6777  * 4ch mode
6778  */
6779 static struct hda_verb alc885_mbp_ch4_init[] = {
6780         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6781         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6782         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6783         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6784         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6785         { } /* end */
6786 };
6787
6788 static struct hda_channel_mode alc885_mbp_4ch_modes[2] = {
6789         { 2, alc885_mbp_ch2_init },
6790         { 4, alc885_mbp_ch4_init },
6791 };
6792
6793 /*
6794  * 2ch
6795  * Speakers/Woofer/HP = Front
6796  * LineIn = Input
6797  */
6798 static struct hda_verb alc885_mb5_ch2_init[] = {
6799         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6800         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6801         { } /* end */
6802 };
6803
6804 /*
6805  * 6ch mode
6806  * Speakers/HP = Front
6807  * Woofer = LFE
6808  * LineIn = Surround
6809  */
6810 static struct hda_verb alc885_mb5_ch6_init[] = {
6811         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6812         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6813         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
6814         { } /* end */
6815 };
6816
6817 static struct hda_channel_mode alc885_mb5_6ch_modes[2] = {
6818         { 2, alc885_mb5_ch2_init },
6819         { 6, alc885_mb5_ch6_init },
6820 };
6821
6822
6823 /*
6824  * 2ch mode
6825  */
6826 static struct hda_verb alc883_4ST_ch2_init[] = {
6827         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6828         { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6829         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6830         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6831         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6832         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6833         { } /* end */
6834 };
6835
6836 /*
6837  * 4ch mode
6838  */
6839 static struct hda_verb alc883_4ST_ch4_init[] = {
6840         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6841         { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6842         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6843         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6844         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6845         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6846         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6847         { } /* end */
6848 };
6849
6850 /*
6851  * 6ch mode
6852  */
6853 static struct hda_verb alc883_4ST_ch6_init[] = {
6854         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6855         { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6856         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6857         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6858         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6859         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6860         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6861         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6862         { } /* end */
6863 };
6864
6865 /*
6866  * 8ch mode
6867  */
6868 static struct hda_verb alc883_4ST_ch8_init[] = {
6869         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6870         { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6871         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03 },
6872         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6873         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6874         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6875         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6876         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6877         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6878         { } /* end */
6879 };
6880
6881 static struct hda_channel_mode alc883_4ST_8ch_modes[4] = {
6882         { 2, alc883_4ST_ch2_init },
6883         { 4, alc883_4ST_ch4_init },
6884         { 6, alc883_4ST_ch6_init },
6885         { 8, alc883_4ST_ch8_init },
6886 };
6887
6888
6889 /*
6890  * 2ch mode
6891  */
6892 static struct hda_verb alc883_3ST_ch2_intel_init[] = {
6893         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6894         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6895         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6896         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6897         { } /* end */
6898 };
6899
6900 /*
6901  * 4ch mode
6902  */
6903 static struct hda_verb alc883_3ST_ch4_intel_init[] = {
6904         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6905         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6906         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6907         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6908         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6909         { } /* end */
6910 };
6911
6912 /*
6913  * 6ch mode
6914  */
6915 static struct hda_verb alc883_3ST_ch6_intel_init[] = {
6916         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6917         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6918         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x02 },
6919         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6920         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6921         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6922         { } /* end */
6923 };
6924
6925 static struct hda_channel_mode alc883_3ST_6ch_intel_modes[3] = {
6926         { 2, alc883_3ST_ch2_intel_init },
6927         { 4, alc883_3ST_ch4_intel_init },
6928         { 6, alc883_3ST_ch6_intel_init },
6929 };
6930
6931 /*
6932  * 2ch mode
6933  */
6934 static struct hda_verb alc889_ch2_intel_init[] = {
6935         { 0x14, AC_VERB_SET_CONNECT_SEL, 0x00 },
6936         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x00 },
6937         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x00 },
6938         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00 },
6939         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6940         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6941         { } /* end */
6942 };
6943
6944 /*
6945  * 6ch mode
6946  */
6947 static struct hda_verb alc889_ch6_intel_init[] = {
6948         { 0x14, AC_VERB_SET_CONNECT_SEL, 0x00 },
6949         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x01 },
6950         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x02 },
6951         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03 },
6952         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6953         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6954         { } /* end */
6955 };
6956
6957 /*
6958  * 8ch mode
6959  */
6960 static struct hda_verb alc889_ch8_intel_init[] = {
6961         { 0x14, AC_VERB_SET_CONNECT_SEL, 0x00 },
6962         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x01 },
6963         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x02 },
6964         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03 },
6965         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x03 },
6966         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6967         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6968         { } /* end */
6969 };
6970
6971 static struct hda_channel_mode alc889_8ch_intel_modes[3] = {
6972         { 2, alc889_ch2_intel_init },
6973         { 6, alc889_ch6_intel_init },
6974         { 8, alc889_ch8_intel_init },
6975 };
6976
6977 /*
6978  * 6ch mode
6979  */
6980 static struct hda_verb alc883_sixstack_ch6_init[] = {
6981         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
6982         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6983         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6984         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6985         { } /* end */
6986 };
6987
6988 /*
6989  * 8ch mode
6990  */
6991 static struct hda_verb alc883_sixstack_ch8_init[] = {
6992         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6993         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6994         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6995         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6996         { } /* end */
6997 };
6998
6999 static struct hda_channel_mode alc883_sixstack_modes[2] = {
7000         { 6, alc883_sixstack_ch6_init },
7001         { 8, alc883_sixstack_ch8_init },
7002 };
7003
7004
7005 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
7006  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
7007  */
7008 static struct snd_kcontrol_new alc882_base_mixer[] = {
7009         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7010         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7011         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7012         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7013         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7014         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7015         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7016         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7017         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7018         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7019         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7020         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7021         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7022         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7023         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7024         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7025         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7026         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7027         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7028         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7029         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7030         { } /* end */
7031 };
7032
7033 static struct snd_kcontrol_new alc885_mbp3_mixer[] = {
7034         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
7035         HDA_BIND_MUTE   ("Speaker Playback Switch", 0x0c, 0x02, HDA_INPUT),
7036         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0e, 0x00, HDA_OUTPUT),
7037         HDA_BIND_MUTE   ("Headphone Playback Switch", 0x0e, 0x02, HDA_INPUT),
7038         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
7039         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7040         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7041         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
7042         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
7043         HDA_CODEC_VOLUME("Line Boost", 0x1a, 0x00, HDA_INPUT),
7044         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
7045         { } /* end */
7046 };
7047
7048 static struct snd_kcontrol_new alc885_mb5_mixer[] = {
7049         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
7050         HDA_BIND_MUTE   ("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
7051         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
7052         HDA_BIND_MUTE   ("Surround Playback Switch", 0x0d, 0x02, HDA_INPUT),
7053         HDA_CODEC_VOLUME("LFE Playback Volume", 0x0e, 0x00, HDA_OUTPUT),
7054         HDA_BIND_MUTE   ("LFE Playback Switch", 0x0e, 0x02, HDA_INPUT),
7055         HDA_CODEC_VOLUME("HP Playback Volume", 0x0f, 0x00, HDA_OUTPUT),
7056         HDA_BIND_MUTE   ("HP Playback Switch", 0x0f, 0x02, HDA_INPUT),
7057         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7058         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7059         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
7060         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
7061         HDA_CODEC_VOLUME("Line Boost", 0x15, 0x00, HDA_INPUT),
7062         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0x00, HDA_INPUT),
7063         { } /* end */
7064 };
7065
7066 static struct snd_kcontrol_new alc882_w2jc_mixer[] = {
7067         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7068         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7069         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7070         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7071         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7072         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7073         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7074         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7075         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7076         { } /* end */
7077 };
7078
7079 static struct snd_kcontrol_new alc882_targa_mixer[] = {
7080         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7081         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7082         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7083         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7084         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7085         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7086         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7087         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7088         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7089         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7090         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7091         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7092         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7093         { } /* end */
7094 };
7095
7096 /* Pin assignment: Front=0x14, HP = 0x15, Front = 0x16, ???
7097  *                 Front Mic=0x18, Line In = 0x1a, Line In = 0x1b, CD = 0x1c
7098  */
7099 static struct snd_kcontrol_new alc882_asus_a7j_mixer[] = {
7100         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7101         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7102         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7103         HDA_CODEC_MUTE("Mobile Front Playback Switch", 0x16, 0x0, HDA_OUTPUT),
7104         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7105         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7106         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7107         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7108         HDA_CODEC_VOLUME("Mobile Line Playback Volume", 0x0b, 0x03, HDA_INPUT),
7109         HDA_CODEC_MUTE("Mobile Line Playback Switch", 0x0b, 0x03, HDA_INPUT),
7110         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7111         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7112         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7113         { } /* end */
7114 };
7115
7116 static struct snd_kcontrol_new alc882_asus_a7m_mixer[] = {
7117         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7118         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7119         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7120         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7121         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7122         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7123         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7124         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7125         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7126         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7127         { } /* end */
7128 };
7129
7130 static struct snd_kcontrol_new alc882_chmode_mixer[] = {
7131         {
7132                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7133                 .name = "Channel Mode",
7134                 .info = alc_ch_mode_info,
7135                 .get = alc_ch_mode_get,
7136                 .put = alc_ch_mode_put,
7137         },
7138         { } /* end */
7139 };
7140
7141 static struct hda_verb alc882_base_init_verbs[] = {
7142         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7143         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7144         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7145         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7146         /* Rear mixer */
7147         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7148         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7149         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7150         /* CLFE mixer */
7151         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7152         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7153         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7154         /* Side mixer */
7155         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7156         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7157         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7158
7159         /* mute analog input loopbacks */
7160         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7161         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7162         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7163         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7164         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7165
7166         /* Front Pin: output 0 (0x0c) */
7167         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7168         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7169         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7170         /* Rear Pin: output 1 (0x0d) */
7171         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7172         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7173         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7174         /* CLFE Pin: output 2 (0x0e) */
7175         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7176         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7177         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
7178         /* Side Pin: output 3 (0x0f) */
7179         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7180         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7181         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
7182         /* Mic (rear) pin: input vref at 80% */
7183         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7184         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7185         /* Front Mic pin: input vref at 80% */
7186         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7187         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7188         /* Line In pin: input */
7189         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7190         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7191         /* Line-2 In: Headphone output (output 0 - 0x0c) */
7192         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7193         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7194         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7195         /* CD pin widget for input */
7196         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7197
7198         /* FIXME: use matrix-type input source selection */
7199         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7200         /* Input mixer2 */
7201         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7202         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7203         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7204         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7205         /* Input mixer3 */
7206         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7207         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7208         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7209         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7210         /* ADC2: mute amp left and right */
7211         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7212         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7213         /* ADC3: mute amp left and right */
7214         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7215         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7216
7217         { }
7218 };
7219
7220 static struct hda_verb alc882_adc1_init_verbs[] = {
7221         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
7222         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7223         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7224         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7225         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7226         /* ADC1: mute amp left and right */
7227         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7228         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
7229         { }
7230 };
7231
7232 static struct hda_verb alc882_eapd_verbs[] = {
7233         /* change to EAPD mode */
7234         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7235         {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
7236         { }
7237 };
7238
7239 static struct hda_verb alc889_eapd_verbs[] = {
7240         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
7241         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
7242         { }
7243 };
7244
7245 static struct hda_verb alc_hp15_unsol_verbs[] = {
7246         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
7247         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7248         {}
7249 };
7250
7251 static struct hda_verb alc885_init_verbs[] = {
7252         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7253         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7254         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7255         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7256         /* Rear mixer */
7257         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7258         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7259         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7260         /* CLFE mixer */
7261         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7262         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7263         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7264         /* Side mixer */
7265         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7266         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7267         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7268
7269         /* mute analog input loopbacks */
7270         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7271         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7272         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7273
7274         /* Front HP Pin: output 0 (0x0c) */
7275         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7276         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7277         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7278         /* Front Pin: output 0 (0x0c) */
7279         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7280         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7281         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7282         /* Rear Pin: output 1 (0x0d) */
7283         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7284         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7285         {0x19, AC_VERB_SET_CONNECT_SEL, 0x01},
7286         /* CLFE Pin: output 2 (0x0e) */
7287         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7288         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7289         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
7290         /* Side Pin: output 3 (0x0f) */
7291         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7292         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7293         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
7294         /* Mic (rear) pin: input vref at 80% */
7295         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7296         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7297         /* Front Mic pin: input vref at 80% */
7298         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7299         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7300         /* Line In pin: input */
7301         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7302         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7303
7304         /* Mixer elements: 0x18, , 0x1a, 0x1b */
7305         /* Input mixer1 */
7306         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
7307         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7308         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7309         /* Input mixer2 */
7310         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7311         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7312         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7313         /* Input mixer3 */
7314         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7315         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7316         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7317         /* ADC2: mute amp left and right */
7318         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7319         /* ADC3: mute amp left and right */
7320         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7321
7322         { }
7323 };
7324
7325 static struct hda_verb alc885_init_input_verbs[] = {
7326         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7327         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7328         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
7329         { }
7330 };
7331
7332
7333 /* Unmute Selector 24h and set the default input to front mic */
7334 static struct hda_verb alc889_init_input_verbs[] = {
7335         {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
7336         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7337         { }
7338 };
7339
7340
7341 #define alc883_init_verbs       alc882_base_init_verbs
7342
7343 /* Mac Pro test */
7344 static struct snd_kcontrol_new alc882_macpro_mixer[] = {
7345         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7346         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7347         HDA_CODEC_MUTE("Headphone Playback Switch", 0x18, 0x0, HDA_OUTPUT),
7348         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
7349         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
7350         /* FIXME: this looks suspicious...
7351         HDA_CODEC_VOLUME("Beep Playback Volume", 0x0b, 0x02, HDA_INPUT),
7352         HDA_CODEC_MUTE("Beep Playback Switch", 0x0b, 0x02, HDA_INPUT),
7353         */
7354         { } /* end */
7355 };
7356
7357 static struct hda_verb alc882_macpro_init_verbs[] = {
7358         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7359         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7360         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7361         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7362         /* Front Pin: output 0 (0x0c) */
7363         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7364         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7365         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7366         /* Front Mic pin: input vref at 80% */
7367         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7368         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7369         /* Speaker:  output */
7370         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7371         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7372         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x04},
7373         /* Headphone output (output 0 - 0x0c) */
7374         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7375         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7376         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
7377
7378         /* FIXME: use matrix-type input source selection */
7379         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7380         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
7381         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7382         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7383         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7384         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7385         /* Input mixer2 */
7386         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7387         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7388         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7389         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7390         /* Input mixer3 */
7391         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7392         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7393         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7394         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7395         /* ADC1: mute amp left and right */
7396         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7397         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
7398         /* ADC2: mute amp left and right */
7399         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7400         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7401         /* ADC3: mute amp left and right */
7402         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7403         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7404
7405         { }
7406 };
7407
7408 /* Macbook 5,1 */
7409 static struct hda_verb alc885_mb5_init_verbs[] = {
7410         /* DACs */
7411         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7412         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7413         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7414         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7415         /* Front mixer */
7416         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7417         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7418         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7419         /* Surround mixer */
7420         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7421         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7422         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7423         /* LFE mixer */
7424         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7425         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7426         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7427         /* HP mixer */
7428         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7429         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7430         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7431         /* Front Pin (0x0c) */
7432         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x01},
7433         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7434         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
7435         /* LFE Pin (0x0e) */
7436         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x01},
7437         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7438         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x02},
7439         /* HP Pin (0x0f) */
7440         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7441         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7442         {0x14, AC_VERB_SET_CONNECT_SEL, 0x03},
7443         /* Front Mic pin: input vref at 80% */
7444         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7445         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7446         /* Line In pin */
7447         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7448         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7449
7450         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7451         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7452         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7453         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7454         { }
7455 };
7456
7457 /* Macbook Pro rev3 */
7458 static struct hda_verb alc885_mbp3_init_verbs[] = {
7459         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7460         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7461         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7462         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7463         /* Rear mixer */
7464         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7465         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7466         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7467         /* HP mixer */
7468         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7469         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7470         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7471         /* Front Pin: output 0 (0x0c) */
7472         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7473         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7474         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7475         /* HP Pin: output 0 (0x0e) */
7476         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},
7477         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7478         {0x15, AC_VERB_SET_CONNECT_SEL, 0x02},
7479         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7480         /* Mic (rear) pin: input vref at 80% */
7481         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7482         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7483         /* Front Mic pin: input vref at 80% */
7484         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7485         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7486         /* Line In pin: use output 1 when in LineOut mode */
7487         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7488         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7489         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
7490
7491         /* FIXME: use matrix-type input source selection */
7492         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7493         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
7494         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7495         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7496         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7497         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7498         /* Input mixer2 */
7499         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7500         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7501         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7502         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7503         /* Input mixer3 */
7504         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7505         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7506         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7507         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7508         /* ADC1: mute amp left and right */
7509         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7510         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
7511         /* ADC2: mute amp left and right */
7512         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7513         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7514         /* ADC3: mute amp left and right */
7515         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7516         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7517
7518         { }
7519 };
7520
7521 /* iMac 24 mixer. */
7522 static struct snd_kcontrol_new alc885_imac24_mixer[] = {
7523         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
7524         HDA_CODEC_MUTE("Master Playback Switch", 0x0c, 0x00, HDA_INPUT),
7525         { } /* end */
7526 };
7527
7528 /* iMac 24 init verbs. */
7529 static struct hda_verb alc885_imac24_init_verbs[] = {
7530         /* Internal speakers: output 0 (0x0c) */
7531         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7532         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7533         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
7534         /* Internal speakers: output 0 (0x0c) */
7535         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7536         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7537         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
7538         /* Headphone: output 0 (0x0c) */
7539         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7540         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7541         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7542         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7543         /* Front Mic: input vref at 80% */
7544         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7545         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7546         { }
7547 };
7548
7549 /* Toggle speaker-output according to the hp-jack state */
7550 static void alc885_imac24_setup(struct hda_codec *codec)
7551 {
7552         struct alc_spec *spec = codec->spec;
7553
7554         spec->autocfg.hp_pins[0] = 0x14;
7555         spec->autocfg.speaker_pins[0] = 0x18;
7556         spec->autocfg.speaker_pins[1] = 0x1a;
7557 }
7558
7559 static void alc885_mbp3_setup(struct hda_codec *codec)
7560 {
7561         struct alc_spec *spec = codec->spec;
7562
7563         spec->autocfg.hp_pins[0] = 0x15;
7564         spec->autocfg.speaker_pins[0] = 0x14;
7565 }
7566
7567
7568 static struct hda_verb alc882_targa_verbs[] = {
7569         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7570         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7571
7572         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7573         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7574
7575         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
7576         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
7577         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7578
7579         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7580         { } /* end */
7581 };
7582
7583 /* toggle speaker-output according to the hp-jack state */
7584 static void alc882_targa_automute(struct hda_codec *codec)
7585 {
7586         struct alc_spec *spec = codec->spec;
7587         alc_automute_amp(codec);
7588         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
7589                                   spec->jack_present ? 1 : 3);
7590 }
7591
7592 static void alc882_targa_setup(struct hda_codec *codec)
7593 {
7594         struct alc_spec *spec = codec->spec;
7595
7596         spec->autocfg.hp_pins[0] = 0x14;
7597         spec->autocfg.speaker_pins[0] = 0x1b;
7598 }
7599
7600 static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res)
7601 {
7602         if ((res >> 26) == ALC880_HP_EVENT)
7603                 alc882_targa_automute(codec);
7604 }
7605
7606 static struct hda_verb alc882_asus_a7j_verbs[] = {
7607         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7608         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7609
7610         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7611         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7612         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7613
7614         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
7615         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7616         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
7617
7618         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
7619         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
7620         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7621         { } /* end */
7622 };
7623
7624 static struct hda_verb alc882_asus_a7m_verbs[] = {
7625         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7626         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7627
7628         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7629         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7630         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7631
7632         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
7633         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7634         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
7635
7636         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
7637         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
7638         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7639         { } /* end */
7640 };
7641
7642 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
7643 {
7644         unsigned int gpiostate, gpiomask, gpiodir;
7645
7646         gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
7647                                        AC_VERB_GET_GPIO_DATA, 0);
7648
7649         if (!muted)
7650                 gpiostate |= (1 << pin);
7651         else
7652                 gpiostate &= ~(1 << pin);
7653
7654         gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
7655                                       AC_VERB_GET_GPIO_MASK, 0);
7656         gpiomask |= (1 << pin);
7657
7658         gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
7659                                      AC_VERB_GET_GPIO_DIRECTION, 0);
7660         gpiodir |= (1 << pin);
7661
7662
7663         snd_hda_codec_write(codec, codec->afg, 0,
7664                             AC_VERB_SET_GPIO_MASK, gpiomask);
7665         snd_hda_codec_write(codec, codec->afg, 0,
7666                             AC_VERB_SET_GPIO_DIRECTION, gpiodir);
7667
7668         msleep(1);
7669
7670         snd_hda_codec_write(codec, codec->afg, 0,
7671                             AC_VERB_SET_GPIO_DATA, gpiostate);
7672 }
7673
7674 /* set up GPIO at initialization */
7675 static void alc885_macpro_init_hook(struct hda_codec *codec)
7676 {
7677         alc882_gpio_mute(codec, 0, 0);
7678         alc882_gpio_mute(codec, 1, 0);
7679 }
7680
7681 /* set up GPIO and update auto-muting at initialization */
7682 static void alc885_imac24_init_hook(struct hda_codec *codec)
7683 {
7684         alc885_macpro_init_hook(codec);
7685         alc_automute_amp(codec);
7686 }
7687
7688 /*
7689  * generic initialization of ADC, input mixers and output mixers
7690  */
7691 static struct hda_verb alc883_auto_init_verbs[] = {
7692         /*
7693          * Unmute ADC0-2 and set the default input to mic-in
7694          */
7695         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7696         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7697         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7698         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7699
7700         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
7701          * mixer widget
7702          * Note: PASD motherboards uses the Line In 2 as the input for
7703          * front panel mic (mic 2)
7704          */
7705         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
7706         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7707         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7708         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7709         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7710         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7711
7712         /*
7713          * Set up output mixers (0x0c - 0x0f)
7714          */
7715         /* set vol=0 to output mixers */
7716         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7717         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7718         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7719         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7720         /* set up input amps for analog loopback */
7721         /* Amp Indices: DAC = 0, mixer = 1 */
7722         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7723         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7724         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7725         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7726         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7727         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7728         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7729         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7730         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7731         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7732
7733         /* FIXME: use matrix-type input source selection */
7734         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7735         /* Input mixer2 */
7736         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7737         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7738         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
7739         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
7740         /* Input mixer3 */
7741         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7742         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7743         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
7744         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
7745
7746         { }
7747 };
7748
7749 /* 2ch mode (Speaker:front, Subwoofer:CLFE, Line:input, Headphones:front) */
7750 static struct hda_verb alc889A_mb31_ch2_init[] = {
7751         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},             /* HP as front */
7752         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Subwoofer on */
7753         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},    /* Line as input */
7754         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},   /* Line off */
7755         { } /* end */
7756 };
7757
7758 /* 4ch mode (Speaker:front, Subwoofer:CLFE, Line:CLFE, Headphones:front) */
7759 static struct hda_verb alc889A_mb31_ch4_init[] = {
7760         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},             /* HP as front */
7761         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Subwoofer on */
7762         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},   /* Line as output */
7763         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Line on */
7764         { } /* end */
7765 };
7766
7767 /* 5ch mode (Speaker:front, Subwoofer:CLFE, Line:input, Headphones:rear) */
7768 static struct hda_verb alc889A_mb31_ch5_init[] = {
7769         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},             /* HP as rear */
7770         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Subwoofer on */
7771         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},    /* Line as input */
7772         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},   /* Line off */
7773         { } /* end */
7774 };
7775
7776 /* 6ch mode (Speaker:front, Subwoofer:off, Line:CLFE, Headphones:Rear) */
7777 static struct hda_verb alc889A_mb31_ch6_init[] = {
7778         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},             /* HP as front */
7779         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},   /* Subwoofer off */
7780         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},   /* Line as output */
7781         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Line on */
7782         { } /* end */
7783 };
7784
7785 static struct hda_channel_mode alc889A_mb31_6ch_modes[4] = {
7786         { 2, alc889A_mb31_ch2_init },
7787         { 4, alc889A_mb31_ch4_init },
7788         { 5, alc889A_mb31_ch5_init },
7789         { 6, alc889A_mb31_ch6_init },
7790 };
7791
7792 static struct hda_verb alc883_medion_eapd_verbs[] = {
7793         /* eanable EAPD on medion laptop */
7794         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7795         {0x20, AC_VERB_SET_PROC_COEF, 0x3070},
7796         { }
7797 };
7798
7799 #define alc883_base_mixer       alc882_base_mixer
7800
7801 static struct snd_kcontrol_new alc883_mitac_mixer[] = {
7802         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7803         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7804         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7805         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7806         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7807         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7808         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7809         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7810         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7811         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7812         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7813         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7814         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7815         { } /* end */
7816 };
7817
7818 static struct snd_kcontrol_new alc883_clevo_m720_mixer[] = {
7819         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7820         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7821         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7822         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7823         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7824         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7825         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7826         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7827         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7828         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7829         { } /* end */
7830 };
7831
7832 static struct snd_kcontrol_new alc883_2ch_fujitsu_pi2515_mixer[] = {
7833         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7834         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7835         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7836         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7837         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7838         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7839         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7840         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7841         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7842         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7843         { } /* end */
7844 };
7845
7846 static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
7847         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7848         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7849         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7850         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7851         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7852         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7853         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7854         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7855         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7856         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7857         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7858         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7859         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7860         { } /* end */
7861 };
7862
7863 static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
7864         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7865         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7866         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7867         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7868         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7869         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7870         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7871         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7872         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7873         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7874         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7875         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7876         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7877         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7878         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7879         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7880         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7881         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7882         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7883         { } /* end */
7884 };
7885
7886 static struct snd_kcontrol_new alc883_3ST_6ch_intel_mixer[] = {
7887         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7888         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7889         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7890         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7891         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
7892                               HDA_OUTPUT),
7893         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7894         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7895         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7896         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7897         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7898         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7899         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7900         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7901         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7902         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
7903         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7904         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7905         HDA_CODEC_VOLUME("Front Mic Boost", 0x18, 0, HDA_INPUT),
7906         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7907         { } /* end */
7908 };
7909
7910 static struct snd_kcontrol_new alc885_8ch_intel_mixer[] = {
7911         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7912         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7913         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7914         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7915         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
7916                               HDA_OUTPUT),
7917         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7918         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7919         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7920         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7921         HDA_BIND_MUTE("Speaker Playback Switch", 0x0f, 2, HDA_INPUT),
7922         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7923         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7924         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7925         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
7926         HDA_CODEC_VOLUME("Mic Boost", 0x1b, 0, HDA_INPUT),
7927         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
7928         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7929         HDA_CODEC_VOLUME("Front Mic Boost", 0x18, 0, HDA_INPUT),
7930         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7931         { } /* end */
7932 };
7933
7934 static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
7935         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7936         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7937         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7938         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7939         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7940         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7941         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7942         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7943         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7944         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7945         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7946         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7947         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7948         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7949         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7950         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7951         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7952         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7953         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7954         { } /* end */
7955 };
7956
7957 static struct snd_kcontrol_new alc883_targa_mixer[] = {
7958         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7959         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7960         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7961         HDA_CODEC_MUTE("Speaker Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7962         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7963         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7964         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7965         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7966         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7967         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7968         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7969         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7970         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7971         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7972         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7973         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7974         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7975         { } /* end */
7976 };
7977
7978 static struct snd_kcontrol_new alc883_targa_2ch_mixer[] = {
7979         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7980         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7981         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7982         HDA_CODEC_MUTE("Speaker Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7983         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7984         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7985         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7986         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7987         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7988         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7989         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7990         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7991         { } /* end */
7992 };
7993
7994 static struct snd_kcontrol_new alc883_targa_8ch_mixer[] = {
7995         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7996         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7997         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7998         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7999         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8000         { } /* end */
8001 };
8002
8003 static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
8004         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8005         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8006         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8007         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
8008         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8009         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8010         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8011         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8012         { } /* end */
8013 };
8014
8015 static struct snd_kcontrol_new alc883_lenovo_nb0763_mixer[] = {
8016         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8017         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
8018         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8019         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8020         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8021         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8022         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8023         HDA_CODEC_VOLUME("iMic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8024         HDA_CODEC_MUTE("iMic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8025         { } /* end */
8026 };
8027
8028 static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
8029         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8030         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8031         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8032         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8033         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8034         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8035         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8036         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8037         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8038         { } /* end */
8039 };
8040
8041 static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
8042         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8043         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8044         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8045         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8046         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8047         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8048         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8049         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8050         { } /* end */
8051 };
8052
8053 static struct snd_kcontrol_new alc888_acer_aspire_6530_mixer[] = {
8054         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8055         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8056         HDA_CODEC_VOLUME("LFE Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
8057         HDA_BIND_MUTE("LFE Playback Switch", 0x0f, 2, HDA_INPUT),
8058         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8059         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8060         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8061         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8062         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8063         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8064         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8065         { } /* end */
8066 };
8067
8068 static struct snd_kcontrol_new alc888_lenovo_sky_mixer[] = {
8069         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8070         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8071         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
8072         HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
8073         HDA_CODEC_VOLUME_MONO("Center Playback Volume",
8074                                                 0x0d, 1, 0x0, HDA_OUTPUT),
8075         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
8076         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
8077         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
8078         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
8079         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
8080         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8081         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8082         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8083         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8084         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8085         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8086         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8087         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8088         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8089         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8090         { } /* end */
8091 };
8092
8093 static struct snd_kcontrol_new alc889A_mb31_mixer[] = {
8094         /* Output mixers */
8095         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
8096         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
8097         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
8098         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 0x02, HDA_INPUT),
8099         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x00,
8100                 HDA_OUTPUT),
8101         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x02, HDA_INPUT),
8102         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x00, HDA_OUTPUT),
8103         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x02, HDA_INPUT),
8104         /* Output switches */
8105         HDA_CODEC_MUTE("Enable Speaker", 0x14, 0x00, HDA_OUTPUT),
8106         HDA_CODEC_MUTE("Enable Headphones", 0x15, 0x00, HDA_OUTPUT),
8107         HDA_CODEC_MUTE_MONO("Enable LFE", 0x16, 2, 0x00, HDA_OUTPUT),
8108         /* Boost mixers */
8109         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
8110         HDA_CODEC_VOLUME("Line Boost", 0x1a, 0x00, HDA_INPUT),
8111         /* Input mixers */
8112         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
8113         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
8114         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8115         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8116         { } /* end */
8117 };
8118
8119 static struct snd_kcontrol_new alc883_vaiott_mixer[] = {
8120         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8121         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8122         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8123         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8124         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
8125         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8126         { } /* end */
8127 };
8128
8129 static struct hda_bind_ctls alc883_bind_cap_vol = {
8130         .ops = &snd_hda_bind_vol,
8131         .values = {
8132                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
8133                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
8134                 0
8135         },
8136 };
8137
8138 static struct hda_bind_ctls alc883_bind_cap_switch = {
8139         .ops = &snd_hda_bind_sw,
8140         .values = {
8141                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
8142                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
8143                 0
8144         },
8145 };
8146
8147 static struct snd_kcontrol_new alc883_asus_eee1601_mixer[] = {
8148         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8149         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8150         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8151         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8152         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8153         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8154         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8155         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8156         { } /* end */
8157 };
8158
8159 static struct snd_kcontrol_new alc883_asus_eee1601_cap_mixer[] = {
8160         HDA_BIND_VOL("Capture Volume", &alc883_bind_cap_vol),
8161         HDA_BIND_SW("Capture Switch", &alc883_bind_cap_switch),
8162         {
8163                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8164                 /* .name = "Capture Source", */
8165                 .name = "Input Source",
8166                 .count = 1,
8167                 .info = alc_mux_enum_info,
8168                 .get = alc_mux_enum_get,
8169                 .put = alc_mux_enum_put,
8170         },
8171         { } /* end */
8172 };
8173
8174 static struct snd_kcontrol_new alc883_chmode_mixer[] = {
8175         {
8176                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8177                 .name = "Channel Mode",
8178                 .info = alc_ch_mode_info,
8179                 .get = alc_ch_mode_get,
8180                 .put = alc_ch_mode_put,
8181         },
8182         { } /* end */
8183 };
8184
8185 /* toggle speaker-output according to the hp-jack state */
8186 static void alc883_mitac_setup(struct hda_codec *codec)
8187 {
8188         struct alc_spec *spec = codec->spec;
8189
8190         spec->autocfg.hp_pins[0] = 0x15;
8191         spec->autocfg.speaker_pins[0] = 0x14;
8192         spec->autocfg.speaker_pins[1] = 0x17;
8193 }
8194
8195 /* auto-toggle front mic */
8196 /*
8197 static void alc883_mitac_mic_automute(struct hda_codec *codec)
8198 {
8199         unsigned int present;
8200         unsigned char bits;
8201
8202         present = snd_hda_codec_read(codec, 0x18, 0,
8203                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8204         bits = present ? HDA_AMP_MUTE : 0;
8205         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
8206 }
8207 */
8208
8209 static struct hda_verb alc883_mitac_verbs[] = {
8210         /* HP */
8211         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8212         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8213         /* Subwoofer */
8214         {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
8215         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8216
8217         /* enable unsolicited event */
8218         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8219         /* {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN}, */
8220
8221         { } /* end */
8222 };
8223
8224 static struct hda_verb alc883_clevo_m540r_verbs[] = {
8225         /* HP */
8226         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8227         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8228         /* Int speaker */
8229         /*{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},*/
8230
8231         /* enable unsolicited event */
8232         /*
8233         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8234         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
8235         */
8236
8237         { } /* end */
8238 };
8239
8240 static struct hda_verb alc883_clevo_m720_verbs[] = {
8241         /* HP */
8242         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8243         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8244         /* Int speaker */
8245         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
8246         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8247
8248         /* enable unsolicited event */
8249         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8250         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
8251
8252         { } /* end */
8253 };
8254
8255 static struct hda_verb alc883_2ch_fujitsu_pi2515_verbs[] = {
8256         /* HP */
8257         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8258         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8259         /* Subwoofer */
8260         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
8261         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8262
8263         /* enable unsolicited event */
8264         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8265
8266         { } /* end */
8267 };
8268
8269 static struct hda_verb alc883_targa_verbs[] = {
8270         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8271         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8272
8273         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8274         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8275
8276 /* Connect Line-Out side jack (SPDIF) to Side */
8277         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8278         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8279         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
8280 /* Connect Mic jack to CLFE */
8281         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8282         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8283         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},
8284 /* Connect Line-in jack to Surround */
8285         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8286         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8287         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
8288 /* Connect HP out jack to Front */
8289         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8290         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8291         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8292
8293         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8294
8295         { } /* end */
8296 };
8297
8298 static struct hda_verb alc883_lenovo_101e_verbs[] = {
8299         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8300         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT|AC_USRSP_EN},
8301         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT|AC_USRSP_EN},
8302         { } /* end */
8303 };
8304
8305 static struct hda_verb alc883_lenovo_nb0763_verbs[] = {
8306         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8307         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8308         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8309         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8310         { } /* end */
8311 };
8312
8313 static struct hda_verb alc888_lenovo_ms7195_verbs[] = {
8314         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8315         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8316         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8317         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT | AC_USRSP_EN},
8318         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT    | AC_USRSP_EN},
8319         { } /* end */
8320 };
8321
8322 static struct hda_verb alc883_haier_w66_verbs[] = {
8323         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8324         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8325
8326         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8327
8328         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8329         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8330         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8331         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8332         { } /* end */
8333 };
8334
8335 static struct hda_verb alc888_lenovo_sky_verbs[] = {
8336         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8337         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8338         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8339         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8340         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8341         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8342         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
8343         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8344         { } /* end */
8345 };
8346
8347 static struct hda_verb alc888_6st_dell_verbs[] = {
8348         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8349         { }
8350 };
8351
8352 static struct hda_verb alc883_vaiott_verbs[] = {
8353         /* HP */
8354         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8355         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8356
8357         /* enable unsolicited event */
8358         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8359
8360         { } /* end */
8361 };
8362
8363 static void alc888_3st_hp_setup(struct hda_codec *codec)
8364 {
8365         struct alc_spec *spec = codec->spec;
8366
8367         spec->autocfg.hp_pins[0] = 0x1b;
8368         spec->autocfg.speaker_pins[0] = 0x14;
8369         spec->autocfg.speaker_pins[1] = 0x16;
8370         spec->autocfg.speaker_pins[2] = 0x18;
8371 }
8372
8373 static struct hda_verb alc888_3st_hp_verbs[] = {
8374         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
8375         {0x16, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Rear : output 1 (0x0d) */
8376         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},  /* CLFE : output 2 (0x0e) */
8377         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8378         { } /* end */
8379 };
8380
8381 /*
8382  * 2ch mode
8383  */
8384 static struct hda_verb alc888_3st_hp_2ch_init[] = {
8385         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
8386         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8387         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
8388         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8389         { } /* end */
8390 };
8391
8392 /*
8393  * 4ch mode
8394  */
8395 static struct hda_verb alc888_3st_hp_4ch_init[] = {
8396         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
8397         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8398         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8399         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8400         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x01 },
8401         { } /* end */
8402 };
8403
8404 /*
8405  * 6ch mode
8406  */
8407 static struct hda_verb alc888_3st_hp_6ch_init[] = {
8408         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8409         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8410         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
8411         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8412         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8413         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x01 },
8414         { } /* end */
8415 };
8416
8417 static struct hda_channel_mode alc888_3st_hp_modes[3] = {
8418         { 2, alc888_3st_hp_2ch_init },
8419         { 4, alc888_3st_hp_4ch_init },
8420         { 6, alc888_3st_hp_6ch_init },
8421 };
8422
8423 /* toggle front-jack and RCA according to the hp-jack state */
8424 static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
8425 {
8426         unsigned int present;
8427
8428         present = snd_hda_codec_read(codec, 0x1b, 0,
8429                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8430         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8431                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8432         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8433                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8434 }
8435
8436 /* toggle RCA according to the front-jack state */
8437 static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
8438 {
8439         unsigned int present;
8440
8441         present = snd_hda_codec_read(codec, 0x14, 0,
8442                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8443         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8444                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8445 }
8446
8447 static void alc883_lenovo_ms7195_unsol_event(struct hda_codec *codec,
8448                                              unsigned int res)
8449 {
8450         if ((res >> 26) == ALC880_HP_EVENT)
8451                 alc888_lenovo_ms7195_front_automute(codec);
8452         if ((res >> 26) == ALC880_FRONT_EVENT)
8453                 alc888_lenovo_ms7195_rca_automute(codec);
8454 }
8455
8456 static struct hda_verb alc883_medion_md2_verbs[] = {
8457         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8458         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8459
8460         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8461
8462         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8463         { } /* end */
8464 };
8465
8466 /* toggle speaker-output according to the hp-jack state */
8467 static void alc883_medion_md2_setup(struct hda_codec *codec)
8468 {
8469         struct alc_spec *spec = codec->spec;
8470
8471         spec->autocfg.hp_pins[0] = 0x14;
8472         spec->autocfg.speaker_pins[0] = 0x15;
8473 }
8474
8475 /* toggle speaker-output according to the hp-jack state */
8476 #define alc883_targa_init_hook          alc882_targa_init_hook
8477 #define alc883_targa_unsol_event        alc882_targa_unsol_event
8478
8479 static void alc883_clevo_m720_mic_automute(struct hda_codec *codec)
8480 {
8481         unsigned int present;
8482
8483         present = snd_hda_codec_read(codec, 0x18, 0,
8484                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8485         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
8486                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8487 }
8488
8489 static void alc883_clevo_m720_setup(struct hda_codec *codec)
8490 {
8491         struct alc_spec *spec = codec->spec;
8492
8493         spec->autocfg.hp_pins[0] = 0x15;
8494         spec->autocfg.speaker_pins[0] = 0x14;
8495 }
8496
8497 static void alc883_clevo_m720_init_hook(struct hda_codec *codec)
8498 {
8499         alc_automute_amp(codec);
8500         alc883_clevo_m720_mic_automute(codec);
8501 }
8502
8503 static void alc883_clevo_m720_unsol_event(struct hda_codec *codec,
8504                                            unsigned int res)
8505 {
8506         switch (res >> 26) {
8507         case ALC880_MIC_EVENT:
8508                 alc883_clevo_m720_mic_automute(codec);
8509                 break;
8510         default:
8511                 alc_automute_amp_unsol_event(codec, res);
8512                 break;
8513         }
8514 }
8515
8516 /* toggle speaker-output according to the hp-jack state */
8517 static void alc883_2ch_fujitsu_pi2515_setup(struct hda_codec *codec)
8518 {
8519         struct alc_spec *spec = codec->spec;
8520
8521         spec->autocfg.hp_pins[0] = 0x14;
8522         spec->autocfg.speaker_pins[0] = 0x15;
8523 }
8524
8525 static void alc883_haier_w66_setup(struct hda_codec *codec)
8526 {
8527         struct alc_spec *spec = codec->spec;
8528
8529         spec->autocfg.hp_pins[0] = 0x1b;
8530         spec->autocfg.speaker_pins[0] = 0x14;
8531 }
8532
8533 static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
8534 {
8535         unsigned int present;
8536         unsigned char bits;
8537
8538         present = snd_hda_codec_read(codec, 0x14, 0, AC_VERB_GET_PIN_SENSE, 0)
8539                 & AC_PINSENSE_PRESENCE;
8540         bits = present ? HDA_AMP_MUTE : 0;
8541         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8542                                  HDA_AMP_MUTE, bits);
8543 }
8544
8545 static void alc883_lenovo_101e_all_automute(struct hda_codec *codec)
8546 {
8547         unsigned int present;
8548         unsigned char bits;
8549
8550         present = snd_hda_codec_read(codec, 0x1b, 0,
8551                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8552         bits = present ? HDA_AMP_MUTE : 0;
8553         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8554                                  HDA_AMP_MUTE, bits);
8555         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8556                                  HDA_AMP_MUTE, bits);
8557 }
8558
8559 static void alc883_lenovo_101e_unsol_event(struct hda_codec *codec,
8560                                            unsigned int res)
8561 {
8562         if ((res >> 26) == ALC880_HP_EVENT)
8563                 alc883_lenovo_101e_all_automute(codec);
8564         if ((res >> 26) == ALC880_FRONT_EVENT)
8565                 alc883_lenovo_101e_ispeaker_automute(codec);
8566 }
8567
8568 /* toggle speaker-output according to the hp-jack state */
8569 static void alc883_acer_aspire_setup(struct hda_codec *codec)
8570 {
8571         struct alc_spec *spec = codec->spec;
8572
8573         spec->autocfg.hp_pins[0] = 0x14;
8574         spec->autocfg.speaker_pins[0] = 0x15;
8575         spec->autocfg.speaker_pins[1] = 0x16;
8576 }
8577
8578 static struct hda_verb alc883_acer_eapd_verbs[] = {
8579         /* HP Pin: output 0 (0x0c) */
8580         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8581         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8582         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8583         /* Front Pin: output 0 (0x0c) */
8584         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8585         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8586         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8587         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
8588         /* eanable EAPD on medion laptop */
8589         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
8590         {0x20, AC_VERB_SET_PROC_COEF, 0x3050},
8591         /* enable unsolicited event */
8592         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8593         { }
8594 };
8595
8596 static struct hda_verb alc888_acer_aspire_7730G_verbs[] = {
8597         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8598         {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
8599         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8600         { } /* end */
8601 };
8602
8603 static void alc888_6st_dell_setup(struct hda_codec *codec)
8604 {
8605         struct alc_spec *spec = codec->spec;
8606
8607         spec->autocfg.hp_pins[0] = 0x1b;
8608         spec->autocfg.speaker_pins[0] = 0x14;
8609         spec->autocfg.speaker_pins[1] = 0x15;
8610         spec->autocfg.speaker_pins[2] = 0x16;
8611         spec->autocfg.speaker_pins[3] = 0x17;
8612 }
8613
8614 static void alc888_lenovo_sky_setup(struct hda_codec *codec)
8615 {
8616         struct alc_spec *spec = codec->spec;
8617
8618         spec->autocfg.hp_pins[0] = 0x1b;
8619         spec->autocfg.speaker_pins[0] = 0x14;
8620         spec->autocfg.speaker_pins[1] = 0x15;
8621         spec->autocfg.speaker_pins[2] = 0x16;
8622         spec->autocfg.speaker_pins[3] = 0x17;
8623         spec->autocfg.speaker_pins[4] = 0x1a;
8624 }
8625
8626 static void alc883_vaiott_setup(struct hda_codec *codec)
8627 {
8628         struct alc_spec *spec = codec->spec;
8629
8630         spec->autocfg.hp_pins[0] = 0x15;
8631         spec->autocfg.speaker_pins[0] = 0x14;
8632         spec->autocfg.speaker_pins[1] = 0x17;
8633 }
8634
8635 static struct hda_verb alc888_asus_m90v_verbs[] = {
8636         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8637         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8638         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8639         /* enable unsolicited event */
8640         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8641         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
8642         { } /* end */
8643 };
8644
8645 static void alc883_mode2_setup(struct hda_codec *codec)
8646 {
8647         struct alc_spec *spec = codec->spec;
8648
8649         spec->autocfg.hp_pins[0] = 0x1b;
8650         spec->autocfg.speaker_pins[0] = 0x14;
8651         spec->autocfg.speaker_pins[1] = 0x15;
8652         spec->autocfg.speaker_pins[2] = 0x16;
8653         spec->ext_mic.pin = 0x18;
8654         spec->int_mic.pin = 0x19;
8655         spec->ext_mic.mux_idx = 0;
8656         spec->int_mic.mux_idx = 1;
8657         spec->auto_mic = 1;
8658 }
8659
8660 static struct hda_verb alc888_asus_eee1601_verbs[] = {
8661         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8662         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8663         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8664         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8665         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8666         {0x20, AC_VERB_SET_COEF_INDEX, 0x0b},
8667         {0x20, AC_VERB_SET_PROC_COEF,  0x0838},
8668         /* enable unsolicited event */
8669         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8670         { } /* end */
8671 };
8672
8673 static void alc883_eee1601_inithook(struct hda_codec *codec)
8674 {
8675         struct alc_spec *spec = codec->spec;
8676
8677         spec->autocfg.hp_pins[0] = 0x14;
8678         spec->autocfg.speaker_pins[0] = 0x1b;
8679         alc_automute_pin(codec);
8680 }
8681
8682 static struct hda_verb alc889A_mb31_verbs[] = {
8683         /* Init rear pin (used as headphone output) */
8684         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},    /* Apple Headphones */
8685         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},           /* Connect to front */
8686         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8687         /* Init line pin (used as output in 4ch and 6ch mode) */
8688         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x02},           /* Connect to CLFE */
8689         /* Init line 2 pin (used as headphone out by default) */
8690         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},  /* Use as input */
8691         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Mute output */
8692         { } /* end */
8693 };
8694
8695 /* Mute speakers according to the headphone jack state */
8696 static void alc889A_mb31_automute(struct hda_codec *codec)
8697 {
8698         unsigned int present;
8699
8700         /* Mute only in 2ch or 4ch mode */
8701         if (snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_CONNECT_SEL, 0)
8702             == 0x00) {
8703                 present = snd_hda_codec_read(codec, 0x15, 0,
8704                         AC_VERB_GET_PIN_SENSE, 0) & AC_PINSENSE_PRESENCE;
8705                 snd_hda_codec_amp_stereo(codec, 0x14,  HDA_OUTPUT, 0,
8706                         HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8707                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8708                         HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8709         }
8710 }
8711
8712 static void alc889A_mb31_unsol_event(struct hda_codec *codec, unsigned int res)
8713 {
8714         if ((res >> 26) == ALC880_HP_EVENT)
8715                 alc889A_mb31_automute(codec);
8716 }
8717
8718
8719 #ifdef CONFIG_SND_HDA_POWER_SAVE
8720 #define alc882_loopbacks        alc880_loopbacks
8721 #endif
8722
8723 /* pcm configuration: identical with ALC880 */
8724 #define alc882_pcm_analog_playback      alc880_pcm_analog_playback
8725 #define alc882_pcm_analog_capture       alc880_pcm_analog_capture
8726 #define alc882_pcm_digital_playback     alc880_pcm_digital_playback
8727 #define alc882_pcm_digital_capture      alc880_pcm_digital_capture
8728
8729 static hda_nid_t alc883_slave_dig_outs[] = {
8730         ALC1200_DIGOUT_NID, 0,
8731 };
8732
8733 static hda_nid_t alc1200_slave_dig_outs[] = {
8734         ALC883_DIGOUT_NID, 0,
8735 };
8736
8737 /*
8738  * configuration and preset
8739  */
8740 static const char *alc882_models[ALC882_MODEL_LAST] = {
8741         [ALC882_3ST_DIG]        = "3stack-dig",
8742         [ALC882_6ST_DIG]        = "6stack-dig",
8743         [ALC882_ARIMA]          = "arima",
8744         [ALC882_W2JC]           = "w2jc",
8745         [ALC882_TARGA]          = "targa",
8746         [ALC882_ASUS_A7J]       = "asus-a7j",
8747         [ALC882_ASUS_A7M]       = "asus-a7m",
8748         [ALC885_MACPRO]         = "macpro",
8749         [ALC885_MB5]            = "mb5",
8750         [ALC885_MBP3]           = "mbp3",
8751         [ALC885_IMAC24]         = "imac24",
8752         [ALC883_3ST_2ch_DIG]    = "3stack-2ch-dig",
8753         [ALC883_3ST_6ch_DIG]    = "3stack-6ch-dig",
8754         [ALC883_3ST_6ch]        = "3stack-6ch",
8755         [ALC883_6ST_DIG]        = "alc883-6stack-dig",
8756         [ALC883_TARGA_DIG]      = "targa-dig",
8757         [ALC883_TARGA_2ch_DIG]  = "targa-2ch-dig",
8758         [ALC883_TARGA_8ch_DIG]  = "targa-8ch-dig",
8759         [ALC883_ACER]           = "acer",
8760         [ALC883_ACER_ASPIRE]    = "acer-aspire",
8761         [ALC888_ACER_ASPIRE_4930G]      = "acer-aspire-4930g",
8762         [ALC888_ACER_ASPIRE_6530G]      = "acer-aspire-6530g",
8763         [ALC888_ACER_ASPIRE_8930G]      = "acer-aspire-8930g",
8764         [ALC888_ACER_ASPIRE_7730G]      = "acer-aspire-7730g",
8765         [ALC883_MEDION]         = "medion",
8766         [ALC883_MEDION_MD2]     = "medion-md2",
8767         [ALC883_LAPTOP_EAPD]    = "laptop-eapd",
8768         [ALC883_LENOVO_101E_2ch] = "lenovo-101e",
8769         [ALC883_LENOVO_NB0763]  = "lenovo-nb0763",
8770         [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
8771         [ALC888_LENOVO_SKY] = "lenovo-sky",
8772         [ALC883_HAIER_W66]      = "haier-w66",
8773         [ALC888_3ST_HP]         = "3stack-hp",
8774         [ALC888_6ST_DELL]       = "6stack-dell",
8775         [ALC883_MITAC]          = "mitac",
8776         [ALC883_CLEVO_M540R]    = "clevo-m540r",
8777         [ALC883_CLEVO_M720]     = "clevo-m720",
8778         [ALC883_FUJITSU_PI2515] = "fujitsu-pi2515",
8779         [ALC888_FUJITSU_XA3530] = "fujitsu-xa3530",
8780         [ALC883_3ST_6ch_INTEL]  = "3stack-6ch-intel",
8781         [ALC889A_INTEL]         = "intel-alc889a",
8782         [ALC889_INTEL]          = "intel-x58",
8783         [ALC1200_ASUS_P5Q]      = "asus-p5q",
8784         [ALC889A_MB31]          = "mb31",
8785         [ALC883_SONY_VAIO_TT]   = "sony-vaio-tt",
8786         [ALC882_AUTO]           = "auto",
8787 };
8788
8789 static struct snd_pci_quirk alc882_cfg_tbl[] = {
8790         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),
8791
8792         SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE),
8793         SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_ACER_ASPIRE),
8794         SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_ACER_ASPIRE),
8795         SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE),
8796         SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE),
8797         SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_ACER_ASPIRE),
8798         SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
8799                 ALC888_ACER_ASPIRE_4930G),
8800         SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
8801                 ALC888_ACER_ASPIRE_4930G),
8802         SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
8803                 ALC888_ACER_ASPIRE_8930G),
8804         SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
8805                 ALC888_ACER_ASPIRE_8930G),
8806         SND_PCI_QUIRK(0x1025, 0x0157, "Acer X3200", ALC882_AUTO),
8807         SND_PCI_QUIRK(0x1025, 0x0158, "Acer AX1700-U3700A", ALC882_AUTO),
8808         SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
8809                 ALC888_ACER_ASPIRE_6530G),
8810         SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
8811                 ALC888_ACER_ASPIRE_6530G),
8812         SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
8813                 ALC888_ACER_ASPIRE_7730G),
8814         /* default Acer -- disabled as it causes more problems.
8815          *    model=auto should work fine now
8816          */
8817         /* SND_PCI_QUIRK_VENDOR(0x1025, "Acer laptop", ALC883_ACER), */
8818
8819         SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL),
8820
8821         SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
8822         SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
8823         SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
8824         SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG),
8825         SND_PCI_QUIRK(0x103c, 0x2a66, "HP Acacia", ALC888_3ST_HP),
8826         SND_PCI_QUIRK(0x103c, 0x2a72, "HP Educ.ar", ALC888_3ST_HP),
8827
8828         SND_PCI_QUIRK(0x1043, 0x060d, "Asus A7J", ALC882_ASUS_A7J),
8829         SND_PCI_QUIRK(0x1043, 0x1243, "Asus A7J", ALC882_ASUS_A7J),
8830         SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_ASUS_A7M),
8831         SND_PCI_QUIRK(0x1043, 0x1873, "Asus M90V", ALC888_ASUS_M90V),
8832         SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_W2JC),
8833         SND_PCI_QUIRK(0x1043, 0x817f, "Asus P5LD2", ALC882_6ST_DIG),
8834         SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
8835         SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG),
8836         SND_PCI_QUIRK(0x1043, 0x8284, "Asus Z37E", ALC883_6ST_DIG),
8837         SND_PCI_QUIRK(0x1043, 0x82fe, "Asus P5Q-EM HDMI", ALC1200_ASUS_P5Q),
8838         SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_ASUS_EEE1601),
8839
8840         SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC883_SONY_VAIO_TT),
8841         SND_PCI_QUIRK(0x105b, 0x0ce8, "Foxconn P35AX-S", ALC883_6ST_DIG),
8842         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
8843         SND_PCI_QUIRK(0x1071, 0x8227, "Mitac 82801H", ALC883_MITAC),
8844         SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC),
8845         SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
8846         SND_PCI_QUIRK(0x10f1, 0x2350, "TYAN-S2350", ALC888_6ST_DELL),
8847         SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
8848         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte P35 DS3R", ALC882_6ST_DIG),
8849
8850         SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
8851         SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG),
8852         SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
8853         SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8  */
8854         SND_PCI_QUIRK(0x1462, 0x2fb3, "MSI", ALC883_TARGA_2ch_DIG),
8855         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
8856         SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
8857         SND_PCI_QUIRK(0x1462, 0x3783, "NEC S970", ALC883_TARGA_DIG),
8858         SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
8859         SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
8860         SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
8861         SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG),
8862         SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG),
8863         SND_PCI_QUIRK(0x1462, 0x3fdf, "MSI", ALC883_TARGA_DIG),
8864         SND_PCI_QUIRK(0x1462, 0x42cd, "MSI", ALC883_TARGA_DIG),
8865         SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
8866         SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
8867         SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
8868         SND_PCI_QUIRK(0x1462, 0x6510, "MSI GX620", ALC883_TARGA_8ch_DIG),
8869         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
8870         SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
8871         SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
8872         SND_PCI_QUIRK(0x1462, 0x7260, "MSI 7260", ALC883_TARGA_DIG),
8873         SND_PCI_QUIRK(0x1462, 0x7267, "MSI", ALC883_3ST_6ch_DIG),
8874         SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
8875         SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
8876         SND_PCI_QUIRK(0x1462, 0x7350, "MSI", ALC883_6ST_DIG),
8877         SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
8878         SND_PCI_QUIRK(0x1462, 0xaa08, "MSI", ALC883_TARGA_2ch_DIG),
8879
8880         SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG),
8881         SND_PCI_QUIRK(0x1558, 0x0721, "Clevo laptop M720R", ALC883_CLEVO_M720),
8882         SND_PCI_QUIRK(0x1558, 0x0722, "Clevo laptop M720SR", ALC883_CLEVO_M720),
8883         SND_PCI_QUIRK(0x1558, 0x5409, "Clevo laptop M540R", ALC883_CLEVO_M540R),
8884         SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC883_LAPTOP_EAPD),
8885         SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
8886         /* SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA), */
8887         SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
8888         SND_PCI_QUIRK_MASK(0x1734, 0xfff0, 0x1100, "FSC AMILO Xi/Pi25xx",
8889                       ALC883_FUJITSU_PI2515),
8890         SND_PCI_QUIRK_MASK(0x1734, 0xfff0, 0x1130, "Fujitsu AMILO Xa35xx",
8891                 ALC888_FUJITSU_XA3530),
8892         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
8893         SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8894         SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8895         SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8896         SND_PCI_QUIRK(0x17aa, 0x101d, "Lenovo Sky", ALC888_LENOVO_SKY),
8897         SND_PCI_QUIRK(0x17c0, 0x4071, "MEDION MD2", ALC883_MEDION_MD2),
8898         SND_PCI_QUIRK(0x17c0, 0x4085, "MEDION MD96630", ALC888_LENOVO_MS7195_DIG),
8899         SND_PCI_QUIRK(0x17f2, 0x5000, "Albatron KI690-AM2", ALC883_6ST_DIG),
8900         SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66),
8901
8902         SND_PCI_QUIRK(0x8086, 0x0001, "DG33BUC", ALC883_3ST_6ch_INTEL),
8903         SND_PCI_QUIRK(0x8086, 0x0002, "DG33FBC", ALC883_3ST_6ch_INTEL),
8904         SND_PCI_QUIRK(0x8086, 0x2503, "82801H", ALC883_MITAC),
8905         SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_INTEL),
8906         SND_PCI_QUIRK(0x8086, 0x0021, "Intel IbexPeak", ALC889A_INTEL),
8907         SND_PCI_QUIRK(0x8086, 0x3b56, "Intel IbexPeak", ALC889A_INTEL),
8908         SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch),
8909
8910         {}
8911 };
8912
8913 /* codec SSID table for Intel Mac */
8914 static struct snd_pci_quirk alc882_ssid_cfg_tbl[] = {
8915         SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC885_MBP3),
8916         SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC885_MBP3),
8917         SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC885_MBP3),
8918         SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_MACPRO),
8919         SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_IMAC24),
8920         SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_IMAC24),
8921         SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC885_MBP3),
8922         SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889A_MB31),
8923         SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC885_MBP3),
8924         SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_IMAC24),
8925         SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC885_MB5),
8926         /* FIXME: HP jack sense seems not working for MBP 5,1 or 5,2,
8927          * so apparently no perfect solution yet
8928          */
8929         SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC885_MB5),
8930         SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC885_MB5),
8931         {} /* terminator */
8932 };
8933
8934 static struct alc_config_preset alc882_presets[] = {
8935         [ALC882_3ST_DIG] = {
8936                 .mixers = { alc882_base_mixer },
8937                 .init_verbs = { alc882_base_init_verbs,
8938                                 alc882_adc1_init_verbs },
8939                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
8940                 .dac_nids = alc882_dac_nids,
8941                 .dig_out_nid = ALC882_DIGOUT_NID,
8942                 .dig_in_nid = ALC882_DIGIN_NID,
8943                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
8944                 .channel_mode = alc882_ch_modes,
8945                 .need_dac_fix = 1,
8946                 .input_mux = &alc882_capture_source,
8947         },
8948         [ALC882_6ST_DIG] = {
8949                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
8950                 .init_verbs = { alc882_base_init_verbs,
8951                                 alc882_adc1_init_verbs },
8952                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
8953                 .dac_nids = alc882_dac_nids,
8954                 .dig_out_nid = ALC882_DIGOUT_NID,
8955                 .dig_in_nid = ALC882_DIGIN_NID,
8956                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
8957                 .channel_mode = alc882_sixstack_modes,
8958                 .input_mux = &alc882_capture_source,
8959         },
8960         [ALC882_ARIMA] = {
8961                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
8962                 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
8963                                 alc882_eapd_verbs },
8964                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
8965                 .dac_nids = alc882_dac_nids,
8966                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
8967                 .channel_mode = alc882_sixstack_modes,
8968                 .input_mux = &alc882_capture_source,
8969         },
8970         [ALC882_W2JC] = {
8971                 .mixers = { alc882_w2jc_mixer, alc882_chmode_mixer },
8972                 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
8973                                 alc882_eapd_verbs, alc880_gpio1_init_verbs },
8974                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
8975                 .dac_nids = alc882_dac_nids,
8976                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
8977                 .channel_mode = alc880_threestack_modes,
8978                 .need_dac_fix = 1,
8979                 .input_mux = &alc882_capture_source,
8980                 .dig_out_nid = ALC882_DIGOUT_NID,
8981         },
8982         [ALC885_MBP3] = {
8983                 .mixers = { alc885_mbp3_mixer, alc882_chmode_mixer },
8984                 .init_verbs = { alc885_mbp3_init_verbs,
8985                                 alc880_gpio1_init_verbs },
8986                 .num_dacs = 2,
8987                 .dac_nids = alc882_dac_nids,
8988                 .hp_nid = 0x04,
8989                 .channel_mode = alc885_mbp_4ch_modes,
8990                 .num_channel_mode = ARRAY_SIZE(alc885_mbp_4ch_modes),
8991                 .input_mux = &alc882_capture_source,
8992                 .dig_out_nid = ALC882_DIGOUT_NID,
8993                 .dig_in_nid = ALC882_DIGIN_NID,
8994                 .unsol_event = alc_automute_amp_unsol_event,
8995                 .setup = alc885_mbp3_setup,
8996                 .init_hook = alc_automute_amp,
8997         },
8998         [ALC885_MB5] = {
8999                 .mixers = { alc885_mb5_mixer, alc882_chmode_mixer },
9000                 .init_verbs = { alc885_mb5_init_verbs,
9001                                 alc880_gpio1_init_verbs },
9002                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
9003                 .dac_nids = alc882_dac_nids,
9004                 .channel_mode = alc885_mb5_6ch_modes,
9005                 .num_channel_mode = ARRAY_SIZE(alc885_mb5_6ch_modes),
9006                 .input_mux = &mb5_capture_source,
9007                 .dig_out_nid = ALC882_DIGOUT_NID,
9008                 .dig_in_nid = ALC882_DIGIN_NID,
9009         },
9010         [ALC885_MACPRO] = {
9011                 .mixers = { alc882_macpro_mixer },
9012                 .init_verbs = { alc882_macpro_init_verbs },
9013                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
9014                 .dac_nids = alc882_dac_nids,
9015                 .dig_out_nid = ALC882_DIGOUT_NID,
9016                 .dig_in_nid = ALC882_DIGIN_NID,
9017                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
9018                 .channel_mode = alc882_ch_modes,
9019                 .input_mux = &alc882_capture_source,
9020                 .init_hook = alc885_macpro_init_hook,
9021         },
9022         [ALC885_IMAC24] = {
9023                 .mixers = { alc885_imac24_mixer },
9024                 .init_verbs = { alc885_imac24_init_verbs },
9025                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
9026                 .dac_nids = alc882_dac_nids,
9027                 .dig_out_nid = ALC882_DIGOUT_NID,
9028                 .dig_in_nid = ALC882_DIGIN_NID,
9029                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
9030                 .channel_mode = alc882_ch_modes,
9031                 .input_mux = &alc882_capture_source,
9032                 .unsol_event = alc_automute_amp_unsol_event,
9033                 .setup = alc885_imac24_setup,
9034                 .init_hook = alc885_imac24_init_hook,
9035         },
9036         [ALC882_TARGA] = {
9037                 .mixers = { alc882_targa_mixer, alc882_chmode_mixer },
9038                 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
9039                                 alc880_gpio3_init_verbs, alc882_targa_verbs},
9040                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
9041                 .dac_nids = alc882_dac_nids,
9042                 .dig_out_nid = ALC882_DIGOUT_NID,
9043                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
9044                 .adc_nids = alc882_adc_nids,
9045                 .capsrc_nids = alc882_capsrc_nids,
9046                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
9047                 .channel_mode = alc882_3ST_6ch_modes,
9048                 .need_dac_fix = 1,
9049                 .input_mux = &alc882_capture_source,
9050                 .unsol_event = alc882_targa_unsol_event,
9051                 .setup = alc882_targa_setup,
9052                 .init_hook = alc882_targa_automute,
9053         },
9054         [ALC882_ASUS_A7J] = {
9055                 .mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer },
9056                 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
9057                                 alc882_asus_a7j_verbs},
9058                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
9059                 .dac_nids = alc882_dac_nids,
9060                 .dig_out_nid = ALC882_DIGOUT_NID,
9061                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
9062                 .adc_nids = alc882_adc_nids,
9063                 .capsrc_nids = alc882_capsrc_nids,
9064                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
9065                 .channel_mode = alc882_3ST_6ch_modes,
9066                 .need_dac_fix = 1,
9067                 .input_mux = &alc882_capture_source,
9068         },
9069         [ALC882_ASUS_A7M] = {
9070                 .mixers = { alc882_asus_a7m_mixer, alc882_chmode_mixer },
9071                 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
9072                                 alc882_eapd_verbs, alc880_gpio1_init_verbs,
9073                                 alc882_asus_a7m_verbs },
9074                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
9075                 .dac_nids = alc882_dac_nids,
9076                 .dig_out_nid = ALC882_DIGOUT_NID,
9077                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
9078                 .channel_mode = alc880_threestack_modes,
9079                 .need_dac_fix = 1,
9080                 .input_mux = &alc882_capture_source,
9081         },
9082         [ALC883_3ST_2ch_DIG] = {
9083                 .mixers = { alc883_3ST_2ch_mixer },
9084                 .init_verbs = { alc883_init_verbs },
9085                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9086                 .dac_nids = alc883_dac_nids,
9087                 .dig_out_nid = ALC883_DIGOUT_NID,
9088                 .dig_in_nid = ALC883_DIGIN_NID,
9089                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9090                 .channel_mode = alc883_3ST_2ch_modes,
9091                 .input_mux = &alc883_capture_source,
9092         },
9093         [ALC883_3ST_6ch_DIG] = {
9094                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9095                 .init_verbs = { alc883_init_verbs },
9096                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9097                 .dac_nids = alc883_dac_nids,
9098                 .dig_out_nid = ALC883_DIGOUT_NID,
9099                 .dig_in_nid = ALC883_DIGIN_NID,
9100                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9101                 .channel_mode = alc883_3ST_6ch_modes,
9102                 .need_dac_fix = 1,
9103                 .input_mux = &alc883_capture_source,
9104         },
9105         [ALC883_3ST_6ch] = {
9106                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9107                 .init_verbs = { alc883_init_verbs },
9108                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9109                 .dac_nids = alc883_dac_nids,
9110                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9111                 .channel_mode = alc883_3ST_6ch_modes,
9112                 .need_dac_fix = 1,
9113                 .input_mux = &alc883_capture_source,
9114         },
9115         [ALC883_3ST_6ch_INTEL] = {
9116                 .mixers = { alc883_3ST_6ch_intel_mixer, alc883_chmode_mixer },
9117                 .init_verbs = { alc883_init_verbs },
9118                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9119                 .dac_nids = alc883_dac_nids,
9120                 .dig_out_nid = ALC883_DIGOUT_NID,
9121                 .dig_in_nid = ALC883_DIGIN_NID,
9122                 .slave_dig_outs = alc883_slave_dig_outs,
9123                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_intel_modes),
9124                 .channel_mode = alc883_3ST_6ch_intel_modes,
9125                 .need_dac_fix = 1,
9126                 .input_mux = &alc883_3stack_6ch_intel,
9127         },
9128         [ALC889A_INTEL] = {
9129                 .mixers = { alc885_8ch_intel_mixer, alc883_chmode_mixer },
9130                 .init_verbs = { alc885_init_verbs, alc885_init_input_verbs,
9131                                 alc_hp15_unsol_verbs },
9132                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9133                 .dac_nids = alc883_dac_nids,
9134                 .num_adc_nids = ARRAY_SIZE(alc889_adc_nids),
9135                 .adc_nids = alc889_adc_nids,
9136                 .dig_out_nid = ALC883_DIGOUT_NID,
9137                 .dig_in_nid = ALC883_DIGIN_NID,
9138                 .slave_dig_outs = alc883_slave_dig_outs,
9139                 .num_channel_mode = ARRAY_SIZE(alc889_8ch_intel_modes),
9140                 .channel_mode = alc889_8ch_intel_modes,
9141                 .capsrc_nids = alc889_capsrc_nids,
9142                 .input_mux = &alc889_capture_source,
9143                 .setup = alc889_automute_setup,
9144                 .init_hook = alc_automute_amp,
9145                 .unsol_event = alc_automute_amp_unsol_event,
9146                 .need_dac_fix = 1,
9147         },
9148         [ALC889_INTEL] = {
9149                 .mixers = { alc885_8ch_intel_mixer, alc883_chmode_mixer },
9150                 .init_verbs = { alc885_init_verbs, alc889_init_input_verbs,
9151                                 alc889_eapd_verbs, alc_hp15_unsol_verbs},
9152                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9153                 .dac_nids = alc883_dac_nids,
9154                 .num_adc_nids = ARRAY_SIZE(alc889_adc_nids),
9155                 .adc_nids = alc889_adc_nids,
9156                 .dig_out_nid = ALC883_DIGOUT_NID,
9157                 .dig_in_nid = ALC883_DIGIN_NID,
9158                 .slave_dig_outs = alc883_slave_dig_outs,
9159                 .num_channel_mode = ARRAY_SIZE(alc889_8ch_intel_modes),
9160                 .channel_mode = alc889_8ch_intel_modes,
9161                 .capsrc_nids = alc889_capsrc_nids,
9162                 .input_mux = &alc889_capture_source,
9163                 .setup = alc889_automute_setup,
9164                 .init_hook = alc889_intel_init_hook,
9165                 .unsol_event = alc_automute_amp_unsol_event,
9166                 .need_dac_fix = 1,
9167         },
9168         [ALC883_6ST_DIG] = {
9169                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
9170                 .init_verbs = { alc883_init_verbs },
9171                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9172                 .dac_nids = alc883_dac_nids,
9173                 .dig_out_nid = ALC883_DIGOUT_NID,
9174                 .dig_in_nid = ALC883_DIGIN_NID,
9175                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9176                 .channel_mode = alc883_sixstack_modes,
9177                 .input_mux = &alc883_capture_source,
9178         },
9179         [ALC883_TARGA_DIG] = {
9180                 .mixers = { alc883_targa_mixer, alc883_chmode_mixer },
9181                 .init_verbs = { alc883_init_verbs, alc880_gpio3_init_verbs,
9182                                 alc883_targa_verbs},
9183                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9184                 .dac_nids = alc883_dac_nids,
9185                 .dig_out_nid = ALC883_DIGOUT_NID,
9186                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9187                 .channel_mode = alc883_3ST_6ch_modes,
9188                 .need_dac_fix = 1,
9189                 .input_mux = &alc883_capture_source,
9190                 .unsol_event = alc883_targa_unsol_event,
9191                 .setup = alc882_targa_setup,
9192                 .init_hook = alc882_targa_automute,
9193         },
9194         [ALC883_TARGA_2ch_DIG] = {
9195                 .mixers = { alc883_targa_2ch_mixer},
9196                 .init_verbs = { alc883_init_verbs, alc880_gpio3_init_verbs,
9197                                 alc883_targa_verbs},
9198                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9199                 .dac_nids = alc883_dac_nids,
9200                 .adc_nids = alc883_adc_nids_alt,
9201                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
9202                 .dig_out_nid = ALC883_DIGOUT_NID,
9203                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9204                 .channel_mode = alc883_3ST_2ch_modes,
9205                 .input_mux = &alc883_capture_source,
9206                 .unsol_event = alc883_targa_unsol_event,
9207                 .setup = alc882_targa_setup,
9208                 .init_hook = alc882_targa_automute,
9209         },
9210         [ALC883_TARGA_8ch_DIG] = {
9211                 .mixers = { alc883_targa_mixer, alc883_targa_8ch_mixer,
9212                             alc883_chmode_mixer },
9213                 .init_verbs = { alc883_init_verbs, alc880_gpio3_init_verbs,
9214                                 alc883_targa_verbs },
9215                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9216                 .dac_nids = alc883_dac_nids,
9217                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
9218                 .adc_nids = alc883_adc_nids_rev,
9219                 .capsrc_nids = alc883_capsrc_nids_rev,
9220                 .dig_out_nid = ALC883_DIGOUT_NID,
9221                 .dig_in_nid = ALC883_DIGIN_NID,
9222                 .num_channel_mode = ARRAY_SIZE(alc883_4ST_8ch_modes),
9223                 .channel_mode = alc883_4ST_8ch_modes,
9224                 .need_dac_fix = 1,
9225                 .input_mux = &alc883_capture_source,
9226                 .unsol_event = alc883_targa_unsol_event,
9227                 .setup = alc882_targa_setup,
9228                 .init_hook = alc882_targa_automute,
9229         },
9230         [ALC883_ACER] = {
9231                 .mixers = { alc883_base_mixer },
9232                 /* On TravelMate laptops, GPIO 0 enables the internal speaker
9233                  * and the headphone jack.  Turn this on and rely on the
9234                  * standard mute methods whenever the user wants to turn
9235                  * these outputs off.
9236                  */
9237                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
9238                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9239                 .dac_nids = alc883_dac_nids,
9240                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9241                 .channel_mode = alc883_3ST_2ch_modes,
9242                 .input_mux = &alc883_capture_source,
9243         },
9244         [ALC883_ACER_ASPIRE] = {
9245                 .mixers = { alc883_acer_aspire_mixer },
9246                 .init_verbs = { alc883_init_verbs, alc883_acer_eapd_verbs },
9247                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9248                 .dac_nids = alc883_dac_nids,
9249                 .dig_out_nid = ALC883_DIGOUT_NID,
9250                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9251                 .channel_mode = alc883_3ST_2ch_modes,
9252                 .input_mux = &alc883_capture_source,
9253                 .unsol_event = alc_automute_amp_unsol_event,
9254                 .setup = alc883_acer_aspire_setup,
9255                 .init_hook = alc_automute_amp,
9256         },
9257         [ALC888_ACER_ASPIRE_4930G] = {
9258                 .mixers = { alc888_base_mixer,
9259                                 alc883_chmode_mixer },
9260                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
9261                                 alc888_acer_aspire_4930g_verbs },
9262                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9263                 .dac_nids = alc883_dac_nids,
9264                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
9265                 .adc_nids = alc883_adc_nids_rev,
9266                 .capsrc_nids = alc883_capsrc_nids_rev,
9267                 .dig_out_nid = ALC883_DIGOUT_NID,
9268                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9269                 .channel_mode = alc883_3ST_6ch_modes,
9270                 .need_dac_fix = 1,
9271                 .num_mux_defs =
9272                         ARRAY_SIZE(alc888_2_capture_sources),
9273                 .input_mux = alc888_2_capture_sources,
9274                 .unsol_event = alc_automute_amp_unsol_event,
9275                 .setup = alc888_acer_aspire_4930g_setup,
9276                 .init_hook = alc_automute_amp,
9277         },
9278         [ALC888_ACER_ASPIRE_6530G] = {
9279                 .mixers = { alc888_acer_aspire_6530_mixer },
9280                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
9281                                 alc888_acer_aspire_6530g_verbs },
9282                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9283                 .dac_nids = alc883_dac_nids,
9284                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
9285                 .adc_nids = alc883_adc_nids_rev,
9286                 .capsrc_nids = alc883_capsrc_nids_rev,
9287                 .dig_out_nid = ALC883_DIGOUT_NID,
9288                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9289                 .channel_mode = alc883_3ST_2ch_modes,
9290                 .num_mux_defs =
9291                         ARRAY_SIZE(alc888_2_capture_sources),
9292                 .input_mux = alc888_acer_aspire_6530_sources,
9293                 .unsol_event = alc_automute_amp_unsol_event,
9294                 .setup = alc888_acer_aspire_6530g_setup,
9295                 .init_hook = alc_automute_amp,
9296         },
9297         [ALC888_ACER_ASPIRE_8930G] = {
9298                 .mixers = { alc888_base_mixer,
9299                                 alc883_chmode_mixer },
9300                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
9301                                 alc889_acer_aspire_8930g_verbs },
9302                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9303                 .dac_nids = alc883_dac_nids,
9304                 .num_adc_nids = ARRAY_SIZE(alc889_adc_nids),
9305                 .adc_nids = alc889_adc_nids,
9306                 .capsrc_nids = alc889_capsrc_nids,
9307                 .dig_out_nid = ALC883_DIGOUT_NID,
9308                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9309                 .channel_mode = alc883_3ST_6ch_modes,
9310                 .need_dac_fix = 1,
9311                 .const_channel_count = 6,
9312                 .num_mux_defs =
9313                         ARRAY_SIZE(alc889_capture_sources),
9314                 .input_mux = alc889_capture_sources,
9315                 .unsol_event = alc_automute_amp_unsol_event,
9316                 .setup = alc889_acer_aspire_8930g_setup,
9317                 .init_hook = alc_automute_amp,
9318         },
9319         [ALC888_ACER_ASPIRE_7730G] = {
9320                 .mixers = { alc883_3ST_6ch_mixer,
9321                                 alc883_chmode_mixer },
9322                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
9323                                 alc888_acer_aspire_7730G_verbs },
9324                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9325                 .dac_nids = alc883_dac_nids,
9326                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
9327                 .adc_nids = alc883_adc_nids_rev,
9328                 .capsrc_nids = alc883_capsrc_nids_rev,
9329                 .dig_out_nid = ALC883_DIGOUT_NID,
9330                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9331                 .channel_mode = alc883_3ST_6ch_modes,
9332                 .need_dac_fix = 1,
9333                 .const_channel_count = 6,
9334                 .input_mux = &alc883_capture_source,
9335                 .unsol_event = alc_automute_amp_unsol_event,
9336                 .setup = alc888_acer_aspire_6530g_setup,
9337                 .init_hook = alc_automute_amp,
9338         },
9339         [ALC883_MEDION] = {
9340                 .mixers = { alc883_fivestack_mixer,
9341                             alc883_chmode_mixer },
9342                 .init_verbs = { alc883_init_verbs,
9343                                 alc883_medion_eapd_verbs },
9344                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9345                 .dac_nids = alc883_dac_nids,
9346                 .adc_nids = alc883_adc_nids_alt,
9347                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
9348                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9349                 .channel_mode = alc883_sixstack_modes,
9350                 .input_mux = &alc883_capture_source,
9351         },
9352         [ALC883_MEDION_MD2] = {
9353                 .mixers = { alc883_medion_md2_mixer},
9354                 .init_verbs = { alc883_init_verbs, alc883_medion_md2_verbs},
9355                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9356                 .dac_nids = alc883_dac_nids,
9357                 .dig_out_nid = ALC883_DIGOUT_NID,
9358                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9359                 .channel_mode = alc883_3ST_2ch_modes,
9360                 .input_mux = &alc883_capture_source,
9361                 .unsol_event = alc_automute_amp_unsol_event,
9362                 .setup = alc883_medion_md2_setup,
9363                 .init_hook = alc_automute_amp,
9364         },
9365         [ALC883_LAPTOP_EAPD] = {
9366                 .mixers = { alc883_base_mixer },
9367                 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
9368                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9369                 .dac_nids = alc883_dac_nids,
9370                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9371                 .channel_mode = alc883_3ST_2ch_modes,
9372                 .input_mux = &alc883_capture_source,
9373         },
9374         [ALC883_CLEVO_M540R] = {
9375                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9376                 .init_verbs = { alc883_init_verbs, alc883_clevo_m540r_verbs },
9377                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9378                 .dac_nids = alc883_dac_nids,
9379                 .dig_out_nid = ALC883_DIGOUT_NID,
9380                 .dig_in_nid = ALC883_DIGIN_NID,
9381                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_clevo_modes),
9382                 .channel_mode = alc883_3ST_6ch_clevo_modes,
9383                 .need_dac_fix = 1,
9384                 .input_mux = &alc883_capture_source,
9385                 /* This machine has the hardware HP auto-muting, thus
9386                  * we need no software mute via unsol event
9387                  */
9388         },
9389         [ALC883_CLEVO_M720] = {
9390                 .mixers = { alc883_clevo_m720_mixer },
9391                 .init_verbs = { alc883_init_verbs, alc883_clevo_m720_verbs },
9392                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9393                 .dac_nids = alc883_dac_nids,
9394                 .dig_out_nid = ALC883_DIGOUT_NID,
9395                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9396                 .channel_mode = alc883_3ST_2ch_modes,
9397                 .input_mux = &alc883_capture_source,
9398                 .unsol_event = alc883_clevo_m720_unsol_event,
9399                 .setup = alc883_clevo_m720_setup,
9400                 .init_hook = alc883_clevo_m720_init_hook,
9401         },
9402         [ALC883_LENOVO_101E_2ch] = {
9403                 .mixers = { alc883_lenovo_101e_2ch_mixer},
9404                 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
9405                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9406                 .dac_nids = alc883_dac_nids,
9407                 .adc_nids = alc883_adc_nids_alt,
9408                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
9409                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9410                 .channel_mode = alc883_3ST_2ch_modes,
9411                 .input_mux = &alc883_lenovo_101e_capture_source,
9412                 .unsol_event = alc883_lenovo_101e_unsol_event,
9413                 .init_hook = alc883_lenovo_101e_all_automute,
9414         },
9415         [ALC883_LENOVO_NB0763] = {
9416                 .mixers = { alc883_lenovo_nb0763_mixer },
9417                 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs},
9418                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9419                 .dac_nids = alc883_dac_nids,
9420                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9421                 .channel_mode = alc883_3ST_2ch_modes,
9422                 .need_dac_fix = 1,
9423                 .input_mux = &alc883_lenovo_nb0763_capture_source,
9424                 .unsol_event = alc_automute_amp_unsol_event,
9425                 .setup = alc883_medion_md2_setup,
9426                 .init_hook = alc_automute_amp,
9427         },
9428         [ALC888_LENOVO_MS7195_DIG] = {
9429                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9430                 .init_verbs = { alc883_init_verbs, alc888_lenovo_ms7195_verbs},
9431                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9432                 .dac_nids = alc883_dac_nids,
9433                 .dig_out_nid = ALC883_DIGOUT_NID,
9434                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9435                 .channel_mode = alc883_3ST_6ch_modes,
9436                 .need_dac_fix = 1,
9437                 .input_mux = &alc883_capture_source,
9438                 .unsol_event = alc883_lenovo_ms7195_unsol_event,
9439                 .init_hook = alc888_lenovo_ms7195_front_automute,
9440         },
9441         [ALC883_HAIER_W66] = {
9442                 .mixers = { alc883_targa_2ch_mixer},
9443                 .init_verbs = { alc883_init_verbs, alc883_haier_w66_verbs},
9444                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9445                 .dac_nids = alc883_dac_nids,
9446                 .dig_out_nid = ALC883_DIGOUT_NID,
9447                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9448                 .channel_mode = alc883_3ST_2ch_modes,
9449                 .input_mux = &alc883_capture_source,
9450                 .unsol_event = alc_automute_amp_unsol_event,
9451                 .setup = alc883_haier_w66_setup,
9452                 .init_hook = alc_automute_amp,
9453         },
9454         [ALC888_3ST_HP] = {
9455                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9456                 .init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs },
9457                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9458                 .dac_nids = alc883_dac_nids,
9459                 .num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes),
9460                 .channel_mode = alc888_3st_hp_modes,
9461                 .need_dac_fix = 1,
9462                 .input_mux = &alc883_capture_source,
9463                 .unsol_event = alc_automute_amp_unsol_event,
9464                 .setup = alc888_3st_hp_setup,
9465                 .init_hook = alc_automute_amp,
9466         },
9467         [ALC888_6ST_DELL] = {
9468                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
9469                 .init_verbs = { alc883_init_verbs, alc888_6st_dell_verbs },
9470                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9471                 .dac_nids = alc883_dac_nids,
9472                 .dig_out_nid = ALC883_DIGOUT_NID,
9473                 .dig_in_nid = ALC883_DIGIN_NID,
9474                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9475                 .channel_mode = alc883_sixstack_modes,
9476                 .input_mux = &alc883_capture_source,
9477                 .unsol_event = alc_automute_amp_unsol_event,
9478                 .setup = alc888_6st_dell_setup,
9479                 .init_hook = alc_automute_amp,
9480         },
9481         [ALC883_MITAC] = {
9482                 .mixers = { alc883_mitac_mixer },
9483                 .init_verbs = { alc883_init_verbs, alc883_mitac_verbs },
9484                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9485                 .dac_nids = alc883_dac_nids,
9486                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9487                 .channel_mode = alc883_3ST_2ch_modes,
9488                 .input_mux = &alc883_capture_source,
9489                 .unsol_event = alc_automute_amp_unsol_event,
9490                 .setup = alc883_mitac_setup,
9491                 .init_hook = alc_automute_amp,
9492         },
9493         [ALC883_FUJITSU_PI2515] = {
9494                 .mixers = { alc883_2ch_fujitsu_pi2515_mixer },
9495                 .init_verbs = { alc883_init_verbs,
9496                                 alc883_2ch_fujitsu_pi2515_verbs},
9497                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9498                 .dac_nids = alc883_dac_nids,
9499                 .dig_out_nid = ALC883_DIGOUT_NID,
9500                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9501                 .channel_mode = alc883_3ST_2ch_modes,
9502                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
9503                 .unsol_event = alc_automute_amp_unsol_event,
9504                 .setup = alc883_2ch_fujitsu_pi2515_setup,
9505                 .init_hook = alc_automute_amp,
9506         },
9507         [ALC888_FUJITSU_XA3530] = {
9508                 .mixers = { alc888_base_mixer, alc883_chmode_mixer },
9509                 .init_verbs = { alc883_init_verbs,
9510                         alc888_fujitsu_xa3530_verbs },
9511                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9512                 .dac_nids = alc883_dac_nids,
9513                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
9514                 .adc_nids = alc883_adc_nids_rev,
9515                 .capsrc_nids = alc883_capsrc_nids_rev,
9516                 .dig_out_nid = ALC883_DIGOUT_NID,
9517                 .num_channel_mode = ARRAY_SIZE(alc888_4ST_8ch_intel_modes),
9518                 .channel_mode = alc888_4ST_8ch_intel_modes,
9519                 .num_mux_defs =
9520                         ARRAY_SIZE(alc888_2_capture_sources),
9521                 .input_mux = alc888_2_capture_sources,
9522                 .unsol_event = alc_automute_amp_unsol_event,
9523                 .setup = alc888_fujitsu_xa3530_setup,
9524                 .init_hook = alc_automute_amp,
9525         },
9526         [ALC888_LENOVO_SKY] = {
9527                 .mixers = { alc888_lenovo_sky_mixer, alc883_chmode_mixer },
9528                 .init_verbs = { alc883_init_verbs, alc888_lenovo_sky_verbs},
9529                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9530                 .dac_nids = alc883_dac_nids,
9531                 .dig_out_nid = ALC883_DIGOUT_NID,
9532                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9533                 .channel_mode = alc883_sixstack_modes,
9534                 .need_dac_fix = 1,
9535                 .input_mux = &alc883_lenovo_sky_capture_source,
9536                 .unsol_event = alc_automute_amp_unsol_event,
9537                 .setup = alc888_lenovo_sky_setup,
9538                 .init_hook = alc_automute_amp,
9539         },
9540         [ALC888_ASUS_M90V] = {
9541                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9542                 .init_verbs = { alc883_init_verbs, alc888_asus_m90v_verbs },
9543                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9544                 .dac_nids = alc883_dac_nids,
9545                 .dig_out_nid = ALC883_DIGOUT_NID,
9546                 .dig_in_nid = ALC883_DIGIN_NID,
9547                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9548                 .channel_mode = alc883_3ST_6ch_modes,
9549                 .need_dac_fix = 1,
9550                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
9551                 .unsol_event = alc_sku_unsol_event,
9552                 .setup = alc883_mode2_setup,
9553                 .init_hook = alc_inithook,
9554         },
9555         [ALC888_ASUS_EEE1601] = {
9556                 .mixers = { alc883_asus_eee1601_mixer },
9557                 .cap_mixer = alc883_asus_eee1601_cap_mixer,
9558                 .init_verbs = { alc883_init_verbs, alc888_asus_eee1601_verbs },
9559                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9560                 .dac_nids = alc883_dac_nids,
9561                 .dig_out_nid = ALC883_DIGOUT_NID,
9562                 .dig_in_nid = ALC883_DIGIN_NID,
9563                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9564                 .channel_mode = alc883_3ST_2ch_modes,
9565                 .need_dac_fix = 1,
9566                 .input_mux = &alc883_asus_eee1601_capture_source,
9567                 .unsol_event = alc_sku_unsol_event,
9568                 .init_hook = alc883_eee1601_inithook,
9569         },
9570         [ALC1200_ASUS_P5Q] = {
9571                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
9572                 .init_verbs = { alc883_init_verbs },
9573                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9574                 .dac_nids = alc883_dac_nids,
9575                 .dig_out_nid = ALC1200_DIGOUT_NID,
9576                 .dig_in_nid = ALC883_DIGIN_NID,
9577                 .slave_dig_outs = alc1200_slave_dig_outs,
9578                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9579                 .channel_mode = alc883_sixstack_modes,
9580                 .input_mux = &alc883_capture_source,
9581         },
9582         [ALC889A_MB31] = {
9583                 .mixers = { alc889A_mb31_mixer, alc883_chmode_mixer},
9584                 .init_verbs = { alc883_init_verbs, alc889A_mb31_verbs,
9585                         alc880_gpio1_init_verbs },
9586                 .adc_nids = alc883_adc_nids,
9587                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
9588                 .dac_nids = alc883_dac_nids,
9589                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9590                 .channel_mode = alc889A_mb31_6ch_modes,
9591                 .num_channel_mode = ARRAY_SIZE(alc889A_mb31_6ch_modes),
9592                 .input_mux = &alc889A_mb31_capture_source,
9593                 .dig_out_nid = ALC883_DIGOUT_NID,
9594                 .unsol_event = alc889A_mb31_unsol_event,
9595                 .init_hook = alc889A_mb31_automute,
9596         },
9597         [ALC883_SONY_VAIO_TT] = {
9598                 .mixers = { alc883_vaiott_mixer },
9599                 .init_verbs = { alc883_init_verbs, alc883_vaiott_verbs },
9600                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9601                 .dac_nids = alc883_dac_nids,
9602                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9603                 .channel_mode = alc883_3ST_2ch_modes,
9604                 .input_mux = &alc883_capture_source,
9605                 .unsol_event = alc_automute_amp_unsol_event,
9606                 .setup = alc883_vaiott_setup,
9607                 .init_hook = alc_automute_amp,
9608         },
9609 };
9610
9611
9612 /*
9613  * Pin config fixes
9614  */
9615 enum {
9616         PINFIX_ABIT_AW9D_MAX
9617 };
9618
9619 static struct alc_pincfg alc882_abit_aw9d_pinfix[] = {
9620         { 0x15, 0x01080104 }, /* side */
9621         { 0x16, 0x01011012 }, /* rear */
9622         { 0x17, 0x01016011 }, /* clfe */
9623         { }
9624 };
9625
9626 static const struct alc_fixup alc882_fixups[] = {
9627         [PINFIX_ABIT_AW9D_MAX] = {
9628                 .pins = alc882_abit_aw9d_pinfix
9629         },
9630 };
9631
9632 static struct snd_pci_quirk alc882_fixup_tbl[] = {
9633         SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
9634         {}
9635 };
9636
9637 /*
9638  * BIOS auto configuration
9639  */
9640 static int alc882_auto_create_input_ctls(struct hda_codec *codec,
9641                                                 const struct auto_pin_cfg *cfg)
9642 {
9643         return alc_auto_create_input_ctls(codec, cfg, 0x0b, 0x23, 0x22);
9644 }
9645
9646 static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
9647                                               hda_nid_t nid, int pin_type,
9648                                               int dac_idx)
9649 {
9650         /* set as output */
9651         struct alc_spec *spec = codec->spec;
9652         int idx;
9653
9654         alc_set_pin_output(codec, nid, pin_type);
9655         if (spec->multiout.dac_nids[dac_idx] == 0x25)
9656                 idx = 4;
9657         else
9658                 idx = spec->multiout.dac_nids[dac_idx] - 2;
9659         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
9660
9661 }
9662
9663 static void alc882_auto_init_multi_out(struct hda_codec *codec)
9664 {
9665         struct alc_spec *spec = codec->spec;
9666         int i;
9667
9668         for (i = 0; i <= HDA_SIDE; i++) {
9669                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
9670                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
9671                 if (nid)
9672                         alc882_auto_set_output_and_unmute(codec, nid, pin_type,
9673                                                           i);
9674         }
9675 }
9676
9677 static void alc882_auto_init_hp_out(struct hda_codec *codec)
9678 {
9679         struct alc_spec *spec = codec->spec;
9680         hda_nid_t pin;
9681
9682         pin = spec->autocfg.hp_pins[0];
9683         if (pin) /* connect to front */
9684                 /* use dac 0 */
9685                 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
9686         pin = spec->autocfg.speaker_pins[0];
9687         if (pin)
9688                 alc882_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
9689 }
9690
9691 static void alc882_auto_init_analog_input(struct hda_codec *codec)
9692 {
9693         struct alc_spec *spec = codec->spec;
9694         int i;
9695
9696         for (i = 0; i < AUTO_PIN_LAST; i++) {
9697                 hda_nid_t nid = spec->autocfg.input_pins[i];
9698                 if (!nid)
9699                         continue;
9700                 alc_set_input_pin(codec, nid, i);
9701                 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
9702                         snd_hda_codec_write(codec, nid, 0,
9703                                             AC_VERB_SET_AMP_GAIN_MUTE,
9704                                             AMP_OUT_MUTE);
9705         }
9706 }
9707
9708 static void alc882_auto_init_input_src(struct hda_codec *codec)
9709 {
9710         struct alc_spec *spec = codec->spec;
9711         int c;
9712
9713         for (c = 0; c < spec->num_adc_nids; c++) {
9714                 hda_nid_t conn_list[HDA_MAX_NUM_INPUTS];
9715                 hda_nid_t nid = spec->capsrc_nids[c];
9716                 unsigned int mux_idx;
9717                 const struct hda_input_mux *imux;
9718                 int conns, mute, idx, item;
9719
9720                 conns = snd_hda_get_connections(codec, nid, conn_list,
9721                                                 ARRAY_SIZE(conn_list));
9722                 if (conns < 0)
9723                         continue;
9724                 mux_idx = c >= spec->num_mux_defs ? 0 : c;
9725                 imux = &spec->input_mux[mux_idx];
9726                 for (idx = 0; idx < conns; idx++) {
9727                         /* if the current connection is the selected one,
9728                          * unmute it as default - otherwise mute it
9729                          */
9730                         mute = AMP_IN_MUTE(idx);
9731                         for (item = 0; item < imux->num_items; item++) {
9732                                 if (imux->items[item].index == idx) {
9733                                         if (spec->cur_mux[c] == item)
9734                                                 mute = AMP_IN_UNMUTE(idx);
9735                                         break;
9736                                 }
9737                         }
9738                         /* check if we have a selector or mixer
9739                          * we could check for the widget type instead, but
9740                          * just check for Amp-In presence (in case of mixer
9741                          * without amp-in there is something wrong, this
9742                          * function shouldn't be used or capsrc nid is wrong)
9743                          */
9744                         if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)
9745                                 snd_hda_codec_write(codec, nid, 0,
9746                                                     AC_VERB_SET_AMP_GAIN_MUTE,
9747                                                     mute);
9748                         else if (mute != AMP_IN_MUTE(idx))
9749                                 snd_hda_codec_write(codec, nid, 0,
9750                                                     AC_VERB_SET_CONNECT_SEL,
9751                                                     idx);
9752                 }
9753         }
9754 }
9755
9756 /* add mic boosts if needed */
9757 static int alc_auto_add_mic_boost(struct hda_codec *codec)
9758 {
9759         struct alc_spec *spec = codec->spec;
9760         int err;
9761         hda_nid_t nid;
9762
9763         nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
9764         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
9765                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
9766                                   "Mic Boost",
9767                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
9768                 if (err < 0)
9769                         return err;
9770         }
9771         nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
9772         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
9773                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
9774                                   "Front Mic Boost",
9775                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
9776                 if (err < 0)
9777                         return err;
9778         }
9779         return 0;
9780 }
9781
9782 /* almost identical with ALC880 parser... */
9783 static int alc882_parse_auto_config(struct hda_codec *codec)
9784 {
9785         struct alc_spec *spec = codec->spec;
9786         static hda_nid_t alc882_ignore[] = { 0x1d, 0 };
9787         int i, err;
9788
9789         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
9790                                            alc882_ignore);
9791         if (err < 0)
9792                 return err;
9793         if (!spec->autocfg.line_outs)
9794                 return 0; /* can't find valid BIOS pin config */
9795
9796         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
9797         if (err < 0)
9798                 return err;
9799         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
9800         if (err < 0)
9801                 return err;
9802         err = alc880_auto_create_extra_out(spec,
9803                                            spec->autocfg.speaker_pins[0],
9804                                            "Speaker");
9805         if (err < 0)
9806                 return err;
9807         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
9808                                            "Headphone");
9809         if (err < 0)
9810                 return err;
9811         err = alc882_auto_create_input_ctls(codec, &spec->autocfg);
9812         if (err < 0)
9813                 return err;
9814
9815         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
9816
9817         /* check multiple SPDIF-out (for recent codecs) */
9818         for (i = 0; i < spec->autocfg.dig_outs; i++) {
9819                 hda_nid_t dig_nid;
9820                 err = snd_hda_get_connections(codec,
9821                                               spec->autocfg.dig_out_pins[i],
9822                                               &dig_nid, 1);
9823                 if (err < 0)
9824                         continue;
9825                 if (!i)
9826                         spec->multiout.dig_out_nid = dig_nid;
9827                 else {
9828                         spec->multiout.slave_dig_outs = spec->slave_dig_outs;
9829                         if (i >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
9830                                 break;
9831                         spec->slave_dig_outs[i - 1] = dig_nid;
9832                 }
9833         }
9834         if (spec->autocfg.dig_in_pin)
9835                 spec->dig_in_nid = ALC880_DIGIN_NID;
9836
9837         if (spec->kctls.list)
9838                 add_mixer(spec, spec->kctls.list);
9839
9840         add_verb(spec, alc883_auto_init_verbs);
9841         /* if ADC 0x07 is available, initialize it, too */
9842         if (get_wcaps_type(get_wcaps(codec, 0x07)) == AC_WID_AUD_IN)
9843                 add_verb(spec, alc882_adc1_init_verbs);
9844
9845         spec->num_mux_defs = 1;
9846         spec->input_mux = &spec->private_imux[0];
9847
9848         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
9849
9850         err = alc_auto_add_mic_boost(codec);
9851         if (err < 0)
9852                 return err;
9853
9854         return 1; /* config found */
9855 }
9856
9857 /* additional initialization for auto-configuration model */
9858 static void alc882_auto_init(struct hda_codec *codec)
9859 {
9860         struct alc_spec *spec = codec->spec;
9861         alc882_auto_init_multi_out(codec);
9862         alc882_auto_init_hp_out(codec);
9863         alc882_auto_init_analog_input(codec);
9864         alc882_auto_init_input_src(codec);
9865         if (spec->unsol_event)
9866                 alc_inithook(codec);
9867 }
9868
9869 static int patch_alc882(struct hda_codec *codec)
9870 {
9871         struct alc_spec *spec;
9872         int err, board_config;
9873
9874         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
9875         if (spec == NULL)
9876                 return -ENOMEM;
9877
9878         codec->spec = spec;
9879
9880         switch (codec->vendor_id) {
9881         case 0x10ec0882:
9882         case 0x10ec0885:
9883                 break;
9884         default:
9885                 /* ALC883 and variants */
9886                 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
9887                 break;
9888         }
9889
9890         board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
9891                                                   alc882_models,
9892                                                   alc882_cfg_tbl);
9893
9894         if (board_config < 0 || board_config >= ALC882_MODEL_LAST)
9895                 board_config = snd_hda_check_board_codec_sid_config(codec,
9896                         ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl);
9897
9898         if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
9899                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
9900                        codec->chip_name);
9901                 board_config = ALC882_AUTO;
9902         }
9903
9904         alc_pick_fixup(codec, alc882_fixup_tbl, alc882_fixups);
9905
9906         if (board_config == ALC882_AUTO) {
9907                 /* automatic parse from the BIOS config */
9908                 err = alc882_parse_auto_config(codec);
9909                 if (err < 0) {
9910                         alc_free(codec);
9911                         return err;
9912                 } else if (!err) {
9913                         printk(KERN_INFO
9914                                "hda_codec: Cannot set up configuration "
9915                                "from BIOS.  Using base mode...\n");
9916                         board_config = ALC882_3ST_DIG;
9917                 }
9918         }
9919
9920         err = snd_hda_attach_beep_device(codec, 0x1);
9921         if (err < 0) {
9922                 alc_free(codec);
9923                 return err;
9924         }
9925
9926         if (board_config != ALC882_AUTO)
9927                 setup_preset(codec, &alc882_presets[board_config]);
9928
9929         spec->stream_analog_playback = &alc882_pcm_analog_playback;
9930         spec->stream_analog_capture = &alc882_pcm_analog_capture;
9931         /* FIXME: setup DAC5 */
9932         /*spec->stream_analog_alt_playback = &alc880_pcm_analog_alt_playback;*/
9933         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
9934
9935         spec->stream_digital_playback = &alc882_pcm_digital_playback;
9936         spec->stream_digital_capture = &alc882_pcm_digital_capture;
9937
9938         if (codec->vendor_id == 0x10ec0888)
9939                 spec->init_amp = ALC_INIT_DEFAULT; /* always initialize */
9940
9941         if (!spec->adc_nids && spec->input_mux) {
9942                 int i;
9943                 spec->num_adc_nids = 0;
9944                 for (i = 0; i < ARRAY_SIZE(alc882_adc_nids); i++) {
9945                         hda_nid_t cap;
9946                         hda_nid_t nid = alc882_adc_nids[i];
9947                         unsigned int wcap = get_wcaps(codec, nid);
9948                         /* get type */
9949                         wcap = get_wcaps_type(wcap);
9950                         if (wcap != AC_WID_AUD_IN)
9951                                 continue;
9952                         spec->private_adc_nids[spec->num_adc_nids] = nid;
9953                         err = snd_hda_get_connections(codec, nid, &cap, 1);
9954                         if (err < 0)
9955                                 continue;
9956                         spec->private_capsrc_nids[spec->num_adc_nids] = cap;
9957                         spec->num_adc_nids++;
9958                 }
9959                 spec->adc_nids = spec->private_adc_nids;
9960                 spec->capsrc_nids = spec->private_capsrc_nids;
9961         }
9962
9963         set_capture_mixer(codec);
9964         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
9965
9966         spec->vmaster_nid = 0x0c;
9967
9968         codec->patch_ops = alc_patch_ops;
9969         if (board_config == ALC882_AUTO)
9970                 spec->init_hook = alc882_auto_init;
9971 #ifdef CONFIG_SND_HDA_POWER_SAVE
9972         if (!spec->loopback.amplist)
9973                 spec->loopback.amplist = alc882_loopbacks;
9974 #endif
9975         codec->proc_widget_hook = print_realtek_coef;
9976
9977         return 0;
9978 }
9979
9980
9981 /*
9982  * ALC262 support
9983  */
9984
9985 #define ALC262_DIGOUT_NID       ALC880_DIGOUT_NID
9986 #define ALC262_DIGIN_NID        ALC880_DIGIN_NID
9987
9988 #define alc262_dac_nids         alc260_dac_nids
9989 #define alc262_adc_nids         alc882_adc_nids
9990 #define alc262_adc_nids_alt     alc882_adc_nids_alt
9991 #define alc262_capsrc_nids      alc882_capsrc_nids
9992 #define alc262_capsrc_nids_alt  alc882_capsrc_nids_alt
9993
9994 #define alc262_modes            alc260_modes
9995 #define alc262_capture_source   alc882_capture_source
9996
9997 static hda_nid_t alc262_dmic_adc_nids[1] = {
9998         /* ADC0 */
9999         0x09
10000 };
10001
10002 static hda_nid_t alc262_dmic_capsrc_nids[1] = { 0x22 };
10003
10004 static struct snd_kcontrol_new alc262_base_mixer[] = {
10005         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10006         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10007         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10008         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10009         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10010         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10011         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10012         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10013         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10014         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10015         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10016         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10017         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
10018         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10019         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
10020         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
10021         { } /* end */
10022 };
10023
10024 /* update HP, line and mono-out pins according to the master switch */
10025 static void alc262_hp_master_update(struct hda_codec *codec)
10026 {
10027         struct alc_spec *spec = codec->spec;
10028         int val = spec->master_sw;
10029
10030         /* HP & line-out */
10031         snd_hda_codec_write_cache(codec, 0x1b, 0,
10032                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
10033                                   val ? PIN_HP : 0);
10034         snd_hda_codec_write_cache(codec, 0x15, 0,
10035                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
10036                                   val ? PIN_HP : 0);
10037         /* mono (speaker) depending on the HP jack sense */
10038         val = val && !spec->jack_present;
10039         snd_hda_codec_write_cache(codec, 0x16, 0,
10040                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
10041                                   val ? PIN_OUT : 0);
10042 }
10043
10044 static void alc262_hp_bpc_automute(struct hda_codec *codec)
10045 {
10046         struct alc_spec *spec = codec->spec;
10047         unsigned int presence;
10048         presence = snd_hda_codec_read(codec, 0x1b, 0,
10049                                       AC_VERB_GET_PIN_SENSE, 0);
10050         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
10051         alc262_hp_master_update(codec);
10052 }
10053
10054 static void alc262_hp_bpc_unsol_event(struct hda_codec *codec, unsigned int res)
10055 {
10056         if ((res >> 26) != ALC880_HP_EVENT)
10057                 return;
10058         alc262_hp_bpc_automute(codec);
10059 }
10060
10061 static void alc262_hp_wildwest_automute(struct hda_codec *codec)
10062 {
10063         struct alc_spec *spec = codec->spec;
10064         unsigned int presence;
10065         presence = snd_hda_codec_read(codec, 0x15, 0,
10066                                       AC_VERB_GET_PIN_SENSE, 0);
10067         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
10068         alc262_hp_master_update(codec);
10069 }
10070
10071 static void alc262_hp_wildwest_unsol_event(struct hda_codec *codec,
10072                                            unsigned int res)
10073 {
10074         if ((res >> 26) != ALC880_HP_EVENT)
10075                 return;
10076         alc262_hp_wildwest_automute(codec);
10077 }
10078
10079 #define alc262_hp_master_sw_get         alc260_hp_master_sw_get
10080
10081 static int alc262_hp_master_sw_put(struct snd_kcontrol *kcontrol,
10082                                    struct snd_ctl_elem_value *ucontrol)
10083 {
10084         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10085         struct alc_spec *spec = codec->spec;
10086         int val = !!*ucontrol->value.integer.value;
10087
10088         if (val == spec->master_sw)
10089                 return 0;
10090         spec->master_sw = val;
10091         alc262_hp_master_update(codec);
10092         return 1;
10093 }
10094
10095 #define ALC262_HP_MASTER_SWITCH                                 \
10096         {                                                       \
10097                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,            \
10098                 .name = "Master Playback Switch",               \
10099                 .info = snd_ctl_boolean_mono_info,              \
10100                 .get = alc262_hp_master_sw_get,                 \
10101                 .put = alc262_hp_master_sw_put,                 \
10102         }
10103
10104 static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
10105         ALC262_HP_MASTER_SWITCH,
10106         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10107         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10108         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
10109         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
10110                               HDA_OUTPUT),
10111         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
10112                             HDA_OUTPUT),
10113         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10114         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10115         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10116         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10117         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10118         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10119         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10120         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10121         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10122         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10123         HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
10124         HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
10125         { } /* end */
10126 };
10127
10128 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
10129         ALC262_HP_MASTER_SWITCH,
10130         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10131         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
10132         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
10133         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10134         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
10135                               HDA_OUTPUT),
10136         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
10137                             HDA_OUTPUT),
10138         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
10139         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
10140         HDA_CODEC_VOLUME("Front Mic Boost", 0x1a, 0, HDA_INPUT),
10141         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
10142         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
10143         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10144         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10145         { } /* end */
10146 };
10147
10148 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
10149         HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10150         HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10151         HDA_CODEC_VOLUME("Rear Mic Boost", 0x18, 0, HDA_INPUT),
10152         { } /* end */
10153 };
10154
10155 /* mute/unmute internal speaker according to the hp jack and mute state */
10156 static void alc262_hp_t5735_setup(struct hda_codec *codec)
10157 {
10158         struct alc_spec *spec = codec->spec;
10159
10160         spec->autocfg.hp_pins[0] = 0x15;
10161         spec->autocfg.speaker_pins[0] = 0x0c; /* HACK: not actually a pin */
10162 }
10163
10164 static struct snd_kcontrol_new alc262_hp_t5735_mixer[] = {
10165         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10166         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10167         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
10168         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10169         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10170         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10171         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10172         { } /* end */
10173 };
10174
10175 static struct hda_verb alc262_hp_t5735_verbs[] = {
10176         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10177         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10178
10179         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10180         { }
10181 };
10182
10183 static struct snd_kcontrol_new alc262_hp_rp5700_mixer[] = {
10184         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10185         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
10186         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
10187         HDA_CODEC_MUTE("Speaker Playback Switch", 0x16, 0x0, HDA_OUTPUT),
10188         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
10189         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
10190         { } /* end */
10191 };
10192
10193 static struct hda_verb alc262_hp_rp5700_verbs[] = {
10194         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10195         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10196         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10197         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10198         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10199         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10200         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10201         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10202         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
10203         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
10204         {}
10205 };
10206
10207 static struct hda_input_mux alc262_hp_rp5700_capture_source = {
10208         .num_items = 1,
10209         .items = {
10210                 { "Line", 0x1 },
10211         },
10212 };
10213
10214 /* bind hp and internal speaker mute (with plug check) as master switch */
10215 static void alc262_hippo_master_update(struct hda_codec *codec)
10216 {
10217         struct alc_spec *spec = codec->spec;
10218         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
10219         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
10220         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
10221         unsigned int mute;
10222
10223         /* HP */
10224         mute = spec->master_sw ? 0 : HDA_AMP_MUTE;
10225         snd_hda_codec_amp_stereo(codec, hp_nid, HDA_OUTPUT, 0,
10226                                  HDA_AMP_MUTE, mute);
10227         /* mute internal speaker per jack sense */
10228         if (spec->jack_present)
10229                 mute = HDA_AMP_MUTE;
10230         if (line_nid)
10231                 snd_hda_codec_amp_stereo(codec, line_nid, HDA_OUTPUT, 0,
10232                                          HDA_AMP_MUTE, mute);
10233         if (speaker_nid && speaker_nid != line_nid)
10234                 snd_hda_codec_amp_stereo(codec, speaker_nid, HDA_OUTPUT, 0,
10235                                          HDA_AMP_MUTE, mute);
10236 }
10237
10238 #define alc262_hippo_master_sw_get      alc262_hp_master_sw_get
10239
10240 static int alc262_hippo_master_sw_put(struct snd_kcontrol *kcontrol,
10241                                       struct snd_ctl_elem_value *ucontrol)
10242 {
10243         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10244         struct alc_spec *spec = codec->spec;
10245         int val = !!*ucontrol->value.integer.value;
10246
10247         if (val == spec->master_sw)
10248                 return 0;
10249         spec->master_sw = val;
10250         alc262_hippo_master_update(codec);
10251         return 1;
10252 }
10253
10254 #define ALC262_HIPPO_MASTER_SWITCH                              \
10255         {                                                       \
10256                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,            \
10257                 .name = "Master Playback Switch",               \
10258                 .info = snd_ctl_boolean_mono_info,              \
10259                 .get = alc262_hippo_master_sw_get,              \
10260                 .put = alc262_hippo_master_sw_put,              \
10261         }
10262
10263 static struct snd_kcontrol_new alc262_hippo_mixer[] = {
10264         ALC262_HIPPO_MASTER_SWITCH,
10265         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10266         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10267         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10268         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10269         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10270         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10271         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10272         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10273         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10274         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10275         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10276         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
10277         { } /* end */
10278 };
10279
10280 static struct snd_kcontrol_new alc262_hippo1_mixer[] = {
10281         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10282         ALC262_HIPPO_MASTER_SWITCH,
10283         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10284         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10285         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10286         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10287         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10288         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10289         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10290         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10291         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10292         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10293         { } /* end */
10294 };
10295
10296 /* mute/unmute internal speaker according to the hp jack and mute state */
10297 static void alc262_hippo_automute(struct hda_codec *codec)
10298 {
10299         struct alc_spec *spec = codec->spec;
10300         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
10301         unsigned int present;
10302
10303         /* need to execute and sync at first */
10304         snd_hda_codec_read(codec, hp_nid, 0, AC_VERB_SET_PIN_SENSE, 0);
10305         present = snd_hda_codec_read(codec, hp_nid, 0,
10306                                      AC_VERB_GET_PIN_SENSE, 0);
10307         spec->jack_present = (present & 0x80000000) != 0;
10308         alc262_hippo_master_update(codec);
10309 }
10310
10311 static void alc262_hippo_unsol_event(struct hda_codec *codec, unsigned int res)
10312 {
10313         if ((res >> 26) != ALC880_HP_EVENT)
10314                 return;
10315         alc262_hippo_automute(codec);
10316 }
10317
10318 static void alc262_hippo_setup(struct hda_codec *codec)
10319 {
10320         struct alc_spec *spec = codec->spec;
10321
10322         spec->autocfg.hp_pins[0] = 0x15;
10323         spec->autocfg.speaker_pins[0] = 0x14;
10324 }
10325
10326 static void alc262_hippo1_setup(struct hda_codec *codec)
10327 {
10328         struct alc_spec *spec = codec->spec;
10329
10330         spec->autocfg.hp_pins[0] = 0x1b;
10331         spec->autocfg.speaker_pins[0] = 0x14;
10332 }
10333
10334
10335 static struct snd_kcontrol_new alc262_sony_mixer[] = {
10336         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10337         ALC262_HIPPO_MASTER_SWITCH,
10338         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10339         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10340         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10341         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10342         { } /* end */
10343 };
10344
10345 static struct snd_kcontrol_new alc262_benq_t31_mixer[] = {
10346         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10347         ALC262_HIPPO_MASTER_SWITCH,
10348         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10349         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10350         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10351         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10352         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10353         { } /* end */
10354 };
10355
10356 static struct snd_kcontrol_new alc262_tyan_mixer[] = {
10357         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10358         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
10359         HDA_CODEC_VOLUME("Aux Playback Volume", 0x0b, 0x06, HDA_INPUT),
10360         HDA_CODEC_MUTE("Aux Playback Switch", 0x0b, 0x06, HDA_INPUT),
10361         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10362         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10363         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10364         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10365         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10366         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10367         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10368         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10369         { } /* end */
10370 };
10371
10372 static struct hda_verb alc262_tyan_verbs[] = {
10373         /* Headphone automute */
10374         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10375         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10376         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10377
10378         /* P11 AUX_IN, white 4-pin connector */
10379         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10380         {0x14, AC_VERB_SET_CONFIG_DEFAULT_BYTES_1, 0xe1},
10381         {0x14, AC_VERB_SET_CONFIG_DEFAULT_BYTES_2, 0x93},
10382         {0x14, AC_VERB_SET_CONFIG_DEFAULT_BYTES_3, 0x19},
10383
10384         {}
10385 };
10386
10387 /* unsolicited event for HP jack sensing */
10388 static void alc262_tyan_setup(struct hda_codec *codec)
10389 {
10390         struct alc_spec *spec = codec->spec;
10391
10392         spec->autocfg.hp_pins[0] = 0x1b;
10393         spec->autocfg.speaker_pins[0] = 0x15;
10394 }
10395
10396
10397 #define alc262_capture_mixer            alc882_capture_mixer
10398 #define alc262_capture_alt_mixer        alc882_capture_alt_mixer
10399
10400 /*
10401  * generic initialization of ADC, input mixers and output mixers
10402  */
10403 static struct hda_verb alc262_init_verbs[] = {
10404         /*
10405          * Unmute ADC0-2 and set the default input to mic-in
10406          */
10407         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10408         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10409         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10410         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10411         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10412         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10413
10414         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10415          * mixer widget
10416          * Note: PASD motherboards uses the Line In 2 as the input for
10417          * front panel mic (mic 2)
10418          */
10419         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10420         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10421         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10422         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10423         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10424         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10425
10426         /*
10427          * Set up output mixers (0x0c - 0x0e)
10428          */
10429         /* set vol=0 to output mixers */
10430         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10431         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10432         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10433         /* set up input amps for analog loopback */
10434         /* Amp Indices: DAC = 0, mixer = 1 */
10435         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10436         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10437         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10438         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10439         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10440         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10441
10442         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
10443         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
10444         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
10445         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10446         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10447         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10448
10449         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10450         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10451         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10452         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10453         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10454
10455         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
10456         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
10457
10458         /* FIXME: use matrix-type input source selection */
10459         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10460         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10461         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10462         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10463         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10464         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10465         /* Input mixer2 */
10466         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10467         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10468         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10469         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10470         /* Input mixer3 */
10471         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10472         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10473         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10474         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10475
10476         { }
10477 };
10478
10479 static struct hda_verb alc262_eapd_verbs[] = {
10480         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
10481         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
10482         { }
10483 };
10484
10485 static struct hda_verb alc262_hippo1_unsol_verbs[] = {
10486         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
10487         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10488         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10489
10490         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10491         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10492         {}
10493 };
10494
10495 static struct hda_verb alc262_sony_unsol_verbs[] = {
10496         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
10497         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10498         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},   // Front Mic
10499
10500         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10501         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10502         {}
10503 };
10504
10505 static struct snd_kcontrol_new alc262_toshiba_s06_mixer[] = {
10506         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10507         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10508         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10509         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10510         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10511         { } /* end */
10512 };
10513
10514 static struct hda_verb alc262_toshiba_s06_verbs[] = {
10515         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10516         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10517         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10518         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10519         {0x22, AC_VERB_SET_CONNECT_SEL, 0x09},
10520         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10521         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
10522         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10523         {}
10524 };
10525
10526 static void alc262_toshiba_s06_setup(struct hda_codec *codec)
10527 {
10528         struct alc_spec *spec = codec->spec;
10529
10530         spec->autocfg.hp_pins[0] = 0x15;
10531         spec->autocfg.speaker_pins[0] = 0x14;
10532         spec->ext_mic.pin = 0x18;
10533         spec->ext_mic.mux_idx = 0;
10534         spec->int_mic.pin = 0x12;
10535         spec->int_mic.mux_idx = 9;
10536         spec->auto_mic = 1;
10537 }
10538
10539 /*
10540  * nec model
10541  *  0x15 = headphone
10542  *  0x16 = internal speaker
10543  *  0x18 = external mic
10544  */
10545
10546 static struct snd_kcontrol_new alc262_nec_mixer[] = {
10547         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
10548         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 0, 0x0, HDA_OUTPUT),
10549
10550         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10551         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10552         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10553
10554         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
10555         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10556         { } /* end */
10557 };
10558
10559 static struct hda_verb alc262_nec_verbs[] = {
10560         /* Unmute Speaker */
10561         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10562
10563         /* Headphone */
10564         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10565         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10566
10567         /* External mic to headphone */
10568         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10569         /* External mic to speaker */
10570         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10571         {}
10572 };
10573
10574 /*
10575  * fujitsu model
10576  *  0x14 = headphone/spdif-out, 0x15 = internal speaker,
10577  *  0x1b = port replicator headphone out
10578  */
10579
10580 #define ALC_HP_EVENT    0x37
10581
10582 static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
10583         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
10584         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10585         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
10586         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10587         {}
10588 };
10589
10590 static struct hda_verb alc262_lenovo_3000_unsol_verbs[] = {
10591         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
10592         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10593         {}
10594 };
10595
10596 static struct hda_input_mux alc262_fujitsu_capture_source = {
10597         .num_items = 3,
10598         .items = {
10599                 { "Mic", 0x0 },
10600                 { "Int Mic", 0x1 },
10601                 { "CD", 0x4 },
10602         },
10603 };
10604
10605 static struct hda_input_mux alc262_HP_capture_source = {
10606         .num_items = 5,
10607         .items = {
10608                 { "Mic", 0x0 },
10609                 { "Front Mic", 0x1 },
10610                 { "Line", 0x2 },
10611                 { "CD", 0x4 },
10612                 { "AUX IN", 0x6 },
10613         },
10614 };
10615
10616 static struct hda_input_mux alc262_HP_D7000_capture_source = {
10617         .num_items = 4,
10618         .items = {
10619                 { "Mic", 0x0 },
10620                 { "Front Mic", 0x2 },
10621                 { "Line", 0x1 },
10622                 { "CD", 0x4 },
10623         },
10624 };
10625
10626 /* mute/unmute internal speaker according to the hp jacks and mute state */
10627 static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
10628 {
10629         struct alc_spec *spec = codec->spec;
10630         unsigned int mute;
10631
10632         if (force || !spec->sense_updated) {
10633                 unsigned int present;
10634                 /* need to execute and sync at first */
10635                 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
10636                 /* check laptop HP jack */
10637                 present = snd_hda_codec_read(codec, 0x14, 0,
10638                                              AC_VERB_GET_PIN_SENSE, 0);
10639                 /* need to execute and sync at first */
10640                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
10641                 /* check docking HP jack */
10642                 present |= snd_hda_codec_read(codec, 0x1b, 0,
10643                                               AC_VERB_GET_PIN_SENSE, 0);
10644                 if (present & AC_PINSENSE_PRESENCE)
10645                         spec->jack_present = 1;
10646                 else
10647                         spec->jack_present = 0;
10648                 spec->sense_updated = 1;
10649         }
10650         /* unmute internal speaker only if both HPs are unplugged and
10651          * master switch is on
10652          */
10653         if (spec->jack_present)
10654                 mute = HDA_AMP_MUTE;
10655         else
10656                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
10657         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
10658                                  HDA_AMP_MUTE, mute);
10659 }
10660
10661 /* unsolicited event for HP jack sensing */
10662 static void alc262_fujitsu_unsol_event(struct hda_codec *codec,
10663                                        unsigned int res)
10664 {
10665         if ((res >> 26) != ALC_HP_EVENT)
10666                 return;
10667         alc262_fujitsu_automute(codec, 1);
10668 }
10669
10670 static void alc262_fujitsu_init_hook(struct hda_codec *codec)
10671 {
10672         alc262_fujitsu_automute(codec, 1);
10673 }
10674
10675 /* bind volumes of both NID 0x0c and 0x0d */
10676 static struct hda_bind_ctls alc262_fujitsu_bind_master_vol = {
10677         .ops = &snd_hda_bind_vol,
10678         .values = {
10679                 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
10680                 HDA_COMPOSE_AMP_VAL(0x0d, 3, 0, HDA_OUTPUT),
10681                 0
10682         },
10683 };
10684
10685 /* mute/unmute internal speaker according to the hp jack and mute state */
10686 static void alc262_lenovo_3000_automute(struct hda_codec *codec, int force)
10687 {
10688         struct alc_spec *spec = codec->spec;
10689         unsigned int mute;
10690
10691         if (force || !spec->sense_updated) {
10692                 unsigned int present_int_hp;
10693                 /* need to execute and sync at first */
10694                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
10695                 present_int_hp = snd_hda_codec_read(codec, 0x1b, 0,
10696                                         AC_VERB_GET_PIN_SENSE, 0);
10697                 spec->jack_present = (present_int_hp & 0x80000000) != 0;
10698                 spec->sense_updated = 1;
10699         }
10700         if (spec->jack_present) {
10701                 /* mute internal speaker */
10702                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10703                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
10704                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
10705                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
10706         } else {
10707                 /* unmute internal speaker if necessary */
10708                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
10709                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10710                                          HDA_AMP_MUTE, mute);
10711                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
10712                                          HDA_AMP_MUTE, mute);
10713         }
10714 }
10715
10716 /* unsolicited event for HP jack sensing */
10717 static void alc262_lenovo_3000_unsol_event(struct hda_codec *codec,
10718                                        unsigned int res)
10719 {
10720         if ((res >> 26) != ALC_HP_EVENT)
10721                 return;
10722         alc262_lenovo_3000_automute(codec, 1);
10723 }
10724
10725 static int amp_stereo_mute_update(struct hda_codec *codec, hda_nid_t nid,
10726                                   int dir, int idx, long *valp)
10727 {
10728         int i, change = 0;
10729
10730         for (i = 0; i < 2; i++, valp++)
10731                 change |= snd_hda_codec_amp_update(codec, nid, i, dir, idx,
10732                                                    HDA_AMP_MUTE,
10733                                                    *valp ? 0 : HDA_AMP_MUTE);
10734         return change;
10735 }
10736
10737 /* bind hp and internal speaker mute (with plug check) */
10738 static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
10739                                          struct snd_ctl_elem_value *ucontrol)
10740 {
10741         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10742         long *valp = ucontrol->value.integer.value;
10743         int change;
10744
10745         change = amp_stereo_mute_update(codec, 0x14, HDA_OUTPUT, 0, valp);
10746         change |= amp_stereo_mute_update(codec, 0x1b, HDA_OUTPUT, 0, valp);
10747         if (change)
10748                 alc262_fujitsu_automute(codec, 0);
10749         return change;
10750 }
10751
10752 static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
10753         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
10754         {
10755                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10756                 .name = "Master Playback Switch",
10757                 .info = snd_hda_mixer_amp_switch_info,
10758                 .get = snd_hda_mixer_amp_switch_get,
10759                 .put = alc262_fujitsu_master_sw_put,
10760                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
10761         },
10762         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10763         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10764         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10765         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10766         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10767         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
10768         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
10769         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
10770         { } /* end */
10771 };
10772
10773 /* bind hp and internal speaker mute (with plug check) */
10774 static int alc262_lenovo_3000_master_sw_put(struct snd_kcontrol *kcontrol,
10775                                          struct snd_ctl_elem_value *ucontrol)
10776 {
10777         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10778         long *valp = ucontrol->value.integer.value;
10779         int change;
10780
10781         change = amp_stereo_mute_update(codec, 0x1b, HDA_OUTPUT, 0, valp);
10782         if (change)
10783                 alc262_lenovo_3000_automute(codec, 0);
10784         return change;
10785 }
10786
10787 static struct snd_kcontrol_new alc262_lenovo_3000_mixer[] = {
10788         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
10789         {
10790                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10791                 .name = "Master Playback Switch",
10792                 .info = snd_hda_mixer_amp_switch_info,
10793                 .get = snd_hda_mixer_amp_switch_get,
10794                 .put = alc262_lenovo_3000_master_sw_put,
10795                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
10796         },
10797         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10798         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10799         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10800         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10801         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10802         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
10803         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
10804         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
10805         { } /* end */
10806 };
10807
10808 static struct snd_kcontrol_new alc262_toshiba_rx1_mixer[] = {
10809         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
10810         ALC262_HIPPO_MASTER_SWITCH,
10811         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10812         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10813         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10814         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10815         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10816         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10817         { } /* end */
10818 };
10819
10820 /* additional init verbs for Benq laptops */
10821 static struct hda_verb alc262_EAPD_verbs[] = {
10822         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
10823         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
10824         {}
10825 };
10826
10827 static struct hda_verb alc262_benq_t31_EAPD_verbs[] = {
10828         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10829         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10830
10831         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
10832         {0x20, AC_VERB_SET_PROC_COEF,  0x3050},
10833         {}
10834 };
10835
10836 /* Samsung Q1 Ultra Vista model setup */
10837 static struct snd_kcontrol_new alc262_ultra_mixer[] = {
10838         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10839         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
10840         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10841         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10842         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
10843         HDA_CODEC_VOLUME("Headphone Mic Boost", 0x15, 0, HDA_INPUT),
10844         { } /* end */
10845 };
10846
10847 static struct hda_verb alc262_ultra_verbs[] = {
10848         /* output mixer */
10849         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10850         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10851         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10852         /* speaker */
10853         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10854         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10855         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10856         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
10857         /* HP */
10858         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10859         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10860         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10861         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10862         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10863         /* internal mic */
10864         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10865         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10866         /* ADC, choose mic */
10867         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10868         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10869         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10870         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10871         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10872         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10873         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10874         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10875         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
10876         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(8)},
10877         {}
10878 };
10879
10880 /* mute/unmute internal speaker according to the hp jack and mute state */
10881 static void alc262_ultra_automute(struct hda_codec *codec)
10882 {
10883         struct alc_spec *spec = codec->spec;
10884         unsigned int mute;
10885
10886         mute = 0;
10887         /* auto-mute only when HP is used as HP */
10888         if (!spec->cur_mux[0]) {
10889                 unsigned int present;
10890                 /* need to execute and sync at first */
10891                 snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
10892                 present = snd_hda_codec_read(codec, 0x15, 0,
10893                                              AC_VERB_GET_PIN_SENSE, 0);
10894                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
10895                 if (spec->jack_present)
10896                         mute = HDA_AMP_MUTE;
10897         }
10898         /* mute/unmute internal speaker */
10899         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10900                                  HDA_AMP_MUTE, mute);
10901         /* mute/unmute HP */
10902         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
10903                                  HDA_AMP_MUTE, mute ? 0 : HDA_AMP_MUTE);
10904 }
10905
10906 /* unsolicited event for HP jack sensing */
10907 static void alc262_ultra_unsol_event(struct hda_codec *codec,
10908                                        unsigned int res)
10909 {
10910         if ((res >> 26) != ALC880_HP_EVENT)
10911                 return;
10912         alc262_ultra_automute(codec);
10913 }
10914
10915 static struct hda_input_mux alc262_ultra_capture_source = {
10916         .num_items = 2,
10917         .items = {
10918                 { "Mic", 0x1 },
10919                 { "Headphone", 0x7 },
10920         },
10921 };
10922
10923 static int alc262_ultra_mux_enum_put(struct snd_kcontrol *kcontrol,
10924                                      struct snd_ctl_elem_value *ucontrol)
10925 {
10926         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10927         struct alc_spec *spec = codec->spec;
10928         int ret;
10929
10930         ret = alc_mux_enum_put(kcontrol, ucontrol);
10931         if (!ret)
10932                 return 0;
10933         /* reprogram the HP pin as mic or HP according to the input source */
10934         snd_hda_codec_write_cache(codec, 0x15, 0,
10935                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
10936                                   spec->cur_mux[0] ? PIN_VREF80 : PIN_HP);
10937         alc262_ultra_automute(codec); /* mute/unmute HP */
10938         return ret;
10939 }
10940
10941 static struct snd_kcontrol_new alc262_ultra_capture_mixer[] = {
10942         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
10943         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
10944         {
10945                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10946                 .name = "Capture Source",
10947                 .info = alc_mux_enum_info,
10948                 .get = alc_mux_enum_get,
10949                 .put = alc262_ultra_mux_enum_put,
10950         },
10951         { } /* end */
10952 };
10953
10954 /* We use two mixers depending on the output pin; 0x16 is a mono output
10955  * and thus it's bound with a different mixer.
10956  * This function returns which mixer amp should be used.
10957  */
10958 static int alc262_check_volbit(hda_nid_t nid)
10959 {
10960         if (!nid)
10961                 return 0;
10962         else if (nid == 0x16)
10963                 return 2;
10964         else
10965                 return 1;
10966 }
10967
10968 static int alc262_add_out_vol_ctl(struct alc_spec *spec, hda_nid_t nid,
10969                                   const char *pfx, int *vbits)
10970 {
10971         unsigned long val;
10972         int vbit;
10973
10974         vbit = alc262_check_volbit(nid);
10975         if (!vbit)
10976                 return 0;
10977         if (*vbits & vbit) /* a volume control for this mixer already there */
10978                 return 0;
10979         *vbits |= vbit;
10980         if (vbit == 2)
10981                 val = HDA_COMPOSE_AMP_VAL(0x0e, 2, 0, HDA_OUTPUT);
10982         else
10983                 val = HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT);
10984         return add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx, val);
10985 }
10986
10987 static int alc262_add_out_sw_ctl(struct alc_spec *spec, hda_nid_t nid,
10988                                  const char *pfx)
10989 {
10990         unsigned long val;
10991
10992         if (!nid)
10993                 return 0;
10994         if (nid == 0x16)
10995                 val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
10996         else
10997                 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
10998         return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, val);
10999 }
11000
11001 /* add playback controls from the parsed DAC table */
11002 static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
11003                                              const struct auto_pin_cfg *cfg)
11004 {
11005         const char *pfx;
11006         int vbits;
11007         int err;
11008
11009         spec->multiout.num_dacs = 1;    /* only use one dac */
11010         spec->multiout.dac_nids = spec->private_dac_nids;
11011         spec->multiout.dac_nids[0] = 2;
11012
11013         if (!cfg->speaker_pins[0] && !cfg->hp_pins[0])
11014                 pfx = "Master";
11015         else if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
11016                 pfx = "Speaker";
11017         else
11018                 pfx = "Front";
11019         err = alc262_add_out_sw_ctl(spec, cfg->line_out_pins[0], pfx);
11020         if (err < 0)
11021                 return err;
11022         err = alc262_add_out_sw_ctl(spec, cfg->speaker_pins[0], "Speaker");
11023         if (err < 0)
11024                 return err;
11025         err = alc262_add_out_sw_ctl(spec, cfg->hp_pins[0], "Headphone");
11026         if (err < 0)
11027                 return err;
11028
11029         vbits = alc262_check_volbit(cfg->line_out_pins[0]) |
11030                 alc262_check_volbit(cfg->speaker_pins[0]) |
11031                 alc262_check_volbit(cfg->hp_pins[0]);
11032         if (vbits == 1 || vbits == 2)
11033                 pfx = "Master"; /* only one mixer is used */
11034         else if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
11035                 pfx = "Speaker";
11036         else
11037                 pfx = "Front";
11038         vbits = 0;
11039         err = alc262_add_out_vol_ctl(spec, cfg->line_out_pins[0], pfx, &vbits);
11040         if (err < 0)
11041                 return err;
11042         err = alc262_add_out_vol_ctl(spec, cfg->speaker_pins[0], "Speaker",
11043                                      &vbits);
11044         if (err < 0)
11045                 return err;
11046         err = alc262_add_out_vol_ctl(spec, cfg->hp_pins[0], "Headphone",
11047                                      &vbits);
11048         if (err < 0)
11049                 return err;
11050         return 0;
11051 }
11052
11053 #define alc262_auto_create_input_ctls \
11054         alc880_auto_create_input_ctls
11055
11056 /*
11057  * generic initialization of ADC, input mixers and output mixers
11058  */
11059 static struct hda_verb alc262_volume_init_verbs[] = {
11060         /*
11061          * Unmute ADC0-2 and set the default input to mic-in
11062          */
11063         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
11064         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11065         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11066         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11067         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
11068         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11069
11070         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
11071          * mixer widget
11072          * Note: PASD motherboards uses the Line In 2 as the input for
11073          * front panel mic (mic 2)
11074          */
11075         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
11076         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11077         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11078         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11079         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11080         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
11081
11082         /*
11083          * Set up output mixers (0x0c - 0x0f)
11084          */
11085         /* set vol=0 to output mixers */
11086         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11087         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11088         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11089
11090         /* set up input amps for analog loopback */
11091         /* Amp Indices: DAC = 0, mixer = 1 */
11092         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11093         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11094         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11095         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11096         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11097         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11098
11099         /* FIXME: use matrix-type input source selection */
11100         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
11101         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
11102         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11103         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11104         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11105         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11106         /* Input mixer2 */
11107         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11108         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11109         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11110         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11111         /* Input mixer3 */
11112         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11113         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11114         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11115         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11116
11117         { }
11118 };
11119
11120 static struct hda_verb alc262_HP_BPC_init_verbs[] = {
11121         /*
11122          * Unmute ADC0-2 and set the default input to mic-in
11123          */
11124         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
11125         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11126         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11127         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11128         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
11129         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11130
11131         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
11132          * mixer widget
11133          * Note: PASD motherboards uses the Line In 2 as the input for
11134          * front panel mic (mic 2)
11135          */
11136         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
11137         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11138         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11139         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11140         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11141         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
11142         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
11143         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
11144
11145         /*
11146          * Set up output mixers (0x0c - 0x0e)
11147          */
11148         /* set vol=0 to output mixers */
11149         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11150         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11151         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11152
11153         /* set up input amps for analog loopback */
11154         /* Amp Indices: DAC = 0, mixer = 1 */
11155         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11156         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11157         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11158         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11159         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11160         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11161
11162         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11163         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11164         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11165
11166         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11167         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11168
11169         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
11170         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
11171
11172         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11173         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11174         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11175         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11176         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11177
11178         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11179         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11180         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11181         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11182         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11183         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11184
11185
11186         /* FIXME: use matrix-type input source selection */
11187         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 0b, 12 */
11188         /* Input mixer1: only unmute Mic */
11189         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11190         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8))},
11191         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11192         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11193         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11194         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x05 << 8))},
11195         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x06 << 8))},
11196         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x07 << 8))},
11197         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x08 << 8))},
11198         /* Input mixer2 */
11199         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11200         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8))},
11201         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11202         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11203         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11204         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x05 << 8))},
11205         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x06 << 8))},
11206         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x07 << 8))},
11207         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x08 << 8))},
11208         /* Input mixer3 */
11209         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11210         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8))},
11211         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11212         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11213         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11214         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x05 << 8))},
11215         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x06 << 8))},
11216         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x07 << 8))},
11217         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x08 << 8))},
11218
11219         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11220
11221         { }
11222 };
11223
11224 static struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
11225         /*
11226          * Unmute ADC0-2 and set the default input to mic-in
11227          */
11228         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
11229         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11230         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11231         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11232         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
11233         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11234
11235         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
11236          * mixer widget
11237          * Note: PASD motherboards uses the Line In 2 as the input for front
11238          * panel mic (mic 2)
11239          */
11240         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
11241         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11242         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11243         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11244         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11245         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
11246         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
11247         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
11248         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
11249         /*
11250          * Set up output mixers (0x0c - 0x0e)
11251          */
11252         /* set vol=0 to output mixers */
11253         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11254         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11255         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11256
11257         /* set up input amps for analog loopback */
11258         /* Amp Indices: DAC = 0, mixer = 1 */
11259         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11260         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11261         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11262         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11263         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11264         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11265
11266
11267         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP */
11268         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Mono */
11269         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* rear MIC */
11270         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* Line in */
11271         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
11272         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Line out */
11273         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* CD in */
11274
11275         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11276         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11277
11278         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
11279         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
11280
11281         /* {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 }, */
11282         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11283         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11284         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
11285         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11286         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11287
11288         /* FIXME: use matrix-type input source selection */
11289         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
11290         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
11291         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, /*rear MIC*/
11292         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, /*Line in*/
11293         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))}, /*F MIC*/
11294         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))}, /*Front*/
11295         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))}, /*CD*/
11296         /* {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))},  */
11297         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))}, /*HP*/
11298         /* Input mixer2 */
11299         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11300         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
11301         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
11302         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
11303         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
11304         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
11305         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
11306         /* Input mixer3 */
11307         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11308         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
11309         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
11310         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
11311         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
11312         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
11313         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
11314
11315         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11316
11317         { }
11318 };
11319
11320 static struct hda_verb alc262_toshiba_rx1_unsol_verbs[] = {
11321
11322         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Front Speaker */
11323         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11324         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
11325
11326         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* MIC jack */
11327         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
11328         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
11329         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
11330
11331         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP  jack */
11332         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
11333         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
11334         {}
11335 };
11336
11337
11338 #ifdef CONFIG_SND_HDA_POWER_SAVE
11339 #define alc262_loopbacks        alc880_loopbacks
11340 #endif
11341
11342 /* pcm configuration: identical with ALC880 */
11343 #define alc262_pcm_analog_playback      alc880_pcm_analog_playback
11344 #define alc262_pcm_analog_capture       alc880_pcm_analog_capture
11345 #define alc262_pcm_digital_playback     alc880_pcm_digital_playback
11346 #define alc262_pcm_digital_capture      alc880_pcm_digital_capture
11347
11348 /*
11349  * BIOS auto configuration
11350  */
11351 static int alc262_parse_auto_config(struct hda_codec *codec)
11352 {
11353         struct alc_spec *spec = codec->spec;
11354         int err;
11355         static hda_nid_t alc262_ignore[] = { 0x1d, 0 };
11356
11357         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
11358                                            alc262_ignore);
11359         if (err < 0)
11360                 return err;
11361         if (!spec->autocfg.line_outs) {
11362                 if (spec->autocfg.dig_outs || spec->autocfg.dig_in_pin) {
11363                         spec->multiout.max_channels = 2;
11364                         spec->no_analog = 1;
11365                         goto dig_only;
11366                 }
11367                 return 0; /* can't find valid BIOS pin config */
11368         }
11369         err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
11370         if (err < 0)
11371                 return err;
11372         err = alc262_auto_create_input_ctls(codec, &spec->autocfg);
11373         if (err < 0)
11374                 return err;
11375
11376         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
11377
11378  dig_only:
11379         if (spec->autocfg.dig_outs) {
11380                 spec->multiout.dig_out_nid = ALC262_DIGOUT_NID;
11381                 spec->dig_out_type = spec->autocfg.dig_out_type[0];
11382         }
11383         if (spec->autocfg.dig_in_pin)
11384                 spec->dig_in_nid = ALC262_DIGIN_NID;
11385
11386         if (spec->kctls.list)
11387                 add_mixer(spec, spec->kctls.list);
11388
11389         add_verb(spec, alc262_volume_init_verbs);
11390         spec->num_mux_defs = 1;
11391         spec->input_mux = &spec->private_imux[0];
11392
11393         err = alc_auto_add_mic_boost(codec);
11394         if (err < 0)
11395                 return err;
11396
11397         alc_ssid_check(codec, 0x15, 0x14, 0x1b);
11398
11399         return 1;
11400 }
11401
11402 #define alc262_auto_init_multi_out      alc882_auto_init_multi_out
11403 #define alc262_auto_init_hp_out         alc882_auto_init_hp_out
11404 #define alc262_auto_init_analog_input   alc882_auto_init_analog_input
11405 #define alc262_auto_init_input_src      alc882_auto_init_input_src
11406
11407
11408 /* init callback for auto-configuration model -- overriding the default init */
11409 static void alc262_auto_init(struct hda_codec *codec)
11410 {
11411         struct alc_spec *spec = codec->spec;
11412         alc262_auto_init_multi_out(codec);
11413         alc262_auto_init_hp_out(codec);
11414         alc262_auto_init_analog_input(codec);
11415         alc262_auto_init_input_src(codec);
11416         if (spec->unsol_event)
11417                 alc_inithook(codec);
11418 }
11419
11420 /*
11421  * configuration and preset
11422  */
11423 static const char *alc262_models[ALC262_MODEL_LAST] = {
11424         [ALC262_BASIC]          = "basic",
11425         [ALC262_HIPPO]          = "hippo",
11426         [ALC262_HIPPO_1]        = "hippo_1",
11427         [ALC262_FUJITSU]        = "fujitsu",
11428         [ALC262_HP_BPC]         = "hp-bpc",
11429         [ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000",
11430         [ALC262_HP_TC_T5735]    = "hp-tc-t5735",
11431         [ALC262_HP_RP5700]      = "hp-rp5700",
11432         [ALC262_BENQ_ED8]       = "benq",
11433         [ALC262_BENQ_T31]       = "benq-t31",
11434         [ALC262_SONY_ASSAMD]    = "sony-assamd",
11435         [ALC262_TOSHIBA_S06]    = "toshiba-s06",
11436         [ALC262_TOSHIBA_RX1]    = "toshiba-rx1",
11437         [ALC262_ULTRA]          = "ultra",
11438         [ALC262_LENOVO_3000]    = "lenovo-3000",
11439         [ALC262_NEC]            = "nec",
11440         [ALC262_TYAN]           = "tyan",
11441         [ALC262_AUTO]           = "auto",
11442 };
11443
11444 static struct snd_pci_quirk alc262_cfg_tbl[] = {
11445         SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
11446         SND_PCI_QUIRK(0x1033, 0x8895, "NEC Versa S9100", ALC262_NEC),
11447         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1200, "HP xw series",
11448                            ALC262_HP_BPC),
11449         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1300, "HP xw series",
11450                            ALC262_HP_BPC),
11451         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1700, "HP xw series",
11452                            ALC262_HP_BPC),
11453         SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
11454         SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
11455         SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
11456         SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF),
11457         SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL),
11458         SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF),
11459         SND_PCI_QUIRK(0x103c, 0x2806, "HP D7000", ALC262_HP_BPC_D7000_WL),
11460         SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF),
11461         SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC),
11462         SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC),
11463         SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC),
11464         SND_PCI_QUIRK(0x103c, 0x302f, "HP Thin Client T5735",
11465                       ALC262_HP_TC_T5735),
11466         SND_PCI_QUIRK(0x103c, 0x2817, "HP RP5700", ALC262_HP_RP5700),
11467         SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD),
11468         SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
11469         SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
11470         SND_PCI_QUIRK(0x104d, 0x9016, "Sony VAIO", ALC262_AUTO), /* dig-only */
11471         SND_PCI_QUIRK(0x104d, 0x9025, "Sony VAIO Z21MN", ALC262_TOSHIBA_S06),
11472         SND_PCI_QUIRK(0x104d, 0x9035, "Sony VAIO VGN-FW170J", ALC262_AUTO),
11473         SND_PCI_QUIRK(0x104d, 0x9047, "Sony VAIO Type G", ALC262_AUTO),
11474 #if 0 /* disable the quirk since model=auto works better in recent versions */
11475         SND_PCI_QUIRK_MASK(0x104d, 0xff00, 0x9000, "Sony VAIO",
11476                            ALC262_SONY_ASSAMD),
11477 #endif
11478         SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
11479                       ALC262_TOSHIBA_RX1),
11480         SND_PCI_QUIRK(0x1179, 0xff7b, "Toshiba S06", ALC262_TOSHIBA_S06),
11481         SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
11482         SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU),
11483         SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_TYAN),
11484         SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc032, "Samsung Q1",
11485                            ALC262_ULTRA),
11486         SND_PCI_QUIRK(0x144d, 0xc510, "Samsung Q45", ALC262_HIPPO),
11487         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 y410", ALC262_LENOVO_3000),
11488         SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
11489         SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
11490         SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
11491         {}
11492 };
11493
11494 static struct alc_config_preset alc262_presets[] = {
11495         [ALC262_BASIC] = {
11496                 .mixers = { alc262_base_mixer },
11497                 .init_verbs = { alc262_init_verbs },
11498                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11499                 .dac_nids = alc262_dac_nids,
11500                 .hp_nid = 0x03,
11501                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11502                 .channel_mode = alc262_modes,
11503                 .input_mux = &alc262_capture_source,
11504         },
11505         [ALC262_HIPPO] = {
11506                 .mixers = { alc262_hippo_mixer },
11507                 .init_verbs = { alc262_init_verbs, alc_hp15_unsol_verbs},
11508                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11509                 .dac_nids = alc262_dac_nids,
11510                 .hp_nid = 0x03,
11511                 .dig_out_nid = ALC262_DIGOUT_NID,
11512                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11513                 .channel_mode = alc262_modes,
11514                 .input_mux = &alc262_capture_source,
11515                 .unsol_event = alc262_hippo_unsol_event,
11516                 .setup = alc262_hippo_setup,
11517                 .init_hook = alc262_hippo_automute,
11518         },
11519         [ALC262_HIPPO_1] = {
11520                 .mixers = { alc262_hippo1_mixer },
11521                 .init_verbs = { alc262_init_verbs, alc262_hippo1_unsol_verbs},
11522                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11523                 .dac_nids = alc262_dac_nids,
11524                 .hp_nid = 0x02,
11525                 .dig_out_nid = ALC262_DIGOUT_NID,
11526                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11527                 .channel_mode = alc262_modes,
11528                 .input_mux = &alc262_capture_source,
11529                 .unsol_event = alc262_hippo_unsol_event,
11530                 .setup = alc262_hippo1_setup,
11531                 .init_hook = alc262_hippo_automute,
11532         },
11533         [ALC262_FUJITSU] = {
11534                 .mixers = { alc262_fujitsu_mixer },
11535                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
11536                                 alc262_fujitsu_unsol_verbs },
11537                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11538                 .dac_nids = alc262_dac_nids,
11539                 .hp_nid = 0x03,
11540                 .dig_out_nid = ALC262_DIGOUT_NID,
11541                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11542                 .channel_mode = alc262_modes,
11543                 .input_mux = &alc262_fujitsu_capture_source,
11544                 .unsol_event = alc262_fujitsu_unsol_event,
11545                 .init_hook = alc262_fujitsu_init_hook,
11546         },
11547         [ALC262_HP_BPC] = {
11548                 .mixers = { alc262_HP_BPC_mixer },
11549                 .init_verbs = { alc262_HP_BPC_init_verbs },
11550                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11551                 .dac_nids = alc262_dac_nids,
11552                 .hp_nid = 0x03,
11553                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11554                 .channel_mode = alc262_modes,
11555                 .input_mux = &alc262_HP_capture_source,
11556                 .unsol_event = alc262_hp_bpc_unsol_event,
11557                 .init_hook = alc262_hp_bpc_automute,
11558         },
11559         [ALC262_HP_BPC_D7000_WF] = {
11560                 .mixers = { alc262_HP_BPC_WildWest_mixer },
11561                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
11562                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11563                 .dac_nids = alc262_dac_nids,
11564                 .hp_nid = 0x03,
11565                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11566                 .channel_mode = alc262_modes,
11567                 .input_mux = &alc262_HP_D7000_capture_source,
11568                 .unsol_event = alc262_hp_wildwest_unsol_event,
11569                 .init_hook = alc262_hp_wildwest_automute,
11570         },
11571         [ALC262_HP_BPC_D7000_WL] = {
11572                 .mixers = { alc262_HP_BPC_WildWest_mixer,
11573                             alc262_HP_BPC_WildWest_option_mixer },
11574                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
11575                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11576                 .dac_nids = alc262_dac_nids,
11577                 .hp_nid = 0x03,
11578                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11579                 .channel_mode = alc262_modes,
11580                 .input_mux = &alc262_HP_D7000_capture_source,
11581                 .unsol_event = alc262_hp_wildwest_unsol_event,
11582                 .init_hook = alc262_hp_wildwest_automute,
11583         },
11584         [ALC262_HP_TC_T5735] = {
11585                 .mixers = { alc262_hp_t5735_mixer },
11586                 .init_verbs = { alc262_init_verbs, alc262_hp_t5735_verbs },
11587                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11588                 .dac_nids = alc262_dac_nids,
11589                 .hp_nid = 0x03,
11590                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11591                 .channel_mode = alc262_modes,
11592                 .input_mux = &alc262_capture_source,
11593                 .unsol_event = alc_automute_amp_unsol_event,
11594                 .setup = alc262_hp_t5735_setup,
11595                 .init_hook = alc_automute_amp,
11596         },
11597         [ALC262_HP_RP5700] = {
11598                 .mixers = { alc262_hp_rp5700_mixer },
11599                 .init_verbs = { alc262_init_verbs, alc262_hp_rp5700_verbs },
11600                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11601                 .dac_nids = alc262_dac_nids,
11602                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11603                 .channel_mode = alc262_modes,
11604                 .input_mux = &alc262_hp_rp5700_capture_source,
11605         },
11606         [ALC262_BENQ_ED8] = {
11607                 .mixers = { alc262_base_mixer },
11608                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs },
11609                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11610                 .dac_nids = alc262_dac_nids,
11611                 .hp_nid = 0x03,
11612                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11613                 .channel_mode = alc262_modes,
11614                 .input_mux = &alc262_capture_source,
11615         },
11616         [ALC262_SONY_ASSAMD] = {
11617                 .mixers = { alc262_sony_mixer },
11618                 .init_verbs = { alc262_init_verbs, alc262_sony_unsol_verbs},
11619                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11620                 .dac_nids = alc262_dac_nids,
11621                 .hp_nid = 0x02,
11622                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11623                 .channel_mode = alc262_modes,
11624                 .input_mux = &alc262_capture_source,
11625                 .unsol_event = alc262_hippo_unsol_event,
11626                 .setup = alc262_hippo_setup,
11627                 .init_hook = alc262_hippo_automute,
11628         },
11629         [ALC262_BENQ_T31] = {
11630                 .mixers = { alc262_benq_t31_mixer },
11631                 .init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs,
11632                                 alc_hp15_unsol_verbs },
11633                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11634                 .dac_nids = alc262_dac_nids,
11635                 .hp_nid = 0x03,
11636                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11637                 .channel_mode = alc262_modes,
11638                 .input_mux = &alc262_capture_source,
11639                 .unsol_event = alc262_hippo_unsol_event,
11640                 .setup = alc262_hippo_setup,
11641                 .init_hook = alc262_hippo_automute,
11642         },
11643         [ALC262_ULTRA] = {
11644                 .mixers = { alc262_ultra_mixer },
11645                 .cap_mixer = alc262_ultra_capture_mixer,
11646                 .init_verbs = { alc262_ultra_verbs },
11647                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11648                 .dac_nids = alc262_dac_nids,
11649                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11650                 .channel_mode = alc262_modes,
11651                 .input_mux = &alc262_ultra_capture_source,
11652                 .adc_nids = alc262_adc_nids, /* ADC0 */
11653                 .capsrc_nids = alc262_capsrc_nids,
11654                 .num_adc_nids = 1, /* single ADC */
11655                 .unsol_event = alc262_ultra_unsol_event,
11656                 .init_hook = alc262_ultra_automute,
11657         },
11658         [ALC262_LENOVO_3000] = {
11659                 .mixers = { alc262_lenovo_3000_mixer },
11660                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
11661                                 alc262_lenovo_3000_unsol_verbs },
11662                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11663                 .dac_nids = alc262_dac_nids,
11664                 .hp_nid = 0x03,
11665                 .dig_out_nid = ALC262_DIGOUT_NID,
11666                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11667                 .channel_mode = alc262_modes,
11668                 .input_mux = &alc262_fujitsu_capture_source,
11669                 .unsol_event = alc262_lenovo_3000_unsol_event,
11670         },
11671         [ALC262_NEC] = {
11672                 .mixers = { alc262_nec_mixer },
11673                 .init_verbs = { alc262_nec_verbs },
11674                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11675                 .dac_nids = alc262_dac_nids,
11676                 .hp_nid = 0x03,
11677                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11678                 .channel_mode = alc262_modes,
11679                 .input_mux = &alc262_capture_source,
11680         },
11681         [ALC262_TOSHIBA_S06] = {
11682                 .mixers = { alc262_toshiba_s06_mixer },
11683                 .init_verbs = { alc262_init_verbs, alc262_toshiba_s06_verbs,
11684                                                         alc262_eapd_verbs },
11685                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11686                 .capsrc_nids = alc262_dmic_capsrc_nids,
11687                 .dac_nids = alc262_dac_nids,
11688                 .adc_nids = alc262_dmic_adc_nids, /* ADC0 */
11689                 .num_adc_nids = 1, /* single ADC */
11690                 .dig_out_nid = ALC262_DIGOUT_NID,
11691                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11692                 .channel_mode = alc262_modes,
11693                 .unsol_event = alc_sku_unsol_event,
11694                 .setup = alc262_toshiba_s06_setup,
11695                 .init_hook = alc_inithook,
11696         },
11697         [ALC262_TOSHIBA_RX1] = {
11698                 .mixers = { alc262_toshiba_rx1_mixer },
11699                 .init_verbs = { alc262_init_verbs, alc262_toshiba_rx1_unsol_verbs },
11700                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11701                 .dac_nids = alc262_dac_nids,
11702                 .hp_nid = 0x03,
11703                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11704                 .channel_mode = alc262_modes,
11705                 .input_mux = &alc262_capture_source,
11706                 .unsol_event = alc262_hippo_unsol_event,
11707                 .setup = alc262_hippo_setup,
11708                 .init_hook = alc262_hippo_automute,
11709         },
11710         [ALC262_TYAN] = {
11711                 .mixers = { alc262_tyan_mixer },
11712                 .init_verbs = { alc262_init_verbs, alc262_tyan_verbs},
11713                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11714                 .dac_nids = alc262_dac_nids,
11715                 .hp_nid = 0x02,
11716                 .dig_out_nid = ALC262_DIGOUT_NID,
11717                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11718                 .channel_mode = alc262_modes,
11719                 .input_mux = &alc262_capture_source,
11720                 .unsol_event = alc_automute_amp_unsol_event,
11721                 .setup = alc262_tyan_setup,
11722                 .init_hook = alc_automute_amp,
11723         },
11724 };
11725
11726 static int patch_alc262(struct hda_codec *codec)
11727 {
11728         struct alc_spec *spec;
11729         int board_config;
11730         int err;
11731
11732         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
11733         if (spec == NULL)
11734                 return -ENOMEM;
11735
11736         codec->spec = spec;
11737 #if 0
11738         /* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is
11739          * under-run
11740          */
11741         {
11742         int tmp;
11743         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
11744         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
11745         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
11746         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
11747         }
11748 #endif
11749
11750         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
11751
11752         board_config = snd_hda_check_board_config(codec, ALC262_MODEL_LAST,
11753                                                   alc262_models,
11754                                                   alc262_cfg_tbl);
11755
11756         if (board_config < 0) {
11757                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
11758                        codec->chip_name);
11759                 board_config = ALC262_AUTO;
11760         }
11761
11762         if (board_config == ALC262_AUTO) {
11763                 /* automatic parse from the BIOS config */
11764                 err = alc262_parse_auto_config(codec);
11765                 if (err < 0) {
11766                         alc_free(codec);
11767                         return err;
11768                 } else if (!err) {
11769                         printk(KERN_INFO
11770                                "hda_codec: Cannot set up configuration "
11771                                "from BIOS.  Using base mode...\n");
11772                         board_config = ALC262_BASIC;
11773                 }
11774         }
11775
11776         if (!spec->no_analog) {
11777                 err = snd_hda_attach_beep_device(codec, 0x1);
11778                 if (err < 0) {
11779                         alc_free(codec);
11780                         return err;
11781                 }
11782         }
11783
11784         if (board_config != ALC262_AUTO)
11785                 setup_preset(codec, &alc262_presets[board_config]);
11786
11787         spec->stream_analog_playback = &alc262_pcm_analog_playback;
11788         spec->stream_analog_capture = &alc262_pcm_analog_capture;
11789
11790         spec->stream_digital_playback = &alc262_pcm_digital_playback;
11791         spec->stream_digital_capture = &alc262_pcm_digital_capture;
11792
11793         if (!spec->adc_nids && spec->input_mux) {
11794                 int i;
11795                 /* check whether the digital-mic has to be supported */
11796                 for (i = 0; i < spec->input_mux->num_items; i++) {
11797                         if (spec->input_mux->items[i].index >= 9)
11798                                 break;
11799                 }
11800                 if (i < spec->input_mux->num_items) {
11801                         /* use only ADC0 */
11802                         spec->adc_nids = alc262_dmic_adc_nids;
11803                         spec->num_adc_nids = 1;
11804                         spec->capsrc_nids = alc262_dmic_capsrc_nids;
11805                 } else {
11806                         /* all analog inputs */
11807                         /* check whether NID 0x07 is valid */
11808                         unsigned int wcap = get_wcaps(codec, 0x07);
11809
11810                         /* get type */
11811                         wcap = get_wcaps_type(wcap);
11812                         if (wcap != AC_WID_AUD_IN) {
11813                                 spec->adc_nids = alc262_adc_nids_alt;
11814                                 spec->num_adc_nids =
11815                                         ARRAY_SIZE(alc262_adc_nids_alt);
11816                                 spec->capsrc_nids = alc262_capsrc_nids_alt;
11817                         } else {
11818                                 spec->adc_nids = alc262_adc_nids;
11819                                 spec->num_adc_nids =
11820                                         ARRAY_SIZE(alc262_adc_nids);
11821                                 spec->capsrc_nids = alc262_capsrc_nids;
11822                         }
11823                 }
11824         }
11825         if (!spec->cap_mixer && !spec->no_analog)
11826                 set_capture_mixer(codec);
11827         if (!spec->no_analog)
11828                 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
11829
11830         spec->vmaster_nid = 0x0c;
11831
11832         codec->patch_ops = alc_patch_ops;
11833         if (board_config == ALC262_AUTO)
11834                 spec->init_hook = alc262_auto_init;
11835 #ifdef CONFIG_SND_HDA_POWER_SAVE
11836         if (!spec->loopback.amplist)
11837                 spec->loopback.amplist = alc262_loopbacks;
11838 #endif
11839         codec->proc_widget_hook = print_realtek_coef;
11840
11841         return 0;
11842 }
11843
11844 /*
11845  *  ALC268 channel source setting (2 channel)
11846  */
11847 #define ALC268_DIGOUT_NID       ALC880_DIGOUT_NID
11848 #define alc268_modes            alc260_modes
11849
11850 static hda_nid_t alc268_dac_nids[2] = {
11851         /* front, hp */
11852         0x02, 0x03
11853 };
11854
11855 static hda_nid_t alc268_adc_nids[2] = {
11856         /* ADC0-1 */
11857         0x08, 0x07
11858 };
11859
11860 static hda_nid_t alc268_adc_nids_alt[1] = {
11861         /* ADC0 */
11862         0x08
11863 };
11864
11865 static hda_nid_t alc268_capsrc_nids[2] = { 0x23, 0x24 };
11866
11867 static struct snd_kcontrol_new alc268_base_mixer[] = {
11868         /* output mixer control */
11869         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
11870         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11871         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
11872         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11873         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11874         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
11875         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11876         { }
11877 };
11878
11879 static struct snd_kcontrol_new alc268_toshiba_mixer[] = {
11880         /* output mixer control */
11881         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
11882         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
11883         ALC262_HIPPO_MASTER_SWITCH,
11884         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11885         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
11886         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11887         { }
11888 };
11889
11890 /* bind Beep switches of both NID 0x0f and 0x10 */
11891 static struct hda_bind_ctls alc268_bind_beep_sw = {
11892         .ops = &snd_hda_bind_sw,
11893         .values = {
11894                 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
11895                 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
11896                 0
11897         },
11898 };
11899
11900 static struct snd_kcontrol_new alc268_beep_mixer[] = {
11901         HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
11902         HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
11903         { }
11904 };
11905
11906 static struct hda_verb alc268_eapd_verbs[] = {
11907         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
11908         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
11909         { }
11910 };
11911
11912 /* Toshiba specific */
11913 static struct hda_verb alc268_toshiba_verbs[] = {
11914         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11915         { } /* end */
11916 };
11917
11918 /* Acer specific */
11919 /* bind volumes of both NID 0x02 and 0x03 */
11920 static struct hda_bind_ctls alc268_acer_bind_master_vol = {
11921         .ops = &snd_hda_bind_vol,
11922         .values = {
11923                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
11924                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
11925                 0
11926         },
11927 };
11928
11929 /* mute/unmute internal speaker according to the hp jack and mute state */
11930 static void alc268_acer_automute(struct hda_codec *codec, int force)
11931 {
11932         struct alc_spec *spec = codec->spec;
11933         unsigned int mute;
11934
11935         if (force || !spec->sense_updated) {
11936                 unsigned int present;
11937                 present = snd_hda_codec_read(codec, 0x14, 0,
11938                                          AC_VERB_GET_PIN_SENSE, 0);
11939                 spec->jack_present = (present & 0x80000000) != 0;
11940                 spec->sense_updated = 1;
11941         }
11942         if (spec->jack_present)
11943                 mute = HDA_AMP_MUTE; /* mute internal speaker */
11944         else /* unmute internal speaker if necessary */
11945                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
11946         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
11947                                  HDA_AMP_MUTE, mute);
11948 }
11949
11950
11951 /* bind hp and internal speaker mute (with plug check) */
11952 static int alc268_acer_master_sw_put(struct snd_kcontrol *kcontrol,
11953                                      struct snd_ctl_elem_value *ucontrol)
11954 {
11955         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
11956         long *valp = ucontrol->value.integer.value;
11957         int change;
11958
11959         change = amp_stereo_mute_update(codec, 0x14, HDA_OUTPUT, 0, valp);
11960         if (change)
11961                 alc268_acer_automute(codec, 0);
11962         return change;
11963 }
11964
11965 static struct snd_kcontrol_new alc268_acer_aspire_one_mixer[] = {
11966         /* output mixer control */
11967         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11968         {
11969                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11970                 .name = "Master Playback Switch",
11971                 .info = snd_hda_mixer_amp_switch_info,
11972                 .get = snd_hda_mixer_amp_switch_get,
11973                 .put = alc268_acer_master_sw_put,
11974                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11975         },
11976         HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x18, 0, HDA_INPUT),
11977         { }
11978 };
11979
11980 static struct snd_kcontrol_new alc268_acer_mixer[] = {
11981         /* output mixer control */
11982         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11983         {
11984                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11985                 .name = "Master Playback Switch",
11986                 .info = snd_hda_mixer_amp_switch_info,
11987                 .get = snd_hda_mixer_amp_switch_get,
11988                 .put = alc268_acer_master_sw_put,
11989                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11990         },
11991         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11992         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
11993         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11994         { }
11995 };
11996
11997 static struct snd_kcontrol_new alc268_acer_dmic_mixer[] = {
11998         /* output mixer control */
11999         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
12000         {
12001                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12002                 .name = "Master Playback Switch",
12003                 .info = snd_hda_mixer_amp_switch_info,
12004                 .get = snd_hda_mixer_amp_switch_get,
12005                 .put = alc268_acer_master_sw_put,
12006                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
12007         },
12008         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12009         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
12010         { }
12011 };
12012
12013 static struct hda_verb alc268_acer_aspire_one_verbs[] = {
12014         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12015         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12016         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12017         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12018         {0x23, AC_VERB_SET_CONNECT_SEL, 0x06},
12019         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, 0xa017},
12020         { }
12021 };
12022
12023 static struct hda_verb alc268_acer_verbs[] = {
12024         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* internal dmic? */
12025         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12026         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12027         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12028         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12029         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12030         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12031         { }
12032 };
12033
12034 /* unsolicited event for HP jack sensing */
12035 #define alc268_toshiba_unsol_event      alc262_hippo_unsol_event
12036 #define alc268_toshiba_setup            alc262_hippo_setup
12037 #define alc268_toshiba_automute         alc262_hippo_automute
12038
12039 static void alc268_acer_unsol_event(struct hda_codec *codec,
12040                                        unsigned int res)
12041 {
12042         if ((res >> 26) != ALC880_HP_EVENT)
12043                 return;
12044         alc268_acer_automute(codec, 1);
12045 }
12046
12047 static void alc268_acer_init_hook(struct hda_codec *codec)
12048 {
12049         alc268_acer_automute(codec, 1);
12050 }
12051
12052 /* toggle speaker-output according to the hp-jack state */
12053 static void alc268_aspire_one_speaker_automute(struct hda_codec *codec)
12054 {
12055         unsigned int present;
12056         unsigned char bits;
12057
12058         present = snd_hda_codec_read(codec, 0x15, 0,
12059                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12060         bits = present ? AMP_IN_MUTE(0) : 0;
12061         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 0,
12062                                 AMP_IN_MUTE(0), bits);
12063         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 1,
12064                                 AMP_IN_MUTE(0), bits);
12065 }
12066
12067 static void alc268_acer_lc_unsol_event(struct hda_codec *codec,
12068                                     unsigned int res)
12069 {
12070         switch (res >> 26) {
12071         case ALC880_HP_EVENT:
12072                 alc268_aspire_one_speaker_automute(codec);
12073                 break;
12074         case ALC880_MIC_EVENT:
12075                 alc_mic_automute(codec);
12076                 break;
12077         }
12078 }
12079
12080 static void alc268_acer_lc_setup(struct hda_codec *codec)
12081 {
12082         struct alc_spec *spec = codec->spec;
12083         spec->ext_mic.pin = 0x18;
12084         spec->ext_mic.mux_idx = 0;
12085         spec->int_mic.pin = 0x12;
12086         spec->int_mic.mux_idx = 6;
12087         spec->auto_mic = 1;
12088 }
12089
12090 static void alc268_acer_lc_init_hook(struct hda_codec *codec)
12091 {
12092         alc268_aspire_one_speaker_automute(codec);
12093         alc_mic_automute(codec);
12094 }
12095
12096 static struct snd_kcontrol_new alc268_dell_mixer[] = {
12097         /* output mixer control */
12098         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12099         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12100         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12101         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12102         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12103         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
12104         { }
12105 };
12106
12107 static struct hda_verb alc268_dell_verbs[] = {
12108         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12109         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12110         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12111         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
12112         { }
12113 };
12114
12115 /* mute/unmute internal speaker according to the hp jack and mute state */
12116 static void alc268_dell_setup(struct hda_codec *codec)
12117 {
12118         struct alc_spec *spec = codec->spec;
12119
12120         spec->autocfg.hp_pins[0] = 0x15;
12121         spec->autocfg.speaker_pins[0] = 0x14;
12122         spec->ext_mic.pin = 0x18;
12123         spec->ext_mic.mux_idx = 0;
12124         spec->int_mic.pin = 0x19;
12125         spec->int_mic.mux_idx = 1;
12126         spec->auto_mic = 1;
12127 }
12128
12129 static struct snd_kcontrol_new alc267_quanta_il1_mixer[] = {
12130         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x2, 0x0, HDA_OUTPUT),
12131         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12132         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
12133         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12134         HDA_CODEC_VOLUME("Mic Capture Volume", 0x23, 0x0, HDA_OUTPUT),
12135         HDA_BIND_MUTE("Mic Capture Switch", 0x23, 2, HDA_OUTPUT),
12136         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
12137         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
12138         { }
12139 };
12140
12141 static struct hda_verb alc267_quanta_il1_verbs[] = {
12142         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12143         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
12144         { }
12145 };
12146
12147 static void alc267_quanta_il1_setup(struct hda_codec *codec)
12148 {
12149         struct alc_spec *spec = codec->spec;
12150         spec->autocfg.hp_pins[0] = 0x15;
12151         spec->autocfg.speaker_pins[0] = 0x14;
12152         spec->ext_mic.pin = 0x18;
12153         spec->ext_mic.mux_idx = 0;
12154         spec->int_mic.pin = 0x19;
12155         spec->int_mic.mux_idx = 1;
12156         spec->auto_mic = 1;
12157 }
12158
12159 /*
12160  * generic initialization of ADC, input mixers and output mixers
12161  */
12162 static struct hda_verb alc268_base_init_verbs[] = {
12163         /* Unmute DAC0-1 and set vol = 0 */
12164         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12165         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12166
12167         /*
12168          * Set up output mixers (0x0c - 0x0e)
12169          */
12170         /* set vol=0 to output mixers */
12171         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12172         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
12173
12174         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12175         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12176
12177         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
12178         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
12179         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
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         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12187         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12188         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12189         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12190         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12191
12192         /* set PCBEEP vol = 0, mute connections */
12193         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12194         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12195         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12196
12197         /* Unmute Selector 23h,24h and set the default input to mic-in */
12198
12199         {0x23, AC_VERB_SET_CONNECT_SEL, 0x00},
12200         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12201         {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
12202         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12203
12204         { }
12205 };
12206
12207 /*
12208  * generic initialization of ADC, input mixers and output mixers
12209  */
12210 static struct hda_verb alc268_volume_init_verbs[] = {
12211         /* set output DAC */
12212         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12213         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12214
12215         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
12216         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
12217         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12218         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12219         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12220
12221         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12222         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12223         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12224
12225         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12226         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12227
12228         /* set PCBEEP vol = 0, mute connections */
12229         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12230         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12231         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12232
12233         { }
12234 };
12235
12236 static struct snd_kcontrol_new alc268_capture_nosrc_mixer[] = {
12237         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
12238         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
12239         { } /* end */
12240 };
12241
12242 static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
12243         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
12244         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
12245         _DEFINE_CAPSRC(1),
12246         { } /* end */
12247 };
12248
12249 static struct snd_kcontrol_new alc268_capture_mixer[] = {
12250         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
12251         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
12252         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
12253         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
12254         _DEFINE_CAPSRC(2),
12255         { } /* end */
12256 };
12257
12258 static struct hda_input_mux alc268_capture_source = {
12259         .num_items = 4,
12260         .items = {
12261                 { "Mic", 0x0 },
12262                 { "Front Mic", 0x1 },
12263                 { "Line", 0x2 },
12264                 { "CD", 0x3 },
12265         },
12266 };
12267
12268 static struct hda_input_mux alc268_acer_capture_source = {
12269         .num_items = 3,
12270         .items = {
12271                 { "Mic", 0x0 },
12272                 { "Internal Mic", 0x1 },
12273                 { "Line", 0x2 },
12274         },
12275 };
12276
12277 static struct hda_input_mux alc268_acer_dmic_capture_source = {
12278         .num_items = 3,
12279         .items = {
12280                 { "Mic", 0x0 },
12281                 { "Internal Mic", 0x6 },
12282                 { "Line", 0x2 },
12283         },
12284 };
12285
12286 #ifdef CONFIG_SND_DEBUG
12287 static struct snd_kcontrol_new alc268_test_mixer[] = {
12288         /* Volume widgets */
12289         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12290         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12291         HDA_BIND_MUTE_MONO("Mono sum Playback Switch", 0x0e, 1, 2, HDA_INPUT),
12292         HDA_BIND_MUTE("LINE-OUT sum Playback Switch", 0x0f, 2, HDA_INPUT),
12293         HDA_BIND_MUTE("HP-OUT sum Playback Switch", 0x10, 2, HDA_INPUT),
12294         HDA_BIND_MUTE("LINE-OUT Playback Switch", 0x14, 2, HDA_OUTPUT),
12295         HDA_BIND_MUTE("HP-OUT Playback Switch", 0x15, 2, HDA_OUTPUT),
12296         HDA_BIND_MUTE("Mono Playback Switch", 0x16, 2, HDA_OUTPUT),
12297         HDA_CODEC_VOLUME("MIC1 Capture Volume", 0x18, 0x0, HDA_INPUT),
12298         HDA_BIND_MUTE("MIC1 Capture Switch", 0x18, 2, HDA_OUTPUT),
12299         HDA_CODEC_VOLUME("MIC2 Capture Volume", 0x19, 0x0, HDA_INPUT),
12300         HDA_CODEC_VOLUME("LINE1 Capture Volume", 0x1a, 0x0, HDA_INPUT),
12301         HDA_BIND_MUTE("LINE1 Capture Switch", 0x1a, 2, HDA_OUTPUT),
12302         /* The below appears problematic on some hardwares */
12303         /*HDA_CODEC_VOLUME("PCBEEP Playback Volume", 0x1d, 0x0, HDA_INPUT),*/
12304         HDA_CODEC_VOLUME("PCM-IN1 Capture Volume", 0x23, 0x0, HDA_OUTPUT),
12305         HDA_BIND_MUTE("PCM-IN1 Capture Switch", 0x23, 2, HDA_OUTPUT),
12306         HDA_CODEC_VOLUME("PCM-IN2 Capture Volume", 0x24, 0x0, HDA_OUTPUT),
12307         HDA_BIND_MUTE("PCM-IN2 Capture Switch", 0x24, 2, HDA_OUTPUT),
12308
12309         /* Modes for retasking pin widgets */
12310         ALC_PIN_MODE("LINE-OUT pin mode", 0x14, ALC_PIN_DIR_INOUT),
12311         ALC_PIN_MODE("HP-OUT pin mode", 0x15, ALC_PIN_DIR_INOUT),
12312         ALC_PIN_MODE("MIC1 pin mode", 0x18, ALC_PIN_DIR_INOUT),
12313         ALC_PIN_MODE("LINE1 pin mode", 0x1a, ALC_PIN_DIR_INOUT),
12314
12315         /* Controls for GPIO pins, assuming they are configured as outputs */
12316         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
12317         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
12318         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
12319         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
12320
12321         /* Switches to allow the digital SPDIF output pin to be enabled.
12322          * The ALC268 does not have an SPDIF input.
12323          */
12324         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x06, 0x01),
12325
12326         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
12327          * this output to turn on an external amplifier.
12328          */
12329         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
12330         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
12331
12332         { } /* end */
12333 };
12334 #endif
12335
12336 /* create input playback/capture controls for the given pin */
12337 static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
12338                                     const char *ctlname, int idx)
12339 {
12340         hda_nid_t dac;
12341         int err;
12342
12343         switch (nid) {
12344         case 0x14:
12345         case 0x16:
12346                 dac = 0x02;
12347                 break;
12348         case 0x15:
12349                 dac = 0x03;
12350                 break;
12351         default:
12352                 return 0;
12353         }
12354         if (spec->multiout.dac_nids[0] != dac &&
12355             spec->multiout.dac_nids[1] != dac) {
12356                 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname,
12357                                   HDA_COMPOSE_AMP_VAL(dac, 3, idx,
12358                                                       HDA_OUTPUT));
12359                 if (err < 0)
12360                         return err;
12361                 spec->multiout.dac_nids[spec->multiout.num_dacs++] = dac;
12362         }
12363
12364         if (nid != 0x16)
12365                 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname,
12366                           HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
12367         else /* mono */
12368                 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname,
12369                           HDA_COMPOSE_AMP_VAL(nid, 2, idx, HDA_OUTPUT));
12370         if (err < 0)
12371                 return err;
12372         return 0;
12373 }
12374
12375 /* add playback controls from the parsed DAC table */
12376 static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
12377                                              const struct auto_pin_cfg *cfg)
12378 {
12379         hda_nid_t nid;
12380         int err;
12381
12382         spec->multiout.dac_nids = spec->private_dac_nids;
12383
12384         nid = cfg->line_out_pins[0];
12385         if (nid) {
12386                 const char *name;
12387                 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
12388                         name = "Speaker";
12389                 else
12390                         name = "Front";
12391                 err = alc268_new_analog_output(spec, nid, name, 0);
12392                 if (err < 0)
12393                         return err;
12394         }
12395
12396         nid = cfg->speaker_pins[0];
12397         if (nid == 0x1d) {
12398                 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, "Speaker",
12399                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
12400                 if (err < 0)
12401                         return err;
12402         } else {
12403                 err = alc268_new_analog_output(spec, nid, "Speaker", 0);
12404                 if (err < 0)
12405                         return err;
12406         }
12407         nid = cfg->hp_pins[0];
12408         if (nid) {
12409                 err = alc268_new_analog_output(spec, nid, "Headphone", 0);
12410                 if (err < 0)
12411                         return err;
12412         }
12413
12414         nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
12415         if (nid == 0x16) {
12416                 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, "Mono",
12417                                   HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT));
12418                 if (err < 0)
12419                         return err;
12420         }
12421         return 0;
12422 }
12423
12424 /* create playback/capture controls for input pins */
12425 static int alc268_auto_create_input_ctls(struct hda_codec *codec,
12426                                                 const struct auto_pin_cfg *cfg)
12427 {
12428         return alc_auto_create_input_ctls(codec, cfg, 0, 0x23, 0x24);
12429 }
12430
12431 static void alc268_auto_set_output_and_unmute(struct hda_codec *codec,
12432                                               hda_nid_t nid, int pin_type)
12433 {
12434         int idx;
12435
12436         alc_set_pin_output(codec, nid, pin_type);
12437         if (nid == 0x14 || nid == 0x16)
12438                 idx = 0;
12439         else
12440                 idx = 1;
12441         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
12442 }
12443
12444 static void alc268_auto_init_multi_out(struct hda_codec *codec)
12445 {
12446         struct alc_spec *spec = codec->spec;
12447         hda_nid_t nid = spec->autocfg.line_out_pins[0];
12448         if (nid) {
12449                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
12450                 alc268_auto_set_output_and_unmute(codec, nid, pin_type);
12451         }
12452 }
12453
12454 static void alc268_auto_init_hp_out(struct hda_codec *codec)
12455 {
12456         struct alc_spec *spec = codec->spec;
12457         hda_nid_t pin;
12458
12459         pin = spec->autocfg.hp_pins[0];
12460         if (pin)
12461                 alc268_auto_set_output_and_unmute(codec, pin, PIN_HP);
12462         pin = spec->autocfg.speaker_pins[0];
12463         if (pin)
12464                 alc268_auto_set_output_and_unmute(codec, pin, PIN_OUT);
12465 }
12466
12467 static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
12468 {
12469         struct alc_spec *spec = codec->spec;
12470         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
12471         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
12472         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
12473         unsigned int    dac_vol1, dac_vol2;
12474
12475         if (line_nid == 0x1d || speaker_nid == 0x1d) {
12476                 snd_hda_codec_write(codec, speaker_nid, 0,
12477                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
12478                 /* mute mixer inputs from 0x1d */
12479                 snd_hda_codec_write(codec, 0x0f, 0,
12480                                     AC_VERB_SET_AMP_GAIN_MUTE,
12481                                     AMP_IN_UNMUTE(1));
12482                 snd_hda_codec_write(codec, 0x10, 0,
12483                                     AC_VERB_SET_AMP_GAIN_MUTE,
12484                                     AMP_IN_UNMUTE(1));
12485         } else {
12486                 /* unmute mixer inputs from 0x1d */
12487                 snd_hda_codec_write(codec, 0x0f, 0,
12488                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
12489                 snd_hda_codec_write(codec, 0x10, 0,
12490                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
12491         }
12492
12493         dac_vol1 = dac_vol2 = 0xb000 | 0x40;    /* set max volume  */
12494         if (line_nid == 0x14)
12495                 dac_vol2 = AMP_OUT_ZERO;
12496         else if (line_nid == 0x15)
12497                 dac_vol1 = AMP_OUT_ZERO;
12498         if (hp_nid == 0x14)
12499                 dac_vol2 = AMP_OUT_ZERO;
12500         else if (hp_nid == 0x15)
12501                 dac_vol1 = AMP_OUT_ZERO;
12502         if (line_nid != 0x16 || hp_nid != 0x16 ||
12503             spec->autocfg.line_out_pins[1] != 0x16 ||
12504             spec->autocfg.line_out_pins[2] != 0x16)
12505                 dac_vol1 = dac_vol2 = AMP_OUT_ZERO;
12506
12507         snd_hda_codec_write(codec, 0x02, 0,
12508                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol1);
12509         snd_hda_codec_write(codec, 0x03, 0,
12510                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol2);
12511 }
12512
12513 /* pcm configuration: identical with ALC880 */
12514 #define alc268_pcm_analog_playback      alc880_pcm_analog_playback
12515 #define alc268_pcm_analog_capture       alc880_pcm_analog_capture
12516 #define alc268_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
12517 #define alc268_pcm_digital_playback     alc880_pcm_digital_playback
12518
12519 /*
12520  * BIOS auto configuration
12521  */
12522 static int alc268_parse_auto_config(struct hda_codec *codec)
12523 {
12524         struct alc_spec *spec = codec->spec;
12525         int err;
12526         static hda_nid_t alc268_ignore[] = { 0 };
12527
12528         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
12529                                            alc268_ignore);
12530         if (err < 0)
12531                 return err;
12532         if (!spec->autocfg.line_outs) {
12533                 if (spec->autocfg.dig_outs || spec->autocfg.dig_in_pin) {
12534                         spec->multiout.max_channels = 2;
12535                         spec->no_analog = 1;
12536                         goto dig_only;
12537                 }
12538                 return 0; /* can't find valid BIOS pin config */
12539         }
12540         err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
12541         if (err < 0)
12542                 return err;
12543         err = alc268_auto_create_input_ctls(codec, &spec->autocfg);
12544         if (err < 0)
12545                 return err;
12546
12547         spec->multiout.max_channels = 2;
12548
12549  dig_only:
12550         /* digital only support output */
12551         if (spec->autocfg.dig_outs) {
12552                 spec->multiout.dig_out_nid = ALC268_DIGOUT_NID;
12553                 spec->dig_out_type = spec->autocfg.dig_out_type[0];
12554         }
12555         if (spec->kctls.list)
12556                 add_mixer(spec, spec->kctls.list);
12557
12558         if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d)
12559                 add_mixer(spec, alc268_beep_mixer);
12560
12561         add_verb(spec, alc268_volume_init_verbs);
12562         spec->num_mux_defs = 2;
12563         spec->input_mux = &spec->private_imux[0];
12564
12565         err = alc_auto_add_mic_boost(codec);
12566         if (err < 0)
12567                 return err;
12568
12569         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
12570
12571         return 1;
12572 }
12573
12574 #define alc268_auto_init_analog_input   alc882_auto_init_analog_input
12575
12576 /* init callback for auto-configuration model -- overriding the default init */
12577 static void alc268_auto_init(struct hda_codec *codec)
12578 {
12579         struct alc_spec *spec = codec->spec;
12580         alc268_auto_init_multi_out(codec);
12581         alc268_auto_init_hp_out(codec);
12582         alc268_auto_init_mono_speaker_out(codec);
12583         alc268_auto_init_analog_input(codec);
12584         if (spec->unsol_event)
12585                 alc_inithook(codec);
12586 }
12587
12588 /*
12589  * configuration and preset
12590  */
12591 static const char *alc268_models[ALC268_MODEL_LAST] = {
12592         [ALC267_QUANTA_IL1]     = "quanta-il1",
12593         [ALC268_3ST]            = "3stack",
12594         [ALC268_TOSHIBA]        = "toshiba",
12595         [ALC268_ACER]           = "acer",
12596         [ALC268_ACER_DMIC]      = "acer-dmic",
12597         [ALC268_ACER_ASPIRE_ONE]        = "acer-aspire",
12598         [ALC268_DELL]           = "dell",
12599         [ALC268_ZEPTO]          = "zepto",
12600 #ifdef CONFIG_SND_DEBUG
12601         [ALC268_TEST]           = "test",
12602 #endif
12603         [ALC268_AUTO]           = "auto",
12604 };
12605
12606 static struct snd_pci_quirk alc268_cfg_tbl[] = {
12607         SND_PCI_QUIRK(0x1025, 0x011e, "Acer Aspire 5720z", ALC268_ACER),
12608         SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
12609         SND_PCI_QUIRK(0x1025, 0x012e, "Acer Aspire 5310", ALC268_ACER),
12610         SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
12611         SND_PCI_QUIRK(0x1025, 0x0136, "Acer Aspire 5315", ALC268_ACER),
12612         SND_PCI_QUIRK(0x1025, 0x015b, "Acer Aspire One",
12613                                                 ALC268_ACER_ASPIRE_ONE),
12614         SND_PCI_QUIRK(0x1028, 0x0253, "Dell OEM", ALC268_DELL),
12615         SND_PCI_QUIRK_MASK(0x1028, 0xfff0, 0x02b0,
12616                         "Dell Inspiron Mini9/Vostro A90", ALC268_DELL),
12617         /* almost compatible with toshiba but with optional digital outs;
12618          * auto-probing seems working fine
12619          */
12620         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP TX25xx series",
12621                            ALC268_AUTO),
12622         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
12623         SND_PCI_QUIRK(0x1170, 0x0040, "ZEPTO", ALC268_ZEPTO),
12624         SND_PCI_QUIRK(0x14c0, 0x0025, "COMPAL IFL90/JFL-92", ALC268_TOSHIBA),
12625         SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER),
12626         SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1),
12627         SND_PCI_QUIRK(0x1854, 0x1775, "LG R510", ALC268_DELL),
12628         {}
12629 };
12630
12631 /* Toshiba laptops have no unique PCI SSID but only codec SSID */
12632 static struct snd_pci_quirk alc268_ssid_cfg_tbl[] = {
12633         SND_PCI_QUIRK(0x1179, 0xff0a, "TOSHIBA X-200", ALC268_AUTO),
12634         SND_PCI_QUIRK(0x1179, 0xff0e, "TOSHIBA X-200 HDMI", ALC268_AUTO),
12635         SND_PCI_QUIRK_MASK(0x1179, 0xff00, 0xff00, "TOSHIBA A/Lx05",
12636                            ALC268_TOSHIBA),
12637         {}
12638 };
12639
12640 static struct alc_config_preset alc268_presets[] = {
12641         [ALC267_QUANTA_IL1] = {
12642                 .mixers = { alc267_quanta_il1_mixer, alc268_beep_mixer,
12643                             alc268_capture_nosrc_mixer },
12644                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12645                                 alc267_quanta_il1_verbs },
12646                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12647                 .dac_nids = alc268_dac_nids,
12648                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12649                 .adc_nids = alc268_adc_nids_alt,
12650                 .hp_nid = 0x03,
12651                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12652                 .channel_mode = alc268_modes,
12653                 .unsol_event = alc_sku_unsol_event,
12654                 .setup = alc267_quanta_il1_setup,
12655                 .init_hook = alc_inithook,
12656         },
12657         [ALC268_3ST] = {
12658                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
12659                             alc268_beep_mixer },
12660                 .init_verbs = { alc268_base_init_verbs },
12661                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12662                 .dac_nids = alc268_dac_nids,
12663                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12664                 .adc_nids = alc268_adc_nids_alt,
12665                 .capsrc_nids = alc268_capsrc_nids,
12666                 .hp_nid = 0x03,
12667                 .dig_out_nid = ALC268_DIGOUT_NID,
12668                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12669                 .channel_mode = alc268_modes,
12670                 .input_mux = &alc268_capture_source,
12671         },
12672         [ALC268_TOSHIBA] = {
12673                 .mixers = { alc268_toshiba_mixer, alc268_capture_alt_mixer,
12674                             alc268_beep_mixer },
12675                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12676                                 alc268_toshiba_verbs },
12677                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12678                 .dac_nids = alc268_dac_nids,
12679                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12680                 .adc_nids = alc268_adc_nids_alt,
12681                 .capsrc_nids = alc268_capsrc_nids,
12682                 .hp_nid = 0x03,
12683                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12684                 .channel_mode = alc268_modes,
12685                 .input_mux = &alc268_capture_source,
12686                 .unsol_event = alc268_toshiba_unsol_event,
12687                 .setup = alc268_toshiba_setup,
12688                 .init_hook = alc268_toshiba_automute,
12689         },
12690         [ALC268_ACER] = {
12691                 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer,
12692                             alc268_beep_mixer },
12693                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12694                                 alc268_acer_verbs },
12695                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12696                 .dac_nids = alc268_dac_nids,
12697                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12698                 .adc_nids = alc268_adc_nids_alt,
12699                 .capsrc_nids = alc268_capsrc_nids,
12700                 .hp_nid = 0x02,
12701                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12702                 .channel_mode = alc268_modes,
12703                 .input_mux = &alc268_acer_capture_source,
12704                 .unsol_event = alc268_acer_unsol_event,
12705                 .init_hook = alc268_acer_init_hook,
12706         },
12707         [ALC268_ACER_DMIC] = {
12708                 .mixers = { alc268_acer_dmic_mixer, alc268_capture_alt_mixer,
12709                             alc268_beep_mixer },
12710                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12711                                 alc268_acer_verbs },
12712                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12713                 .dac_nids = alc268_dac_nids,
12714                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12715                 .adc_nids = alc268_adc_nids_alt,
12716                 .capsrc_nids = alc268_capsrc_nids,
12717                 .hp_nid = 0x02,
12718                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12719                 .channel_mode = alc268_modes,
12720                 .input_mux = &alc268_acer_dmic_capture_source,
12721                 .unsol_event = alc268_acer_unsol_event,
12722                 .init_hook = alc268_acer_init_hook,
12723         },
12724         [ALC268_ACER_ASPIRE_ONE] = {
12725                 .mixers = { alc268_acer_aspire_one_mixer,
12726                             alc268_beep_mixer,
12727                             alc268_capture_nosrc_mixer },
12728                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12729                                 alc268_acer_aspire_one_verbs },
12730                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12731                 .dac_nids = alc268_dac_nids,
12732                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12733                 .adc_nids = alc268_adc_nids_alt,
12734                 .capsrc_nids = alc268_capsrc_nids,
12735                 .hp_nid = 0x03,
12736                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12737                 .channel_mode = alc268_modes,
12738                 .unsol_event = alc268_acer_lc_unsol_event,
12739                 .setup = alc268_acer_lc_setup,
12740                 .init_hook = alc268_acer_lc_init_hook,
12741         },
12742         [ALC268_DELL] = {
12743                 .mixers = { alc268_dell_mixer, alc268_beep_mixer,
12744                             alc268_capture_nosrc_mixer },
12745                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12746                                 alc268_dell_verbs },
12747                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12748                 .dac_nids = alc268_dac_nids,
12749                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12750                 .adc_nids = alc268_adc_nids_alt,
12751                 .capsrc_nids = alc268_capsrc_nids,
12752                 .hp_nid = 0x02,
12753                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12754                 .channel_mode = alc268_modes,
12755                 .unsol_event = alc_sku_unsol_event,
12756                 .setup = alc268_dell_setup,
12757                 .init_hook = alc_inithook,
12758         },
12759         [ALC268_ZEPTO] = {
12760                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
12761                             alc268_beep_mixer },
12762                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12763                                 alc268_toshiba_verbs },
12764                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12765                 .dac_nids = alc268_dac_nids,
12766                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12767                 .adc_nids = alc268_adc_nids_alt,
12768                 .capsrc_nids = alc268_capsrc_nids,
12769                 .hp_nid = 0x03,
12770                 .dig_out_nid = ALC268_DIGOUT_NID,
12771                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12772                 .channel_mode = alc268_modes,
12773                 .input_mux = &alc268_capture_source,
12774                 .setup = alc268_toshiba_setup,
12775                 .init_hook = alc268_toshiba_automute,
12776         },
12777 #ifdef CONFIG_SND_DEBUG
12778         [ALC268_TEST] = {
12779                 .mixers = { alc268_test_mixer, alc268_capture_mixer },
12780                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12781                                 alc268_volume_init_verbs },
12782                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12783                 .dac_nids = alc268_dac_nids,
12784                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12785                 .adc_nids = alc268_adc_nids_alt,
12786                 .capsrc_nids = alc268_capsrc_nids,
12787                 .hp_nid = 0x03,
12788                 .dig_out_nid = ALC268_DIGOUT_NID,
12789                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12790                 .channel_mode = alc268_modes,
12791                 .input_mux = &alc268_capture_source,
12792         },
12793 #endif
12794 };
12795
12796 static int patch_alc268(struct hda_codec *codec)
12797 {
12798         struct alc_spec *spec;
12799         int board_config;
12800         int i, has_beep, err;
12801
12802         spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
12803         if (spec == NULL)
12804                 return -ENOMEM;
12805
12806         codec->spec = spec;
12807
12808         board_config = snd_hda_check_board_config(codec, ALC268_MODEL_LAST,
12809                                                   alc268_models,
12810                                                   alc268_cfg_tbl);
12811
12812         if (board_config < 0 || board_config >= ALC268_MODEL_LAST)
12813                 board_config = snd_hda_check_board_codec_sid_config(codec,
12814                         ALC882_MODEL_LAST, alc268_models, alc268_ssid_cfg_tbl);
12815
12816         if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
12817                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
12818                        codec->chip_name);
12819                 board_config = ALC268_AUTO;
12820         }
12821
12822         if (board_config == ALC268_AUTO) {
12823                 /* automatic parse from the BIOS config */
12824                 err = alc268_parse_auto_config(codec);
12825                 if (err < 0) {
12826                         alc_free(codec);
12827                         return err;
12828                 } else if (!err) {
12829                         printk(KERN_INFO
12830                                "hda_codec: Cannot set up configuration "
12831                                "from BIOS.  Using base mode...\n");
12832                         board_config = ALC268_3ST;
12833                 }
12834         }
12835
12836         if (board_config != ALC268_AUTO)
12837                 setup_preset(codec, &alc268_presets[board_config]);
12838
12839         spec->stream_analog_playback = &alc268_pcm_analog_playback;
12840         spec->stream_analog_capture = &alc268_pcm_analog_capture;
12841         spec->stream_analog_alt_capture = &alc268_pcm_analog_alt_capture;
12842
12843         spec->stream_digital_playback = &alc268_pcm_digital_playback;
12844
12845         has_beep = 0;
12846         for (i = 0; i < spec->num_mixers; i++) {
12847                 if (spec->mixers[i] == alc268_beep_mixer) {
12848                         has_beep = 1;
12849                         break;
12850                 }
12851         }
12852
12853         if (has_beep) {
12854                 err = snd_hda_attach_beep_device(codec, 0x1);
12855                 if (err < 0) {
12856                         alc_free(codec);
12857                         return err;
12858                 }
12859                 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
12860                         /* override the amp caps for beep generator */
12861                         snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
12862                                           (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
12863                                           (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
12864                                           (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
12865                                           (0 << AC_AMPCAP_MUTE_SHIFT));
12866         }
12867
12868         if (!spec->no_analog && !spec->adc_nids && spec->input_mux) {
12869                 /* check whether NID 0x07 is valid */
12870                 unsigned int wcap = get_wcaps(codec, 0x07);
12871                 int i;
12872
12873                 spec->capsrc_nids = alc268_capsrc_nids;
12874                 /* get type */
12875                 wcap = get_wcaps_type(wcap);
12876                 if (spec->auto_mic ||
12877                     wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
12878                         spec->adc_nids = alc268_adc_nids_alt;
12879                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt);
12880                         if (spec->auto_mic)
12881                                 fixup_automic_adc(codec);
12882                         if (spec->auto_mic || spec->input_mux->num_items == 1)
12883                                 add_mixer(spec, alc268_capture_nosrc_mixer);
12884                         else
12885                                 add_mixer(spec, alc268_capture_alt_mixer);
12886                 } else {
12887                         spec->adc_nids = alc268_adc_nids;
12888                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids);
12889                         add_mixer(spec, alc268_capture_mixer);
12890                 }
12891                 /* set default input source */
12892                 for (i = 0; i < spec->num_adc_nids; i++)
12893                         snd_hda_codec_write_cache(codec, alc268_capsrc_nids[i],
12894                                 0, AC_VERB_SET_CONNECT_SEL,
12895                                 i < spec->num_mux_defs ?
12896                                 spec->input_mux[i].items[0].index :
12897                                 spec->input_mux->items[0].index);
12898         }
12899
12900         spec->vmaster_nid = 0x02;
12901
12902         codec->patch_ops = alc_patch_ops;
12903         if (board_config == ALC268_AUTO)
12904                 spec->init_hook = alc268_auto_init;
12905
12906         codec->proc_widget_hook = print_realtek_coef;
12907
12908         return 0;
12909 }
12910
12911 /*
12912  *  ALC269 channel source setting (2 channel)
12913  */
12914 #define ALC269_DIGOUT_NID       ALC880_DIGOUT_NID
12915
12916 #define alc269_dac_nids         alc260_dac_nids
12917
12918 static hda_nid_t alc269_adc_nids[1] = {
12919         /* ADC1 */
12920         0x08,
12921 };
12922
12923 static hda_nid_t alc269_capsrc_nids[1] = {
12924         0x23,
12925 };
12926
12927 /* NOTE: ADC2 (0x07) is connected from a recording *MIXER* (0x24),
12928  *       not a mux!
12929  */
12930
12931 #define alc269_modes            alc260_modes
12932 #define alc269_capture_source   alc880_lg_lw_capture_source
12933
12934 static struct snd_kcontrol_new alc269_base_mixer[] = {
12935         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12936         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12937         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
12938         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
12939         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12940         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12941         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12942         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12943         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12944         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
12945         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12946         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
12947         { } /* end */
12948 };
12949
12950 static struct snd_kcontrol_new alc269_quanta_fl1_mixer[] = {
12951         /* output mixer control */
12952         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
12953         {
12954                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12955                 .name = "Master Playback Switch",
12956                 .info = snd_hda_mixer_amp_switch_info,
12957                 .get = snd_hda_mixer_amp_switch_get,
12958                 .put = alc268_acer_master_sw_put,
12959                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
12960         },
12961         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12962         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12963         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12964         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12965         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12966         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
12967         { }
12968 };
12969
12970 static struct snd_kcontrol_new alc269_lifebook_mixer[] = {
12971         /* output mixer control */
12972         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
12973         {
12974                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12975                 .name = "Master Playback Switch",
12976                 .info = snd_hda_mixer_amp_switch_info,
12977                 .get = snd_hda_mixer_amp_switch_get,
12978                 .put = alc268_acer_master_sw_put,
12979                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
12980         },
12981         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12982         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12983         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12984         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12985         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12986         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
12987         HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x0b, 0x03, HDA_INPUT),
12988         HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x0b, 0x03, HDA_INPUT),
12989         HDA_CODEC_VOLUME("Dock Mic Boost", 0x1b, 0, HDA_INPUT),
12990         { }
12991 };
12992
12993 static struct snd_kcontrol_new alc269_eeepc_mixer[] = {
12994         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12995         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12996         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12997         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12998         { } /* end */
12999 };
13000
13001 /* capture mixer elements */
13002 static struct snd_kcontrol_new alc269_epc_capture_mixer[] = {
13003         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
13004         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
13005         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
13006         { } /* end */
13007 };
13008
13009 /* FSC amilo */
13010 #define alc269_fujitsu_mixer    alc269_eeepc_mixer
13011
13012 static struct hda_verb alc269_quanta_fl1_verbs[] = {
13013         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
13014         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13015         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13016         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
13017         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
13018         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13019         { }
13020 };
13021
13022 static struct hda_verb alc269_lifebook_verbs[] = {
13023         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
13024         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
13025         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13026         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13027         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
13028         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13029         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13030         {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
13031         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
13032         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13033         { }
13034 };
13035
13036 /* toggle speaker-output according to the hp-jack state */
13037 static void alc269_quanta_fl1_speaker_automute(struct hda_codec *codec)
13038 {
13039         unsigned int present;
13040         unsigned char bits;
13041
13042         present = snd_hda_codec_read(codec, 0x15, 0,
13043                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13044         bits = present ? AMP_IN_MUTE(0) : 0;
13045         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
13046                         AMP_IN_MUTE(0), bits);
13047         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
13048                         AMP_IN_MUTE(0), bits);
13049
13050         snd_hda_codec_write(codec, 0x20, 0,
13051                         AC_VERB_SET_COEF_INDEX, 0x0c);
13052         snd_hda_codec_write(codec, 0x20, 0,
13053                         AC_VERB_SET_PROC_COEF, 0x680);
13054
13055         snd_hda_codec_write(codec, 0x20, 0,
13056                         AC_VERB_SET_COEF_INDEX, 0x0c);
13057         snd_hda_codec_write(codec, 0x20, 0,
13058                         AC_VERB_SET_PROC_COEF, 0x480);
13059 }
13060
13061 /* toggle speaker-output according to the hp-jacks state */
13062 static void alc269_lifebook_speaker_automute(struct hda_codec *codec)
13063 {
13064         unsigned int present;
13065         unsigned char bits;
13066
13067         /* Check laptop headphone socket */
13068         present = snd_hda_codec_read(codec, 0x15, 0,
13069                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13070
13071         /* Check port replicator headphone socket */
13072         present |= snd_hda_codec_read(codec, 0x1a, 0,
13073                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13074
13075         bits = present ? AMP_IN_MUTE(0) : 0;
13076         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
13077                         AMP_IN_MUTE(0), bits);
13078         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
13079                         AMP_IN_MUTE(0), bits);
13080
13081         snd_hda_codec_write(codec, 0x20, 0,
13082                         AC_VERB_SET_COEF_INDEX, 0x0c);
13083         snd_hda_codec_write(codec, 0x20, 0,
13084                         AC_VERB_SET_PROC_COEF, 0x680);
13085
13086         snd_hda_codec_write(codec, 0x20, 0,
13087                         AC_VERB_SET_COEF_INDEX, 0x0c);
13088         snd_hda_codec_write(codec, 0x20, 0,
13089                         AC_VERB_SET_PROC_COEF, 0x480);
13090 }
13091
13092 static void alc269_lifebook_mic_autoswitch(struct hda_codec *codec)
13093 {
13094         unsigned int present_laptop;
13095         unsigned int present_dock;
13096
13097         present_laptop = snd_hda_codec_read(codec, 0x18, 0,
13098                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13099
13100         present_dock = snd_hda_codec_read(codec, 0x1b, 0,
13101                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13102
13103         /* Laptop mic port overrides dock mic port, design decision */
13104         if (present_dock)
13105                 snd_hda_codec_write(codec, 0x23, 0,
13106                                 AC_VERB_SET_CONNECT_SEL, 0x3);
13107         if (present_laptop)
13108                 snd_hda_codec_write(codec, 0x23, 0,
13109                                 AC_VERB_SET_CONNECT_SEL, 0x0);
13110         if (!present_dock && !present_laptop)
13111                 snd_hda_codec_write(codec, 0x23, 0,
13112                                 AC_VERB_SET_CONNECT_SEL, 0x1);
13113 }
13114
13115 static void alc269_quanta_fl1_unsol_event(struct hda_codec *codec,
13116                                     unsigned int res)
13117 {
13118         switch (res >> 26) {
13119         case ALC880_HP_EVENT:
13120                 alc269_quanta_fl1_speaker_automute(codec);
13121                 break;
13122         case ALC880_MIC_EVENT:
13123                 alc_mic_automute(codec);
13124                 break;
13125         }
13126 }
13127
13128 static void alc269_lifebook_unsol_event(struct hda_codec *codec,
13129                                         unsigned int res)
13130 {
13131         if ((res >> 26) == ALC880_HP_EVENT)
13132                 alc269_lifebook_speaker_automute(codec);
13133         if ((res >> 26) == ALC880_MIC_EVENT)
13134                 alc269_lifebook_mic_autoswitch(codec);
13135 }
13136
13137 static void alc269_quanta_fl1_setup(struct hda_codec *codec)
13138 {
13139         struct alc_spec *spec = codec->spec;
13140         spec->ext_mic.pin = 0x18;
13141         spec->ext_mic.mux_idx = 0;
13142         spec->int_mic.pin = 0x19;
13143         spec->int_mic.mux_idx = 1;
13144         spec->auto_mic = 1;
13145 }
13146
13147 static void alc269_quanta_fl1_init_hook(struct hda_codec *codec)
13148 {
13149         alc269_quanta_fl1_speaker_automute(codec);
13150         alc_mic_automute(codec);
13151 }
13152
13153 static void alc269_lifebook_init_hook(struct hda_codec *codec)
13154 {
13155         alc269_lifebook_speaker_automute(codec);
13156         alc269_lifebook_mic_autoswitch(codec);
13157 }
13158
13159 static struct hda_verb alc269_eeepc_dmic_init_verbs[] = {
13160         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
13161         {0x23, AC_VERB_SET_CONNECT_SEL, 0x05},
13162         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
13163         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))},
13164         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13165         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
13166         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13167         {}
13168 };
13169
13170 static struct hda_verb alc269_eeepc_amic_init_verbs[] = {
13171         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
13172         {0x23, AC_VERB_SET_CONNECT_SEL, 0x01},
13173         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
13174         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x701b | (0x00 << 8))},
13175         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
13176         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13177         {}
13178 };
13179
13180 /* toggle speaker-output according to the hp-jack state */
13181 static void alc269_speaker_automute(struct hda_codec *codec)
13182 {
13183         unsigned int present;
13184         unsigned char bits;
13185
13186         present = snd_hda_codec_read(codec, 0x15, 0,
13187                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13188         bits = present ? AMP_IN_MUTE(0) : 0;
13189         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
13190                                 AMP_IN_MUTE(0), bits);
13191         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
13192                                 AMP_IN_MUTE(0), bits);
13193 }
13194
13195 /* unsolicited event for HP jack sensing */
13196 static void alc269_eeepc_unsol_event(struct hda_codec *codec,
13197                                      unsigned int res)
13198 {
13199         switch (res >> 26) {
13200         case ALC880_HP_EVENT:
13201                 alc269_speaker_automute(codec);
13202                 break;
13203         case ALC880_MIC_EVENT:
13204                 alc_mic_automute(codec);
13205                 break;
13206         }
13207 }
13208
13209 static void alc269_eeepc_dmic_setup(struct hda_codec *codec)
13210 {
13211         struct alc_spec *spec = codec->spec;
13212         spec->ext_mic.pin = 0x18;
13213         spec->ext_mic.mux_idx = 0;
13214         spec->int_mic.pin = 0x12;
13215         spec->int_mic.mux_idx = 5;
13216         spec->auto_mic = 1;
13217 }
13218
13219 static void alc269_eeepc_amic_setup(struct hda_codec *codec)
13220 {
13221         struct alc_spec *spec = codec->spec;
13222         spec->ext_mic.pin = 0x18;
13223         spec->ext_mic.mux_idx = 0;
13224         spec->int_mic.pin = 0x19;
13225         spec->int_mic.mux_idx = 1;
13226         spec->auto_mic = 1;
13227 }
13228
13229 static void alc269_eeepc_inithook(struct hda_codec *codec)
13230 {
13231         alc269_speaker_automute(codec);
13232         alc_mic_automute(codec);
13233 }
13234
13235 /*
13236  * generic initialization of ADC, input mixers and output mixers
13237  */
13238 static struct hda_verb alc269_init_verbs[] = {
13239         /*
13240          * Unmute ADC0 and set the default input to mic-in
13241          */
13242         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13243
13244         /* Mute input amps (PCBeep, Line In, Mic 1 & Mic 2) of the
13245          * analog-loopback mixer widget
13246          * Note: PASD motherboards uses the Line In 2 as the input for
13247          * front panel mic (mic 2)
13248          */
13249         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
13250         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13251         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13252         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
13253         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
13254         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
13255
13256         /*
13257          * Set up output mixers (0x0c - 0x0e)
13258          */
13259         /* set vol=0 to output mixers */
13260         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13261         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13262
13263         /* set up input amps for analog loopback */
13264         /* Amp Indices: DAC = 0, mixer = 1 */
13265         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13266         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13267         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13268         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13269         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13270         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13271
13272         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13273         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13274         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13275         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13276         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13277         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13278         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13279
13280         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13281         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13282         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13283         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13284         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13285         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13286         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13287
13288         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
13289         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
13290
13291         /* FIXME: use matrix-type input source selection */
13292         /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
13293         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
13294         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13295         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13296         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
13297         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
13298
13299         /* set EAPD */
13300         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
13301         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
13302         { }
13303 };
13304
13305 #define alc269_auto_create_multi_out_ctls \
13306         alc268_auto_create_multi_out_ctls
13307 #define alc269_auto_create_input_ctls \
13308         alc268_auto_create_input_ctls
13309
13310 #ifdef CONFIG_SND_HDA_POWER_SAVE
13311 #define alc269_loopbacks        alc880_loopbacks
13312 #endif
13313
13314 /* pcm configuration: identical with ALC880 */
13315 #define alc269_pcm_analog_playback      alc880_pcm_analog_playback
13316 #define alc269_pcm_analog_capture       alc880_pcm_analog_capture
13317 #define alc269_pcm_digital_playback     alc880_pcm_digital_playback
13318 #define alc269_pcm_digital_capture      alc880_pcm_digital_capture
13319
13320 static struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
13321         .substreams = 1,
13322         .channels_min = 2,
13323         .channels_max = 8,
13324         .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
13325         /* NID is set in alc_build_pcms */
13326         .ops = {
13327                 .open = alc880_playback_pcm_open,
13328                 .prepare = alc880_playback_pcm_prepare,
13329                 .cleanup = alc880_playback_pcm_cleanup
13330         },
13331 };
13332
13333 static struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
13334         .substreams = 1,
13335         .channels_min = 2,
13336         .channels_max = 2,
13337         .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
13338         /* NID is set in alc_build_pcms */
13339 };
13340
13341 /*
13342  * BIOS auto configuration
13343  */
13344 static int alc269_parse_auto_config(struct hda_codec *codec)
13345 {
13346         struct alc_spec *spec = codec->spec;
13347         int err;
13348         static hda_nid_t alc269_ignore[] = { 0x1d, 0 };
13349
13350         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
13351                                            alc269_ignore);
13352         if (err < 0)
13353                 return err;
13354
13355         err = alc269_auto_create_multi_out_ctls(spec, &spec->autocfg);
13356         if (err < 0)
13357                 return err;
13358         err = alc269_auto_create_input_ctls(codec, &spec->autocfg);
13359         if (err < 0)
13360                 return err;
13361
13362         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
13363
13364         if (spec->autocfg.dig_outs)
13365                 spec->multiout.dig_out_nid = ALC269_DIGOUT_NID;
13366
13367         if (spec->kctls.list)
13368                 add_mixer(spec, spec->kctls.list);
13369
13370         add_verb(spec, alc269_init_verbs);
13371         spec->num_mux_defs = 1;
13372         spec->input_mux = &spec->private_imux[0];
13373         /* set default input source */
13374         snd_hda_codec_write_cache(codec, alc269_capsrc_nids[0],
13375                                   0, AC_VERB_SET_CONNECT_SEL,
13376                                   spec->input_mux->items[0].index);
13377
13378         err = alc_auto_add_mic_boost(codec);
13379         if (err < 0)
13380                 return err;
13381
13382         if (!spec->cap_mixer && !spec->no_analog)
13383                 set_capture_mixer(codec);
13384
13385         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
13386
13387         return 1;
13388 }
13389
13390 #define alc269_auto_init_multi_out      alc268_auto_init_multi_out
13391 #define alc269_auto_init_hp_out         alc268_auto_init_hp_out
13392 #define alc269_auto_init_analog_input   alc882_auto_init_analog_input
13393
13394
13395 /* init callback for auto-configuration model -- overriding the default init */
13396 static void alc269_auto_init(struct hda_codec *codec)
13397 {
13398         struct alc_spec *spec = codec->spec;
13399         alc269_auto_init_multi_out(codec);
13400         alc269_auto_init_hp_out(codec);
13401         alc269_auto_init_analog_input(codec);
13402         if (spec->unsol_event)
13403                 alc_inithook(codec);
13404 }
13405
13406 /*
13407  * configuration and preset
13408  */
13409 static const char *alc269_models[ALC269_MODEL_LAST] = {
13410         [ALC269_BASIC]                  = "basic",
13411         [ALC269_QUANTA_FL1]             = "quanta",
13412         [ALC269_ASUS_EEEPC_P703]        = "eeepc-p703",
13413         [ALC269_ASUS_EEEPC_P901]        = "eeepc-p901",
13414         [ALC269_FUJITSU]                = "fujitsu",
13415         [ALC269_LIFEBOOK]               = "lifebook",
13416         [ALC269_AUTO]                   = "auto",
13417 };
13418
13419 static struct snd_pci_quirk alc269_cfg_tbl[] = {
13420         SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_QUANTA_FL1),
13421         SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
13422                       ALC269_ASUS_EEEPC_P703),
13423         SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_ASUS_EEEPC_P703),
13424         SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_ASUS_EEEPC_P703),
13425         SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_ASUS_EEEPC_P703),
13426         SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_ASUS_EEEPC_P703),
13427         SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_ASUS_EEEPC_P703),
13428         SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_ASUS_EEEPC_P703),
13429         SND_PCI_QUIRK(0x1043, 0x831a, "ASUS Eeepc P901",
13430                       ALC269_ASUS_EEEPC_P901),
13431         SND_PCI_QUIRK(0x1043, 0x834a, "ASUS Eeepc S101",
13432                       ALC269_ASUS_EEEPC_P901),
13433         SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_ASUS_EEEPC_P901),
13434         SND_PCI_QUIRK(0x1734, 0x115d, "FSC Amilo", ALC269_FUJITSU),
13435         SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook ICH9M-based", ALC269_LIFEBOOK),
13436         {}
13437 };
13438
13439 static struct alc_config_preset alc269_presets[] = {
13440         [ALC269_BASIC] = {
13441                 .mixers = { alc269_base_mixer },
13442                 .init_verbs = { alc269_init_verbs },
13443                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13444                 .dac_nids = alc269_dac_nids,
13445                 .hp_nid = 0x03,
13446                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13447                 .channel_mode = alc269_modes,
13448                 .input_mux = &alc269_capture_source,
13449         },
13450         [ALC269_QUANTA_FL1] = {
13451                 .mixers = { alc269_quanta_fl1_mixer },
13452                 .init_verbs = { alc269_init_verbs, alc269_quanta_fl1_verbs },
13453                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13454                 .dac_nids = alc269_dac_nids,
13455                 .hp_nid = 0x03,
13456                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13457                 .channel_mode = alc269_modes,
13458                 .input_mux = &alc269_capture_source,
13459                 .unsol_event = alc269_quanta_fl1_unsol_event,
13460                 .setup = alc269_quanta_fl1_setup,
13461                 .init_hook = alc269_quanta_fl1_init_hook,
13462         },
13463         [ALC269_ASUS_EEEPC_P703] = {
13464                 .mixers = { alc269_eeepc_mixer },
13465                 .cap_mixer = alc269_epc_capture_mixer,
13466                 .init_verbs = { alc269_init_verbs,
13467                                 alc269_eeepc_amic_init_verbs },
13468                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13469                 .dac_nids = alc269_dac_nids,
13470                 .hp_nid = 0x03,
13471                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13472                 .channel_mode = alc269_modes,
13473                 .unsol_event = alc269_eeepc_unsol_event,
13474                 .setup = alc269_eeepc_amic_setup,
13475                 .init_hook = alc269_eeepc_inithook,
13476         },
13477         [ALC269_ASUS_EEEPC_P901] = {
13478                 .mixers = { alc269_eeepc_mixer },
13479                 .cap_mixer = alc269_epc_capture_mixer,
13480                 .init_verbs = { alc269_init_verbs,
13481                                 alc269_eeepc_dmic_init_verbs },
13482                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13483                 .dac_nids = alc269_dac_nids,
13484                 .hp_nid = 0x03,
13485                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13486                 .channel_mode = alc269_modes,
13487                 .unsol_event = alc269_eeepc_unsol_event,
13488                 .setup = alc269_eeepc_dmic_setup,
13489                 .init_hook = alc269_eeepc_inithook,
13490         },
13491         [ALC269_FUJITSU] = {
13492                 .mixers = { alc269_fujitsu_mixer },
13493                 .cap_mixer = alc269_epc_capture_mixer,
13494                 .init_verbs = { alc269_init_verbs,
13495                                 alc269_eeepc_dmic_init_verbs },
13496                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13497                 .dac_nids = alc269_dac_nids,
13498                 .hp_nid = 0x03,
13499                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13500                 .channel_mode = alc269_modes,
13501                 .unsol_event = alc269_eeepc_unsol_event,
13502                 .setup = alc269_eeepc_dmic_setup,
13503                 .init_hook = alc269_eeepc_inithook,
13504         },
13505         [ALC269_LIFEBOOK] = {
13506                 .mixers = { alc269_lifebook_mixer },
13507                 .init_verbs = { alc269_init_verbs, alc269_lifebook_verbs },
13508                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13509                 .dac_nids = alc269_dac_nids,
13510                 .hp_nid = 0x03,
13511                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13512                 .channel_mode = alc269_modes,
13513                 .input_mux = &alc269_capture_source,
13514                 .unsol_event = alc269_lifebook_unsol_event,
13515                 .init_hook = alc269_lifebook_init_hook,
13516         },
13517 };
13518
13519 static int patch_alc269(struct hda_codec *codec)
13520 {
13521         struct alc_spec *spec;
13522         int board_config;
13523         int err;
13524
13525         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
13526         if (spec == NULL)
13527                 return -ENOMEM;
13528
13529         codec->spec = spec;
13530
13531         alc_fix_pll_init(codec, 0x20, 0x04, 15);
13532
13533         board_config = snd_hda_check_board_config(codec, ALC269_MODEL_LAST,
13534                                                   alc269_models,
13535                                                   alc269_cfg_tbl);
13536
13537         if (board_config < 0) {
13538                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
13539                        codec->chip_name);
13540                 board_config = ALC269_AUTO;
13541         }
13542
13543         if (board_config == ALC269_AUTO) {
13544                 /* automatic parse from the BIOS config */
13545                 err = alc269_parse_auto_config(codec);
13546                 if (err < 0) {
13547                         alc_free(codec);
13548                         return err;
13549                 } else if (!err) {
13550                         printk(KERN_INFO
13551                                "hda_codec: Cannot set up configuration "
13552                                "from BIOS.  Using base mode...\n");
13553                         board_config = ALC269_BASIC;
13554                 }
13555         }
13556
13557         err = snd_hda_attach_beep_device(codec, 0x1);
13558         if (err < 0) {
13559                 alc_free(codec);
13560                 return err;
13561         }
13562
13563         if (board_config != ALC269_AUTO)
13564                 setup_preset(codec, &alc269_presets[board_config]);
13565
13566         if (codec->subsystem_id == 0x17aa3bf8) {
13567                 /* Due to a hardware problem on Lenovo Ideadpad, we need to
13568                  * fix the sample rate of analog I/O to 44.1kHz
13569                  */
13570                 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
13571                 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
13572         } else {
13573                 spec->stream_analog_playback = &alc269_pcm_analog_playback;
13574                 spec->stream_analog_capture = &alc269_pcm_analog_capture;
13575         }
13576         spec->stream_digital_playback = &alc269_pcm_digital_playback;
13577         spec->stream_digital_capture = &alc269_pcm_digital_capture;
13578
13579         spec->adc_nids = alc269_adc_nids;
13580         spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids);
13581         spec->capsrc_nids = alc269_capsrc_nids;
13582         if (!spec->cap_mixer)
13583                 set_capture_mixer(codec);
13584         set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
13585
13586         spec->vmaster_nid = 0x02;
13587
13588         codec->patch_ops = alc_patch_ops;
13589         if (board_config == ALC269_AUTO)
13590                 spec->init_hook = alc269_auto_init;
13591 #ifdef CONFIG_SND_HDA_POWER_SAVE
13592         if (!spec->loopback.amplist)
13593                 spec->loopback.amplist = alc269_loopbacks;
13594 #endif
13595         codec->proc_widget_hook = print_realtek_coef;
13596
13597         return 0;
13598 }
13599
13600 /*
13601  *  ALC861 channel source setting (2/6 channel selection for 3-stack)
13602  */
13603
13604 /*
13605  * set the path ways for 2 channel output
13606  * need to set the codec line out and mic 1 pin widgets to inputs
13607  */
13608 static struct hda_verb alc861_threestack_ch2_init[] = {
13609         /* set pin widget 1Ah (line in) for input */
13610         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13611         /* set pin widget 18h (mic1/2) for input, for mic also enable
13612          * the vref
13613          */
13614         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13615
13616         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
13617 #if 0
13618         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
13619         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
13620 #endif
13621         { } /* end */
13622 };
13623 /*
13624  * 6ch mode
13625  * need to set the codec line out and mic 1 pin widgets to outputs
13626  */
13627 static struct hda_verb alc861_threestack_ch6_init[] = {
13628         /* set pin widget 1Ah (line in) for output (Back Surround)*/
13629         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13630         /* set pin widget 18h (mic1) for output (CLFE)*/
13631         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13632
13633         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
13634         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
13635
13636         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
13637 #if 0
13638         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
13639         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
13640 #endif
13641         { } /* end */
13642 };
13643
13644 static struct hda_channel_mode alc861_threestack_modes[2] = {
13645         { 2, alc861_threestack_ch2_init },
13646         { 6, alc861_threestack_ch6_init },
13647 };
13648 /* Set mic1 as input and unmute the mixer */
13649 static struct hda_verb alc861_uniwill_m31_ch2_init[] = {
13650         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13651         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
13652         { } /* end */
13653 };
13654 /* Set mic1 as output and mute mixer */
13655 static struct hda_verb alc861_uniwill_m31_ch4_init[] = {
13656         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13657         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
13658         { } /* end */
13659 };
13660
13661 static struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
13662         { 2, alc861_uniwill_m31_ch2_init },
13663         { 4, alc861_uniwill_m31_ch4_init },
13664 };
13665
13666 /* Set mic1 and line-in as input and unmute the mixer */
13667 static struct hda_verb alc861_asus_ch2_init[] = {
13668         /* set pin widget 1Ah (line in) for input */
13669         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13670         /* set pin widget 18h (mic1/2) for input, for mic also enable
13671          * the vref
13672          */
13673         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13674
13675         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
13676 #if 0
13677         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
13678         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
13679 #endif
13680         { } /* end */
13681 };
13682 /* Set mic1 nad line-in as output and mute mixer */
13683 static struct hda_verb alc861_asus_ch6_init[] = {
13684         /* set pin widget 1Ah (line in) for output (Back Surround)*/
13685         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13686         /* { 0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
13687         /* set pin widget 18h (mic1) for output (CLFE)*/
13688         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13689         /* { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
13690         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
13691         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
13692
13693         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
13694 #if 0
13695         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
13696         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
13697 #endif
13698         { } /* end */
13699 };
13700
13701 static struct hda_channel_mode alc861_asus_modes[2] = {
13702         { 2, alc861_asus_ch2_init },
13703         { 6, alc861_asus_ch6_init },
13704 };
13705
13706 /* patch-ALC861 */
13707
13708 static struct snd_kcontrol_new alc861_base_mixer[] = {
13709         /* output mixer control */
13710         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13711         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
13712         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
13713         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13714         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
13715
13716         /*Input mixer control */
13717         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13718            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
13719         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13720         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13721         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13722         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13723         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13724         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13725         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13726         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
13727
13728         { } /* end */
13729 };
13730
13731 static struct snd_kcontrol_new alc861_3ST_mixer[] = {
13732         /* output mixer control */
13733         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13734         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
13735         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
13736         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13737         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
13738
13739         /* Input mixer control */
13740         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13741            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
13742         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13743         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13744         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13745         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13746         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13747         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13748         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13749         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
13750
13751         {
13752                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13753                 .name = "Channel Mode",
13754                 .info = alc_ch_mode_info,
13755                 .get = alc_ch_mode_get,
13756                 .put = alc_ch_mode_put,
13757                 .private_value = ARRAY_SIZE(alc861_threestack_modes),
13758         },
13759         { } /* end */
13760 };
13761
13762 static struct snd_kcontrol_new alc861_toshiba_mixer[] = {
13763         /* output mixer control */
13764         HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13765         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13766         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13767
13768         { } /* end */
13769 };
13770
13771 static struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
13772         /* output mixer control */
13773         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13774         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
13775         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
13776         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13777         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
13778
13779         /* Input mixer control */
13780         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13781            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
13782         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13783         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13784         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13785         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13786         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13787         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13788         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13789         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
13790
13791         {
13792                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13793                 .name = "Channel Mode",
13794                 .info = alc_ch_mode_info,
13795                 .get = alc_ch_mode_get,
13796                 .put = alc_ch_mode_put,
13797                 .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
13798         },
13799         { } /* end */
13800 };
13801
13802 static struct snd_kcontrol_new alc861_asus_mixer[] = {
13803         /* output mixer control */
13804         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13805         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
13806         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
13807         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13808         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
13809
13810         /* Input mixer control */
13811         HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13812         HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT),
13813         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13814         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13815         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13816         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13817         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13818         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13819         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13820         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT),
13821
13822         {
13823                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13824                 .name = "Channel Mode",
13825                 .info = alc_ch_mode_info,
13826                 .get = alc_ch_mode_get,
13827                 .put = alc_ch_mode_put,
13828                 .private_value = ARRAY_SIZE(alc861_asus_modes),
13829         },
13830         { }
13831 };
13832
13833 /* additional mixer */
13834 static struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
13835         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13836         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13837         { }
13838 };
13839
13840 /*
13841  * generic initialization of ADC, input mixers and output mixers
13842  */
13843 static struct hda_verb alc861_base_init_verbs[] = {
13844         /*
13845          * Unmute ADC0 and set the default input to mic-in
13846          */
13847         /* port-A for surround (rear panel) */
13848         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13849         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
13850         /* port-B for mic-in (rear panel) with vref */
13851         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13852         /* port-C for line-in (rear panel) */
13853         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13854         /* port-D for Front */
13855         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13856         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13857         /* port-E for HP out (front panel) */
13858         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
13859         /* route front PCM to HP */
13860         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13861         /* port-F for mic-in (front panel) with vref */
13862         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13863         /* port-G for CLFE (rear panel) */
13864         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13865         { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13866         /* port-H for side (rear panel) */
13867         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13868         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
13869         /* CD-in */
13870         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13871         /* route front mic to ADC1*/
13872         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13873         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13874
13875         /* Unmute DAC0~3 & spdif out*/
13876         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13877         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13878         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13879         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13880         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13881
13882         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13883         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13884         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13885         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13886         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13887
13888         /* Unmute Stereo Mixer 15 */
13889         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13890         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13891         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13892         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13893
13894         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13895         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13896         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13897         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13898         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13899         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13900         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13901         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13902         /* hp used DAC 3 (Front) */
13903         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13904         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13905
13906         { }
13907 };
13908
13909 static struct hda_verb alc861_threestack_init_verbs[] = {
13910         /*
13911          * Unmute ADC0 and set the default input to mic-in
13912          */
13913         /* port-A for surround (rear panel) */
13914         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13915         /* port-B for mic-in (rear panel) with vref */
13916         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13917         /* port-C for line-in (rear panel) */
13918         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13919         /* port-D for Front */
13920         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13921         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13922         /* port-E for HP out (front panel) */
13923         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
13924         /* route front PCM to HP */
13925         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13926         /* port-F for mic-in (front panel) with vref */
13927         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13928         /* port-G for CLFE (rear panel) */
13929         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13930         /* port-H for side (rear panel) */
13931         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13932         /* CD-in */
13933         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13934         /* route front mic to ADC1*/
13935         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13936         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13937         /* Unmute DAC0~3 & spdif out*/
13938         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13939         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13940         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13941         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13942         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13943
13944         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13945         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13946         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13947         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13948         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13949
13950         /* Unmute Stereo Mixer 15 */
13951         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13952         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13953         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13954         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13955
13956         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13957         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13958         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13959         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13960         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13961         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13962         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13963         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13964         /* hp used DAC 3 (Front) */
13965         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13966         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13967         { }
13968 };
13969
13970 static struct hda_verb alc861_uniwill_m31_init_verbs[] = {
13971         /*
13972          * Unmute ADC0 and set the default input to mic-in
13973          */
13974         /* port-A for surround (rear panel) */
13975         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13976         /* port-B for mic-in (rear panel) with vref */
13977         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13978         /* port-C for line-in (rear panel) */
13979         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13980         /* port-D for Front */
13981         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13982         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13983         /* port-E for HP out (front panel) */
13984         /* this has to be set to VREF80 */
13985         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13986         /* route front PCM to HP */
13987         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13988         /* port-F for mic-in (front panel) with vref */
13989         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13990         /* port-G for CLFE (rear panel) */
13991         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13992         /* port-H for side (rear panel) */
13993         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13994         /* CD-in */
13995         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13996         /* route front mic to ADC1*/
13997         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13998         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13999         /* Unmute DAC0~3 & spdif out*/
14000         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14001         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14002         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14003         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14004         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14005
14006         /* Unmute Mixer 14 (mic) 1c (Line in)*/
14007         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14008         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14009         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14010         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14011
14012         /* Unmute Stereo Mixer 15 */
14013         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14014         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14015         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14016         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
14017
14018         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14019         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14020         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14021         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14022         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14023         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14024         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14025         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14026         /* hp used DAC 3 (Front) */
14027         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
14028         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14029         { }
14030 };
14031
14032 static struct hda_verb alc861_asus_init_verbs[] = {
14033         /*
14034          * Unmute ADC0 and set the default input to mic-in
14035          */
14036         /* port-A for surround (rear panel)
14037          * according to codec#0 this is the HP jack
14038          */
14039         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, /* was 0x00 */
14040         /* route front PCM to HP */
14041         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x01 },
14042         /* port-B for mic-in (rear panel) with vref */
14043         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
14044         /* port-C for line-in (rear panel) */
14045         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
14046         /* port-D for Front */
14047         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
14048         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
14049         /* port-E for HP out (front panel) */
14050         /* this has to be set to VREF80 */
14051         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
14052         /* route front PCM to HP */
14053         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
14054         /* port-F for mic-in (front panel) with vref */
14055         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
14056         /* port-G for CLFE (rear panel) */
14057         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
14058         /* port-H for side (rear panel) */
14059         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
14060         /* CD-in */
14061         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
14062         /* route front mic to ADC1*/
14063         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
14064         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14065         /* Unmute DAC0~3 & spdif out*/
14066         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14067         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14068         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14069         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14070         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14071         /* Unmute Mixer 14 (mic) 1c (Line in)*/
14072         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14073         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14074         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14075         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14076
14077         /* Unmute Stereo Mixer 15 */
14078         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14079         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14080         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14081         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
14082
14083         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14084         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14085         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14086         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14087         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14088         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14089         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14090         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14091         /* hp used DAC 3 (Front) */
14092         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
14093         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14094         { }
14095 };
14096
14097 /* additional init verbs for ASUS laptops */
14098 static struct hda_verb alc861_asus_laptop_init_verbs[] = {
14099         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x45 }, /* HP-out */
14100         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2) }, /* mute line-in */
14101         { }
14102 };
14103
14104 /*
14105  * generic initialization of ADC, input mixers and output mixers
14106  */
14107 static struct hda_verb alc861_auto_init_verbs[] = {
14108         /*
14109          * Unmute ADC0 and set the default input to mic-in
14110          */
14111         /* {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, */
14112         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14113
14114         /* Unmute DAC0~3 & spdif out*/
14115         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14116         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14117         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14118         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14119         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14120
14121         /* Unmute Mixer 14 (mic) 1c (Line in)*/
14122         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14123         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14124         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14125         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14126
14127         /* Unmute Stereo Mixer 15 */
14128         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14129         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14130         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14131         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c},
14132
14133         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14134         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14135         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14136         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14137         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14138         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14139         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14140         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14141
14142         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14143         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14144         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14145         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14146         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14147         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14148         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14149         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14150
14151         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},  /* set Mic 1 */
14152
14153         { }
14154 };
14155
14156 static struct hda_verb alc861_toshiba_init_verbs[] = {
14157         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14158
14159         { }
14160 };
14161
14162 /* toggle speaker-output according to the hp-jack state */
14163 static void alc861_toshiba_automute(struct hda_codec *codec)
14164 {
14165         unsigned int present;
14166
14167         present = snd_hda_codec_read(codec, 0x0f, 0,
14168                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14169         snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
14170                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
14171         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
14172                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
14173 }
14174
14175 static void alc861_toshiba_unsol_event(struct hda_codec *codec,
14176                                        unsigned int res)
14177 {
14178         if ((res >> 26) == ALC880_HP_EVENT)
14179                 alc861_toshiba_automute(codec);
14180 }
14181
14182 /* pcm configuration: identical with ALC880 */
14183 #define alc861_pcm_analog_playback      alc880_pcm_analog_playback
14184 #define alc861_pcm_analog_capture       alc880_pcm_analog_capture
14185 #define alc861_pcm_digital_playback     alc880_pcm_digital_playback
14186 #define alc861_pcm_digital_capture      alc880_pcm_digital_capture
14187
14188
14189 #define ALC861_DIGOUT_NID       0x07
14190
14191 static struct hda_channel_mode alc861_8ch_modes[1] = {
14192         { 8, NULL }
14193 };
14194
14195 static hda_nid_t alc861_dac_nids[4] = {
14196         /* front, surround, clfe, side */
14197         0x03, 0x06, 0x05, 0x04
14198 };
14199
14200 static hda_nid_t alc660_dac_nids[3] = {
14201         /* front, clfe, surround */
14202         0x03, 0x05, 0x06
14203 };
14204
14205 static hda_nid_t alc861_adc_nids[1] = {
14206         /* ADC0-2 */
14207         0x08,
14208 };
14209
14210 static struct hda_input_mux alc861_capture_source = {
14211         .num_items = 5,
14212         .items = {
14213                 { "Mic", 0x0 },
14214                 { "Front Mic", 0x3 },
14215                 { "Line", 0x1 },
14216                 { "CD", 0x4 },
14217                 { "Mixer", 0x5 },
14218         },
14219 };
14220
14221 static hda_nid_t alc861_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
14222 {
14223         struct alc_spec *spec = codec->spec;
14224         hda_nid_t mix, srcs[5];
14225         int i, j, num;
14226
14227         if (snd_hda_get_connections(codec, pin, &mix, 1) != 1)
14228                 return 0;
14229         num = snd_hda_get_connections(codec, mix, srcs, ARRAY_SIZE(srcs));
14230         if (num < 0)
14231                 return 0;
14232         for (i = 0; i < num; i++) {
14233                 unsigned int type;
14234                 type = get_wcaps_type(get_wcaps(codec, srcs[i]));
14235                 if (type != AC_WID_AUD_OUT)
14236                         continue;
14237                 for (j = 0; j < spec->multiout.num_dacs; j++)
14238                         if (spec->multiout.dac_nids[j] == srcs[i])
14239                                 break;
14240                 if (j >= spec->multiout.num_dacs)
14241                         return srcs[i];
14242         }
14243         return 0;
14244 }
14245
14246 /* fill in the dac_nids table from the parsed pin configuration */
14247 static int alc861_auto_fill_dac_nids(struct hda_codec *codec,
14248                                      const struct auto_pin_cfg *cfg)
14249 {
14250         struct alc_spec *spec = codec->spec;
14251         int i;
14252         hda_nid_t nid, dac;
14253
14254         spec->multiout.dac_nids = spec->private_dac_nids;
14255         for (i = 0; i < cfg->line_outs; i++) {
14256                 nid = cfg->line_out_pins[i];
14257                 dac = alc861_look_for_dac(codec, nid);
14258                 if (!dac)
14259                         continue;
14260                 spec->multiout.dac_nids[spec->multiout.num_dacs++] = dac;
14261         }
14262         return 0;
14263 }
14264
14265 static int alc861_create_out_sw(struct hda_codec *codec, const char *pfx,
14266                                 hda_nid_t nid, unsigned int chs)
14267 {
14268         return add_pb_sw_ctrl(codec->spec, ALC_CTL_WIDGET_MUTE, pfx,
14269                            HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
14270 }
14271
14272 /* add playback controls from the parsed DAC table */
14273 static int alc861_auto_create_multi_out_ctls(struct hda_codec *codec,
14274                                              const struct auto_pin_cfg *cfg)
14275 {
14276         struct alc_spec *spec = codec->spec;
14277         static const char *chname[4] = {
14278                 "Front", "Surround", NULL /*CLFE*/, "Side"
14279         };
14280         hda_nid_t nid;
14281         int i, err;
14282
14283         if (cfg->line_outs == 1) {
14284                 const char *pfx = NULL;
14285                 if (!cfg->hp_outs)
14286                         pfx = "Master";
14287                 else if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
14288                         pfx = "Speaker";
14289                 if (pfx) {
14290                         nid = spec->multiout.dac_nids[0];
14291                         return alc861_create_out_sw(codec, pfx, nid, 3);
14292                 }
14293         }
14294
14295         for (i = 0; i < cfg->line_outs; i++) {
14296                 nid = spec->multiout.dac_nids[i];
14297                 if (!nid)
14298                         continue;
14299                 if (i == 2) {
14300                         /* Center/LFE */
14301                         err = alc861_create_out_sw(codec, "Center", nid, 1);
14302                         if (err < 0)
14303                                 return err;
14304                         err = alc861_create_out_sw(codec, "LFE", nid, 2);
14305                         if (err < 0)
14306                                 return err;
14307                 } else {
14308                         err = alc861_create_out_sw(codec, chname[i], nid, 3);
14309                         if (err < 0)
14310                                 return err;
14311                 }
14312         }
14313         return 0;
14314 }
14315
14316 static int alc861_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin)
14317 {
14318         struct alc_spec *spec = codec->spec;
14319         int err;
14320         hda_nid_t nid;
14321
14322         if (!pin)
14323                 return 0;
14324
14325         if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
14326                 nid = alc861_look_for_dac(codec, pin);
14327                 if (nid) {
14328                         err = alc861_create_out_sw(codec, "Headphone", nid, 3);
14329                         if (err < 0)
14330                                 return err;
14331                         spec->multiout.hp_nid = nid;
14332                 }
14333         }
14334         return 0;
14335 }
14336
14337 /* create playback/capture controls for input pins */
14338 static int alc861_auto_create_input_ctls(struct hda_codec *codec,
14339                                                 const struct auto_pin_cfg *cfg)
14340 {
14341         return alc_auto_create_input_ctls(codec, cfg, 0x15, 0x08, 0);
14342 }
14343
14344 static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
14345                                               hda_nid_t nid,
14346                                               int pin_type, hda_nid_t dac)
14347 {
14348         hda_nid_t mix, srcs[5];
14349         int i, num;
14350
14351         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
14352                             pin_type);
14353         snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14354                             AMP_OUT_UNMUTE);
14355         if (snd_hda_get_connections(codec, nid, &mix, 1) != 1)
14356                 return;
14357         num = snd_hda_get_connections(codec, mix, srcs, ARRAY_SIZE(srcs));
14358         if (num < 0)
14359                 return;
14360         for (i = 0; i < num; i++) {
14361                 unsigned int mute;
14362                 if (srcs[i] == dac || srcs[i] == 0x15)
14363                         mute = AMP_IN_UNMUTE(i);
14364                 else
14365                         mute = AMP_IN_MUTE(i);
14366                 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14367                                     mute);
14368         }
14369 }
14370
14371 static void alc861_auto_init_multi_out(struct hda_codec *codec)
14372 {
14373         struct alc_spec *spec = codec->spec;
14374         int i;
14375
14376         for (i = 0; i < spec->autocfg.line_outs; i++) {
14377                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
14378                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
14379                 if (nid)
14380                         alc861_auto_set_output_and_unmute(codec, nid, pin_type,
14381                                                           spec->multiout.dac_nids[i]);
14382         }
14383 }
14384
14385 static void alc861_auto_init_hp_out(struct hda_codec *codec)
14386 {
14387         struct alc_spec *spec = codec->spec;
14388
14389         if (spec->autocfg.hp_outs)
14390                 alc861_auto_set_output_and_unmute(codec,
14391                                                   spec->autocfg.hp_pins[0],
14392                                                   PIN_HP,
14393                                                   spec->multiout.hp_nid);
14394         if (spec->autocfg.speaker_outs)
14395                 alc861_auto_set_output_and_unmute(codec,
14396                                                   spec->autocfg.speaker_pins[0],
14397                                                   PIN_OUT,
14398                                                   spec->multiout.dac_nids[0]);
14399 }
14400
14401 static void alc861_auto_init_analog_input(struct hda_codec *codec)
14402 {
14403         struct alc_spec *spec = codec->spec;
14404         int i;
14405
14406         for (i = 0; i < AUTO_PIN_LAST; i++) {
14407                 hda_nid_t nid = spec->autocfg.input_pins[i];
14408                 if (nid >= 0x0c && nid <= 0x11)
14409                         alc_set_input_pin(codec, nid, i);
14410         }
14411 }
14412
14413 /* parse the BIOS configuration and set up the alc_spec */
14414 /* return 1 if successful, 0 if the proper config is not found,
14415  * or a negative error code
14416  */
14417 static int alc861_parse_auto_config(struct hda_codec *codec)
14418 {
14419         struct alc_spec *spec = codec->spec;
14420         int err;
14421         static hda_nid_t alc861_ignore[] = { 0x1d, 0 };
14422
14423         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
14424                                            alc861_ignore);
14425         if (err < 0)
14426                 return err;
14427         if (!spec->autocfg.line_outs)
14428                 return 0; /* can't find valid BIOS pin config */
14429
14430         err = alc861_auto_fill_dac_nids(codec, &spec->autocfg);
14431         if (err < 0)
14432                 return err;
14433         err = alc861_auto_create_multi_out_ctls(codec, &spec->autocfg);
14434         if (err < 0)
14435                 return err;
14436         err = alc861_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
14437         if (err < 0)
14438                 return err;
14439         err = alc861_auto_create_input_ctls(codec, &spec->autocfg);
14440         if (err < 0)
14441                 return err;
14442
14443         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
14444
14445         if (spec->autocfg.dig_outs)
14446                 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;
14447
14448         if (spec->kctls.list)
14449                 add_mixer(spec, spec->kctls.list);
14450
14451         add_verb(spec, alc861_auto_init_verbs);
14452
14453         spec->num_mux_defs = 1;
14454         spec->input_mux = &spec->private_imux[0];
14455
14456         spec->adc_nids = alc861_adc_nids;
14457         spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
14458         set_capture_mixer(codec);
14459
14460         alc_ssid_check(codec, 0x0e, 0x0f, 0x0b);
14461
14462         return 1;
14463 }
14464
14465 /* additional initialization for auto-configuration model */
14466 static void alc861_auto_init(struct hda_codec *codec)
14467 {
14468         struct alc_spec *spec = codec->spec;
14469         alc861_auto_init_multi_out(codec);
14470         alc861_auto_init_hp_out(codec);
14471         alc861_auto_init_analog_input(codec);
14472         if (spec->unsol_event)
14473                 alc_inithook(codec);
14474 }
14475
14476 #ifdef CONFIG_SND_HDA_POWER_SAVE
14477 static struct hda_amp_list alc861_loopbacks[] = {
14478         { 0x15, HDA_INPUT, 0 },
14479         { 0x15, HDA_INPUT, 1 },
14480         { 0x15, HDA_INPUT, 2 },
14481         { 0x15, HDA_INPUT, 3 },
14482         { } /* end */
14483 };
14484 #endif
14485
14486
14487 /*
14488  * configuration and preset
14489  */
14490 static const char *alc861_models[ALC861_MODEL_LAST] = {
14491         [ALC861_3ST]            = "3stack",
14492         [ALC660_3ST]            = "3stack-660",
14493         [ALC861_3ST_DIG]        = "3stack-dig",
14494         [ALC861_6ST_DIG]        = "6stack-dig",
14495         [ALC861_UNIWILL_M31]    = "uniwill-m31",
14496         [ALC861_TOSHIBA]        = "toshiba",
14497         [ALC861_ASUS]           = "asus",
14498         [ALC861_ASUS_LAPTOP]    = "asus-laptop",
14499         [ALC861_AUTO]           = "auto",
14500 };
14501
14502 static struct snd_pci_quirk alc861_cfg_tbl[] = {
14503         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC861_3ST),
14504         SND_PCI_QUIRK(0x1043, 0x1335, "ASUS F2/3", ALC861_ASUS_LAPTOP),
14505         SND_PCI_QUIRK(0x1043, 0x1338, "ASUS F2/3", ALC861_ASUS_LAPTOP),
14506         SND_PCI_QUIRK(0x1043, 0x1393, "ASUS", ALC861_ASUS),
14507         SND_PCI_QUIRK(0x1043, 0x13d7, "ASUS A9rp", ALC861_ASUS_LAPTOP),
14508         SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS P1-AH2", ALC861_3ST_DIG),
14509         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba", ALC861_TOSHIBA),
14510         /* FIXME: the entry below breaks Toshiba A100 (model=auto works!)
14511          *        Any other models that need this preset?
14512          */
14513         /* SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba", ALC861_TOSHIBA), */
14514         SND_PCI_QUIRK(0x1462, 0x7254, "HP dx2200 (MSI MS-7254)", ALC861_3ST),
14515         SND_PCI_QUIRK(0x1462, 0x7297, "HP dx2250 (MSI MS-7297)", ALC861_3ST),
14516         SND_PCI_QUIRK(0x1584, 0x2b01, "Uniwill X40AIx", ALC861_UNIWILL_M31),
14517         SND_PCI_QUIRK(0x1584, 0x9072, "Uniwill m31", ALC861_UNIWILL_M31),
14518         SND_PCI_QUIRK(0x1584, 0x9075, "Airis Praxis N1212", ALC861_ASUS_LAPTOP),
14519         /* FIXME: the below seems conflict */
14520         /* SND_PCI_QUIRK(0x1584, 0x9075, "Uniwill", ALC861_UNIWILL_M31), */
14521         SND_PCI_QUIRK(0x1849, 0x0660, "Asrock 939SLI32", ALC660_3ST),
14522         SND_PCI_QUIRK(0x8086, 0xd600, "Intel", ALC861_3ST),
14523         {}
14524 };
14525
14526 static struct alc_config_preset alc861_presets[] = {
14527         [ALC861_3ST] = {
14528                 .mixers = { alc861_3ST_mixer },
14529                 .init_verbs = { alc861_threestack_init_verbs },
14530                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14531                 .dac_nids = alc861_dac_nids,
14532                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
14533                 .channel_mode = alc861_threestack_modes,
14534                 .need_dac_fix = 1,
14535                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14536                 .adc_nids = alc861_adc_nids,
14537                 .input_mux = &alc861_capture_source,
14538         },
14539         [ALC861_3ST_DIG] = {
14540                 .mixers = { alc861_base_mixer },
14541                 .init_verbs = { alc861_threestack_init_verbs },
14542                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14543                 .dac_nids = alc861_dac_nids,
14544                 .dig_out_nid = ALC861_DIGOUT_NID,
14545                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
14546                 .channel_mode = alc861_threestack_modes,
14547                 .need_dac_fix = 1,
14548                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14549                 .adc_nids = alc861_adc_nids,
14550                 .input_mux = &alc861_capture_source,
14551         },
14552         [ALC861_6ST_DIG] = {
14553                 .mixers = { alc861_base_mixer },
14554                 .init_verbs = { alc861_base_init_verbs },
14555                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14556                 .dac_nids = alc861_dac_nids,
14557                 .dig_out_nid = ALC861_DIGOUT_NID,
14558                 .num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
14559                 .channel_mode = alc861_8ch_modes,
14560                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14561                 .adc_nids = alc861_adc_nids,
14562                 .input_mux = &alc861_capture_source,
14563         },
14564         [ALC660_3ST] = {
14565                 .mixers = { alc861_3ST_mixer },
14566                 .init_verbs = { alc861_threestack_init_verbs },
14567                 .num_dacs = ARRAY_SIZE(alc660_dac_nids),
14568                 .dac_nids = alc660_dac_nids,
14569                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
14570                 .channel_mode = alc861_threestack_modes,
14571                 .need_dac_fix = 1,
14572                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14573                 .adc_nids = alc861_adc_nids,
14574                 .input_mux = &alc861_capture_source,
14575         },
14576         [ALC861_UNIWILL_M31] = {
14577                 .mixers = { alc861_uniwill_m31_mixer },
14578                 .init_verbs = { alc861_uniwill_m31_init_verbs },
14579                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14580                 .dac_nids = alc861_dac_nids,
14581                 .dig_out_nid = ALC861_DIGOUT_NID,
14582                 .num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
14583                 .channel_mode = alc861_uniwill_m31_modes,
14584                 .need_dac_fix = 1,
14585                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14586                 .adc_nids = alc861_adc_nids,
14587                 .input_mux = &alc861_capture_source,
14588         },
14589         [ALC861_TOSHIBA] = {
14590                 .mixers = { alc861_toshiba_mixer },
14591                 .init_verbs = { alc861_base_init_verbs,
14592                                 alc861_toshiba_init_verbs },
14593                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14594                 .dac_nids = alc861_dac_nids,
14595                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
14596                 .channel_mode = alc883_3ST_2ch_modes,
14597                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14598                 .adc_nids = alc861_adc_nids,
14599                 .input_mux = &alc861_capture_source,
14600                 .unsol_event = alc861_toshiba_unsol_event,
14601                 .init_hook = alc861_toshiba_automute,
14602         },
14603         [ALC861_ASUS] = {
14604                 .mixers = { alc861_asus_mixer },
14605                 .init_verbs = { alc861_asus_init_verbs },
14606                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14607                 .dac_nids = alc861_dac_nids,
14608                 .dig_out_nid = ALC861_DIGOUT_NID,
14609                 .num_channel_mode = ARRAY_SIZE(alc861_asus_modes),
14610                 .channel_mode = alc861_asus_modes,
14611                 .need_dac_fix = 1,
14612                 .hp_nid = 0x06,
14613                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14614                 .adc_nids = alc861_adc_nids,
14615                 .input_mux = &alc861_capture_source,
14616         },
14617         [ALC861_ASUS_LAPTOP] = {
14618                 .mixers = { alc861_toshiba_mixer, alc861_asus_laptop_mixer },
14619                 .init_verbs = { alc861_asus_init_verbs,
14620                                 alc861_asus_laptop_init_verbs },
14621                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14622                 .dac_nids = alc861_dac_nids,
14623                 .dig_out_nid = ALC861_DIGOUT_NID,
14624                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
14625                 .channel_mode = alc883_3ST_2ch_modes,
14626                 .need_dac_fix = 1,
14627                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14628                 .adc_nids = alc861_adc_nids,
14629                 .input_mux = &alc861_capture_source,
14630         },
14631 };
14632
14633
14634 static int patch_alc861(struct hda_codec *codec)
14635 {
14636         struct alc_spec *spec;
14637         int board_config;
14638         int err;
14639
14640         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
14641         if (spec == NULL)
14642                 return -ENOMEM;
14643
14644         codec->spec = spec;
14645
14646         board_config = snd_hda_check_board_config(codec, ALC861_MODEL_LAST,
14647                                                   alc861_models,
14648                                                   alc861_cfg_tbl);
14649
14650         if (board_config < 0) {
14651                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
14652                        codec->chip_name);
14653                 board_config = ALC861_AUTO;
14654         }
14655
14656         if (board_config == ALC861_AUTO) {
14657                 /* automatic parse from the BIOS config */
14658                 err = alc861_parse_auto_config(codec);
14659                 if (err < 0) {
14660                         alc_free(codec);
14661                         return err;
14662                 } else if (!err) {
14663                         printk(KERN_INFO
14664                                "hda_codec: Cannot set up configuration "
14665                                "from BIOS.  Using base mode...\n");
14666                    board_config = ALC861_3ST_DIG;
14667                 }
14668         }
14669
14670         err = snd_hda_attach_beep_device(codec, 0x23);
14671         if (err < 0) {
14672                 alc_free(codec);
14673                 return err;
14674         }
14675
14676         if (board_config != ALC861_AUTO)
14677                 setup_preset(codec, &alc861_presets[board_config]);
14678
14679         spec->stream_analog_playback = &alc861_pcm_analog_playback;
14680         spec->stream_analog_capture = &alc861_pcm_analog_capture;
14681
14682         spec->stream_digital_playback = &alc861_pcm_digital_playback;
14683         spec->stream_digital_capture = &alc861_pcm_digital_capture;
14684
14685         set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
14686
14687         spec->vmaster_nid = 0x03;
14688
14689         codec->patch_ops = alc_patch_ops;
14690         if (board_config == ALC861_AUTO)
14691                 spec->init_hook = alc861_auto_init;
14692 #ifdef CONFIG_SND_HDA_POWER_SAVE
14693         if (!spec->loopback.amplist)
14694                 spec->loopback.amplist = alc861_loopbacks;
14695 #endif
14696         codec->proc_widget_hook = print_realtek_coef;
14697
14698         return 0;
14699 }
14700
14701 /*
14702  * ALC861-VD support
14703  *
14704  * Based on ALC882
14705  *
14706  * In addition, an independent DAC
14707  */
14708 #define ALC861VD_DIGOUT_NID     0x06
14709
14710 static hda_nid_t alc861vd_dac_nids[4] = {
14711         /* front, surr, clfe, side surr */
14712         0x02, 0x03, 0x04, 0x05
14713 };
14714
14715 /* dac_nids for ALC660vd are in a different order - according to
14716  * Realtek's driver.
14717  * This should probably result in a different mixer for 6stack models
14718  * of ALC660vd codecs, but for now there is only 3stack mixer
14719  * - and it is the same as in 861vd.
14720  * adc_nids in ALC660vd are (is) the same as in 861vd
14721  */
14722 static hda_nid_t alc660vd_dac_nids[3] = {
14723         /* front, rear, clfe, rear_surr */
14724         0x02, 0x04, 0x03
14725 };
14726
14727 static hda_nid_t alc861vd_adc_nids[1] = {
14728         /* ADC0 */
14729         0x09,
14730 };
14731
14732 static hda_nid_t alc861vd_capsrc_nids[1] = { 0x22 };
14733
14734 /* input MUX */
14735 /* FIXME: should be a matrix-type input source selection */
14736 static struct hda_input_mux alc861vd_capture_source = {
14737         .num_items = 4,
14738         .items = {
14739                 { "Mic", 0x0 },
14740                 { "Front Mic", 0x1 },
14741                 { "Line", 0x2 },
14742                 { "CD", 0x4 },
14743         },
14744 };
14745
14746 static struct hda_input_mux alc861vd_dallas_capture_source = {
14747         .num_items = 2,
14748         .items = {
14749                 { "Ext Mic", 0x0 },
14750                 { "Int Mic", 0x1 },
14751         },
14752 };
14753
14754 static struct hda_input_mux alc861vd_hp_capture_source = {
14755         .num_items = 2,
14756         .items = {
14757                 { "Front Mic", 0x0 },
14758                 { "ATAPI Mic", 0x1 },
14759         },
14760 };
14761
14762 /*
14763  * 2ch mode
14764  */
14765 static struct hda_channel_mode alc861vd_3stack_2ch_modes[1] = {
14766         { 2, NULL }
14767 };
14768
14769 /*
14770  * 6ch mode
14771  */
14772 static struct hda_verb alc861vd_6stack_ch6_init[] = {
14773         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
14774         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14775         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14776         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14777         { } /* end */
14778 };
14779
14780 /*
14781  * 8ch mode
14782  */
14783 static struct hda_verb alc861vd_6stack_ch8_init[] = {
14784         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14785         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14786         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14787         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14788         { } /* end */
14789 };
14790
14791 static struct hda_channel_mode alc861vd_6stack_modes[2] = {
14792         { 6, alc861vd_6stack_ch6_init },
14793         { 8, alc861vd_6stack_ch8_init },
14794 };
14795
14796 static struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
14797         {
14798                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
14799                 .name = "Channel Mode",
14800                 .info = alc_ch_mode_info,
14801                 .get = alc_ch_mode_get,
14802                 .put = alc_ch_mode_put,
14803         },
14804         { } /* end */
14805 };
14806
14807 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
14808  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
14809  */
14810 static struct snd_kcontrol_new alc861vd_6st_mixer[] = {
14811         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14812         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14813
14814         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14815         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
14816
14817         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0,
14818                                 HDA_OUTPUT),
14819         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0,
14820                                 HDA_OUTPUT),
14821         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
14822         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
14823
14824         HDA_CODEC_VOLUME("Side Playback Volume", 0x05, 0x0, HDA_OUTPUT),
14825         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
14826
14827         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14828
14829         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
14830         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14831         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14832
14833         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
14834         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14835         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14836
14837         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14838         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14839
14840         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14841         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14842
14843         { } /* end */
14844 };
14845
14846 static struct snd_kcontrol_new alc861vd_3st_mixer[] = {
14847         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14848         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14849
14850         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14851
14852         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
14853         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14854         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14855
14856         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
14857         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14858         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14859
14860         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14861         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14862
14863         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14864         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14865
14866         { } /* end */
14867 };
14868
14869 static struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
14870         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14871         /*HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),*/
14872         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14873
14874         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14875
14876         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
14877         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14878         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14879
14880         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
14881         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14882         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14883
14884         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14885         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14886
14887         { } /* end */
14888 };
14889
14890 /* Pin assignment: Speaker=0x14, HP = 0x15,
14891  *                 Ext Mic=0x18, Int Mic = 0x19, CD = 0x1c, PC Beep = 0x1d
14892  */
14893 static struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
14894         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14895         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
14896         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14897         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
14898         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
14899         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14900         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14901         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
14902         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14903         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14904         { } /* end */
14905 };
14906
14907 /* Pin assignment: Speaker=0x14, Line-out = 0x15,
14908  *                 Front Mic=0x18, ATAPI Mic = 0x19,
14909  */
14910 static struct snd_kcontrol_new alc861vd_hp_mixer[] = {
14911         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14912         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14913         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14914         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
14915         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14916         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14917         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14918         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14919
14920         { } /* end */
14921 };
14922
14923 /*
14924  * generic initialization of ADC, input mixers and output mixers
14925  */
14926 static struct hda_verb alc861vd_volume_init_verbs[] = {
14927         /*
14928          * Unmute ADC0 and set the default input to mic-in
14929          */
14930         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
14931         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14932
14933         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of
14934          * the analog-loopback mixer widget
14935          */
14936         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
14937         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14938         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14939         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14940         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14941         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14942
14943         /* Capture mixer: unmute Mic, F-Mic, Line, CD inputs */
14944         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14945         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14946         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14947         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
14948
14949         /*
14950          * Set up output mixers (0x02 - 0x05)
14951          */
14952         /* set vol=0 to output mixers */
14953         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14954         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14955         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14956         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14957
14958         /* set up input amps for analog loopback */
14959         /* Amp Indices: DAC = 0, mixer = 1 */
14960         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14961         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14962         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14963         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14964         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14965         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14966         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14967         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14968
14969         { }
14970 };
14971
14972 /*
14973  * 3-stack pin configuration:
14974  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
14975  */
14976 static struct hda_verb alc861vd_3stack_init_verbs[] = {
14977         /*
14978          * Set pin mode and muting
14979          */
14980         /* set front pin widgets 0x14 for output */
14981         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14982         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14983         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
14984
14985         /* Mic (rear) pin: input vref at 80% */
14986         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14987         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14988         /* Front Mic pin: input vref at 80% */
14989         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14990         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14991         /* Line In pin: input */
14992         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14993         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14994         /* Line-2 In: Headphone output (output 0 - 0x0c) */
14995         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14996         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14997         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
14998         /* CD pin widget for input */
14999         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15000
15001         { }
15002 };
15003
15004 /*
15005  * 6-stack pin configuration:
15006  */
15007 static struct hda_verb alc861vd_6stack_init_verbs[] = {
15008         /*
15009          * Set pin mode and muting
15010          */
15011         /* set front pin widgets 0x14 for output */
15012         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15013         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15014         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
15015
15016         /* Rear Pin: output 1 (0x0d) */
15017         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15018         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15019         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
15020         /* CLFE Pin: output 2 (0x0e) */
15021         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15022         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15023         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
15024         /* Side Pin: output 3 (0x0f) */
15025         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15026         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15027         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
15028
15029         /* Mic (rear) pin: input vref at 80% */
15030         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
15031         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15032         /* Front Mic pin: input vref at 80% */
15033         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
15034         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15035         /* Line In pin: input */
15036         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15037         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15038         /* Line-2 In: Headphone output (output 0 - 0x0c) */
15039         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15040         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15041         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
15042         /* CD pin widget for input */
15043         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15044
15045         { }
15046 };
15047
15048 static struct hda_verb alc861vd_eapd_verbs[] = {
15049         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
15050         { }
15051 };
15052
15053 static struct hda_verb alc660vd_eapd_verbs[] = {
15054         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
15055         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
15056         { }
15057 };
15058
15059 static struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
15060         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15061         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15062         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
15063         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15064         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15065         {}
15066 };
15067
15068 static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
15069 {
15070         unsigned int present;
15071         unsigned char bits;
15072
15073         present = snd_hda_codec_read(codec, 0x18, 0,
15074                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15075         bits = present ? HDA_AMP_MUTE : 0;
15076         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
15077                                  HDA_AMP_MUTE, bits);
15078 }
15079
15080 static void alc861vd_lenovo_setup(struct hda_codec *codec)
15081 {
15082         struct alc_spec *spec = codec->spec;
15083         spec->autocfg.hp_pins[0] = 0x1b;
15084         spec->autocfg.speaker_pins[0] = 0x14;
15085 }
15086
15087 static void alc861vd_lenovo_init_hook(struct hda_codec *codec)
15088 {
15089         alc_automute_amp(codec);
15090         alc861vd_lenovo_mic_automute(codec);
15091 }
15092
15093 static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
15094                                         unsigned int res)
15095 {
15096         switch (res >> 26) {
15097         case ALC880_MIC_EVENT:
15098                 alc861vd_lenovo_mic_automute(codec);
15099                 break;
15100         default:
15101                 alc_automute_amp_unsol_event(codec, res);
15102                 break;
15103         }
15104 }
15105
15106 static struct hda_verb alc861vd_dallas_verbs[] = {
15107         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15108         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15109         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15110         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15111
15112         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15113         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15114         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15115         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15116         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15117         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15118         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15119         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15120
15121         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15122         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15123         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15124         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15125         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15126         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15127         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15128         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15129
15130         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
15131         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15132         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
15133         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15134         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15135         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15136         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15137         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15138
15139         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15140         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
15141         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
15142         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
15143
15144         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15145         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
15146         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15147
15148         { } /* end */
15149 };
15150
15151 /* toggle speaker-output according to the hp-jack state */
15152 static void alc861vd_dallas_setup(struct hda_codec *codec)
15153 {
15154         struct alc_spec *spec = codec->spec;
15155
15156         spec->autocfg.hp_pins[0] = 0x15;
15157         spec->autocfg.speaker_pins[0] = 0x14;
15158 }
15159
15160 #ifdef CONFIG_SND_HDA_POWER_SAVE
15161 #define alc861vd_loopbacks      alc880_loopbacks
15162 #endif
15163
15164 /* pcm configuration: identical with ALC880 */
15165 #define alc861vd_pcm_analog_playback    alc880_pcm_analog_playback
15166 #define alc861vd_pcm_analog_capture     alc880_pcm_analog_capture
15167 #define alc861vd_pcm_digital_playback   alc880_pcm_digital_playback
15168 #define alc861vd_pcm_digital_capture    alc880_pcm_digital_capture
15169
15170 /*
15171  * configuration and preset
15172  */
15173 static const char *alc861vd_models[ALC861VD_MODEL_LAST] = {
15174         [ALC660VD_3ST]          = "3stack-660",
15175         [ALC660VD_3ST_DIG]      = "3stack-660-digout",
15176         [ALC660VD_ASUS_V1S]     = "asus-v1s",
15177         [ALC861VD_3ST]          = "3stack",
15178         [ALC861VD_3ST_DIG]      = "3stack-digout",
15179         [ALC861VD_6ST_DIG]      = "6stack-digout",
15180         [ALC861VD_LENOVO]       = "lenovo",
15181         [ALC861VD_DALLAS]       = "dallas",
15182         [ALC861VD_HP]           = "hp",
15183         [ALC861VD_AUTO]         = "auto",
15184 };
15185
15186 static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
15187         SND_PCI_QUIRK(0x1019, 0xa88d, "Realtek ALC660 demo", ALC660VD_3ST),
15188         SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_HP),
15189         SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST),
15190         /*SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),*/ /* auto */
15191         SND_PCI_QUIRK(0x1043, 0x1633, "Asus V1Sn", ALC660VD_ASUS_V1S),
15192         SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG),
15193         SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
15194         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
15195         /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
15196         SND_PCI_QUIRK(0x1179, 0xff01, "Toshiba A135", ALC861VD_LENOVO),
15197         SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
15198         SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_DALLAS),
15199         SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
15200         SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", ALC861VD_LENOVO),
15201         SND_PCI_QUIRK(0x1849, 0x0862, "ASRock K8NF6G-VSTA", ALC861VD_6ST_DIG),
15202         {}
15203 };
15204
15205 static struct alc_config_preset alc861vd_presets[] = {
15206         [ALC660VD_3ST] = {
15207                 .mixers = { alc861vd_3st_mixer },
15208                 .init_verbs = { alc861vd_volume_init_verbs,
15209                                  alc861vd_3stack_init_verbs },
15210                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
15211                 .dac_nids = alc660vd_dac_nids,
15212                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15213                 .channel_mode = alc861vd_3stack_2ch_modes,
15214                 .input_mux = &alc861vd_capture_source,
15215         },
15216         [ALC660VD_3ST_DIG] = {
15217                 .mixers = { alc861vd_3st_mixer },
15218                 .init_verbs = { alc861vd_volume_init_verbs,
15219                                  alc861vd_3stack_init_verbs },
15220                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
15221                 .dac_nids = alc660vd_dac_nids,
15222                 .dig_out_nid = ALC861VD_DIGOUT_NID,
15223                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15224                 .channel_mode = alc861vd_3stack_2ch_modes,
15225                 .input_mux = &alc861vd_capture_source,
15226         },
15227         [ALC861VD_3ST] = {
15228                 .mixers = { alc861vd_3st_mixer },
15229                 .init_verbs = { alc861vd_volume_init_verbs,
15230                                  alc861vd_3stack_init_verbs },
15231                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
15232                 .dac_nids = alc861vd_dac_nids,
15233                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15234                 .channel_mode = alc861vd_3stack_2ch_modes,
15235                 .input_mux = &alc861vd_capture_source,
15236         },
15237         [ALC861VD_3ST_DIG] = {
15238                 .mixers = { alc861vd_3st_mixer },
15239                 .init_verbs = { alc861vd_volume_init_verbs,
15240                                  alc861vd_3stack_init_verbs },
15241                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
15242                 .dac_nids = alc861vd_dac_nids,
15243                 .dig_out_nid = ALC861VD_DIGOUT_NID,
15244                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15245                 .channel_mode = alc861vd_3stack_2ch_modes,
15246                 .input_mux = &alc861vd_capture_source,
15247         },
15248         [ALC861VD_6ST_DIG] = {
15249                 .mixers = { alc861vd_6st_mixer, alc861vd_chmode_mixer },
15250                 .init_verbs = { alc861vd_volume_init_verbs,
15251                                 alc861vd_6stack_init_verbs },
15252                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
15253                 .dac_nids = alc861vd_dac_nids,
15254                 .dig_out_nid = ALC861VD_DIGOUT_NID,
15255                 .num_channel_mode = ARRAY_SIZE(alc861vd_6stack_modes),
15256                 .channel_mode = alc861vd_6stack_modes,
15257                 .input_mux = &alc861vd_capture_source,
15258         },
15259         [ALC861VD_LENOVO] = {
15260                 .mixers = { alc861vd_lenovo_mixer },
15261                 .init_verbs = { alc861vd_volume_init_verbs,
15262                                 alc861vd_3stack_init_verbs,
15263                                 alc861vd_eapd_verbs,
15264                                 alc861vd_lenovo_unsol_verbs },
15265                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
15266                 .dac_nids = alc660vd_dac_nids,
15267                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15268                 .channel_mode = alc861vd_3stack_2ch_modes,
15269                 .input_mux = &alc861vd_capture_source,
15270                 .unsol_event = alc861vd_lenovo_unsol_event,
15271                 .setup = alc861vd_lenovo_setup,
15272                 .init_hook = alc861vd_lenovo_init_hook,
15273         },
15274         [ALC861VD_DALLAS] = {
15275                 .mixers = { alc861vd_dallas_mixer },
15276                 .init_verbs = { alc861vd_dallas_verbs },
15277                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
15278                 .dac_nids = alc861vd_dac_nids,
15279                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15280                 .channel_mode = alc861vd_3stack_2ch_modes,
15281                 .input_mux = &alc861vd_dallas_capture_source,
15282                 .unsol_event = alc_automute_amp_unsol_event,
15283                 .setup = alc861vd_dallas_setup,
15284                 .init_hook = alc_automute_amp,
15285         },
15286         [ALC861VD_HP] = {
15287                 .mixers = { alc861vd_hp_mixer },
15288                 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs },
15289                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
15290                 .dac_nids = alc861vd_dac_nids,
15291                 .dig_out_nid = ALC861VD_DIGOUT_NID,
15292                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15293                 .channel_mode = alc861vd_3stack_2ch_modes,
15294                 .input_mux = &alc861vd_hp_capture_source,
15295                 .unsol_event = alc_automute_amp_unsol_event,
15296                 .setup = alc861vd_dallas_setup,
15297                 .init_hook = alc_automute_amp,
15298         },
15299         [ALC660VD_ASUS_V1S] = {
15300                 .mixers = { alc861vd_lenovo_mixer },
15301                 .init_verbs = { alc861vd_volume_init_verbs,
15302                                 alc861vd_3stack_init_verbs,
15303                                 alc861vd_eapd_verbs,
15304                                 alc861vd_lenovo_unsol_verbs },
15305                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
15306                 .dac_nids = alc660vd_dac_nids,
15307                 .dig_out_nid = ALC861VD_DIGOUT_NID,
15308                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15309                 .channel_mode = alc861vd_3stack_2ch_modes,
15310                 .input_mux = &alc861vd_capture_source,
15311                 .unsol_event = alc861vd_lenovo_unsol_event,
15312                 .setup = alc861vd_lenovo_setup,
15313                 .init_hook = alc861vd_lenovo_init_hook,
15314         },
15315 };
15316
15317 /*
15318  * BIOS auto configuration
15319  */
15320 static int alc861vd_auto_create_input_ctls(struct hda_codec *codec,
15321                                                 const struct auto_pin_cfg *cfg)
15322 {
15323         return alc_auto_create_input_ctls(codec, cfg, 0x15, 0x09, 0);
15324 }
15325
15326
15327 static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
15328                                 hda_nid_t nid, int pin_type, int dac_idx)
15329 {
15330         alc_set_pin_output(codec, nid, pin_type);
15331 }
15332
15333 static void alc861vd_auto_init_multi_out(struct hda_codec *codec)
15334 {
15335         struct alc_spec *spec = codec->spec;
15336         int i;
15337
15338         for (i = 0; i <= HDA_SIDE; i++) {
15339                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
15340                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
15341                 if (nid)
15342                         alc861vd_auto_set_output_and_unmute(codec, nid,
15343                                                             pin_type, i);
15344         }
15345 }
15346
15347
15348 static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
15349 {
15350         struct alc_spec *spec = codec->spec;
15351         hda_nid_t pin;
15352
15353         pin = spec->autocfg.hp_pins[0];
15354         if (pin) /* connect to front and use dac 0 */
15355                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
15356         pin = spec->autocfg.speaker_pins[0];
15357         if (pin)
15358                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
15359 }
15360
15361 #define ALC861VD_PIN_CD_NID             ALC880_PIN_CD_NID
15362
15363 static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
15364 {
15365         struct alc_spec *spec = codec->spec;
15366         int i;
15367
15368         for (i = 0; i < AUTO_PIN_LAST; i++) {
15369                 hda_nid_t nid = spec->autocfg.input_pins[i];
15370                 if (alc_is_input_pin(codec, nid)) {
15371                         alc_set_input_pin(codec, nid, i);
15372                         if (nid != ALC861VD_PIN_CD_NID &&
15373                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
15374                                 snd_hda_codec_write(codec, nid, 0,
15375                                                 AC_VERB_SET_AMP_GAIN_MUTE,
15376                                                 AMP_OUT_MUTE);
15377                 }
15378         }
15379 }
15380
15381 #define alc861vd_auto_init_input_src    alc882_auto_init_input_src
15382
15383 #define alc861vd_idx_to_mixer_vol(nid)          ((nid) + 0x02)
15384 #define alc861vd_idx_to_mixer_switch(nid)       ((nid) + 0x0c)
15385
15386 /* add playback controls from the parsed DAC table */
15387 /* Based on ALC880 version. But ALC861VD has separate,
15388  * different NIDs for mute/unmute switch and volume control */
15389 static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
15390                                              const struct auto_pin_cfg *cfg)
15391 {
15392         static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"};
15393         hda_nid_t nid_v, nid_s;
15394         int i, err;
15395
15396         for (i = 0; i < cfg->line_outs; i++) {
15397                 if (!spec->multiout.dac_nids[i])
15398                         continue;
15399                 nid_v = alc861vd_idx_to_mixer_vol(
15400                                 alc880_dac_to_idx(
15401                                         spec->multiout.dac_nids[i]));
15402                 nid_s = alc861vd_idx_to_mixer_switch(
15403                                 alc880_dac_to_idx(
15404                                         spec->multiout.dac_nids[i]));
15405
15406                 if (i == 2) {
15407                         /* Center/LFE */
15408                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
15409                                               "Center",
15410                                           HDA_COMPOSE_AMP_VAL(nid_v, 1, 0,
15411                                                               HDA_OUTPUT));
15412                         if (err < 0)
15413                                 return err;
15414                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
15415                                               "LFE",
15416                                           HDA_COMPOSE_AMP_VAL(nid_v, 2, 0,
15417                                                               HDA_OUTPUT));
15418                         if (err < 0)
15419                                 return err;
15420                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
15421                                              "Center",
15422                                           HDA_COMPOSE_AMP_VAL(nid_s, 1, 2,
15423                                                               HDA_INPUT));
15424                         if (err < 0)
15425                                 return err;
15426                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
15427                                              "LFE",
15428                                           HDA_COMPOSE_AMP_VAL(nid_s, 2, 2,
15429                                                               HDA_INPUT));
15430                         if (err < 0)
15431                                 return err;
15432                 } else {
15433                         const char *pfx;
15434                         if (cfg->line_outs == 1 &&
15435                             cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
15436                                 if (!cfg->hp_pins)
15437                                         pfx = "Speaker";
15438                                 else
15439                                         pfx = "PCM";
15440                         } else
15441                                 pfx = chname[i];
15442                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
15443                                           HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
15444                                                               HDA_OUTPUT));
15445                         if (err < 0)
15446                                 return err;
15447                         if (cfg->line_outs == 1 &&
15448                             cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
15449                                 pfx = "Speaker";
15450                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE, pfx,
15451                                           HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
15452                                                               HDA_INPUT));
15453                         if (err < 0)
15454                                 return err;
15455                 }
15456         }
15457         return 0;
15458 }
15459
15460 /* add playback controls for speaker and HP outputs */
15461 /* Based on ALC880 version. But ALC861VD has separate,
15462  * different NIDs for mute/unmute switch and volume control */
15463 static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
15464                                         hda_nid_t pin, const char *pfx)
15465 {
15466         hda_nid_t nid_v, nid_s;
15467         int err;
15468
15469         if (!pin)
15470                 return 0;
15471
15472         if (alc880_is_fixed_pin(pin)) {
15473                 nid_v = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
15474                 /* specify the DAC as the extra output */
15475                 if (!spec->multiout.hp_nid)
15476                         spec->multiout.hp_nid = nid_v;
15477                 else
15478                         spec->multiout.extra_out_nid[0] = nid_v;
15479                 /* control HP volume/switch on the output mixer amp */
15480                 nid_v = alc861vd_idx_to_mixer_vol(
15481                                 alc880_fixed_pin_idx(pin));
15482                 nid_s = alc861vd_idx_to_mixer_switch(
15483                                 alc880_fixed_pin_idx(pin));
15484
15485                 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
15486                                   HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT));
15487                 if (err < 0)
15488                         return err;
15489                 err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE, pfx,
15490                                   HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT));
15491                 if (err < 0)
15492                         return err;
15493         } else if (alc880_is_multi_pin(pin)) {
15494                 /* set manual connection */
15495                 /* we have only a switch on HP-out PIN */
15496                 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
15497                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
15498                 if (err < 0)
15499                         return err;
15500         }
15501         return 0;
15502 }
15503
15504 /* parse the BIOS configuration and set up the alc_spec
15505  * return 1 if successful, 0 if the proper config is not found,
15506  * or a negative error code
15507  * Based on ALC880 version - had to change it to override
15508  * alc880_auto_create_extra_out and alc880_auto_create_multi_out_ctls */
15509 static int alc861vd_parse_auto_config(struct hda_codec *codec)
15510 {
15511         struct alc_spec *spec = codec->spec;
15512         int err;
15513         static hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
15514
15515         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
15516                                            alc861vd_ignore);
15517         if (err < 0)
15518                 return err;
15519         if (!spec->autocfg.line_outs)
15520                 return 0; /* can't find valid BIOS pin config */
15521
15522         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
15523         if (err < 0)
15524                 return err;
15525         err = alc861vd_auto_create_multi_out_ctls(spec, &spec->autocfg);
15526         if (err < 0)
15527                 return err;
15528         err = alc861vd_auto_create_extra_out(spec,
15529                                              spec->autocfg.speaker_pins[0],
15530                                              "Speaker");
15531         if (err < 0)
15532                 return err;
15533         err = alc861vd_auto_create_extra_out(spec,
15534                                              spec->autocfg.hp_pins[0],
15535                                              "Headphone");
15536         if (err < 0)
15537                 return err;
15538         err = alc861vd_auto_create_input_ctls(codec, &spec->autocfg);
15539         if (err < 0)
15540                 return err;
15541
15542         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
15543
15544         if (spec->autocfg.dig_outs)
15545                 spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID;
15546
15547         if (spec->kctls.list)
15548                 add_mixer(spec, spec->kctls.list);
15549
15550         add_verb(spec, alc861vd_volume_init_verbs);
15551
15552         spec->num_mux_defs = 1;
15553         spec->input_mux = &spec->private_imux[0];
15554
15555         err = alc_auto_add_mic_boost(codec);
15556         if (err < 0)
15557                 return err;
15558
15559         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
15560
15561         return 1;
15562 }
15563
15564 /* additional initialization for auto-configuration model */
15565 static void alc861vd_auto_init(struct hda_codec *codec)
15566 {
15567         struct alc_spec *spec = codec->spec;
15568         alc861vd_auto_init_multi_out(codec);
15569         alc861vd_auto_init_hp_out(codec);
15570         alc861vd_auto_init_analog_input(codec);
15571         alc861vd_auto_init_input_src(codec);
15572         if (spec->unsol_event)
15573                 alc_inithook(codec);
15574 }
15575
15576 enum {
15577         ALC660VD_FIX_ASUS_GPIO1
15578 };
15579
15580 /* reset GPIO1 */
15581 static const struct hda_verb alc660vd_fix_asus_gpio1_verbs[] = {
15582         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
15583         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
15584         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
15585         { }
15586 };
15587
15588 static const struct alc_fixup alc861vd_fixups[] = {
15589         [ALC660VD_FIX_ASUS_GPIO1] = {
15590                 .verbs = alc660vd_fix_asus_gpio1_verbs,
15591         },
15592 };
15593
15594 static struct snd_pci_quirk alc861vd_fixup_tbl[] = {
15595         SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
15596         {}
15597 };
15598
15599 static int patch_alc861vd(struct hda_codec *codec)
15600 {
15601         struct alc_spec *spec;
15602         int err, board_config;
15603
15604         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
15605         if (spec == NULL)
15606                 return -ENOMEM;
15607
15608         codec->spec = spec;
15609
15610         board_config = snd_hda_check_board_config(codec, ALC861VD_MODEL_LAST,
15611                                                   alc861vd_models,
15612                                                   alc861vd_cfg_tbl);
15613
15614         if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) {
15615                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
15616                        codec->chip_name);
15617                 board_config = ALC861VD_AUTO;
15618         }
15619
15620         alc_pick_fixup(codec, alc861vd_fixup_tbl, alc861vd_fixups);
15621
15622         if (board_config == ALC861VD_AUTO) {
15623                 /* automatic parse from the BIOS config */
15624                 err = alc861vd_parse_auto_config(codec);
15625                 if (err < 0) {
15626                         alc_free(codec);
15627                         return err;
15628                 } else if (!err) {
15629                         printk(KERN_INFO
15630                                "hda_codec: Cannot set up configuration "
15631                                "from BIOS.  Using base mode...\n");
15632                         board_config = ALC861VD_3ST;
15633                 }
15634         }
15635
15636         err = snd_hda_attach_beep_device(codec, 0x23);
15637         if (err < 0) {
15638                 alc_free(codec);
15639                 return err;
15640         }
15641
15642         if (board_config != ALC861VD_AUTO)
15643                 setup_preset(codec, &alc861vd_presets[board_config]);
15644
15645         if (codec->vendor_id == 0x10ec0660) {
15646                 /* always turn on EAPD */
15647                 add_verb(spec, alc660vd_eapd_verbs);
15648         }
15649
15650         spec->stream_analog_playback = &alc861vd_pcm_analog_playback;
15651         spec->stream_analog_capture = &alc861vd_pcm_analog_capture;
15652
15653         spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
15654         spec->stream_digital_capture = &alc861vd_pcm_digital_capture;
15655
15656         if (!spec->adc_nids) {
15657                 spec->adc_nids = alc861vd_adc_nids;
15658                 spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
15659         }
15660         if (!spec->capsrc_nids)
15661                 spec->capsrc_nids = alc861vd_capsrc_nids;
15662
15663         set_capture_mixer(codec);
15664         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
15665
15666         spec->vmaster_nid = 0x02;
15667
15668         codec->patch_ops = alc_patch_ops;
15669
15670         if (board_config == ALC861VD_AUTO)
15671                 spec->init_hook = alc861vd_auto_init;
15672 #ifdef CONFIG_SND_HDA_POWER_SAVE
15673         if (!spec->loopback.amplist)
15674                 spec->loopback.amplist = alc861vd_loopbacks;
15675 #endif
15676         codec->proc_widget_hook = print_realtek_coef;
15677
15678         return 0;
15679 }
15680
15681 /*
15682  * ALC662 support
15683  *
15684  * ALC662 is almost identical with ALC880 but has cleaner and more flexible
15685  * configuration.  Each pin widget can choose any input DACs and a mixer.
15686  * Each ADC is connected from a mixer of all inputs.  This makes possible
15687  * 6-channel independent captures.
15688  *
15689  * In addition, an independent DAC for the multi-playback (not used in this
15690  * driver yet).
15691  */
15692 #define ALC662_DIGOUT_NID       0x06
15693 #define ALC662_DIGIN_NID        0x0a
15694
15695 static hda_nid_t alc662_dac_nids[4] = {
15696         /* front, rear, clfe, rear_surr */
15697         0x02, 0x03, 0x04
15698 };
15699
15700 static hda_nid_t alc272_dac_nids[2] = {
15701         0x02, 0x03
15702 };
15703
15704 static hda_nid_t alc662_adc_nids[2] = {
15705         /* ADC1-2 */
15706         0x09, 0x08
15707 };
15708
15709 static hda_nid_t alc272_adc_nids[1] = {
15710         /* ADC1-2 */
15711         0x08,
15712 };
15713
15714 static hda_nid_t alc662_capsrc_nids[2] = { 0x22, 0x23 };
15715 static hda_nid_t alc272_capsrc_nids[1] = { 0x23 };
15716
15717
15718 /* input MUX */
15719 /* FIXME: should be a matrix-type input source selection */
15720 static struct hda_input_mux alc662_capture_source = {
15721         .num_items = 4,
15722         .items = {
15723                 { "Mic", 0x0 },
15724                 { "Front Mic", 0x1 },
15725                 { "Line", 0x2 },
15726                 { "CD", 0x4 },
15727         },
15728 };
15729
15730 static struct hda_input_mux alc662_lenovo_101e_capture_source = {
15731         .num_items = 2,
15732         .items = {
15733                 { "Mic", 0x1 },
15734                 { "Line", 0x2 },
15735         },
15736 };
15737
15738 static struct hda_input_mux alc663_capture_source = {
15739         .num_items = 3,
15740         .items = {
15741                 { "Mic", 0x0 },
15742                 { "Front Mic", 0x1 },
15743                 { "Line", 0x2 },
15744         },
15745 };
15746
15747 #if 0 /* set to 1 for testing other input sources below */
15748 static struct hda_input_mux alc272_nc10_capture_source = {
15749         .num_items = 16,
15750         .items = {
15751                 { "Autoselect Mic", 0x0 },
15752                 { "Internal Mic", 0x1 },
15753                 { "In-0x02", 0x2 },
15754                 { "In-0x03", 0x3 },
15755                 { "In-0x04", 0x4 },
15756                 { "In-0x05", 0x5 },
15757                 { "In-0x06", 0x6 },
15758                 { "In-0x07", 0x7 },
15759                 { "In-0x08", 0x8 },
15760                 { "In-0x09", 0x9 },
15761                 { "In-0x0a", 0x0a },
15762                 { "In-0x0b", 0x0b },
15763                 { "In-0x0c", 0x0c },
15764                 { "In-0x0d", 0x0d },
15765                 { "In-0x0e", 0x0e },
15766                 { "In-0x0f", 0x0f },
15767         },
15768 };
15769 #endif
15770
15771 /*
15772  * 2ch mode
15773  */
15774 static struct hda_channel_mode alc662_3ST_2ch_modes[1] = {
15775         { 2, NULL }
15776 };
15777
15778 /*
15779  * 2ch mode
15780  */
15781 static struct hda_verb alc662_3ST_ch2_init[] = {
15782         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
15783         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
15784         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
15785         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
15786         { } /* end */
15787 };
15788
15789 /*
15790  * 6ch mode
15791  */
15792 static struct hda_verb alc662_3ST_ch6_init[] = {
15793         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15794         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
15795         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
15796         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15797         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
15798         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
15799         { } /* end */
15800 };
15801
15802 static struct hda_channel_mode alc662_3ST_6ch_modes[2] = {
15803         { 2, alc662_3ST_ch2_init },
15804         { 6, alc662_3ST_ch6_init },
15805 };
15806
15807 /*
15808  * 2ch mode
15809  */
15810 static struct hda_verb alc662_sixstack_ch6_init[] = {
15811         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
15812         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
15813         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15814         { } /* end */
15815 };
15816
15817 /*
15818  * 6ch mode
15819  */
15820 static struct hda_verb alc662_sixstack_ch8_init[] = {
15821         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15822         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15823         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15824         { } /* end */
15825 };
15826
15827 static struct hda_channel_mode alc662_5stack_modes[2] = {
15828         { 2, alc662_sixstack_ch6_init },
15829         { 6, alc662_sixstack_ch8_init },
15830 };
15831
15832 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
15833  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
15834  */
15835
15836 static struct snd_kcontrol_new alc662_base_mixer[] = {
15837         /* output mixer control */
15838         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
15839         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
15840         HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
15841         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
15842         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15843         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15844         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
15845         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
15846         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15847
15848         /*Input mixer control */
15849         HDA_CODEC_VOLUME("CD Playback Volume", 0xb, 0x4, HDA_INPUT),
15850         HDA_CODEC_MUTE("CD Playback Switch", 0xb, 0x4, HDA_INPUT),
15851         HDA_CODEC_VOLUME("Line Playback Volume", 0xb, 0x02, HDA_INPUT),
15852         HDA_CODEC_MUTE("Line Playback Switch", 0xb, 0x02, HDA_INPUT),
15853         HDA_CODEC_VOLUME("Mic Playback Volume", 0xb, 0x0, HDA_INPUT),
15854         HDA_CODEC_MUTE("Mic Playback Switch", 0xb, 0x0, HDA_INPUT),
15855         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0xb, 0x01, HDA_INPUT),
15856         HDA_CODEC_MUTE("Front Mic Playback Switch", 0xb, 0x01, HDA_INPUT),
15857         { } /* end */
15858 };
15859
15860 static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
15861         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15862         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
15863         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15864         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
15865         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, 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         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15871         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15872         { } /* end */
15873 };
15874
15875 static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
15876         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15877         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
15878         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15879         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
15880         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15881         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15882         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
15883         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
15884         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15885         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
15886         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
15887         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15888         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15889         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15890         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15891         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15892         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15893         { } /* end */
15894 };
15895
15896 static struct snd_kcontrol_new alc662_lenovo_101e_mixer[] = {
15897         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15898         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
15899         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15900         HDA_BIND_MUTE("Speaker Playback Switch", 0x03, 2, HDA_INPUT),
15901         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15902         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15903         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15904         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15905         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15906         { } /* end */
15907 };
15908
15909 static struct snd_kcontrol_new alc662_eeepc_p701_mixer[] = {
15910         HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15911         ALC262_HIPPO_MASTER_SWITCH,
15912
15913         HDA_CODEC_VOLUME("e-Mic Boost", 0x18, 0, HDA_INPUT),
15914         HDA_CODEC_VOLUME("e-Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15915         HDA_CODEC_MUTE("e-Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15916
15917         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
15918         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15919         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15920         { } /* end */
15921 };
15922
15923 static struct snd_kcontrol_new alc662_eeepc_ep20_mixer[] = {
15924         ALC262_HIPPO_MASTER_SWITCH,
15925         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15926         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15927         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15928         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15929         HDA_BIND_MUTE("MuteCtrl Playback Switch", 0x0c, 2, HDA_INPUT),
15930         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15931         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15932         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15933         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15934         { } /* end */
15935 };
15936
15937 static struct hda_bind_ctls alc663_asus_bind_master_vol = {
15938         .ops = &snd_hda_bind_vol,
15939         .values = {
15940                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
15941                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
15942                 0
15943         },
15944 };
15945
15946 static struct hda_bind_ctls alc663_asus_one_bind_switch = {
15947         .ops = &snd_hda_bind_sw,
15948         .values = {
15949                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15950                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
15951                 0
15952         },
15953 };
15954
15955 static struct snd_kcontrol_new alc663_m51va_mixer[] = {
15956         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15957         HDA_BIND_SW("Master Playback Switch", &alc663_asus_one_bind_switch),
15958         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15959         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15960         { } /* end */
15961 };
15962
15963 static struct hda_bind_ctls alc663_asus_tree_bind_switch = {
15964         .ops = &snd_hda_bind_sw,
15965         .values = {
15966                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15967                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
15968                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
15969                 0
15970         },
15971 };
15972
15973 static struct snd_kcontrol_new alc663_two_hp_m1_mixer[] = {
15974         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15975         HDA_BIND_SW("Master Playback Switch", &alc663_asus_tree_bind_switch),
15976         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15977         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15978         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15979         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15980
15981         { } /* end */
15982 };
15983
15984 static struct hda_bind_ctls alc663_asus_four_bind_switch = {
15985         .ops = &snd_hda_bind_sw,
15986         .values = {
15987                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15988                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
15989                 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
15990                 0
15991         },
15992 };
15993
15994 static struct snd_kcontrol_new alc663_two_hp_m2_mixer[] = {
15995         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15996         HDA_BIND_SW("Master Playback Switch", &alc663_asus_four_bind_switch),
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("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16000         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16001         { } /* end */
16002 };
16003
16004 static struct snd_kcontrol_new alc662_1bjd_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", 0x1b, 0x0, HDA_OUTPUT),
16008         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16009         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16010         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16011         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16012         { } /* end */
16013 };
16014
16015 static struct hda_bind_ctls alc663_asus_two_bind_master_vol = {
16016         .ops = &snd_hda_bind_vol,
16017         .values = {
16018                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
16019                 HDA_COMPOSE_AMP_VAL(0x04, 3, 0, HDA_OUTPUT),
16020                 0
16021         },
16022 };
16023
16024 static struct hda_bind_ctls alc663_asus_two_bind_switch = {
16025         .ops = &snd_hda_bind_sw,
16026         .values = {
16027                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
16028                 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT),
16029                 0
16030         },
16031 };
16032
16033 static struct snd_kcontrol_new alc663_asus_21jd_clfe_mixer[] = {
16034         HDA_BIND_VOL("Master Playback Volume",
16035                                 &alc663_asus_two_bind_master_vol),
16036         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
16037         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
16038         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
16039         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16040         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16041         { } /* end */
16042 };
16043
16044 static struct snd_kcontrol_new alc663_asus_15jd_clfe_mixer[] = {
16045         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
16046         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
16047         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
16048         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
16049         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16050         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16051         { } /* end */
16052 };
16053
16054 static struct snd_kcontrol_new alc663_g71v_mixer[] = {
16055         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16056         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
16057         HDA_CODEC_VOLUME("Front Playback Volume", 0x03, 0x0, HDA_OUTPUT),
16058         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
16059         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
16060
16061         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16062         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16063         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16064         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16065         { } /* end */
16066 };
16067
16068 static struct snd_kcontrol_new alc663_g50v_mixer[] = {
16069         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16070         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
16071         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
16072
16073         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16074         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16075         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16076         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16077         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
16078         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
16079         { } /* end */
16080 };
16081
16082 static struct snd_kcontrol_new alc662_chmode_mixer[] = {
16083         {
16084                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
16085                 .name = "Channel Mode",
16086                 .info = alc_ch_mode_info,
16087                 .get = alc_ch_mode_get,
16088                 .put = alc_ch_mode_put,
16089         },
16090         { } /* end */
16091 };
16092
16093 static struct hda_verb alc662_init_verbs[] = {
16094         /* ADC: mute amp left and right */
16095         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16096         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
16097         /* Front mixer: unmute input/output amp left and right (volume = 0) */
16098
16099         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16100         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
16101         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
16102         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
16103         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
16104
16105         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16106         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16107         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16108         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16109         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16110         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16111
16112         /* Front Pin: output 0 (0x0c) */
16113         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16114         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16115
16116         /* Rear Pin: output 1 (0x0d) */
16117         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16118         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16119
16120         /* CLFE Pin: output 2 (0x0e) */
16121         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16122         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16123
16124         /* Mic (rear) pin: input vref at 80% */
16125         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
16126         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16127         /* Front Mic pin: input vref at 80% */
16128         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
16129         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16130         /* Line In pin: input */
16131         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16132         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16133         /* Line-2 In: Headphone output (output 0 - 0x0c) */
16134         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16135         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16136         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
16137         /* CD pin widget for input */
16138         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16139
16140         /* FIXME: use matrix-type input source selection */
16141         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
16142         /* Input mixer */
16143         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16144         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16145
16146         /* always trun on EAPD */
16147         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
16148         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
16149
16150         { }
16151 };
16152
16153 static struct hda_verb alc662_sue_init_verbs[] = {
16154         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
16155         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
16156         {}
16157 };
16158
16159 static struct hda_verb alc662_eeepc_sue_init_verbs[] = {
16160         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16161         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16162         {}
16163 };
16164
16165 /* Set Unsolicited Event*/
16166 static struct hda_verb alc662_eeepc_ep20_sue_init_verbs[] = {
16167         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16168         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16169         {}
16170 };
16171
16172 /*
16173  * generic initialization of ADC, input mixers and output mixers
16174  */
16175 static struct hda_verb alc662_auto_init_verbs[] = {
16176         /*
16177          * Unmute ADC and set the default input to mic-in
16178          */
16179         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
16180         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16181
16182         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
16183          * mixer widget
16184          * Note: PASD motherboards uses the Line In 2 as the input for front
16185          * panel mic (mic 2)
16186          */
16187         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
16188         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16189         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
16190         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
16191         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
16192         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
16193
16194         /*
16195          * Set up output mixers (0x0c - 0x0f)
16196          */
16197         /* set vol=0 to output mixers */
16198         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
16199         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
16200         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
16201
16202         /* set up input amps for analog loopback */
16203         /* Amp Indices: DAC = 0, mixer = 1 */
16204         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16205         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16206         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16207         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16208         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16209         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16210
16211
16212         /* FIXME: use matrix-type input source selection */
16213         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
16214         /* Input mixer */
16215         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16216         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16217         { }
16218 };
16219
16220 /* additional verbs for ALC663 */
16221 static struct hda_verb alc663_auto_init_verbs[] = {
16222         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16223         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16224         { }
16225 };
16226
16227 static struct hda_verb alc663_m51va_init_verbs[] = {
16228         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16229         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16230         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16231         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16232         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16233         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16234         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
16235         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16236         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16237         {}
16238 };
16239
16240 static struct hda_verb alc663_21jd_amic_init_verbs[] = {
16241         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16242         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16243         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16244         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16245         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16246         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16247         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16248         {}
16249 };
16250
16251 static struct hda_verb alc662_1bjd_amic_init_verbs[] = {
16252         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16253         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16254         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16255         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
16256         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16257         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16258         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16259         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16260         {}
16261 };
16262
16263 static struct hda_verb alc663_15jd_amic_init_verbs[] = {
16264         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16265         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16266         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16267         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16268         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16269         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16270         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16271         {}
16272 };
16273
16274 static struct hda_verb alc663_two_hp_amic_m1_init_verbs[] = {
16275         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16276         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16277         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16278         {0x21, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
16279         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16280         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16281         {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
16282         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16283         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16284         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16285         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16286         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16287         {}
16288 };
16289
16290 static struct hda_verb alc663_two_hp_amic_m2_init_verbs[] = {
16291         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16292         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16293         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16294         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16295         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16296         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16297         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16298         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16299         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16300         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16301         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16302         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16303         {}
16304 };
16305
16306 static struct hda_verb alc663_g71v_init_verbs[] = {
16307         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16308         /* {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
16309         /* {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, */ /* Headphone */
16310
16311         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16312         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16313         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
16314
16315         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
16316         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_MIC_EVENT},
16317         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
16318         {}
16319 };
16320
16321 static struct hda_verb alc663_g50v_init_verbs[] = {
16322         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16323         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16324         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
16325
16326         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16327         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16328         {}
16329 };
16330
16331 static struct hda_verb alc662_ecs_init_verbs[] = {
16332         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0x701f},
16333         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16334         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16335         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16336         {}
16337 };
16338
16339 static struct hda_verb alc272_dell_zm1_init_verbs[] = {
16340         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16341         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16342         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16343         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16344         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16345         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16346         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16347         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16348         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
16349         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16350         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16351         {}
16352 };
16353
16354 static struct hda_verb alc272_dell_init_verbs[] = {
16355         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16356         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16357         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16358         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16359         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16360         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16361         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16362         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16363         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
16364         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16365         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16366         {}
16367 };
16368
16369 static struct snd_kcontrol_new alc662_auto_capture_mixer[] = {
16370         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
16371         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
16372         { } /* end */
16373 };
16374
16375 static struct snd_kcontrol_new alc272_auto_capture_mixer[] = {
16376         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
16377         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
16378         { } /* end */
16379 };
16380
16381 static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
16382 {
16383         unsigned int present;
16384         unsigned char bits;
16385
16386         present = snd_hda_codec_read(codec, 0x14, 0,
16387                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
16388         bits = present ? HDA_AMP_MUTE : 0;
16389         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
16390                                  HDA_AMP_MUTE, bits);
16391 }
16392
16393 static void alc662_lenovo_101e_all_automute(struct hda_codec *codec)
16394 {
16395         unsigned int present;
16396         unsigned char bits;
16397
16398         present = snd_hda_codec_read(codec, 0x1b, 0,
16399                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
16400         bits = present ? HDA_AMP_MUTE : 0;
16401         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
16402                                  HDA_AMP_MUTE, bits);
16403         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
16404                                  HDA_AMP_MUTE, bits);
16405 }
16406
16407 static void alc662_lenovo_101e_unsol_event(struct hda_codec *codec,
16408                                            unsigned int res)
16409 {
16410         if ((res >> 26) == ALC880_HP_EVENT)
16411                 alc662_lenovo_101e_all_automute(codec);
16412         if ((res >> 26) == ALC880_FRONT_EVENT)
16413                 alc662_lenovo_101e_ispeaker_automute(codec);
16414 }
16415
16416 /* unsolicited event for HP jack sensing */
16417 static void alc662_eeepc_unsol_event(struct hda_codec *codec,
16418                                      unsigned int res)
16419 {
16420         if ((res >> 26) == ALC880_MIC_EVENT)
16421                 alc_mic_automute(codec);
16422         else
16423                 alc262_hippo_unsol_event(codec, res);
16424 }
16425
16426 static void alc662_eeepc_setup(struct hda_codec *codec)
16427 {
16428         struct alc_spec *spec = codec->spec;
16429
16430         alc262_hippo1_setup(codec);
16431         spec->ext_mic.pin = 0x18;
16432         spec->ext_mic.mux_idx = 0;
16433         spec->int_mic.pin = 0x19;
16434         spec->int_mic.mux_idx = 1;
16435         spec->auto_mic = 1;
16436 }
16437
16438 static void alc662_eeepc_inithook(struct hda_codec *codec)
16439 {
16440         alc262_hippo_automute(codec);
16441         alc_mic_automute(codec);
16442 }
16443
16444 static void alc662_eeepc_ep20_setup(struct hda_codec *codec)
16445 {
16446         struct alc_spec *spec = codec->spec;
16447
16448         spec->autocfg.hp_pins[0] = 0x14;
16449         spec->autocfg.speaker_pins[0] = 0x1b;
16450 }
16451
16452 #define alc662_eeepc_ep20_inithook      alc262_hippo_master_update
16453
16454 static void alc663_m51va_speaker_automute(struct hda_codec *codec)
16455 {
16456         unsigned int present;
16457         unsigned char bits;
16458
16459         present = snd_hda_codec_read(codec, 0x21, 0,
16460                         AC_VERB_GET_PIN_SENSE, 0)
16461                         & AC_PINSENSE_PRESENCE;
16462         bits = present ? HDA_AMP_MUTE : 0;
16463         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16464                                 AMP_IN_MUTE(0), bits);
16465         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16466                                 AMP_IN_MUTE(0), bits);
16467 }
16468
16469 static void alc663_21jd_two_speaker_automute(struct hda_codec *codec)
16470 {
16471         unsigned int present;
16472         unsigned char bits;
16473
16474         present = snd_hda_codec_read(codec, 0x21, 0,
16475                         AC_VERB_GET_PIN_SENSE, 0)
16476                         & AC_PINSENSE_PRESENCE;
16477         bits = present ? HDA_AMP_MUTE : 0;
16478         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16479                                 AMP_IN_MUTE(0), bits);
16480         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16481                                 AMP_IN_MUTE(0), bits);
16482         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
16483                                 AMP_IN_MUTE(0), bits);
16484         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
16485                                 AMP_IN_MUTE(0), bits);
16486 }
16487
16488 static void alc663_15jd_two_speaker_automute(struct hda_codec *codec)
16489 {
16490         unsigned int present;
16491         unsigned char bits;
16492
16493         present = snd_hda_codec_read(codec, 0x15, 0,
16494                         AC_VERB_GET_PIN_SENSE, 0)
16495                         & AC_PINSENSE_PRESENCE;
16496         bits = present ? HDA_AMP_MUTE : 0;
16497         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16498                                 AMP_IN_MUTE(0), bits);
16499         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16500                                 AMP_IN_MUTE(0), bits);
16501         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
16502                                 AMP_IN_MUTE(0), bits);
16503         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
16504                                 AMP_IN_MUTE(0), bits);
16505 }
16506
16507 static void alc662_f5z_speaker_automute(struct hda_codec *codec)
16508 {
16509         unsigned int present;
16510         unsigned char bits;
16511
16512         present = snd_hda_codec_read(codec, 0x1b, 0,
16513                         AC_VERB_GET_PIN_SENSE, 0)
16514                         & AC_PINSENSE_PRESENCE;
16515         bits = present ? 0 : PIN_OUT;
16516         snd_hda_codec_write(codec, 0x14, 0,
16517                          AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
16518 }
16519
16520 static void alc663_two_hp_m1_speaker_automute(struct hda_codec *codec)
16521 {
16522         unsigned int present1, present2;
16523
16524         present1 = snd_hda_codec_read(codec, 0x21, 0,
16525                         AC_VERB_GET_PIN_SENSE, 0)
16526                         & AC_PINSENSE_PRESENCE;
16527         present2 = snd_hda_codec_read(codec, 0x15, 0,
16528                         AC_VERB_GET_PIN_SENSE, 0)
16529                         & AC_PINSENSE_PRESENCE;
16530
16531         if (present1 || present2) {
16532                 snd_hda_codec_write_cache(codec, 0x14, 0,
16533                         AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
16534         } else {
16535                 snd_hda_codec_write_cache(codec, 0x14, 0,
16536                         AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
16537         }
16538 }
16539
16540 static void alc663_two_hp_m2_speaker_automute(struct hda_codec *codec)
16541 {
16542         unsigned int present1, present2;
16543
16544         present1 = snd_hda_codec_read(codec, 0x1b, 0,
16545                                 AC_VERB_GET_PIN_SENSE, 0)
16546                                 & AC_PINSENSE_PRESENCE;
16547         present2 = snd_hda_codec_read(codec, 0x15, 0,
16548                                 AC_VERB_GET_PIN_SENSE, 0)
16549                                 & AC_PINSENSE_PRESENCE;
16550
16551         if (present1 || present2) {
16552                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16553                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
16554                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16555                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
16556         } else {
16557                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16558                                 AMP_IN_MUTE(0), 0);
16559                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16560                                 AMP_IN_MUTE(0), 0);
16561         }
16562 }
16563
16564 static void alc663_m51va_unsol_event(struct hda_codec *codec,
16565                                            unsigned int res)
16566 {
16567         switch (res >> 26) {
16568         case ALC880_HP_EVENT:
16569                 alc663_m51va_speaker_automute(codec);
16570                 break;
16571         case ALC880_MIC_EVENT:
16572                 alc_mic_automute(codec);
16573                 break;
16574         }
16575 }
16576
16577 static void alc663_m51va_setup(struct hda_codec *codec)
16578 {
16579         struct alc_spec *spec = codec->spec;
16580         spec->ext_mic.pin = 0x18;
16581         spec->ext_mic.mux_idx = 0;
16582         spec->int_mic.pin = 0x12;
16583         spec->int_mic.mux_idx = 1;
16584         spec->auto_mic = 1;
16585 }
16586
16587 static void alc663_m51va_inithook(struct hda_codec *codec)
16588 {
16589         alc663_m51va_speaker_automute(codec);
16590         alc_mic_automute(codec);
16591 }
16592
16593 /* ***************** Mode1 ******************************/
16594 #define alc663_mode1_unsol_event        alc663_m51va_unsol_event
16595 #define alc663_mode1_setup              alc663_m51va_setup
16596 #define alc663_mode1_inithook           alc663_m51va_inithook
16597
16598 /* ***************** Mode2 ******************************/
16599 static void alc662_mode2_unsol_event(struct hda_codec *codec,
16600                                            unsigned int res)
16601 {
16602         switch (res >> 26) {
16603         case ALC880_HP_EVENT:
16604                 alc662_f5z_speaker_automute(codec);
16605                 break;
16606         case ALC880_MIC_EVENT:
16607                 alc_mic_automute(codec);
16608                 break;
16609         }
16610 }
16611
16612 #define alc662_mode2_setup      alc663_m51va_setup
16613
16614 static void alc662_mode2_inithook(struct hda_codec *codec)
16615 {
16616         alc662_f5z_speaker_automute(codec);
16617         alc_mic_automute(codec);
16618 }
16619 /* ***************** Mode3 ******************************/
16620 static void alc663_mode3_unsol_event(struct hda_codec *codec,
16621                                            unsigned int res)
16622 {
16623         switch (res >> 26) {
16624         case ALC880_HP_EVENT:
16625                 alc663_two_hp_m1_speaker_automute(codec);
16626                 break;
16627         case ALC880_MIC_EVENT:
16628                 alc_mic_automute(codec);
16629                 break;
16630         }
16631 }
16632
16633 #define alc663_mode3_setup      alc663_m51va_setup
16634
16635 static void alc663_mode3_inithook(struct hda_codec *codec)
16636 {
16637         alc663_two_hp_m1_speaker_automute(codec);
16638         alc_mic_automute(codec);
16639 }
16640 /* ***************** Mode4 ******************************/
16641 static void alc663_mode4_unsol_event(struct hda_codec *codec,
16642                                            unsigned int res)
16643 {
16644         switch (res >> 26) {
16645         case ALC880_HP_EVENT:
16646                 alc663_21jd_two_speaker_automute(codec);
16647                 break;
16648         case ALC880_MIC_EVENT:
16649                 alc_mic_automute(codec);
16650                 break;
16651         }
16652 }
16653
16654 #define alc663_mode4_setup      alc663_m51va_setup
16655
16656 static void alc663_mode4_inithook(struct hda_codec *codec)
16657 {
16658         alc663_21jd_two_speaker_automute(codec);
16659         alc_mic_automute(codec);
16660 }
16661 /* ***************** Mode5 ******************************/
16662 static void alc663_mode5_unsol_event(struct hda_codec *codec,
16663                                            unsigned int res)
16664 {
16665         switch (res >> 26) {
16666         case ALC880_HP_EVENT:
16667                 alc663_15jd_two_speaker_automute(codec);
16668                 break;
16669         case ALC880_MIC_EVENT:
16670                 alc_mic_automute(codec);
16671                 break;
16672         }
16673 }
16674
16675 #define alc663_mode5_setup      alc663_m51va_setup
16676
16677 static void alc663_mode5_inithook(struct hda_codec *codec)
16678 {
16679         alc663_15jd_two_speaker_automute(codec);
16680         alc_mic_automute(codec);
16681 }
16682 /* ***************** Mode6 ******************************/
16683 static void alc663_mode6_unsol_event(struct hda_codec *codec,
16684                                            unsigned int res)
16685 {
16686         switch (res >> 26) {
16687         case ALC880_HP_EVENT:
16688                 alc663_two_hp_m2_speaker_automute(codec);
16689                 break;
16690         case ALC880_MIC_EVENT:
16691                 alc_mic_automute(codec);
16692                 break;
16693         }
16694 }
16695
16696 #define alc663_mode6_setup      alc663_m51va_setup
16697
16698 static void alc663_mode6_inithook(struct hda_codec *codec)
16699 {
16700         alc663_two_hp_m2_speaker_automute(codec);
16701         alc_mic_automute(codec);
16702 }
16703
16704 static void alc663_g71v_hp_automute(struct hda_codec *codec)
16705 {
16706         unsigned int present;
16707         unsigned char bits;
16708
16709         present = snd_hda_codec_read(codec, 0x21, 0,
16710                                      AC_VERB_GET_PIN_SENSE, 0)
16711                 & AC_PINSENSE_PRESENCE;
16712         bits = present ? HDA_AMP_MUTE : 0;
16713         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
16714                                  HDA_AMP_MUTE, bits);
16715         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
16716                                  HDA_AMP_MUTE, bits);
16717 }
16718
16719 static void alc663_g71v_front_automute(struct hda_codec *codec)
16720 {
16721         unsigned int present;
16722         unsigned char bits;
16723
16724         present = snd_hda_codec_read(codec, 0x15, 0,
16725                                      AC_VERB_GET_PIN_SENSE, 0)
16726                 & AC_PINSENSE_PRESENCE;
16727         bits = present ? HDA_AMP_MUTE : 0;
16728         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
16729                                  HDA_AMP_MUTE, bits);
16730 }
16731
16732 static void alc663_g71v_unsol_event(struct hda_codec *codec,
16733                                            unsigned int res)
16734 {
16735         switch (res >> 26) {
16736         case ALC880_HP_EVENT:
16737                 alc663_g71v_hp_automute(codec);
16738                 break;
16739         case ALC880_FRONT_EVENT:
16740                 alc663_g71v_front_automute(codec);
16741                 break;
16742         case ALC880_MIC_EVENT:
16743                 alc_mic_automute(codec);
16744                 break;
16745         }
16746 }
16747
16748 #define alc663_g71v_setup       alc663_m51va_setup
16749
16750 static void alc663_g71v_inithook(struct hda_codec *codec)
16751 {
16752         alc663_g71v_front_automute(codec);
16753         alc663_g71v_hp_automute(codec);
16754         alc_mic_automute(codec);
16755 }
16756
16757 static void alc663_g50v_unsol_event(struct hda_codec *codec,
16758                                            unsigned int res)
16759 {
16760         switch (res >> 26) {
16761         case ALC880_HP_EVENT:
16762                 alc663_m51va_speaker_automute(codec);
16763                 break;
16764         case ALC880_MIC_EVENT:
16765                 alc_mic_automute(codec);
16766                 break;
16767         }
16768 }
16769
16770 #define alc663_g50v_setup       alc663_m51va_setup
16771
16772 static void alc663_g50v_inithook(struct hda_codec *codec)
16773 {
16774         alc663_m51va_speaker_automute(codec);
16775         alc_mic_automute(codec);
16776 }
16777
16778 static struct snd_kcontrol_new alc662_ecs_mixer[] = {
16779         HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16780         ALC262_HIPPO_MASTER_SWITCH,
16781
16782         HDA_CODEC_VOLUME("e-Mic/LineIn Boost", 0x18, 0, HDA_INPUT),
16783         HDA_CODEC_VOLUME("e-Mic/LineIn Playback Volume", 0x0b, 0x0, HDA_INPUT),
16784         HDA_CODEC_MUTE("e-Mic/LineIn Playback Switch", 0x0b, 0x0, HDA_INPUT),
16785
16786         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
16787         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16788         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16789         { } /* end */
16790 };
16791
16792 static struct snd_kcontrol_new alc272_nc10_mixer[] = {
16793         /* Master Playback automatically created from Speaker and Headphone */
16794         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16795         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
16796         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
16797         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
16798
16799         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16800         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16801         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
16802
16803         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16804         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16805         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
16806         { } /* end */
16807 };
16808
16809 #ifdef CONFIG_SND_HDA_POWER_SAVE
16810 #define alc662_loopbacks        alc880_loopbacks
16811 #endif
16812
16813
16814 /* pcm configuration: identical with ALC880 */
16815 #define alc662_pcm_analog_playback      alc880_pcm_analog_playback
16816 #define alc662_pcm_analog_capture       alc880_pcm_analog_capture
16817 #define alc662_pcm_digital_playback     alc880_pcm_digital_playback
16818 #define alc662_pcm_digital_capture      alc880_pcm_digital_capture
16819
16820 /*
16821  * configuration and preset
16822  */
16823 static const char *alc662_models[ALC662_MODEL_LAST] = {
16824         [ALC662_3ST_2ch_DIG]    = "3stack-dig",
16825         [ALC662_3ST_6ch_DIG]    = "3stack-6ch-dig",
16826         [ALC662_3ST_6ch]        = "3stack-6ch",
16827         [ALC662_5ST_DIG]        = "6stack-dig",
16828         [ALC662_LENOVO_101E]    = "lenovo-101e",
16829         [ALC662_ASUS_EEEPC_P701] = "eeepc-p701",
16830         [ALC662_ASUS_EEEPC_EP20] = "eeepc-ep20",
16831         [ALC662_ECS] = "ecs",
16832         [ALC663_ASUS_M51VA] = "m51va",
16833         [ALC663_ASUS_G71V] = "g71v",
16834         [ALC663_ASUS_H13] = "h13",
16835         [ALC663_ASUS_G50V] = "g50v",
16836         [ALC663_ASUS_MODE1] = "asus-mode1",
16837         [ALC662_ASUS_MODE2] = "asus-mode2",
16838         [ALC663_ASUS_MODE3] = "asus-mode3",
16839         [ALC663_ASUS_MODE4] = "asus-mode4",
16840         [ALC663_ASUS_MODE5] = "asus-mode5",
16841         [ALC663_ASUS_MODE6] = "asus-mode6",
16842         [ALC272_DELL]           = "dell",
16843         [ALC272_DELL_ZM1]       = "dell-zm1",
16844         [ALC272_SAMSUNG_NC10]   = "samsung-nc10",
16845         [ALC662_AUTO]           = "auto",
16846 };
16847
16848 static struct snd_pci_quirk alc662_cfg_tbl[] = {
16849         SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_ECS),
16850         SND_PCI_QUIRK(0x1028, 0x02d6, "DELL", ALC272_DELL),
16851         SND_PCI_QUIRK(0x1028, 0x02f4, "DELL ZM1", ALC272_DELL_ZM1),
16852         SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC663_ASUS_MODE1),
16853         SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC663_ASUS_MODE3),
16854         SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC663_ASUS_MODE3),
16855         SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC663_ASUS_MODE1),
16856         SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_ASUS_MODE2),
16857         SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC663_ASUS_MODE1),
16858         SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_ASUS_MODE2),
16859         SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_ASUS_MODE2),
16860         SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_ASUS_MODE2),
16861         SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC663_ASUS_MODE6),
16862         SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC663_ASUS_MODE6),
16863         SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_ASUS_MODE2),
16864         SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC663_ASUS_MODE3),
16865         SND_PCI_QUIRK(0x1043, 0x17c3, "ASUS UX20", ALC663_ASUS_M51VA),
16866         SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_ASUS_MODE2),
16867         SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_ASUS_MODE2),
16868         SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC663_ASUS_MODE5),
16869         SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC663_ASUS_MODE6),
16870         SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_ASUS_MODE2),
16871         SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC663_ASUS_MODE1),
16872         SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_ASUS_MODE2),
16873         SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_ASUS_MODE2),
16874         SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M51VA", ALC663_ASUS_M51VA),
16875         /*SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M50Vr", ALC663_ASUS_MODE1),*/
16876         SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC663_ASUS_MODE3),
16877         SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC663_ASUS_MODE3),
16878         SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC663_ASUS_MODE1),
16879         SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC663_ASUS_MODE1),
16880         SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC663_ASUS_MODE1),
16881         SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC663_ASUS_MODE1),
16882         SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_ASUS_MODE2),
16883         SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_ASUS_MODE2),
16884         SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC663_ASUS_MODE1),
16885         SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC663_ASUS_MODE1),
16886         SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC663_ASUS_MODE3),
16887         SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC663_ASUS_MODE1),
16888         SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC663_ASUS_MODE1),
16889         SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS G50V", ALC663_ASUS_G50V),
16890         /*SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS NB", ALC663_ASUS_MODE1),*/
16891         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC663_ASUS_MODE1),
16892         SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_ASUS_MODE2),
16893         SND_PCI_QUIRK(0x1043, 0x19d3, "ASUS NB", ALC663_ASUS_M51VA),
16894         SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC663_ASUS_MODE1),
16895         SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC663_ASUS_MODE4),
16896         SND_PCI_QUIRK(0x1043, 0x8290, "ASUS P5GC-MX", ALC662_3ST_6ch_DIG),
16897         SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
16898         SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20),
16899         SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_ECS),
16900         SND_PCI_QUIRK(0x105b, 0x0d47, "Foxconn 45CMX/45GMX/45CMX-K",
16901                       ALC662_3ST_6ch_DIG),
16902         SND_PCI_QUIRK(0x1179, 0xff6e, "Toshiba NB200", ALC663_ASUS_MODE4),
16903         SND_PCI_QUIRK(0x144d, 0xca00, "Samsung NC10", ALC272_SAMSUNG_NC10),
16904         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte 945GCM-S2L",
16905                       ALC662_3ST_6ch_DIG),
16906         SND_PCI_QUIRK(0x1565, 0x820f, "Biostar TA780G M2+", ALC662_3ST_6ch_DIG),
16907         SND_PCI_QUIRK(0x1631, 0xc10c, "PB RS65", ALC663_ASUS_M51VA),
16908         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
16909         SND_PCI_QUIRK(0x1849, 0x3662, "ASROCK K10N78FullHD-hSLI R3.0",
16910                                         ALC662_3ST_6ch_DIG),
16911         SND_PCI_QUIRK_MASK(0x1854, 0xf000, 0x2000, "ASUS H13-200x",
16912                            ALC663_ASUS_H13),
16913         {}
16914 };
16915
16916 static struct alc_config_preset alc662_presets[] = {
16917         [ALC662_3ST_2ch_DIG] = {
16918                 .mixers = { alc662_3ST_2ch_mixer },
16919                 .init_verbs = { alc662_init_verbs },
16920                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16921                 .dac_nids = alc662_dac_nids,
16922                 .dig_out_nid = ALC662_DIGOUT_NID,
16923                 .dig_in_nid = ALC662_DIGIN_NID,
16924                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16925                 .channel_mode = alc662_3ST_2ch_modes,
16926                 .input_mux = &alc662_capture_source,
16927         },
16928         [ALC662_3ST_6ch_DIG] = {
16929                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
16930                 .init_verbs = { alc662_init_verbs },
16931                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16932                 .dac_nids = alc662_dac_nids,
16933                 .dig_out_nid = ALC662_DIGOUT_NID,
16934                 .dig_in_nid = ALC662_DIGIN_NID,
16935                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16936                 .channel_mode = alc662_3ST_6ch_modes,
16937                 .need_dac_fix = 1,
16938                 .input_mux = &alc662_capture_source,
16939         },
16940         [ALC662_3ST_6ch] = {
16941                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
16942                 .init_verbs = { alc662_init_verbs },
16943                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16944                 .dac_nids = alc662_dac_nids,
16945                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16946                 .channel_mode = alc662_3ST_6ch_modes,
16947                 .need_dac_fix = 1,
16948                 .input_mux = &alc662_capture_source,
16949         },
16950         [ALC662_5ST_DIG] = {
16951                 .mixers = { alc662_base_mixer, alc662_chmode_mixer },
16952                 .init_verbs = { alc662_init_verbs },
16953                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16954                 .dac_nids = alc662_dac_nids,
16955                 .dig_out_nid = ALC662_DIGOUT_NID,
16956                 .dig_in_nid = ALC662_DIGIN_NID,
16957                 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
16958                 .channel_mode = alc662_5stack_modes,
16959                 .input_mux = &alc662_capture_source,
16960         },
16961         [ALC662_LENOVO_101E] = {
16962                 .mixers = { alc662_lenovo_101e_mixer },
16963                 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs },
16964                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16965                 .dac_nids = alc662_dac_nids,
16966                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16967                 .channel_mode = alc662_3ST_2ch_modes,
16968                 .input_mux = &alc662_lenovo_101e_capture_source,
16969                 .unsol_event = alc662_lenovo_101e_unsol_event,
16970                 .init_hook = alc662_lenovo_101e_all_automute,
16971         },
16972         [ALC662_ASUS_EEEPC_P701] = {
16973                 .mixers = { alc662_eeepc_p701_mixer },
16974                 .init_verbs = { alc662_init_verbs,
16975                                 alc662_eeepc_sue_init_verbs },
16976                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16977                 .dac_nids = alc662_dac_nids,
16978                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16979                 .channel_mode = alc662_3ST_2ch_modes,
16980                 .unsol_event = alc662_eeepc_unsol_event,
16981                 .setup = alc662_eeepc_setup,
16982                 .init_hook = alc662_eeepc_inithook,
16983         },
16984         [ALC662_ASUS_EEEPC_EP20] = {
16985                 .mixers = { alc662_eeepc_ep20_mixer,
16986                             alc662_chmode_mixer },
16987                 .init_verbs = { alc662_init_verbs,
16988                                 alc662_eeepc_ep20_sue_init_verbs },
16989                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16990                 .dac_nids = alc662_dac_nids,
16991                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16992                 .channel_mode = alc662_3ST_6ch_modes,
16993                 .input_mux = &alc662_lenovo_101e_capture_source,
16994                 .unsol_event = alc662_eeepc_unsol_event,
16995                 .setup = alc662_eeepc_ep20_setup,
16996                 .init_hook = alc662_eeepc_ep20_inithook,
16997         },
16998         [ALC662_ECS] = {
16999                 .mixers = { alc662_ecs_mixer },
17000                 .init_verbs = { alc662_init_verbs,
17001                                 alc662_ecs_init_verbs },
17002                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17003                 .dac_nids = alc662_dac_nids,
17004                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17005                 .channel_mode = alc662_3ST_2ch_modes,
17006                 .unsol_event = alc662_eeepc_unsol_event,
17007                 .setup = alc662_eeepc_setup,
17008                 .init_hook = alc662_eeepc_inithook,
17009         },
17010         [ALC663_ASUS_M51VA] = {
17011                 .mixers = { alc663_m51va_mixer },
17012                 .init_verbs = { alc662_init_verbs, alc663_m51va_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 = alc663_m51va_unsol_event,
17019                 .setup = alc663_m51va_setup,
17020                 .init_hook = alc663_m51va_inithook,
17021         },
17022         [ALC663_ASUS_G71V] = {
17023                 .mixers = { alc663_g71v_mixer },
17024                 .init_verbs = { alc662_init_verbs, alc663_g71v_init_verbs },
17025                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17026                 .dac_nids = alc662_dac_nids,
17027                 .dig_out_nid = ALC662_DIGOUT_NID,
17028                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17029                 .channel_mode = alc662_3ST_2ch_modes,
17030                 .unsol_event = alc663_g71v_unsol_event,
17031                 .setup = alc663_g71v_setup,
17032                 .init_hook = alc663_g71v_inithook,
17033         },
17034         [ALC663_ASUS_H13] = {
17035                 .mixers = { alc663_m51va_mixer },
17036                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
17037                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17038                 .dac_nids = alc662_dac_nids,
17039                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17040                 .channel_mode = alc662_3ST_2ch_modes,
17041                 .unsol_event = alc663_m51va_unsol_event,
17042                 .init_hook = alc663_m51va_inithook,
17043         },
17044         [ALC663_ASUS_G50V] = {
17045                 .mixers = { alc663_g50v_mixer },
17046                 .init_verbs = { alc662_init_verbs, alc663_g50v_init_verbs },
17047                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17048                 .dac_nids = alc662_dac_nids,
17049                 .dig_out_nid = ALC662_DIGOUT_NID,
17050                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
17051                 .channel_mode = alc662_3ST_6ch_modes,
17052                 .input_mux = &alc663_capture_source,
17053                 .unsol_event = alc663_g50v_unsol_event,
17054                 .setup = alc663_g50v_setup,
17055                 .init_hook = alc663_g50v_inithook,
17056         },
17057         [ALC663_ASUS_MODE1] = {
17058                 .mixers = { alc663_m51va_mixer },
17059                 .cap_mixer = alc662_auto_capture_mixer,
17060                 .init_verbs = { alc662_init_verbs,
17061                                 alc663_21jd_amic_init_verbs },
17062                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17063                 .hp_nid = 0x03,
17064                 .dac_nids = alc662_dac_nids,
17065                 .dig_out_nid = ALC662_DIGOUT_NID,
17066                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17067                 .channel_mode = alc662_3ST_2ch_modes,
17068                 .unsol_event = alc663_mode1_unsol_event,
17069                 .setup = alc663_mode1_setup,
17070                 .init_hook = alc663_mode1_inithook,
17071         },
17072         [ALC662_ASUS_MODE2] = {
17073                 .mixers = { alc662_1bjd_mixer },
17074                 .cap_mixer = alc662_auto_capture_mixer,
17075                 .init_verbs = { alc662_init_verbs,
17076                                 alc662_1bjd_amic_init_verbs },
17077                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17078                 .dac_nids = alc662_dac_nids,
17079                 .dig_out_nid = ALC662_DIGOUT_NID,
17080                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17081                 .channel_mode = alc662_3ST_2ch_modes,
17082                 .unsol_event = alc662_mode2_unsol_event,
17083                 .setup = alc662_mode2_setup,
17084                 .init_hook = alc662_mode2_inithook,
17085         },
17086         [ALC663_ASUS_MODE3] = {
17087                 .mixers = { alc663_two_hp_m1_mixer },
17088                 .cap_mixer = alc662_auto_capture_mixer,
17089                 .init_verbs = { alc662_init_verbs,
17090                                 alc663_two_hp_amic_m1_init_verbs },
17091                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17092                 .hp_nid = 0x03,
17093                 .dac_nids = alc662_dac_nids,
17094                 .dig_out_nid = ALC662_DIGOUT_NID,
17095                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17096                 .channel_mode = alc662_3ST_2ch_modes,
17097                 .unsol_event = alc663_mode3_unsol_event,
17098                 .setup = alc663_mode3_setup,
17099                 .init_hook = alc663_mode3_inithook,
17100         },
17101         [ALC663_ASUS_MODE4] = {
17102                 .mixers = { alc663_asus_21jd_clfe_mixer },
17103                 .cap_mixer = alc662_auto_capture_mixer,
17104                 .init_verbs = { alc662_init_verbs,
17105                                 alc663_21jd_amic_init_verbs},
17106                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17107                 .hp_nid = 0x03,
17108                 .dac_nids = alc662_dac_nids,
17109                 .dig_out_nid = ALC662_DIGOUT_NID,
17110                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17111                 .channel_mode = alc662_3ST_2ch_modes,
17112                 .unsol_event = alc663_mode4_unsol_event,
17113                 .setup = alc663_mode4_setup,
17114                 .init_hook = alc663_mode4_inithook,
17115         },
17116         [ALC663_ASUS_MODE5] = {
17117                 .mixers = { alc663_asus_15jd_clfe_mixer },
17118                 .cap_mixer = alc662_auto_capture_mixer,
17119                 .init_verbs = { alc662_init_verbs,
17120                                 alc663_15jd_amic_init_verbs },
17121                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17122                 .hp_nid = 0x03,
17123                 .dac_nids = alc662_dac_nids,
17124                 .dig_out_nid = ALC662_DIGOUT_NID,
17125                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17126                 .channel_mode = alc662_3ST_2ch_modes,
17127                 .unsol_event = alc663_mode5_unsol_event,
17128                 .setup = alc663_mode5_setup,
17129                 .init_hook = alc663_mode5_inithook,
17130         },
17131         [ALC663_ASUS_MODE6] = {
17132                 .mixers = { alc663_two_hp_m2_mixer },
17133                 .cap_mixer = alc662_auto_capture_mixer,
17134                 .init_verbs = { alc662_init_verbs,
17135                                 alc663_two_hp_amic_m2_init_verbs },
17136                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17137                 .hp_nid = 0x03,
17138                 .dac_nids = alc662_dac_nids,
17139                 .dig_out_nid = ALC662_DIGOUT_NID,
17140                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17141                 .channel_mode = alc662_3ST_2ch_modes,
17142                 .unsol_event = alc663_mode6_unsol_event,
17143                 .setup = alc663_mode6_setup,
17144                 .init_hook = alc663_mode6_inithook,
17145         },
17146         [ALC272_DELL] = {
17147                 .mixers = { alc663_m51va_mixer },
17148                 .cap_mixer = alc272_auto_capture_mixer,
17149                 .init_verbs = { alc662_init_verbs, alc272_dell_init_verbs },
17150                 .num_dacs = ARRAY_SIZE(alc272_dac_nids),
17151                 .dac_nids = alc662_dac_nids,
17152                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17153                 .adc_nids = alc272_adc_nids,
17154                 .num_adc_nids = ARRAY_SIZE(alc272_adc_nids),
17155                 .capsrc_nids = alc272_capsrc_nids,
17156                 .channel_mode = alc662_3ST_2ch_modes,
17157                 .unsol_event = alc663_m51va_unsol_event,
17158                 .setup = alc663_m51va_setup,
17159                 .init_hook = alc663_m51va_inithook,
17160         },
17161         [ALC272_DELL_ZM1] = {
17162                 .mixers = { alc663_m51va_mixer },
17163                 .cap_mixer = alc662_auto_capture_mixer,
17164                 .init_verbs = { alc662_init_verbs, alc272_dell_zm1_init_verbs },
17165                 .num_dacs = ARRAY_SIZE(alc272_dac_nids),
17166                 .dac_nids = alc662_dac_nids,
17167                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17168                 .adc_nids = alc662_adc_nids,
17169                 .num_adc_nids = 1,
17170                 .capsrc_nids = alc662_capsrc_nids,
17171                 .channel_mode = alc662_3ST_2ch_modes,
17172                 .unsol_event = alc663_m51va_unsol_event,
17173                 .setup = alc663_m51va_setup,
17174                 .init_hook = alc663_m51va_inithook,
17175         },
17176         [ALC272_SAMSUNG_NC10] = {
17177                 .mixers = { alc272_nc10_mixer },
17178                 .init_verbs = { alc662_init_verbs,
17179                                 alc663_21jd_amic_init_verbs },
17180                 .num_dacs = ARRAY_SIZE(alc272_dac_nids),
17181                 .dac_nids = alc272_dac_nids,
17182                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17183                 .channel_mode = alc662_3ST_2ch_modes,
17184                 /*.input_mux = &alc272_nc10_capture_source,*/
17185                 .unsol_event = alc663_mode4_unsol_event,
17186                 .setup = alc663_mode4_setup,
17187                 .init_hook = alc663_mode4_inithook,
17188         },
17189 };
17190
17191
17192 /*
17193  * BIOS auto configuration
17194  */
17195
17196 /* convert from MIX nid to DAC */
17197 static inline hda_nid_t alc662_mix_to_dac(hda_nid_t nid)
17198 {
17199         if (nid == 0x0f)
17200                 return 0x02;
17201         else if (nid >= 0x0c && nid <= 0x0e)
17202                 return nid - 0x0c + 0x02;
17203         else
17204                 return 0;
17205 }
17206
17207 /* get MIX nid connected to the given pin targeted to DAC */
17208 static hda_nid_t alc662_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
17209                                    hda_nid_t dac)
17210 {
17211         hda_nid_t mix[4];
17212         int i, num;
17213
17214         num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
17215         for (i = 0; i < num; i++) {
17216                 if (alc662_mix_to_dac(mix[i]) == dac)
17217                         return mix[i];
17218         }
17219         return 0;
17220 }
17221
17222 /* look for an empty DAC slot */
17223 static hda_nid_t alc662_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
17224 {
17225         struct alc_spec *spec = codec->spec;
17226         hda_nid_t srcs[5];
17227         int i, j, num;
17228
17229         num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
17230         if (num < 0)
17231                 return 0;
17232         for (i = 0; i < num; i++) {
17233                 hda_nid_t nid = alc662_mix_to_dac(srcs[i]);
17234                 if (!nid)
17235                         continue;
17236                 for (j = 0; j < spec->multiout.num_dacs; j++)
17237                         if (spec->multiout.dac_nids[j] == nid)
17238                                 break;
17239                 if (j >= spec->multiout.num_dacs)
17240                         return nid;
17241         }
17242         return 0;
17243 }
17244
17245 /* fill in the dac_nids table from the parsed pin configuration */
17246 static int alc662_auto_fill_dac_nids(struct hda_codec *codec,
17247                                      const struct auto_pin_cfg *cfg)
17248 {
17249         struct alc_spec *spec = codec->spec;
17250         int i;
17251         hda_nid_t dac;
17252
17253         spec->multiout.dac_nids = spec->private_dac_nids;
17254         for (i = 0; i < cfg->line_outs; i++) {
17255                 dac = alc662_look_for_dac(codec, cfg->line_out_pins[i]);
17256                 if (!dac)
17257                         continue;
17258                 spec->multiout.dac_nids[spec->multiout.num_dacs++] = dac;
17259         }
17260         return 0;
17261 }
17262
17263 static inline int alc662_add_vol_ctl(struct alc_spec *spec, const char *pfx,
17264                               hda_nid_t nid, unsigned int chs)
17265 {
17266         return add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
17267                            HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
17268 }
17269
17270 static inline int alc662_add_sw_ctl(struct alc_spec *spec, const char *pfx,
17271                              hda_nid_t nid, unsigned int chs)
17272 {
17273         return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
17274                            HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT));
17275 }
17276
17277 #define alc662_add_stereo_vol(spec, pfx, nid) \
17278         alc662_add_vol_ctl(spec, pfx, nid, 3)
17279 #define alc662_add_stereo_sw(spec, pfx, nid) \
17280         alc662_add_sw_ctl(spec, pfx, nid, 3)
17281
17282 /* add playback controls from the parsed DAC table */
17283 static int alc662_auto_create_multi_out_ctls(struct hda_codec *codec,
17284                                              const struct auto_pin_cfg *cfg)
17285 {
17286         struct alc_spec *spec = codec->spec;
17287         static const char *chname[4] = {
17288                 "Front", "Surround", NULL /*CLFE*/, "Side"
17289         };
17290         hda_nid_t nid, mix;
17291         int i, err;
17292
17293         for (i = 0; i < cfg->line_outs; i++) {
17294                 nid = spec->multiout.dac_nids[i];
17295                 if (!nid)
17296                         continue;
17297                 mix = alc662_dac_to_mix(codec, cfg->line_out_pins[i], nid);
17298                 if (!mix)
17299                         continue;
17300                 if (i == 2) {
17301                         /* Center/LFE */
17302                         err = alc662_add_vol_ctl(spec, "Center", nid, 1);
17303                         if (err < 0)
17304                                 return err;
17305                         err = alc662_add_vol_ctl(spec, "LFE", nid, 2);
17306                         if (err < 0)
17307                                 return err;
17308                         err = alc662_add_sw_ctl(spec, "Center", mix, 1);
17309                         if (err < 0)
17310                                 return err;
17311                         err = alc662_add_sw_ctl(spec, "LFE", mix, 2);
17312                         if (err < 0)
17313                                 return err;
17314                 } else {
17315                         const char *pfx;
17316                         if (cfg->line_outs == 1 &&
17317                             cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
17318                                 if (cfg->hp_outs)
17319                                         pfx = "Speaker";
17320                                 else
17321                                         pfx = "PCM";
17322                         } else
17323                                 pfx = chname[i];
17324                         err = alc662_add_vol_ctl(spec, pfx, nid, 3);
17325                         if (err < 0)
17326                                 return err;
17327                         if (cfg->line_outs == 1 &&
17328                             cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
17329                                 pfx = "Speaker";
17330                         err = alc662_add_sw_ctl(spec, pfx, mix, 3);
17331                         if (err < 0)
17332                                 return err;
17333                 }
17334         }
17335         return 0;
17336 }
17337
17338 /* add playback controls for speaker and HP outputs */
17339 /* return DAC nid if any new DAC is assigned */
17340 static int alc662_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
17341                                         const char *pfx)
17342 {
17343         struct alc_spec *spec = codec->spec;
17344         hda_nid_t nid, mix;
17345         int err;
17346
17347         if (!pin)
17348                 return 0;
17349         nid = alc662_look_for_dac(codec, pin);
17350         if (!nid) {
17351                 /* the corresponding DAC is already occupied */
17352                 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
17353                         return 0; /* no way */
17354                 /* create a switch only */
17355                 return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
17356                                    HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
17357         }
17358
17359         mix = alc662_dac_to_mix(codec, pin, nid);
17360         if (!mix)
17361                 return 0;
17362         err = alc662_add_vol_ctl(spec, pfx, nid, 3);
17363         if (err < 0)
17364                 return err;
17365         err = alc662_add_sw_ctl(spec, pfx, mix, 3);
17366         if (err < 0)
17367                 return err;
17368         return nid;
17369 }
17370
17371 /* create playback/capture controls for input pins */
17372 #define alc662_auto_create_input_ctls \
17373         alc882_auto_create_input_ctls
17374
17375 static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
17376                                               hda_nid_t nid, int pin_type,
17377                                               hda_nid_t dac)
17378 {
17379         int i, num;
17380         hda_nid_t srcs[4];
17381
17382         alc_set_pin_output(codec, nid, pin_type);
17383         /* need the manual connection? */
17384         num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
17385         if (num <= 1)
17386                 return;
17387         for (i = 0; i < num; i++) {
17388                 if (alc662_mix_to_dac(srcs[i]) != dac)
17389                         continue;
17390                 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
17391                 return;
17392         }
17393 }
17394
17395 static void alc662_auto_init_multi_out(struct hda_codec *codec)
17396 {
17397         struct alc_spec *spec = codec->spec;
17398         int pin_type = get_pin_type(spec->autocfg.line_out_type);
17399         int i;
17400
17401         for (i = 0; i <= HDA_SIDE; i++) {
17402                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
17403                 if (nid)
17404                         alc662_auto_set_output_and_unmute(codec, nid, pin_type,
17405                                         spec->multiout.dac_nids[i]);
17406         }
17407 }
17408
17409 static void alc662_auto_init_hp_out(struct hda_codec *codec)
17410 {
17411         struct alc_spec *spec = codec->spec;
17412         hda_nid_t pin;
17413
17414         pin = spec->autocfg.hp_pins[0];
17415         if (pin)
17416                 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP,
17417                                                   spec->multiout.hp_nid);
17418         pin = spec->autocfg.speaker_pins[0];
17419         if (pin)
17420                 alc662_auto_set_output_and_unmute(codec, pin, PIN_OUT,
17421                                         spec->multiout.extra_out_nid[0]);
17422 }
17423
17424 #define ALC662_PIN_CD_NID               ALC880_PIN_CD_NID
17425
17426 static void alc662_auto_init_analog_input(struct hda_codec *codec)
17427 {
17428         struct alc_spec *spec = codec->spec;
17429         int i;
17430
17431         for (i = 0; i < AUTO_PIN_LAST; i++) {
17432                 hda_nid_t nid = spec->autocfg.input_pins[i];
17433                 if (alc_is_input_pin(codec, nid)) {
17434                         alc_set_input_pin(codec, nid, i);
17435                         if (nid != ALC662_PIN_CD_NID &&
17436                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
17437                                 snd_hda_codec_write(codec, nid, 0,
17438                                                     AC_VERB_SET_AMP_GAIN_MUTE,
17439                                                     AMP_OUT_MUTE);
17440                 }
17441         }
17442 }
17443
17444 #define alc662_auto_init_input_src      alc882_auto_init_input_src
17445
17446 static int alc662_parse_auto_config(struct hda_codec *codec)
17447 {
17448         struct alc_spec *spec = codec->spec;
17449         int err;
17450         static hda_nid_t alc662_ignore[] = { 0x1d, 0 };
17451
17452         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
17453                                            alc662_ignore);
17454         if (err < 0)
17455                 return err;
17456         if (!spec->autocfg.line_outs)
17457                 return 0; /* can't find valid BIOS pin config */
17458
17459         err = alc662_auto_fill_dac_nids(codec, &spec->autocfg);
17460         if (err < 0)
17461                 return err;
17462         err = alc662_auto_create_multi_out_ctls(codec, &spec->autocfg);
17463         if (err < 0)
17464                 return err;
17465         err = alc662_auto_create_extra_out(codec,
17466                                            spec->autocfg.speaker_pins[0],
17467                                            "Speaker");
17468         if (err < 0)
17469                 return err;
17470         if (err)
17471                 spec->multiout.extra_out_nid[0] = err;
17472         err = alc662_auto_create_extra_out(codec, spec->autocfg.hp_pins[0],
17473                                            "Headphone");
17474         if (err < 0)
17475                 return err;
17476         if (err)
17477                 spec->multiout.hp_nid = err;
17478         err = alc662_auto_create_input_ctls(codec, &spec->autocfg);
17479         if (err < 0)
17480                 return err;
17481
17482         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
17483
17484         if (spec->autocfg.dig_outs)
17485                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
17486
17487         if (spec->kctls.list)
17488                 add_mixer(spec, spec->kctls.list);
17489
17490         spec->num_mux_defs = 1;
17491         spec->input_mux = &spec->private_imux[0];
17492
17493         add_verb(spec, alc662_auto_init_verbs);
17494         if (codec->vendor_id == 0x10ec0663)
17495                 add_verb(spec, alc663_auto_init_verbs);
17496
17497         err = alc_auto_add_mic_boost(codec);
17498         if (err < 0)
17499                 return err;
17500
17501         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
17502
17503         return 1;
17504 }
17505
17506 /* additional initialization for auto-configuration model */
17507 static void alc662_auto_init(struct hda_codec *codec)
17508 {
17509         struct alc_spec *spec = codec->spec;
17510         alc662_auto_init_multi_out(codec);
17511         alc662_auto_init_hp_out(codec);
17512         alc662_auto_init_analog_input(codec);
17513         alc662_auto_init_input_src(codec);
17514         if (spec->unsol_event)
17515                 alc_inithook(codec);
17516 }
17517
17518 static int patch_alc662(struct hda_codec *codec)
17519 {
17520         struct alc_spec *spec;
17521         int err, board_config;
17522
17523         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
17524         if (!spec)
17525                 return -ENOMEM;
17526
17527         codec->spec = spec;
17528
17529         alc_fix_pll_init(codec, 0x20, 0x04, 15);
17530
17531         board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
17532                                                   alc662_models,
17533                                                   alc662_cfg_tbl);
17534         if (board_config < 0) {
17535                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
17536                        codec->chip_name);
17537                 board_config = ALC662_AUTO;
17538         }
17539
17540         if (board_config == ALC662_AUTO) {
17541                 /* automatic parse from the BIOS config */
17542                 err = alc662_parse_auto_config(codec);
17543                 if (err < 0) {
17544                         alc_free(codec);
17545                         return err;
17546                 } else if (!err) {
17547                         printk(KERN_INFO
17548                                "hda_codec: Cannot set up configuration "
17549                                "from BIOS.  Using base mode...\n");
17550                         board_config = ALC662_3ST_2ch_DIG;
17551                 }
17552         }
17553
17554         err = snd_hda_attach_beep_device(codec, 0x1);
17555         if (err < 0) {
17556                 alc_free(codec);
17557                 return err;
17558         }
17559
17560         if (board_config != ALC662_AUTO)
17561                 setup_preset(codec, &alc662_presets[board_config]);
17562
17563         spec->stream_analog_playback = &alc662_pcm_analog_playback;
17564         spec->stream_analog_capture = &alc662_pcm_analog_capture;
17565
17566         spec->stream_digital_playback = &alc662_pcm_digital_playback;
17567         spec->stream_digital_capture = &alc662_pcm_digital_capture;
17568
17569         if (!spec->adc_nids) {
17570                 spec->adc_nids = alc662_adc_nids;
17571                 spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
17572         }
17573         if (!spec->capsrc_nids)
17574                 spec->capsrc_nids = alc662_capsrc_nids;
17575
17576         if (!spec->cap_mixer)
17577                 set_capture_mixer(codec);
17578         if (codec->vendor_id == 0x10ec0662)
17579                 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
17580         else
17581                 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
17582
17583         spec->vmaster_nid = 0x02;
17584
17585         codec->patch_ops = alc_patch_ops;
17586         if (board_config == ALC662_AUTO)
17587                 spec->init_hook = alc662_auto_init;
17588 #ifdef CONFIG_SND_HDA_POWER_SAVE
17589         if (!spec->loopback.amplist)
17590                 spec->loopback.amplist = alc662_loopbacks;
17591 #endif
17592         codec->proc_widget_hook = print_realtek_coef;
17593
17594         return 0;
17595 }
17596
17597 /*
17598  * patch entries
17599  */
17600 static struct hda_codec_preset snd_hda_preset_realtek[] = {
17601         { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
17602         { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
17603         { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
17604         { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
17605         { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
17606         { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
17607         { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
17608           .patch = patch_alc861 },
17609         { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
17610         { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
17611         { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
17612         { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
17613           .patch = patch_alc882 },
17614         { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
17615           .patch = patch_alc662 },
17616         { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
17617         { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
17618         { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
17619         { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
17620         { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
17621           .patch = patch_alc882 },
17622         { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
17623           .patch = patch_alc882 },
17624         { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
17625         { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
17626         { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
17627           .patch = patch_alc882 },
17628         { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
17629         { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
17630         {} /* terminator */
17631 };
17632
17633 MODULE_ALIAS("snd-hda-codec-id:10ec*");
17634
17635 MODULE_LICENSE("GPL");
17636 MODULE_DESCRIPTION("Realtek HD-audio codec");
17637
17638 static struct hda_codec_preset_list realtek_list = {
17639         .preset = snd_hda_preset_realtek,
17640         .owner = THIS_MODULE,
17641 };
17642
17643 static int __init patch_realtek_init(void)
17644 {
17645         return snd_hda_add_codec_preset(&realtek_list);
17646 }
17647
17648 static void __exit patch_realtek_exit(void)
17649 {
17650         snd_hda_delete_codec_preset(&realtek_list);
17651 }
17652
17653 module_init(patch_realtek_init)
17654 module_exit(patch_realtek_exit)