Merge branch 'fix/hda' into topic/hda
[pandora-kernel.git] / sound / pci / hda / patch_realtek.c
1 /*
2  * Universal Interface for Intel High Definition Audio Codec
3  *
4  * HD audio interface patch for ALC 260/880/882 codecs
5  *
6  * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7  *                    PeiSen Hou <pshou@realtek.com.tw>
8  *                    Takashi Iwai <tiwai@suse.de>
9  *                    Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
10  *
11  *  This driver is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This driver is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
24  */
25
26 #include <linux/init.h>
27 #include <linux/delay.h>
28 #include <linux/slab.h>
29 #include <linux/pci.h>
30 #include <sound/core.h>
31 #include "hda_codec.h"
32 #include "hda_local.h"
33 #include "hda_beep.h"
34
35 #define ALC880_FRONT_EVENT              0x01
36 #define ALC880_DCVOL_EVENT              0x02
37 #define ALC880_HP_EVENT                 0x04
38 #define ALC880_MIC_EVENT                0x08
39
40 /* ALC880 board config type */
41 enum {
42         ALC880_3ST,
43         ALC880_3ST_DIG,
44         ALC880_5ST,
45         ALC880_5ST_DIG,
46         ALC880_W810,
47         ALC880_Z71V,
48         ALC880_6ST,
49         ALC880_6ST_DIG,
50         ALC880_F1734,
51         ALC880_ASUS,
52         ALC880_ASUS_DIG,
53         ALC880_ASUS_W1V,
54         ALC880_ASUS_DIG2,
55         ALC880_FUJITSU,
56         ALC880_UNIWILL_DIG,
57         ALC880_UNIWILL,
58         ALC880_UNIWILL_P53,
59         ALC880_CLEVO,
60         ALC880_TCL_S700,
61         ALC880_LG,
62         ALC880_LG_LW,
63         ALC880_MEDION_RIM,
64 #ifdef CONFIG_SND_DEBUG
65         ALC880_TEST,
66 #endif
67         ALC880_AUTO,
68         ALC880_MODEL_LAST /* last tag */
69 };
70
71 /* ALC260 models */
72 enum {
73         ALC260_BASIC,
74         ALC260_HP,
75         ALC260_HP_DC7600,
76         ALC260_HP_3013,
77         ALC260_FUJITSU_S702X,
78         ALC260_ACER,
79         ALC260_WILL,
80         ALC260_REPLACER_672V,
81         ALC260_FAVORIT100,
82 #ifdef CONFIG_SND_DEBUG
83         ALC260_TEST,
84 #endif
85         ALC260_AUTO,
86         ALC260_MODEL_LAST /* last tag */
87 };
88
89 /* ALC262 models */
90 enum {
91         ALC262_BASIC,
92         ALC262_HIPPO,
93         ALC262_HIPPO_1,
94         ALC262_FUJITSU,
95         ALC262_HP_BPC,
96         ALC262_HP_BPC_D7000_WL,
97         ALC262_HP_BPC_D7000_WF,
98         ALC262_HP_TC_T5735,
99         ALC262_HP_RP5700,
100         ALC262_BENQ_ED8,
101         ALC262_SONY_ASSAMD,
102         ALC262_BENQ_T31,
103         ALC262_ULTRA,
104         ALC262_LENOVO_3000,
105         ALC262_NEC,
106         ALC262_TOSHIBA_S06,
107         ALC262_TOSHIBA_RX1,
108         ALC262_TYAN,
109         ALC262_AUTO,
110         ALC262_MODEL_LAST /* last tag */
111 };
112
113 /* ALC268 models */
114 enum {
115         ALC267_QUANTA_IL1,
116         ALC268_3ST,
117         ALC268_TOSHIBA,
118         ALC268_ACER,
119         ALC268_ACER_DMIC,
120         ALC268_ACER_ASPIRE_ONE,
121         ALC268_DELL,
122         ALC268_ZEPTO,
123 #ifdef CONFIG_SND_DEBUG
124         ALC268_TEST,
125 #endif
126         ALC268_AUTO,
127         ALC268_MODEL_LAST /* last tag */
128 };
129
130 /* ALC269 models */
131 enum {
132         ALC269_BASIC,
133         ALC269_QUANTA_FL1,
134         ALC269_ASUS_EEEPC_P703,
135         ALC269_ASUS_EEEPC_P901,
136         ALC269_FUJITSU,
137         ALC269_LIFEBOOK,
138         ALC269_AUTO,
139         ALC269_MODEL_LAST /* last tag */
140 };
141
142 /* ALC861 models */
143 enum {
144         ALC861_3ST,
145         ALC660_3ST,
146         ALC861_3ST_DIG,
147         ALC861_6ST_DIG,
148         ALC861_UNIWILL_M31,
149         ALC861_TOSHIBA,
150         ALC861_ASUS,
151         ALC861_ASUS_LAPTOP,
152         ALC861_AUTO,
153         ALC861_MODEL_LAST,
154 };
155
156 /* ALC861-VD models */
157 enum {
158         ALC660VD_3ST,
159         ALC660VD_3ST_DIG,
160         ALC660VD_ASUS_V1S,
161         ALC861VD_3ST,
162         ALC861VD_3ST_DIG,
163         ALC861VD_6ST_DIG,
164         ALC861VD_LENOVO,
165         ALC861VD_DALLAS,
166         ALC861VD_HP,
167         ALC861VD_AUTO,
168         ALC861VD_MODEL_LAST,
169 };
170
171 /* ALC662 models */
172 enum {
173         ALC662_3ST_2ch_DIG,
174         ALC662_3ST_6ch_DIG,
175         ALC662_3ST_6ch,
176         ALC662_5ST_DIG,
177         ALC662_LENOVO_101E,
178         ALC662_ASUS_EEEPC_P701,
179         ALC662_ASUS_EEEPC_EP20,
180         ALC663_ASUS_M51VA,
181         ALC663_ASUS_G71V,
182         ALC663_ASUS_H13,
183         ALC663_ASUS_G50V,
184         ALC662_ECS,
185         ALC663_ASUS_MODE1,
186         ALC662_ASUS_MODE2,
187         ALC663_ASUS_MODE3,
188         ALC663_ASUS_MODE4,
189         ALC663_ASUS_MODE5,
190         ALC663_ASUS_MODE6,
191         ALC272_DELL,
192         ALC272_DELL_ZM1,
193         ALC272_SAMSUNG_NC10,
194         ALC662_AUTO,
195         ALC662_MODEL_LAST,
196 };
197
198 /* ALC882 models */
199 enum {
200         ALC882_3ST_DIG,
201         ALC882_6ST_DIG,
202         ALC882_ARIMA,
203         ALC882_W2JC,
204         ALC882_TARGA,
205         ALC882_ASUS_A7J,
206         ALC882_ASUS_A7M,
207         ALC885_MACPRO,
208         ALC885_MBP3,
209         ALC885_MB5,
210         ALC885_IMAC24,
211         ALC883_3ST_2ch_DIG,
212         ALC883_3ST_6ch_DIG,
213         ALC883_3ST_6ch,
214         ALC883_6ST_DIG,
215         ALC883_TARGA_DIG,
216         ALC883_TARGA_2ch_DIG,
217         ALC883_TARGA_8ch_DIG,
218         ALC883_ACER,
219         ALC883_ACER_ASPIRE,
220         ALC888_ACER_ASPIRE_4930G,
221         ALC888_ACER_ASPIRE_6530G,
222         ALC888_ACER_ASPIRE_8930G,
223         ALC888_ACER_ASPIRE_7730G,
224         ALC883_MEDION,
225         ALC883_MEDION_MD2,
226         ALC883_LAPTOP_EAPD,
227         ALC883_LENOVO_101E_2ch,
228         ALC883_LENOVO_NB0763,
229         ALC888_LENOVO_MS7195_DIG,
230         ALC888_LENOVO_SKY,
231         ALC883_HAIER_W66,
232         ALC888_3ST_HP,
233         ALC888_6ST_DELL,
234         ALC883_MITAC,
235         ALC883_CLEVO_M540R,
236         ALC883_CLEVO_M720,
237         ALC883_FUJITSU_PI2515,
238         ALC888_FUJITSU_XA3530,
239         ALC883_3ST_6ch_INTEL,
240         ALC889A_INTEL,
241         ALC889_INTEL,
242         ALC888_ASUS_M90V,
243         ALC888_ASUS_EEE1601,
244         ALC889A_MB31,
245         ALC1200_ASUS_P5Q,
246         ALC883_SONY_VAIO_TT,
247         ALC882_AUTO,
248         ALC882_MODEL_LAST,
249 };
250
251 /* for GPIO Poll */
252 #define GPIO_MASK       0x03
253
254 /* extra amp-initialization sequence types */
255 enum {
256         ALC_INIT_NONE,
257         ALC_INIT_DEFAULT,
258         ALC_INIT_GPIO1,
259         ALC_INIT_GPIO2,
260         ALC_INIT_GPIO3,
261 };
262
263 struct alc_mic_route {
264         hda_nid_t pin;
265         unsigned char mux_idx;
266         unsigned char amix_idx;
267 };
268
269 #define MUX_IDX_UNDEF   ((unsigned char)-1)
270
271 struct alc_spec {
272         /* codec parameterization */
273         struct snd_kcontrol_new *mixers[5];     /* mixer arrays */
274         unsigned int num_mixers;
275         struct snd_kcontrol_new *cap_mixer;     /* capture mixer */
276         unsigned int beep_amp;  /* beep amp value, set via set_beep_amp() */
277
278         const struct hda_verb *init_verbs[10];  /* initialization verbs
279                                                  * don't forget NULL
280                                                  * termination!
281                                                  */
282         unsigned int num_init_verbs;
283
284         char stream_name_analog[32];    /* analog PCM stream */
285         struct hda_pcm_stream *stream_analog_playback;
286         struct hda_pcm_stream *stream_analog_capture;
287         struct hda_pcm_stream *stream_analog_alt_playback;
288         struct hda_pcm_stream *stream_analog_alt_capture;
289
290         char stream_name_digital[32];   /* digital PCM stream */
291         struct hda_pcm_stream *stream_digital_playback;
292         struct hda_pcm_stream *stream_digital_capture;
293
294         /* playback */
295         struct hda_multi_out multiout;  /* playback set-up
296                                          * max_channels, dacs must be set
297                                          * dig_out_nid and hp_nid are optional
298                                          */
299         hda_nid_t alt_dac_nid;
300         hda_nid_t slave_dig_outs[3];    /* optional - for auto-parsing */
301         int dig_out_type;
302
303         /* capture */
304         unsigned int num_adc_nids;
305         hda_nid_t *adc_nids;
306         hda_nid_t *capsrc_nids;
307         hda_nid_t dig_in_nid;           /* digital-in NID; optional */
308
309         /* capture source */
310         unsigned int num_mux_defs;
311         const struct hda_input_mux *input_mux;
312         unsigned int cur_mux[3];
313         struct alc_mic_route ext_mic;
314         struct alc_mic_route int_mic;
315
316         /* channel model */
317         const struct hda_channel_mode *channel_mode;
318         int num_channel_mode;
319         int need_dac_fix;
320         int const_channel_count;
321         int ext_channel_count;
322
323         /* PCM information */
324         struct hda_pcm pcm_rec[3];      /* used in alc_build_pcms() */
325
326         /* dynamic controls, init_verbs and input_mux */
327         struct auto_pin_cfg autocfg;
328         struct snd_array kctls;
329         struct hda_input_mux private_imux[3];
330         hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
331         hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
332         hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
333
334         /* hooks */
335         void (*init_hook)(struct hda_codec *codec);
336         void (*unsol_event)(struct hda_codec *codec, unsigned int res);
337
338         /* for pin sensing */
339         unsigned int sense_updated: 1;
340         unsigned int jack_present: 1;
341         unsigned int master_sw: 1;
342         unsigned int auto_mic:1;
343
344         /* other flags */
345         unsigned int no_analog :1; /* digital I/O only */
346         int init_amp;
347
348         /* for virtual master */
349         hda_nid_t vmaster_nid;
350 #ifdef CONFIG_SND_HDA_POWER_SAVE
351         struct hda_loopback_check loopback;
352 #endif
353
354         /* for PLL fix */
355         hda_nid_t pll_nid;
356         unsigned int pll_coef_idx, pll_coef_bit;
357 };
358
359 /*
360  * configuration template - to be copied to the spec instance
361  */
362 struct alc_config_preset {
363         struct snd_kcontrol_new *mixers[5]; /* should be identical size
364                                              * with spec
365                                              */
366         struct snd_kcontrol_new *cap_mixer; /* capture mixer */
367         const struct hda_verb *init_verbs[5];
368         unsigned int num_dacs;
369         hda_nid_t *dac_nids;
370         hda_nid_t dig_out_nid;          /* optional */
371         hda_nid_t hp_nid;               /* optional */
372         hda_nid_t *slave_dig_outs;
373         unsigned int num_adc_nids;
374         hda_nid_t *adc_nids;
375         hda_nid_t *capsrc_nids;
376         hda_nid_t dig_in_nid;
377         unsigned int num_channel_mode;
378         const struct hda_channel_mode *channel_mode;
379         int need_dac_fix;
380         int const_channel_count;
381         unsigned int num_mux_defs;
382         const struct hda_input_mux *input_mux;
383         void (*unsol_event)(struct hda_codec *, unsigned int);
384         void (*setup)(struct hda_codec *);
385         void (*init_hook)(struct hda_codec *);
386 #ifdef CONFIG_SND_HDA_POWER_SAVE
387         struct hda_amp_list *loopbacks;
388 #endif
389 };
390
391
392 /*
393  * input MUX handling
394  */
395 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
396                              struct snd_ctl_elem_info *uinfo)
397 {
398         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
399         struct alc_spec *spec = codec->spec;
400         unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
401         if (mux_idx >= spec->num_mux_defs)
402                 mux_idx = 0;
403         return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
404 }
405
406 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
407                             struct snd_ctl_elem_value *ucontrol)
408 {
409         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
410         struct alc_spec *spec = codec->spec;
411         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
412
413         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
414         return 0;
415 }
416
417 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
418                             struct snd_ctl_elem_value *ucontrol)
419 {
420         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
421         struct alc_spec *spec = codec->spec;
422         const struct hda_input_mux *imux;
423         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
424         unsigned int mux_idx;
425         hda_nid_t nid = spec->capsrc_nids ?
426                 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
427         unsigned int type;
428
429         mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
430         imux = &spec->input_mux[mux_idx];
431
432         type = get_wcaps_type(get_wcaps(codec, nid));
433         if (type == AC_WID_AUD_MIX) {
434                 /* Matrix-mixer style (e.g. ALC882) */
435                 unsigned int *cur_val = &spec->cur_mux[adc_idx];
436                 unsigned int i, idx;
437
438                 idx = ucontrol->value.enumerated.item[0];
439                 if (idx >= imux->num_items)
440                         idx = imux->num_items - 1;
441                 if (*cur_val == idx)
442                         return 0;
443                 for (i = 0; i < imux->num_items; i++) {
444                         unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
445                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
446                                                  imux->items[i].index,
447                                                  HDA_AMP_MUTE, v);
448                 }
449                 *cur_val = idx;
450                 return 1;
451         } else {
452                 /* MUX style (e.g. ALC880) */
453                 return snd_hda_input_mux_put(codec, imux, ucontrol, nid,
454                                              &spec->cur_mux[adc_idx]);
455         }
456 }
457
458 /*
459  * channel mode setting
460  */
461 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
462                             struct snd_ctl_elem_info *uinfo)
463 {
464         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
465         struct alc_spec *spec = codec->spec;
466         return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
467                                     spec->num_channel_mode);
468 }
469
470 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
471                            struct snd_ctl_elem_value *ucontrol)
472 {
473         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
474         struct alc_spec *spec = codec->spec;
475         return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
476                                    spec->num_channel_mode,
477                                    spec->ext_channel_count);
478 }
479
480 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
481                            struct snd_ctl_elem_value *ucontrol)
482 {
483         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
484         struct alc_spec *spec = codec->spec;
485         int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
486                                       spec->num_channel_mode,
487                                       &spec->ext_channel_count);
488         if (err >= 0 && !spec->const_channel_count) {
489                 spec->multiout.max_channels = spec->ext_channel_count;
490                 if (spec->need_dac_fix)
491                         spec->multiout.num_dacs = spec->multiout.max_channels / 2;
492         }
493         return err;
494 }
495
496 /*
497  * Control the mode of pin widget settings via the mixer.  "pc" is used
498  * instead of "%" to avoid consequences of accidently treating the % as
499  * being part of a format specifier.  Maximum allowed length of a value is
500  * 63 characters plus NULL terminator.
501  *
502  * Note: some retasking pin complexes seem to ignore requests for input
503  * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
504  * are requested.  Therefore order this list so that this behaviour will not
505  * cause problems when mixer clients move through the enum sequentially.
506  * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
507  * March 2006.
508  */
509 static char *alc_pin_mode_names[] = {
510         "Mic 50pc bias", "Mic 80pc bias",
511         "Line in", "Line out", "Headphone out",
512 };
513 static unsigned char alc_pin_mode_values[] = {
514         PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
515 };
516 /* The control can present all 5 options, or it can limit the options based
517  * in the pin being assumed to be exclusively an input or an output pin.  In
518  * addition, "input" pins may or may not process the mic bias option
519  * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
520  * accept requests for bias as of chip versions up to March 2006) and/or
521  * wiring in the computer.
522  */
523 #define ALC_PIN_DIR_IN              0x00
524 #define ALC_PIN_DIR_OUT             0x01
525 #define ALC_PIN_DIR_INOUT           0x02
526 #define ALC_PIN_DIR_IN_NOMICBIAS    0x03
527 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
528
529 /* Info about the pin modes supported by the different pin direction modes.
530  * For each direction the minimum and maximum values are given.
531  */
532 static signed char alc_pin_mode_dir_info[5][2] = {
533         { 0, 2 },    /* ALC_PIN_DIR_IN */
534         { 3, 4 },    /* ALC_PIN_DIR_OUT */
535         { 0, 4 },    /* ALC_PIN_DIR_INOUT */
536         { 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
537         { 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
538 };
539 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
540 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
541 #define alc_pin_mode_n_items(_dir) \
542         (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
543
544 static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
545                              struct snd_ctl_elem_info *uinfo)
546 {
547         unsigned int item_num = uinfo->value.enumerated.item;
548         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
549
550         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
551         uinfo->count = 1;
552         uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
553
554         if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
555                 item_num = alc_pin_mode_min(dir);
556         strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
557         return 0;
558 }
559
560 static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
561                             struct snd_ctl_elem_value *ucontrol)
562 {
563         unsigned int i;
564         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
565         hda_nid_t nid = kcontrol->private_value & 0xffff;
566         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
567         long *valp = ucontrol->value.integer.value;
568         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
569                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
570                                                  0x00);
571
572         /* Find enumerated value for current pinctl setting */
573         i = alc_pin_mode_min(dir);
574         while (i <= alc_pin_mode_max(dir) && alc_pin_mode_values[i] != pinctl)
575                 i++;
576         *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
577         return 0;
578 }
579
580 static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
581                             struct snd_ctl_elem_value *ucontrol)
582 {
583         signed int change;
584         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
585         hda_nid_t nid = kcontrol->private_value & 0xffff;
586         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
587         long val = *ucontrol->value.integer.value;
588         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
589                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
590                                                  0x00);
591
592         if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
593                 val = alc_pin_mode_min(dir);
594
595         change = pinctl != alc_pin_mode_values[val];
596         if (change) {
597                 /* Set pin mode to that requested */
598                 snd_hda_codec_write_cache(codec, nid, 0,
599                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
600                                           alc_pin_mode_values[val]);
601
602                 /* Also enable the retasking pin's input/output as required
603                  * for the requested pin mode.  Enum values of 2 or less are
604                  * input modes.
605                  *
606                  * Dynamically switching the input/output buffers probably
607                  * reduces noise slightly (particularly on input) so we'll
608                  * do it.  However, having both input and output buffers
609                  * enabled simultaneously doesn't seem to be problematic if
610                  * this turns out to be necessary in the future.
611                  */
612                 if (val <= 2) {
613                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
614                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
615                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
616                                                  HDA_AMP_MUTE, 0);
617                 } else {
618                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
619                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
620                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
621                                                  HDA_AMP_MUTE, 0);
622                 }
623         }
624         return change;
625 }
626
627 #define ALC_PIN_MODE(xname, nid, dir) \
628         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
629           .info = alc_pin_mode_info, \
630           .get = alc_pin_mode_get, \
631           .put = alc_pin_mode_put, \
632           .private_value = nid | (dir<<16) }
633
634 /* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
635  * together using a mask with more than one bit set.  This control is
636  * currently used only by the ALC260 test model.  At this stage they are not
637  * needed for any "production" models.
638  */
639 #ifdef CONFIG_SND_DEBUG
640 #define alc_gpio_data_info      snd_ctl_boolean_mono_info
641
642 static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
643                              struct snd_ctl_elem_value *ucontrol)
644 {
645         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
646         hda_nid_t nid = kcontrol->private_value & 0xffff;
647         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
648         long *valp = ucontrol->value.integer.value;
649         unsigned int val = snd_hda_codec_read(codec, nid, 0,
650                                               AC_VERB_GET_GPIO_DATA, 0x00);
651
652         *valp = (val & mask) != 0;
653         return 0;
654 }
655 static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
656                              struct snd_ctl_elem_value *ucontrol)
657 {
658         signed int change;
659         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
660         hda_nid_t nid = kcontrol->private_value & 0xffff;
661         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
662         long val = *ucontrol->value.integer.value;
663         unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
664                                                     AC_VERB_GET_GPIO_DATA,
665                                                     0x00);
666
667         /* Set/unset the masked GPIO bit(s) as needed */
668         change = (val == 0 ? 0 : mask) != (gpio_data & mask);
669         if (val == 0)
670                 gpio_data &= ~mask;
671         else
672                 gpio_data |= mask;
673         snd_hda_codec_write_cache(codec, nid, 0,
674                                   AC_VERB_SET_GPIO_DATA, gpio_data);
675
676         return change;
677 }
678 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
679         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
680           .info = alc_gpio_data_info, \
681           .get = alc_gpio_data_get, \
682           .put = alc_gpio_data_put, \
683           .private_value = nid | (mask<<16) }
684 #endif   /* CONFIG_SND_DEBUG */
685
686 /* A switch control to allow the enabling of the digital IO pins on the
687  * ALC260.  This is incredibly simplistic; the intention of this control is
688  * to provide something in the test model allowing digital outputs to be
689  * identified if present.  If models are found which can utilise these
690  * outputs a more complete mixer control can be devised for those models if
691  * necessary.
692  */
693 #ifdef CONFIG_SND_DEBUG
694 #define alc_spdif_ctrl_info     snd_ctl_boolean_mono_info
695
696 static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
697                               struct snd_ctl_elem_value *ucontrol)
698 {
699         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
700         hda_nid_t nid = kcontrol->private_value & 0xffff;
701         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
702         long *valp = ucontrol->value.integer.value;
703         unsigned int val = snd_hda_codec_read(codec, nid, 0,
704                                               AC_VERB_GET_DIGI_CONVERT_1, 0x00);
705
706         *valp = (val & mask) != 0;
707         return 0;
708 }
709 static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
710                               struct snd_ctl_elem_value *ucontrol)
711 {
712         signed int change;
713         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
714         hda_nid_t nid = kcontrol->private_value & 0xffff;
715         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
716         long val = *ucontrol->value.integer.value;
717         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
718                                                     AC_VERB_GET_DIGI_CONVERT_1,
719                                                     0x00);
720
721         /* Set/unset the masked control bit(s) as needed */
722         change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
723         if (val==0)
724                 ctrl_data &= ~mask;
725         else
726                 ctrl_data |= mask;
727         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
728                                   ctrl_data);
729
730         return change;
731 }
732 #define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
733         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
734           .info = alc_spdif_ctrl_info, \
735           .get = alc_spdif_ctrl_get, \
736           .put = alc_spdif_ctrl_put, \
737           .private_value = nid | (mask<<16) }
738 #endif   /* CONFIG_SND_DEBUG */
739
740 /* A switch control to allow the enabling EAPD digital outputs on the ALC26x.
741  * Again, this is only used in the ALC26x test models to help identify when
742  * the EAPD line must be asserted for features to work.
743  */
744 #ifdef CONFIG_SND_DEBUG
745 #define alc_eapd_ctrl_info      snd_ctl_boolean_mono_info
746
747 static int alc_eapd_ctrl_get(struct snd_kcontrol *kcontrol,
748                               struct snd_ctl_elem_value *ucontrol)
749 {
750         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
751         hda_nid_t nid = kcontrol->private_value & 0xffff;
752         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
753         long *valp = ucontrol->value.integer.value;
754         unsigned int val = snd_hda_codec_read(codec, nid, 0,
755                                               AC_VERB_GET_EAPD_BTLENABLE, 0x00);
756
757         *valp = (val & mask) != 0;
758         return 0;
759 }
760
761 static int alc_eapd_ctrl_put(struct snd_kcontrol *kcontrol,
762                               struct snd_ctl_elem_value *ucontrol)
763 {
764         int change;
765         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
766         hda_nid_t nid = kcontrol->private_value & 0xffff;
767         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
768         long val = *ucontrol->value.integer.value;
769         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
770                                                     AC_VERB_GET_EAPD_BTLENABLE,
771                                                     0x00);
772
773         /* Set/unset the masked control bit(s) as needed */
774         change = (!val ? 0 : mask) != (ctrl_data & mask);
775         if (!val)
776                 ctrl_data &= ~mask;
777         else
778                 ctrl_data |= mask;
779         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
780                                   ctrl_data);
781
782         return change;
783 }
784
785 #define ALC_EAPD_CTRL_SWITCH(xname, nid, mask) \
786         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
787           .info = alc_eapd_ctrl_info, \
788           .get = alc_eapd_ctrl_get, \
789           .put = alc_eapd_ctrl_put, \
790           .private_value = nid | (mask<<16) }
791 #endif   /* CONFIG_SND_DEBUG */
792
793 /*
794  * set up the input pin config (depending on the given auto-pin type)
795  */
796 static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
797                               int auto_pin_type)
798 {
799         unsigned int val = PIN_IN;
800
801         if (auto_pin_type <= AUTO_PIN_FRONT_MIC) {
802                 unsigned int pincap;
803                 pincap = snd_hda_query_pin_caps(codec, nid);
804                 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
805                 if (pincap & AC_PINCAP_VREF_80)
806                         val = PIN_VREF80;
807                 else if (pincap & AC_PINCAP_VREF_50)
808                         val = PIN_VREF50;
809                 else if (pincap & AC_PINCAP_VREF_100)
810                         val = PIN_VREF100;
811                 else if (pincap & AC_PINCAP_VREF_GRD)
812                         val = PIN_VREFGRD;
813         }
814         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
815 }
816
817 /*
818  */
819 static void add_mixer(struct alc_spec *spec, struct snd_kcontrol_new *mix)
820 {
821         if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
822                 return;
823         spec->mixers[spec->num_mixers++] = mix;
824 }
825
826 static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
827 {
828         if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
829                 return;
830         spec->init_verbs[spec->num_init_verbs++] = verb;
831 }
832
833 #ifdef CONFIG_PROC_FS
834 /*
835  * hook for proc
836  */
837 static void print_realtek_coef(struct snd_info_buffer *buffer,
838                                struct hda_codec *codec, hda_nid_t nid)
839 {
840         int coeff;
841
842         if (nid != 0x20)
843                 return;
844         coeff = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PROC_COEF, 0);
845         snd_iprintf(buffer, "  Processing Coefficient: 0x%02x\n", coeff);
846         coeff = snd_hda_codec_read(codec, nid, 0,
847                                    AC_VERB_GET_COEF_INDEX, 0);
848         snd_iprintf(buffer, "  Coefficient Index: 0x%02x\n", coeff);
849 }
850 #else
851 #define print_realtek_coef      NULL
852 #endif
853
854 /*
855  * set up from the preset table
856  */
857 static void setup_preset(struct hda_codec *codec,
858                          const struct alc_config_preset *preset)
859 {
860         struct alc_spec *spec = codec->spec;
861         int i;
862
863         for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
864                 add_mixer(spec, preset->mixers[i]);
865         spec->cap_mixer = preset->cap_mixer;
866         for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
867              i++)
868                 add_verb(spec, preset->init_verbs[i]);
869
870         spec->channel_mode = preset->channel_mode;
871         spec->num_channel_mode = preset->num_channel_mode;
872         spec->need_dac_fix = preset->need_dac_fix;
873         spec->const_channel_count = preset->const_channel_count;
874
875         if (preset->const_channel_count)
876                 spec->multiout.max_channels = preset->const_channel_count;
877         else
878                 spec->multiout.max_channels = spec->channel_mode[0].channels;
879         spec->ext_channel_count = spec->channel_mode[0].channels;
880
881         spec->multiout.num_dacs = preset->num_dacs;
882         spec->multiout.dac_nids = preset->dac_nids;
883         spec->multiout.dig_out_nid = preset->dig_out_nid;
884         spec->multiout.slave_dig_outs = preset->slave_dig_outs;
885         spec->multiout.hp_nid = preset->hp_nid;
886
887         spec->num_mux_defs = preset->num_mux_defs;
888         if (!spec->num_mux_defs)
889                 spec->num_mux_defs = 1;
890         spec->input_mux = preset->input_mux;
891
892         spec->num_adc_nids = preset->num_adc_nids;
893         spec->adc_nids = preset->adc_nids;
894         spec->capsrc_nids = preset->capsrc_nids;
895         spec->dig_in_nid = preset->dig_in_nid;
896
897         spec->unsol_event = preset->unsol_event;
898         spec->init_hook = preset->init_hook;
899 #ifdef CONFIG_SND_HDA_POWER_SAVE
900         spec->loopback.amplist = preset->loopbacks;
901 #endif
902
903         if (preset->setup)
904                 preset->setup(codec);
905 }
906
907 /* Enable GPIO mask and set output */
908 static struct hda_verb alc_gpio1_init_verbs[] = {
909         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
910         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
911         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
912         { }
913 };
914
915 static struct hda_verb alc_gpio2_init_verbs[] = {
916         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
917         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
918         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
919         { }
920 };
921
922 static struct hda_verb alc_gpio3_init_verbs[] = {
923         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
924         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
925         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
926         { }
927 };
928
929 /*
930  * Fix hardware PLL issue
931  * On some codecs, the analog PLL gating control must be off while
932  * the default value is 1.
933  */
934 static void alc_fix_pll(struct hda_codec *codec)
935 {
936         struct alc_spec *spec = codec->spec;
937         unsigned int val;
938
939         if (!spec->pll_nid)
940                 return;
941         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
942                             spec->pll_coef_idx);
943         val = snd_hda_codec_read(codec, spec->pll_nid, 0,
944                                  AC_VERB_GET_PROC_COEF, 0);
945         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
946                             spec->pll_coef_idx);
947         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
948                             val & ~(1 << spec->pll_coef_bit));
949 }
950
951 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
952                              unsigned int coef_idx, unsigned int coef_bit)
953 {
954         struct alc_spec *spec = codec->spec;
955         spec->pll_nid = nid;
956         spec->pll_coef_idx = coef_idx;
957         spec->pll_coef_bit = coef_bit;
958         alc_fix_pll(codec);
959 }
960
961 static void alc_automute_pin(struct hda_codec *codec)
962 {
963         struct alc_spec *spec = codec->spec;
964         unsigned int present, pincap;
965         unsigned int nid = spec->autocfg.hp_pins[0];
966         int i;
967
968         if (!nid)
969                 return;
970         pincap = snd_hda_query_pin_caps(codec, nid);
971         if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */
972                 snd_hda_codec_read(codec, nid, 0, AC_VERB_SET_PIN_SENSE, 0);
973         present = snd_hda_codec_read(codec, nid, 0,
974                                      AC_VERB_GET_PIN_SENSE, 0);
975         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
976         for (i = 0; i < ARRAY_SIZE(spec->autocfg.speaker_pins); i++) {
977                 nid = spec->autocfg.speaker_pins[i];
978                 if (!nid)
979                         break;
980                 snd_hda_codec_write(codec, nid, 0,
981                                     AC_VERB_SET_PIN_WIDGET_CONTROL,
982                                     spec->jack_present ? 0 : PIN_OUT);
983         }
984 }
985
986 static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
987                                 hda_nid_t nid)
988 {
989         hda_nid_t conn[HDA_MAX_NUM_INPUTS];
990         int i, nums;
991
992         nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
993         for (i = 0; i < nums; i++)
994                 if (conn[i] == nid)
995                         return i;
996         return -1;
997 }
998
999 static void alc_mic_automute(struct hda_codec *codec)
1000 {
1001         struct alc_spec *spec = codec->spec;
1002         struct alc_mic_route *dead, *alive;
1003         unsigned int present, type;
1004         hda_nid_t cap_nid;
1005
1006         if (!spec->auto_mic)
1007                 return;
1008         if (!spec->int_mic.pin || !spec->ext_mic.pin)
1009                 return;
1010         if (snd_BUG_ON(!spec->adc_nids))
1011                 return;
1012
1013         cap_nid = spec->capsrc_nids ? spec->capsrc_nids[0] : spec->adc_nids[0];
1014
1015         present = snd_hda_codec_read(codec, spec->ext_mic.pin, 0,
1016                                      AC_VERB_GET_PIN_SENSE, 0);
1017         present &= AC_PINSENSE_PRESENCE;
1018         if (present) {
1019                 alive = &spec->ext_mic;
1020                 dead = &spec->int_mic;
1021         } else {
1022                 alive = &spec->int_mic;
1023                 dead = &spec->ext_mic;
1024         }
1025
1026         type = get_wcaps_type(get_wcaps(codec, cap_nid));
1027         if (type == AC_WID_AUD_MIX) {
1028                 /* Matrix-mixer style (e.g. ALC882) */
1029                 snd_hda_codec_amp_stereo(codec, cap_nid, HDA_INPUT,
1030                                          alive->mux_idx,
1031                                          HDA_AMP_MUTE, 0);
1032                 snd_hda_codec_amp_stereo(codec, cap_nid, HDA_INPUT,
1033                                          dead->mux_idx,
1034                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
1035         } else {
1036                 /* MUX style (e.g. ALC880) */
1037                 snd_hda_codec_write_cache(codec, cap_nid, 0,
1038                                           AC_VERB_SET_CONNECT_SEL,
1039                                           alive->mux_idx);
1040         }
1041
1042         /* FIXME: analog mixer */
1043 }
1044
1045 /* unsolicited event for HP jack sensing */
1046 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
1047 {
1048         if (codec->vendor_id == 0x10ec0880)
1049                 res >>= 28;
1050         else
1051                 res >>= 26;
1052         switch (res) {
1053         case ALC880_HP_EVENT:
1054                 alc_automute_pin(codec);
1055                 break;
1056         case ALC880_MIC_EVENT:
1057                 alc_mic_automute(codec);
1058                 break;
1059         }
1060 }
1061
1062 static void alc_inithook(struct hda_codec *codec)
1063 {
1064         alc_automute_pin(codec);
1065         alc_mic_automute(codec);
1066 }
1067
1068 /* additional initialization for ALC888 variants */
1069 static void alc888_coef_init(struct hda_codec *codec)
1070 {
1071         unsigned int tmp;
1072
1073         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
1074         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
1075         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
1076         if ((tmp & 0xf0) == 0x20)
1077                 /* alc888S-VC */
1078                 snd_hda_codec_read(codec, 0x20, 0,
1079                                    AC_VERB_SET_PROC_COEF, 0x830);
1080          else
1081                  /* alc888-VB */
1082                  snd_hda_codec_read(codec, 0x20, 0,
1083                                     AC_VERB_SET_PROC_COEF, 0x3030);
1084 }
1085
1086 static void alc889_coef_init(struct hda_codec *codec)
1087 {
1088         unsigned int tmp;
1089
1090         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
1091         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
1092         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
1093         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
1094 }
1095
1096 static void alc_auto_init_amp(struct hda_codec *codec, int type)
1097 {
1098         unsigned int tmp;
1099
1100         switch (type) {
1101         case ALC_INIT_GPIO1:
1102                 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
1103                 break;
1104         case ALC_INIT_GPIO2:
1105                 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
1106                 break;
1107         case ALC_INIT_GPIO3:
1108                 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
1109                 break;
1110         case ALC_INIT_DEFAULT:
1111                 switch (codec->vendor_id) {
1112                 case 0x10ec0260:
1113                         snd_hda_codec_write(codec, 0x0f, 0,
1114                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1115                         snd_hda_codec_write(codec, 0x10, 0,
1116                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1117                         break;
1118                 case 0x10ec0262:
1119                 case 0x10ec0267:
1120                 case 0x10ec0268:
1121                 case 0x10ec0269:
1122                 case 0x10ec0272:
1123                 case 0x10ec0660:
1124                 case 0x10ec0662:
1125                 case 0x10ec0663:
1126                 case 0x10ec0862:
1127                 case 0x10ec0889:
1128                         snd_hda_codec_write(codec, 0x14, 0,
1129                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1130                         snd_hda_codec_write(codec, 0x15, 0,
1131                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1132                         break;
1133                 }
1134                 switch (codec->vendor_id) {
1135                 case 0x10ec0260:
1136                         snd_hda_codec_write(codec, 0x1a, 0,
1137                                             AC_VERB_SET_COEF_INDEX, 7);
1138                         tmp = snd_hda_codec_read(codec, 0x1a, 0,
1139                                                  AC_VERB_GET_PROC_COEF, 0);
1140                         snd_hda_codec_write(codec, 0x1a, 0,
1141                                             AC_VERB_SET_COEF_INDEX, 7);
1142                         snd_hda_codec_write(codec, 0x1a, 0,
1143                                             AC_VERB_SET_PROC_COEF,
1144                                             tmp | 0x2010);
1145                         break;
1146                 case 0x10ec0262:
1147                 case 0x10ec0880:
1148                 case 0x10ec0882:
1149                 case 0x10ec0883:
1150                 case 0x10ec0885:
1151                 case 0x10ec0887:
1152                 case 0x10ec0889:
1153                         alc889_coef_init(codec);
1154                         break;
1155                 case 0x10ec0888:
1156                         alc888_coef_init(codec);
1157                         break;
1158                 case 0x10ec0267:
1159                 case 0x10ec0268:
1160                         snd_hda_codec_write(codec, 0x20, 0,
1161                                             AC_VERB_SET_COEF_INDEX, 7);
1162                         tmp = snd_hda_codec_read(codec, 0x20, 0,
1163                                                  AC_VERB_GET_PROC_COEF, 0);
1164                         snd_hda_codec_write(codec, 0x20, 0,
1165                                             AC_VERB_SET_COEF_INDEX, 7);
1166                         snd_hda_codec_write(codec, 0x20, 0,
1167                                             AC_VERB_SET_PROC_COEF,
1168                                             tmp | 0x3000);
1169                         break;
1170                 }
1171                 break;
1172         }
1173 }
1174
1175 static void alc_init_auto_hp(struct hda_codec *codec)
1176 {
1177         struct alc_spec *spec = codec->spec;
1178
1179         if (!spec->autocfg.hp_pins[0])
1180                 return;
1181
1182         if (!spec->autocfg.speaker_pins[0]) {
1183                 if (spec->autocfg.line_out_pins[0] &&
1184                     spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
1185                         spec->autocfg.speaker_pins[0] =
1186                                 spec->autocfg.line_out_pins[0];
1187                 else
1188                         return;
1189         }
1190
1191         snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
1192                     spec->autocfg.hp_pins[0]);
1193         snd_hda_codec_write_cache(codec, spec->autocfg.hp_pins[0], 0,
1194                                   AC_VERB_SET_UNSOLICITED_ENABLE,
1195                                   AC_USRSP_EN | ALC880_HP_EVENT);
1196         spec->unsol_event = alc_sku_unsol_event;
1197 }
1198
1199 static void alc_init_auto_mic(struct hda_codec *codec)
1200 {
1201         struct alc_spec *spec = codec->spec;
1202         struct auto_pin_cfg *cfg = &spec->autocfg;
1203         hda_nid_t fixed, ext;
1204         int i;
1205
1206         /* there must be only two mic inputs exclusively */
1207         for (i = AUTO_PIN_LINE; i < AUTO_PIN_LAST; i++)
1208                 if (cfg->input_pins[i])
1209                         return;
1210
1211         fixed = ext = 0;
1212         for (i = AUTO_PIN_MIC; i <= AUTO_PIN_FRONT_MIC; i++) {
1213                 hda_nid_t nid = cfg->input_pins[i];
1214                 unsigned int defcfg;
1215                 if (!nid)
1216                         return;
1217                 defcfg = snd_hda_codec_get_pincfg(codec, nid);
1218                 switch (get_defcfg_connect(defcfg)) {
1219                 case AC_JACK_PORT_FIXED:
1220                         if (fixed)
1221                                 return; /* already occupied */
1222                         fixed = nid;
1223                         break;
1224                 case AC_JACK_PORT_COMPLEX:
1225                         if (ext)
1226                                 return; /* already occupied */
1227                         ext = nid;
1228                         break;
1229                 default:
1230                         return; /* invalid entry */
1231                 }
1232         }
1233         if (!(get_wcaps(codec, ext) & AC_WCAP_UNSOL_CAP))
1234                 return; /* no unsol support */
1235         snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x\n",
1236                     ext, fixed);
1237         spec->ext_mic.pin = ext;
1238         spec->int_mic.pin = fixed;
1239         spec->ext_mic.mux_idx = MUX_IDX_UNDEF; /* set later */
1240         spec->int_mic.mux_idx = MUX_IDX_UNDEF; /* set later */
1241         spec->auto_mic = 1;
1242         snd_hda_codec_write_cache(codec, spec->ext_mic.pin, 0,
1243                                   AC_VERB_SET_UNSOLICITED_ENABLE,
1244                                   AC_USRSP_EN | ALC880_MIC_EVENT);
1245         spec->unsol_event = alc_sku_unsol_event;
1246 }
1247
1248 /* check subsystem ID and set up device-specific initialization;
1249  * return 1 if initialized, 0 if invalid SSID
1250  */
1251 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1252  *      31 ~ 16 :       Manufacture ID
1253  *      15 ~ 8  :       SKU ID
1254  *      7  ~ 0  :       Assembly ID
1255  *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1256  */
1257 static int alc_subsystem_id(struct hda_codec *codec,
1258                             hda_nid_t porta, hda_nid_t porte,
1259                             hda_nid_t portd)
1260 {
1261         unsigned int ass, tmp, i;
1262         unsigned nid;
1263         struct alc_spec *spec = codec->spec;
1264
1265         ass = codec->subsystem_id & 0xffff;
1266         if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1267                 goto do_sku;
1268
1269         /* invalid SSID, check the special NID pin defcfg instead */
1270         /*
1271          * 31~30        : port connectivity
1272          * 29~21        : reserve
1273          * 20           : PCBEEP input
1274          * 19~16        : Check sum (15:1)
1275          * 15~1         : Custom
1276          * 0            : override
1277         */
1278         nid = 0x1d;
1279         if (codec->vendor_id == 0x10ec0260)
1280                 nid = 0x17;
1281         ass = snd_hda_codec_get_pincfg(codec, nid);
1282         snd_printd("realtek: No valid SSID, "
1283                    "checking pincfg 0x%08x for NID 0x%x\n",
1284                    ass, nid);
1285         if (!(ass & 1) && !(ass & 0x100000))
1286                 return 0;
1287         if ((ass >> 30) != 1)   /* no physical connection */
1288                 return 0;
1289
1290         /* check sum */
1291         tmp = 0;
1292         for (i = 1; i < 16; i++) {
1293                 if ((ass >> i) & 1)
1294                         tmp++;
1295         }
1296         if (((ass >> 16) & 0xf) != tmp)
1297                 return 0;
1298 do_sku:
1299         snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1300                    ass & 0xffff, codec->vendor_id);
1301         /*
1302          * 0 : override
1303          * 1 :  Swap Jack
1304          * 2 : 0 --> Desktop, 1 --> Laptop
1305          * 3~5 : External Amplifier control
1306          * 7~6 : Reserved
1307         */
1308         tmp = (ass & 0x38) >> 3;        /* external Amp control */
1309         switch (tmp) {
1310         case 1:
1311                 spec->init_amp = ALC_INIT_GPIO1;
1312                 break;
1313         case 3:
1314                 spec->init_amp = ALC_INIT_GPIO2;
1315                 break;
1316         case 7:
1317                 spec->init_amp = ALC_INIT_GPIO3;
1318                 break;
1319         case 5:
1320                 spec->init_amp = ALC_INIT_DEFAULT;
1321                 break;
1322         }
1323
1324         /* is laptop or Desktop and enable the function "Mute internal speaker
1325          * when the external headphone out jack is plugged"
1326          */
1327         if (!(ass & 0x8000))
1328                 return 1;
1329         /*
1330          * 10~8 : Jack location
1331          * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1332          * 14~13: Resvered
1333          * 15   : 1 --> enable the function "Mute internal speaker
1334          *              when the external headphone out jack is plugged"
1335          */
1336         if (!spec->autocfg.hp_pins[0]) {
1337                 hda_nid_t nid;
1338                 tmp = (ass >> 11) & 0x3;        /* HP to chassis */
1339                 if (tmp == 0)
1340                         nid = porta;
1341                 else if (tmp == 1)
1342                         nid = porte;
1343                 else if (tmp == 2)
1344                         nid = portd;
1345                 else
1346                         return 1;
1347                 for (i = 0; i < spec->autocfg.line_outs; i++)
1348                         if (spec->autocfg.line_out_pins[i] == nid)
1349                                 return 1;
1350                 spec->autocfg.hp_pins[0] = nid;
1351         }
1352
1353         alc_init_auto_hp(codec);
1354         alc_init_auto_mic(codec);
1355         return 1;
1356 }
1357
1358 static void alc_ssid_check(struct hda_codec *codec,
1359                            hda_nid_t porta, hda_nid_t porte, hda_nid_t portd)
1360 {
1361         if (!alc_subsystem_id(codec, porta, porte, portd)) {
1362                 struct alc_spec *spec = codec->spec;
1363                 snd_printd("realtek: "
1364                            "Enable default setup for auto mode as fallback\n");
1365                 spec->init_amp = ALC_INIT_DEFAULT;
1366                 alc_init_auto_hp(codec);
1367                 alc_init_auto_mic(codec);
1368         }
1369 }
1370
1371 /*
1372  * Fix-up pin default configurations and add default verbs
1373  */
1374
1375 struct alc_pincfg {
1376         hda_nid_t nid;
1377         u32 val;
1378 };
1379
1380 struct alc_fixup {
1381         const struct alc_pincfg *pins;
1382         const struct hda_verb *verbs;
1383 };
1384
1385 static void alc_pick_fixup(struct hda_codec *codec,
1386                            const struct snd_pci_quirk *quirk,
1387                            const struct alc_fixup *fix)
1388 {
1389         const struct alc_pincfg *cfg;
1390
1391         quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1392         if (!quirk)
1393                 return;
1394
1395         fix += quirk->value;
1396         cfg = fix->pins;
1397         if (cfg) {
1398                 for (; cfg->nid; cfg++)
1399                         snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val);
1400         }
1401         if (fix->verbs)
1402                 add_verb(codec->spec, fix->verbs);
1403 }
1404
1405 /*
1406  * ALC888
1407  */
1408
1409 /*
1410  * 2ch mode
1411  */
1412 static struct hda_verb alc888_4ST_ch2_intel_init[] = {
1413 /* Mic-in jack as mic in */
1414         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1415         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1416 /* Line-in jack as Line in */
1417         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1418         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1419 /* Line-Out as Front */
1420         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1421         { } /* end */
1422 };
1423
1424 /*
1425  * 4ch mode
1426  */
1427 static struct hda_verb alc888_4ST_ch4_intel_init[] = {
1428 /* Mic-in jack as mic in */
1429         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1430         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1431 /* Line-in jack as Surround */
1432         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1433         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1434 /* Line-Out as Front */
1435         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1436         { } /* end */
1437 };
1438
1439 /*
1440  * 6ch mode
1441  */
1442 static struct hda_verb alc888_4ST_ch6_intel_init[] = {
1443 /* Mic-in jack as CLFE */
1444         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1445         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1446 /* Line-in jack as Surround */
1447         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1448         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1449 /* Line-Out as CLFE (workaround because Mic-in is not loud enough) */
1450         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1451         { } /* end */
1452 };
1453
1454 /*
1455  * 8ch mode
1456  */
1457 static struct hda_verb alc888_4ST_ch8_intel_init[] = {
1458 /* Mic-in jack as CLFE */
1459         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1460         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1461 /* Line-in jack as Surround */
1462         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1463         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1464 /* Line-Out as Side */
1465         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1466         { } /* end */
1467 };
1468
1469 static struct hda_channel_mode alc888_4ST_8ch_intel_modes[4] = {
1470         { 2, alc888_4ST_ch2_intel_init },
1471         { 4, alc888_4ST_ch4_intel_init },
1472         { 6, alc888_4ST_ch6_intel_init },
1473         { 8, alc888_4ST_ch8_intel_init },
1474 };
1475
1476 /*
1477  * ALC888 Fujitsu Siemens Amillo xa3530
1478  */
1479
1480 static struct hda_verb alc888_fujitsu_xa3530_verbs[] = {
1481 /* Front Mic: set to PIN_IN (empty by default) */
1482         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1483 /* Connect Internal HP to Front */
1484         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1485         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1486         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1487 /* Connect Bass HP to Front */
1488         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1489         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1490         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1491 /* Connect Line-Out side jack (SPDIF) to Side */
1492         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1493         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1494         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1495 /* Connect Mic jack to CLFE */
1496         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1497         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1498         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},
1499 /* Connect Line-in jack to Surround */
1500         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1501         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1502         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
1503 /* Connect HP out jack to Front */
1504         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1505         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1506         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1507 /* Enable unsolicited event for HP jack and Line-out jack */
1508         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1509         {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1510         {}
1511 };
1512
1513 static void alc_automute_amp(struct hda_codec *codec)
1514 {
1515         struct alc_spec *spec = codec->spec;
1516         unsigned int val, mute, pincap;
1517         hda_nid_t nid;
1518         int i;
1519
1520         spec->jack_present = 0;
1521         for (i = 0; i < ARRAY_SIZE(spec->autocfg.hp_pins); i++) {
1522                 nid = spec->autocfg.hp_pins[i];
1523                 if (!nid)
1524                         break;
1525                 pincap = snd_hda_query_pin_caps(codec, nid);
1526                 if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */
1527                         snd_hda_codec_read(codec, nid, 0,
1528                                            AC_VERB_SET_PIN_SENSE, 0);
1529                 val = snd_hda_codec_read(codec, nid, 0,
1530                                          AC_VERB_GET_PIN_SENSE, 0);
1531                 if (val & AC_PINSENSE_PRESENCE) {
1532                         spec->jack_present = 1;
1533                         break;
1534                 }
1535         }
1536
1537         mute = spec->jack_present ? HDA_AMP_MUTE : 0;
1538         /* Toggle internal speakers muting */
1539         for (i = 0; i < ARRAY_SIZE(spec->autocfg.speaker_pins); i++) {
1540                 nid = spec->autocfg.speaker_pins[i];
1541                 if (!nid)
1542                         break;
1543                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
1544                                          HDA_AMP_MUTE, mute);
1545         }
1546 }
1547
1548 static void alc_automute_amp_unsol_event(struct hda_codec *codec,
1549                                          unsigned int res)
1550 {
1551         if (codec->vendor_id == 0x10ec0880)
1552                 res >>= 28;
1553         else
1554                 res >>= 26;
1555         if (res == ALC880_HP_EVENT)
1556                 alc_automute_amp(codec);
1557 }
1558
1559 static void alc889_automute_setup(struct hda_codec *codec)
1560 {
1561         struct alc_spec *spec = codec->spec;
1562
1563         spec->autocfg.hp_pins[0] = 0x15;
1564         spec->autocfg.speaker_pins[0] = 0x14;
1565         spec->autocfg.speaker_pins[1] = 0x16;
1566         spec->autocfg.speaker_pins[2] = 0x17;
1567         spec->autocfg.speaker_pins[3] = 0x19;
1568         spec->autocfg.speaker_pins[4] = 0x1a;
1569 }
1570
1571 static void alc889_intel_init_hook(struct hda_codec *codec)
1572 {
1573         alc889_coef_init(codec);
1574         alc_automute_amp(codec);
1575 }
1576
1577 static void alc888_fujitsu_xa3530_setup(struct hda_codec *codec)
1578 {
1579         struct alc_spec *spec = codec->spec;
1580
1581         spec->autocfg.hp_pins[0] = 0x17; /* line-out */
1582         spec->autocfg.hp_pins[1] = 0x1b; /* hp */
1583         spec->autocfg.speaker_pins[0] = 0x14; /* speaker */
1584         spec->autocfg.speaker_pins[1] = 0x15; /* bass */
1585 }
1586
1587 /*
1588  * ALC888 Acer Aspire 4930G model
1589  */
1590
1591 static struct hda_verb alc888_acer_aspire_4930g_verbs[] = {
1592 /* Front Mic: set to PIN_IN (empty by default) */
1593         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1594 /* Unselect Front Mic by default in input mixer 3 */
1595         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1596 /* Enable unsolicited event for HP jack */
1597         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1598 /* Connect Internal HP to front */
1599         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1600         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1601         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1602 /* Connect HP out to front */
1603         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1604         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1605         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1606         { }
1607 };
1608
1609 /*
1610  * ALC888 Acer Aspire 6530G model
1611  */
1612
1613 static struct hda_verb alc888_acer_aspire_6530g_verbs[] = {
1614 /* Bias voltage on for external mic port */
1615         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN | PIN_VREF80},
1616 /* Front Mic: set to PIN_IN (empty by default) */
1617         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1618 /* Unselect Front Mic by default in input mixer 3 */
1619         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1620 /* Enable unsolicited event for HP jack */
1621         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1622 /* Enable speaker output */
1623         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1624         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1625 /* Enable headphone output */
1626         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | PIN_HP},
1627         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1628         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1629         { }
1630 };
1631
1632 /*
1633  * ALC889 Acer Aspire 8930G model
1634  */
1635
1636 static struct hda_verb alc889_acer_aspire_8930g_verbs[] = {
1637 /* Front Mic: set to PIN_IN (empty by default) */
1638         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1639 /* Unselect Front Mic by default in input mixer 3 */
1640         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1641 /* Enable unsolicited event for HP jack */
1642         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1643 /* Connect Internal Front to Front */
1644         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1645         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1646         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1647 /* Connect Internal Rear to Rear */
1648         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1649         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1650         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},
1651 /* Connect Internal CLFE to CLFE */
1652         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1653         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1654         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
1655 /* Connect HP out to Front */
1656         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | PIN_HP},
1657         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1658         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1659 /* Enable all DACs */
1660 /*  DAC DISABLE/MUTE 1? */
1661 /*  setting bits 1-5 disables DAC nids 0x02-0x06 apparently. Init=0x38 */
1662         {0x20, AC_VERB_SET_COEF_INDEX, 0x03},
1663         {0x20, AC_VERB_SET_PROC_COEF, 0x0000},
1664 /*  DAC DISABLE/MUTE 2? */
1665 /*  some bit here disables the other DACs. Init=0x4900 */
1666         {0x20, AC_VERB_SET_COEF_INDEX, 0x08},
1667         {0x20, AC_VERB_SET_PROC_COEF, 0x0000},
1668 /* Enable amplifiers */
1669         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
1670         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
1671 /* DMIC fix
1672  * This laptop has a stereo digital microphone. The mics are only 1cm apart
1673  * which makes the stereo useless. However, either the mic or the ALC889
1674  * makes the signal become a difference/sum signal instead of standard
1675  * stereo, which is annoying. So instead we flip this bit which makes the
1676  * codec replicate the sum signal to both channels, turning it into a
1677  * normal mono mic.
1678  */
1679 /*  DMIC_CONTROL? Init value = 0x0001 */
1680         {0x20, AC_VERB_SET_COEF_INDEX, 0x0b},
1681         {0x20, AC_VERB_SET_PROC_COEF, 0x0003},
1682         { }
1683 };
1684
1685 static struct hda_input_mux alc888_2_capture_sources[2] = {
1686         /* Front mic only available on one ADC */
1687         {
1688                 .num_items = 4,
1689                 .items = {
1690                         { "Mic", 0x0 },
1691                         { "Line", 0x2 },
1692                         { "CD", 0x4 },
1693                         { "Front Mic", 0xb },
1694                 },
1695         },
1696         {
1697                 .num_items = 3,
1698                 .items = {
1699                         { "Mic", 0x0 },
1700                         { "Line", 0x2 },
1701                         { "CD", 0x4 },
1702                 },
1703         }
1704 };
1705
1706 static struct hda_input_mux alc888_acer_aspire_6530_sources[2] = {
1707         /* Interal mic only available on one ADC */
1708         {
1709                 .num_items = 5,
1710                 .items = {
1711                         { "Ext Mic", 0x0 },
1712                         { "Line In", 0x2 },
1713                         { "CD", 0x4 },
1714                         { "Input Mix", 0xa },
1715                         { "Int Mic", 0xb },
1716                 },
1717         },
1718         {
1719                 .num_items = 4,
1720                 .items = {
1721                         { "Ext Mic", 0x0 },
1722                         { "Line In", 0x2 },
1723                         { "CD", 0x4 },
1724                         { "Input Mix", 0xa },
1725                 },
1726         }
1727 };
1728
1729 static struct hda_input_mux alc889_capture_sources[3] = {
1730         /* Digital mic only available on first "ADC" */
1731         {
1732                 .num_items = 5,
1733                 .items = {
1734                         { "Mic", 0x0 },
1735                         { "Line", 0x2 },
1736                         { "CD", 0x4 },
1737                         { "Front Mic", 0xb },
1738                         { "Input Mix", 0xa },
1739                 },
1740         },
1741         {
1742                 .num_items = 4,
1743                 .items = {
1744                         { "Mic", 0x0 },
1745                         { "Line", 0x2 },
1746                         { "CD", 0x4 },
1747                         { "Input Mix", 0xa },
1748                 },
1749         },
1750         {
1751                 .num_items = 4,
1752                 .items = {
1753                         { "Mic", 0x0 },
1754                         { "Line", 0x2 },
1755                         { "CD", 0x4 },
1756                         { "Input Mix", 0xa },
1757                 },
1758         }
1759 };
1760
1761 static struct snd_kcontrol_new alc888_base_mixer[] = {
1762         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1763         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1764         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1765         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1766         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
1767                 HDA_OUTPUT),
1768         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1769         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1770         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1771         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1772         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1773         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1774         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1775         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1776         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1777         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1778         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
1779         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1780         { } /* end */
1781 };
1782
1783 static void alc888_acer_aspire_4930g_setup(struct hda_codec *codec)
1784 {
1785         struct alc_spec *spec = codec->spec;
1786
1787         spec->autocfg.hp_pins[0] = 0x15;
1788         spec->autocfg.speaker_pins[0] = 0x14;
1789 }
1790
1791 static void alc888_acer_aspire_6530g_setup(struct hda_codec *codec)
1792 {
1793         struct alc_spec *spec = codec->spec;
1794
1795         spec->autocfg.hp_pins[0] = 0x15;
1796         spec->autocfg.speaker_pins[0] = 0x14;
1797         spec->autocfg.speaker_pins[1] = 0x16;
1798         spec->autocfg.speaker_pins[2] = 0x17;
1799 }
1800
1801 static void alc889_acer_aspire_8930g_setup(struct hda_codec *codec)
1802 {
1803         struct alc_spec *spec = codec->spec;
1804
1805         spec->autocfg.hp_pins[0] = 0x15;
1806         spec->autocfg.speaker_pins[0] = 0x14;
1807         spec->autocfg.speaker_pins[1] = 0x16;
1808         spec->autocfg.speaker_pins[2] = 0x1b;
1809 }
1810
1811 /*
1812  * ALC880 3-stack model
1813  *
1814  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
1815  * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
1816  *                 F-Mic = 0x1b, HP = 0x19
1817  */
1818
1819 static hda_nid_t alc880_dac_nids[4] = {
1820         /* front, rear, clfe, rear_surr */
1821         0x02, 0x05, 0x04, 0x03
1822 };
1823
1824 static hda_nid_t alc880_adc_nids[3] = {
1825         /* ADC0-2 */
1826         0x07, 0x08, 0x09,
1827 };
1828
1829 /* The datasheet says the node 0x07 is connected from inputs,
1830  * but it shows zero connection in the real implementation on some devices.
1831  * Note: this is a 915GAV bug, fixed on 915GLV
1832  */
1833 static hda_nid_t alc880_adc_nids_alt[2] = {
1834         /* ADC1-2 */
1835         0x08, 0x09,
1836 };
1837
1838 #define ALC880_DIGOUT_NID       0x06
1839 #define ALC880_DIGIN_NID        0x0a
1840
1841 static struct hda_input_mux alc880_capture_source = {
1842         .num_items = 4,
1843         .items = {
1844                 { "Mic", 0x0 },
1845                 { "Front Mic", 0x3 },
1846                 { "Line", 0x2 },
1847                 { "CD", 0x4 },
1848         },
1849 };
1850
1851 /* channel source setting (2/6 channel selection for 3-stack) */
1852 /* 2ch mode */
1853 static struct hda_verb alc880_threestack_ch2_init[] = {
1854         /* set line-in to input, mute it */
1855         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1856         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1857         /* set mic-in to input vref 80%, mute it */
1858         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1859         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1860         { } /* end */
1861 };
1862
1863 /* 6ch mode */
1864 static struct hda_verb alc880_threestack_ch6_init[] = {
1865         /* set line-in to output, unmute it */
1866         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1867         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1868         /* set mic-in to output, unmute it */
1869         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1870         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1871         { } /* end */
1872 };
1873
1874 static struct hda_channel_mode alc880_threestack_modes[2] = {
1875         { 2, alc880_threestack_ch2_init },
1876         { 6, alc880_threestack_ch6_init },
1877 };
1878
1879 static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
1880         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1881         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1882         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1883         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
1884         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1885         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1886         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1887         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1888         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1889         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1890         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1891         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1892         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1893         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1894         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
1895         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
1896         HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
1897         {
1898                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1899                 .name = "Channel Mode",
1900                 .info = alc_ch_mode_info,
1901                 .get = alc_ch_mode_get,
1902                 .put = alc_ch_mode_put,
1903         },
1904         { } /* end */
1905 };
1906
1907 /* capture mixer elements */
1908 static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1909                             struct snd_ctl_elem_info *uinfo)
1910 {
1911         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1912         struct alc_spec *spec = codec->spec;
1913         int err;
1914
1915         mutex_lock(&codec->control_mutex);
1916         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1917                                                       HDA_INPUT);
1918         err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
1919         mutex_unlock(&codec->control_mutex);
1920         return err;
1921 }
1922
1923 static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1924                            unsigned int size, unsigned int __user *tlv)
1925 {
1926         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1927         struct alc_spec *spec = codec->spec;
1928         int err;
1929
1930         mutex_lock(&codec->control_mutex);
1931         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1932                                                       HDA_INPUT);
1933         err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
1934         mutex_unlock(&codec->control_mutex);
1935         return err;
1936 }
1937
1938 typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1939                              struct snd_ctl_elem_value *ucontrol);
1940
1941 static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1942                                  struct snd_ctl_elem_value *ucontrol,
1943                                  getput_call_t func)
1944 {
1945         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1946         struct alc_spec *spec = codec->spec;
1947         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1948         int err;
1949
1950         mutex_lock(&codec->control_mutex);
1951         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[adc_idx],
1952                                                       3, 0, HDA_INPUT);
1953         err = func(kcontrol, ucontrol);
1954         mutex_unlock(&codec->control_mutex);
1955         return err;
1956 }
1957
1958 static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1959                            struct snd_ctl_elem_value *ucontrol)
1960 {
1961         return alc_cap_getput_caller(kcontrol, ucontrol,
1962                                      snd_hda_mixer_amp_volume_get);
1963 }
1964
1965 static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1966                            struct snd_ctl_elem_value *ucontrol)
1967 {
1968         return alc_cap_getput_caller(kcontrol, ucontrol,
1969                                      snd_hda_mixer_amp_volume_put);
1970 }
1971
1972 /* capture mixer elements */
1973 #define alc_cap_sw_info         snd_ctl_boolean_stereo_info
1974
1975 static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1976                           struct snd_ctl_elem_value *ucontrol)
1977 {
1978         return alc_cap_getput_caller(kcontrol, ucontrol,
1979                                      snd_hda_mixer_amp_switch_get);
1980 }
1981
1982 static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1983                           struct snd_ctl_elem_value *ucontrol)
1984 {
1985         return alc_cap_getput_caller(kcontrol, ucontrol,
1986                                      snd_hda_mixer_amp_switch_put);
1987 }
1988
1989 #define _DEFINE_CAPMIX(num) \
1990         { \
1991                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1992                 .name = "Capture Switch", \
1993                 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1994                 .count = num, \
1995                 .info = alc_cap_sw_info, \
1996                 .get = alc_cap_sw_get, \
1997                 .put = alc_cap_sw_put, \
1998         }, \
1999         { \
2000                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2001                 .name = "Capture Volume", \
2002                 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
2003                            SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
2004                            SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
2005                 .count = num, \
2006                 .info = alc_cap_vol_info, \
2007                 .get = alc_cap_vol_get, \
2008                 .put = alc_cap_vol_put, \
2009                 .tlv = { .c = alc_cap_vol_tlv }, \
2010         }
2011
2012 #define _DEFINE_CAPSRC(num) \
2013         { \
2014                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2015                 /* .name = "Capture Source", */ \
2016                 .name = "Input Source", \
2017                 .count = num, \
2018                 .info = alc_mux_enum_info, \
2019                 .get = alc_mux_enum_get, \
2020                 .put = alc_mux_enum_put, \
2021         }
2022
2023 #define DEFINE_CAPMIX(num) \
2024 static struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
2025         _DEFINE_CAPMIX(num),                                  \
2026         _DEFINE_CAPSRC(num),                                  \
2027         { } /* end */                                         \
2028 }
2029
2030 #define DEFINE_CAPMIX_NOSRC(num) \
2031 static struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
2032         _DEFINE_CAPMIX(num),                                        \
2033         { } /* end */                                               \
2034 }
2035
2036 /* up to three ADCs */
2037 DEFINE_CAPMIX(1);
2038 DEFINE_CAPMIX(2);
2039 DEFINE_CAPMIX(3);
2040 DEFINE_CAPMIX_NOSRC(1);
2041 DEFINE_CAPMIX_NOSRC(2);
2042 DEFINE_CAPMIX_NOSRC(3);
2043
2044 /*
2045  * ALC880 5-stack model
2046  *
2047  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
2048  *      Side = 0x02 (0xd)
2049  * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
2050  *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
2051  */
2052
2053 /* additional mixers to alc880_three_stack_mixer */
2054 static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
2055         HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2056         HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
2057         { } /* end */
2058 };
2059
2060 /* channel source setting (6/8 channel selection for 5-stack) */
2061 /* 6ch mode */
2062 static struct hda_verb alc880_fivestack_ch6_init[] = {
2063         /* set line-in to input, mute it */
2064         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2065         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2066         { } /* end */
2067 };
2068
2069 /* 8ch mode */
2070 static struct hda_verb alc880_fivestack_ch8_init[] = {
2071         /* set line-in to output, unmute it */
2072         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2073         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2074         { } /* end */
2075 };
2076
2077 static struct hda_channel_mode alc880_fivestack_modes[2] = {
2078         { 6, alc880_fivestack_ch6_init },
2079         { 8, alc880_fivestack_ch8_init },
2080 };
2081
2082
2083 /*
2084  * ALC880 6-stack model
2085  *
2086  * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
2087  *      Side = 0x05 (0x0f)
2088  * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
2089  *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
2090  */
2091
2092 static hda_nid_t alc880_6st_dac_nids[4] = {
2093         /* front, rear, clfe, rear_surr */
2094         0x02, 0x03, 0x04, 0x05
2095 };
2096
2097 static struct hda_input_mux alc880_6stack_capture_source = {
2098         .num_items = 4,
2099         .items = {
2100                 { "Mic", 0x0 },
2101                 { "Front Mic", 0x1 },
2102                 { "Line", 0x2 },
2103                 { "CD", 0x4 },
2104         },
2105 };
2106
2107 /* fixed 8-channels */
2108 static struct hda_channel_mode alc880_sixstack_modes[1] = {
2109         { 8, NULL },
2110 };
2111
2112 static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
2113         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2114         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2115         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2116         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2117         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2118         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2119         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2120         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2121         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2122         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
2123         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2124         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2125         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2126         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2127         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2128         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2129         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2130         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2131         {
2132                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2133                 .name = "Channel Mode",
2134                 .info = alc_ch_mode_info,
2135                 .get = alc_ch_mode_get,
2136                 .put = alc_ch_mode_put,
2137         },
2138         { } /* end */
2139 };
2140
2141
2142 /*
2143  * ALC880 W810 model
2144  *
2145  * W810 has rear IO for:
2146  * Front (DAC 02)
2147  * Surround (DAC 03)
2148  * Center/LFE (DAC 04)
2149  * Digital out (06)
2150  *
2151  * The system also has a pair of internal speakers, and a headphone jack.
2152  * These are both connected to Line2 on the codec, hence to DAC 02.
2153  *
2154  * There is a variable resistor to control the speaker or headphone
2155  * volume. This is a hardware-only device without a software API.
2156  *
2157  * Plugging headphones in will disable the internal speakers. This is
2158  * implemented in hardware, not via the driver using jack sense. In
2159  * a similar fashion, plugging into the rear socket marked "front" will
2160  * disable both the speakers and headphones.
2161  *
2162  * For input, there's a microphone jack, and an "audio in" jack.
2163  * These may not do anything useful with this driver yet, because I
2164  * haven't setup any initialization verbs for these yet...
2165  */
2166
2167 static hda_nid_t alc880_w810_dac_nids[3] = {
2168         /* front, rear/surround, clfe */
2169         0x02, 0x03, 0x04
2170 };
2171
2172 /* fixed 6 channels */
2173 static struct hda_channel_mode alc880_w810_modes[1] = {
2174         { 6, NULL }
2175 };
2176
2177 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
2178 static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
2179         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2180         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2181         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2182         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2183         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2184         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2185         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2186         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2187         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
2188         { } /* end */
2189 };
2190
2191
2192 /*
2193  * Z710V model
2194  *
2195  * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
2196  * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
2197  *                 Line = 0x1a
2198  */
2199
2200 static hda_nid_t alc880_z71v_dac_nids[1] = {
2201         0x02
2202 };
2203 #define ALC880_Z71V_HP_DAC      0x03
2204
2205 /* fixed 2 channels */
2206 static struct hda_channel_mode alc880_2_jack_modes[1] = {
2207         { 2, NULL }
2208 };
2209
2210 static struct snd_kcontrol_new alc880_z71v_mixer[] = {
2211         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2212         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2213         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2214         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
2215         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2216         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2217         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2218         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2219         { } /* end */
2220 };
2221
2222
2223 /*
2224  * ALC880 F1734 model
2225  *
2226  * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
2227  * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
2228  */
2229
2230 static hda_nid_t alc880_f1734_dac_nids[1] = {
2231         0x03
2232 };
2233 #define ALC880_F1734_HP_DAC     0x02
2234
2235 static struct snd_kcontrol_new alc880_f1734_mixer[] = {
2236         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2237         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2238         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2239         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2240         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2241         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2242         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2243         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2244         { } /* end */
2245 };
2246
2247 static struct hda_input_mux alc880_f1734_capture_source = {
2248         .num_items = 2,
2249         .items = {
2250                 { "Mic", 0x1 },
2251                 { "CD", 0x4 },
2252         },
2253 };
2254
2255
2256 /*
2257  * ALC880 ASUS model
2258  *
2259  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
2260  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
2261  *  Mic = 0x18, Line = 0x1a
2262  */
2263
2264 #define alc880_asus_dac_nids    alc880_w810_dac_nids    /* identical with w810 */
2265 #define alc880_asus_modes       alc880_threestack_modes /* 2/6 channel mode */
2266
2267 static struct snd_kcontrol_new alc880_asus_mixer[] = {
2268         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2269         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2270         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2271         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2272         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2273         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2274         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2275         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2276         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2277         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2278         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2279         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2280         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2281         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2282         {
2283                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2284                 .name = "Channel Mode",
2285                 .info = alc_ch_mode_info,
2286                 .get = alc_ch_mode_get,
2287                 .put = alc_ch_mode_put,
2288         },
2289         { } /* end */
2290 };
2291
2292 /*
2293  * ALC880 ASUS W1V model
2294  *
2295  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
2296  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
2297  *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
2298  */
2299
2300 /* additional mixers to alc880_asus_mixer */
2301 static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
2302         HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
2303         HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
2304         { } /* end */
2305 };
2306
2307 /* TCL S700 */
2308 static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
2309         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2310         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
2311         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
2312         HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
2313         HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
2314         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
2315         HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
2316         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
2317         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
2318         { } /* end */
2319 };
2320
2321 /* Uniwill */
2322 static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
2323         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2324         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2325         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2326         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2327         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2328         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2329         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2330         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2331         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2332         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2333         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2334         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2335         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2336         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2337         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2338         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2339         {
2340                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2341                 .name = "Channel Mode",
2342                 .info = alc_ch_mode_info,
2343                 .get = alc_ch_mode_get,
2344                 .put = alc_ch_mode_put,
2345         },
2346         { } /* end */
2347 };
2348
2349 static struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
2350         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2351         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2352         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2353         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2354         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2355         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2356         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2357         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2358         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2359         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2360         { } /* end */
2361 };
2362
2363 static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
2364         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2365         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2366         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2367         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2368         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2369         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2370         { } /* end */
2371 };
2372
2373 /*
2374  * virtual master controls
2375  */
2376
2377 /*
2378  * slave controls for virtual master
2379  */
2380 static const char *alc_slave_vols[] = {
2381         "Front Playback Volume",
2382         "Surround Playback Volume",
2383         "Center Playback Volume",
2384         "LFE Playback Volume",
2385         "Side Playback Volume",
2386         "Headphone Playback Volume",
2387         "Speaker Playback Volume",
2388         "Mono Playback Volume",
2389         "Line-Out Playback Volume",
2390         "PCM Playback Volume",
2391         NULL,
2392 };
2393
2394 static const char *alc_slave_sws[] = {
2395         "Front Playback Switch",
2396         "Surround Playback Switch",
2397         "Center Playback Switch",
2398         "LFE Playback Switch",
2399         "Side Playback Switch",
2400         "Headphone Playback Switch",
2401         "Speaker Playback Switch",
2402         "Mono Playback Switch",
2403         "IEC958 Playback Switch",
2404         NULL,
2405 };
2406
2407 /*
2408  * build control elements
2409  */
2410
2411 static void alc_free_kctls(struct hda_codec *codec);
2412
2413 /* additional beep mixers; the actual parameters are overwritten at build */
2414 static struct snd_kcontrol_new alc_beep_mixer[] = {
2415         HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
2416         HDA_CODEC_MUTE("Beep Playback Switch", 0, 0, HDA_INPUT),
2417         { } /* end */
2418 };
2419
2420 static int alc_build_controls(struct hda_codec *codec)
2421 {
2422         struct alc_spec *spec = codec->spec;
2423         int err;
2424         int i;
2425
2426         for (i = 0; i < spec->num_mixers; i++) {
2427                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
2428                 if (err < 0)
2429                         return err;
2430         }
2431         if (spec->cap_mixer) {
2432                 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
2433                 if (err < 0)
2434                         return err;
2435         }
2436         if (spec->multiout.dig_out_nid) {
2437                 err = snd_hda_create_spdif_out_ctls(codec,
2438                                                     spec->multiout.dig_out_nid);
2439                 if (err < 0)
2440                         return err;
2441                 if (!spec->no_analog) {
2442                         err = snd_hda_create_spdif_share_sw(codec,
2443                                                             &spec->multiout);
2444                         if (err < 0)
2445                                 return err;
2446                         spec->multiout.share_spdif = 1;
2447                 }
2448         }
2449         if (spec->dig_in_nid) {
2450                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
2451                 if (err < 0)
2452                         return err;
2453         }
2454
2455         /* create beep controls if needed */
2456         if (spec->beep_amp) {
2457                 struct snd_kcontrol_new *knew;
2458                 for (knew = alc_beep_mixer; knew->name; knew++) {
2459                         struct snd_kcontrol *kctl;
2460                         kctl = snd_ctl_new1(knew, codec);
2461                         if (!kctl)
2462                                 return -ENOMEM;
2463                         kctl->private_value = spec->beep_amp;
2464                         err = snd_hda_ctl_add(codec, kctl);
2465                         if (err < 0)
2466                                 return err;
2467                 }
2468         }
2469
2470         /* if we have no master control, let's create it */
2471         if (!spec->no_analog &&
2472             !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
2473                 unsigned int vmaster_tlv[4];
2474                 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
2475                                         HDA_OUTPUT, vmaster_tlv);
2476                 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
2477                                           vmaster_tlv, alc_slave_vols);
2478                 if (err < 0)
2479                         return err;
2480         }
2481         if (!spec->no_analog &&
2482             !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
2483                 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
2484                                           NULL, alc_slave_sws);
2485                 if (err < 0)
2486                         return err;
2487         }
2488
2489         alc_free_kctls(codec); /* no longer needed */
2490         return 0;
2491 }
2492
2493
2494 /*
2495  * initialize the codec volumes, etc
2496  */
2497
2498 /*
2499  * generic initialization of ADC, input mixers and output mixers
2500  */
2501 static struct hda_verb alc880_volume_init_verbs[] = {
2502         /*
2503          * Unmute ADC0-2 and set the default input to mic-in
2504          */
2505         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
2506         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2507         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
2508         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2509         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
2510         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2511
2512         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2513          * mixer widget
2514          * Note: PASD motherboards uses the Line In 2 as the input for front
2515          * panel mic (mic 2)
2516          */
2517         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
2518         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2519         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2520         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2521         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2522         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2523         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2524         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2525
2526         /*
2527          * Set up output mixers (0x0c - 0x0f)
2528          */
2529         /* set vol=0 to output mixers */
2530         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2531         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2532         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2533         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2534         /* set up input amps for analog loopback */
2535         /* Amp Indices: DAC = 0, mixer = 1 */
2536         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2537         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2538         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2539         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2540         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2541         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2542         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2543         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2544
2545         { }
2546 };
2547
2548 /*
2549  * 3-stack pin configuration:
2550  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
2551  */
2552 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
2553         /*
2554          * preset connection lists of input pins
2555          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2556          */
2557         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2558         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2559         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2560
2561         /*
2562          * Set pin mode and muting
2563          */
2564         /* set front pin widgets 0x14 for output */
2565         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2566         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2567         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2568         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2569         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2570         /* Mic2 (as headphone out) for HP output */
2571         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2572         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2573         /* Line In pin widget for input */
2574         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2575         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2576         /* Line2 (as front mic) pin widget for input and vref at 80% */
2577         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2578         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2579         /* CD pin widget for input */
2580         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2581
2582         { }
2583 };
2584
2585 /*
2586  * 5-stack pin configuration:
2587  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
2588  * line-in/side = 0x1a, f-mic = 0x1b
2589  */
2590 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
2591         /*
2592          * preset connection lists of input pins
2593          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2594          */
2595         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2596         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
2597
2598         /*
2599          * Set pin mode and muting
2600          */
2601         /* set pin widgets 0x14-0x17 for output */
2602         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2603         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2604         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2605         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2606         /* unmute pins for output (no gain on this amp) */
2607         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2608         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2609         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2610         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2611
2612         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2613         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2614         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2615         /* Mic2 (as headphone out) for HP output */
2616         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2617         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2618         /* Line In pin widget for input */
2619         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2620         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2621         /* Line2 (as front mic) pin widget for input and vref at 80% */
2622         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2623         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2624         /* CD pin widget for input */
2625         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2626
2627         { }
2628 };
2629
2630 /*
2631  * W810 pin configuration:
2632  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
2633  */
2634 static struct hda_verb alc880_pin_w810_init_verbs[] = {
2635         /* hphone/speaker input selector: front DAC */
2636         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
2637
2638         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2639         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2640         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2641         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2642         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2643         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2644
2645         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2646         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2647
2648         { }
2649 };
2650
2651 /*
2652  * Z71V pin configuration:
2653  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
2654  */
2655 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
2656         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2657         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2658         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2659         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2660
2661         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2662         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2663         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2664         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2665
2666         { }
2667 };
2668
2669 /*
2670  * 6-stack pin configuration:
2671  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
2672  * f-mic = 0x19, line = 0x1a, HP = 0x1b
2673  */
2674 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
2675         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2676
2677         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2678         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2679         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2680         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2681         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2682         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2683         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2684         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2685
2686         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2687         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2688         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2689         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2690         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2691         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2692         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2693         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2694         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2695
2696         { }
2697 };
2698
2699 /*
2700  * Uniwill pin configuration:
2701  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
2702  * line = 0x1a
2703  */
2704 static struct hda_verb alc880_uniwill_init_verbs[] = {
2705         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2706
2707         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2708         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2709         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2710         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2711         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2712         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2713         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2714         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2715         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2716         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2717         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2718         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2719         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2720         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2721
2722         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2723         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2724         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2725         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2726         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2727         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2728         /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
2729         /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
2730         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2731
2732         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2733         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
2734
2735         { }
2736 };
2737
2738 /*
2739 * Uniwill P53
2740 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19,
2741  */
2742 static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
2743         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2744
2745         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2746         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2747         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2748         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2749         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2750         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2751         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2752         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2753         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2754         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2755         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2756         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2757
2758         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2759         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2760         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2761         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2762         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2763         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2764
2765         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2766         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
2767
2768         { }
2769 };
2770
2771 static struct hda_verb alc880_beep_init_verbs[] = {
2772         { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
2773         { }
2774 };
2775
2776 /* auto-toggle front mic */
2777 static void alc880_uniwill_mic_automute(struct hda_codec *codec)
2778 {
2779         unsigned int present;
2780         unsigned char bits;
2781
2782         present = snd_hda_codec_read(codec, 0x18, 0,
2783                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2784         bits = present ? HDA_AMP_MUTE : 0;
2785         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
2786 }
2787
2788 static void alc880_uniwill_setup(struct hda_codec *codec)
2789 {
2790         struct alc_spec *spec = codec->spec;
2791
2792         spec->autocfg.hp_pins[0] = 0x14;
2793         spec->autocfg.speaker_pins[0] = 0x15;
2794         spec->autocfg.speaker_pins[0] = 0x16;
2795 }
2796
2797 static void alc880_uniwill_init_hook(struct hda_codec *codec)
2798 {
2799         alc_automute_amp(codec);
2800         alc880_uniwill_mic_automute(codec);
2801 }
2802
2803 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
2804                                        unsigned int res)
2805 {
2806         /* Looks like the unsol event is incompatible with the standard
2807          * definition.  4bit tag is placed at 28 bit!
2808          */
2809         switch (res >> 28) {
2810         case ALC880_MIC_EVENT:
2811                 alc880_uniwill_mic_automute(codec);
2812                 break;
2813         default:
2814                 alc_automute_amp_unsol_event(codec, res);
2815                 break;
2816         }
2817 }
2818
2819 static void alc880_uniwill_p53_setup(struct hda_codec *codec)
2820 {
2821         struct alc_spec *spec = codec->spec;
2822
2823         spec->autocfg.hp_pins[0] = 0x14;
2824         spec->autocfg.speaker_pins[0] = 0x15;
2825 }
2826
2827 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
2828 {
2829         unsigned int present;
2830
2831         present = snd_hda_codec_read(codec, 0x21, 0,
2832                                      AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
2833         present &= HDA_AMP_VOLMASK;
2834         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
2835                                  HDA_AMP_VOLMASK, present);
2836         snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
2837                                  HDA_AMP_VOLMASK, present);
2838 }
2839
2840 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
2841                                            unsigned int res)
2842 {
2843         /* Looks like the unsol event is incompatible with the standard
2844          * definition.  4bit tag is placed at 28 bit!
2845          */
2846         if ((res >> 28) == ALC880_DCVOL_EVENT)
2847                 alc880_uniwill_p53_dcvol_automute(codec);
2848         else
2849                 alc_automute_amp_unsol_event(codec, res);
2850 }
2851
2852 /*
2853  * F1734 pin configuration:
2854  * HP = 0x14, speaker-out = 0x15, mic = 0x18
2855  */
2856 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
2857         {0x07, AC_VERB_SET_CONNECT_SEL, 0x01},
2858         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2859         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2860         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2861         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2862
2863         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2864         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2865         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2866         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2867
2868         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2869         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2870         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
2871         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2872         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2873         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2874         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2875         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2876         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2877
2878         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
2879         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_DCVOL_EVENT},
2880
2881         { }
2882 };
2883
2884 /*
2885  * ASUS pin configuration:
2886  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
2887  */
2888 static struct hda_verb alc880_pin_asus_init_verbs[] = {
2889         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2890         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2891         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2892         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2893
2894         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2895         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2896         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2897         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2898         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2899         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2900         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2901         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2902
2903         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2904         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2905         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2906         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2907         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2908         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2909         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2910         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2911         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2912
2913         { }
2914 };
2915
2916 /* Enable GPIO mask and set output */
2917 #define alc880_gpio1_init_verbs alc_gpio1_init_verbs
2918 #define alc880_gpio2_init_verbs alc_gpio2_init_verbs
2919 #define alc880_gpio3_init_verbs alc_gpio3_init_verbs
2920
2921 /* Clevo m520g init */
2922 static struct hda_verb alc880_pin_clevo_init_verbs[] = {
2923         /* headphone output */
2924         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2925         /* line-out */
2926         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2927         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2928         /* Line-in */
2929         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2930         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2931         /* CD */
2932         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2933         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2934         /* Mic1 (rear panel) */
2935         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2936         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2937         /* Mic2 (front panel) */
2938         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2939         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2940         /* headphone */
2941         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2942         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2943         /* change to EAPD mode */
2944         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2945         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2946
2947         { }
2948 };
2949
2950 static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
2951         /* change to EAPD mode */
2952         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2953         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2954
2955         /* Headphone output */
2956         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2957         /* Front output*/
2958         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2959         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
2960
2961         /* Line In pin widget for input */
2962         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2963         /* CD pin widget for input */
2964         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2965         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2966         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2967
2968         /* change to EAPD mode */
2969         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2970         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
2971
2972         { }
2973 };
2974
2975 /*
2976  * LG m1 express dual
2977  *
2978  * Pin assignment:
2979  *   Rear Line-In/Out (blue): 0x14
2980  *   Build-in Mic-In: 0x15
2981  *   Speaker-out: 0x17
2982  *   HP-Out (green): 0x1b
2983  *   Mic-In/Out (red): 0x19
2984  *   SPDIF-Out: 0x1e
2985  */
2986
2987 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
2988 static hda_nid_t alc880_lg_dac_nids[3] = {
2989         0x05, 0x02, 0x03
2990 };
2991
2992 /* seems analog CD is not working */
2993 static struct hda_input_mux alc880_lg_capture_source = {
2994         .num_items = 3,
2995         .items = {
2996                 { "Mic", 0x1 },
2997                 { "Line", 0x5 },
2998                 { "Internal Mic", 0x6 },
2999         },
3000 };
3001
3002 /* 2,4,6 channel modes */
3003 static struct hda_verb alc880_lg_ch2_init[] = {
3004         /* set line-in and mic-in to input */
3005         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
3006         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
3007         { }
3008 };
3009
3010 static struct hda_verb alc880_lg_ch4_init[] = {
3011         /* set line-in to out and mic-in to input */
3012         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
3013         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
3014         { }
3015 };
3016
3017 static struct hda_verb alc880_lg_ch6_init[] = {
3018         /* set line-in and mic-in to output */
3019         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
3020         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
3021         { }
3022 };
3023
3024 static struct hda_channel_mode alc880_lg_ch_modes[3] = {
3025         { 2, alc880_lg_ch2_init },
3026         { 4, alc880_lg_ch4_init },
3027         { 6, alc880_lg_ch6_init },
3028 };
3029
3030 static struct snd_kcontrol_new alc880_lg_mixer[] = {
3031         HDA_CODEC_VOLUME("Front Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3032         HDA_BIND_MUTE("Front Playback Switch", 0x0f, 2, HDA_INPUT),
3033         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3034         HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
3035         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
3036         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
3037         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
3038         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
3039         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
3040         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
3041         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
3042         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
3043         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
3044         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
3045         {
3046                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3047                 .name = "Channel Mode",
3048                 .info = alc_ch_mode_info,
3049                 .get = alc_ch_mode_get,
3050                 .put = alc_ch_mode_put,
3051         },
3052         { } /* end */
3053 };
3054
3055 static struct hda_verb alc880_lg_init_verbs[] = {
3056         /* set capture source to mic-in */
3057         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3058         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3059         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3060         /* mute all amp mixer inputs */
3061         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
3062         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
3063         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
3064         /* line-in to input */
3065         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3066         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3067         /* built-in mic */
3068         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3069         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3070         /* speaker-out */
3071         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3072         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3073         /* mic-in to input */
3074         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
3075         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3076         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3077         /* HP-out */
3078         {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
3079         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3080         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3081         /* jack sense */
3082         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3083         { }
3084 };
3085
3086 /* toggle speaker-output according to the hp-jack state */
3087 static void alc880_lg_setup(struct hda_codec *codec)
3088 {
3089         struct alc_spec *spec = codec->spec;
3090
3091         spec->autocfg.hp_pins[0] = 0x1b;
3092         spec->autocfg.speaker_pins[0] = 0x17;
3093 }
3094
3095 /*
3096  * LG LW20
3097  *
3098  * Pin assignment:
3099  *   Speaker-out: 0x14
3100  *   Mic-In: 0x18
3101  *   Built-in Mic-In: 0x19
3102  *   Line-In: 0x1b
3103  *   HP-Out: 0x1a
3104  *   SPDIF-Out: 0x1e
3105  */
3106
3107 static struct hda_input_mux alc880_lg_lw_capture_source = {
3108         .num_items = 3,
3109         .items = {
3110                 { "Mic", 0x0 },
3111                 { "Internal Mic", 0x1 },
3112                 { "Line In", 0x2 },
3113         },
3114 };
3115
3116 #define alc880_lg_lw_modes alc880_threestack_modes
3117
3118 static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
3119         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3120         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
3121         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3122         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
3123         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
3124         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
3125         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
3126         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
3127         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
3128         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
3129         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
3130         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
3131         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
3132         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
3133         {
3134                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3135                 .name = "Channel Mode",
3136                 .info = alc_ch_mode_info,
3137                 .get = alc_ch_mode_get,
3138                 .put = alc_ch_mode_put,
3139         },
3140         { } /* end */
3141 };
3142
3143 static struct hda_verb alc880_lg_lw_init_verbs[] = {
3144         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3145         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
3146         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
3147
3148         /* set capture source to mic-in */
3149         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3150         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3151         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3152         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
3153         /* speaker-out */
3154         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3155         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3156         /* HP-out */
3157         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3158         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3159         /* mic-in to input */
3160         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3161         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3162         /* built-in mic */
3163         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3164         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3165         /* jack sense */
3166         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3167         { }
3168 };
3169
3170 /* toggle speaker-output according to the hp-jack state */
3171 static void alc880_lg_lw_setup(struct hda_codec *codec)
3172 {
3173         struct alc_spec *spec = codec->spec;
3174
3175         spec->autocfg.hp_pins[0] = 0x1b;
3176         spec->autocfg.speaker_pins[0] = 0x14;
3177 }
3178
3179 static struct snd_kcontrol_new alc880_medion_rim_mixer[] = {
3180         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3181         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
3182         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
3183         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
3184         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
3185         HDA_CODEC_MUTE("Internal Playback Switch", 0x0b, 0x1, HDA_INPUT),
3186         { } /* end */
3187 };
3188
3189 static struct hda_input_mux alc880_medion_rim_capture_source = {
3190         .num_items = 2,
3191         .items = {
3192                 { "Mic", 0x0 },
3193                 { "Internal Mic", 0x1 },
3194         },
3195 };
3196
3197 static struct hda_verb alc880_medion_rim_init_verbs[] = {
3198         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3199
3200         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3201         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3202
3203         /* Mic1 (rear panel) pin widget for input and vref at 80% */
3204         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3205         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3206         /* Mic2 (as headphone out) for HP output */
3207         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3208         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3209         /* Internal Speaker */
3210         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3211         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3212
3213         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
3214         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
3215
3216         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3217         { }
3218 };
3219
3220 /* toggle speaker-output according to the hp-jack state */
3221 static void alc880_medion_rim_automute(struct hda_codec *codec)
3222 {
3223         struct alc_spec *spec = codec->spec;
3224         alc_automute_amp(codec);
3225         /* toggle EAPD */
3226         if (spec->jack_present)
3227                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0);
3228         else
3229                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 2);
3230 }
3231
3232 static void alc880_medion_rim_unsol_event(struct hda_codec *codec,
3233                                           unsigned int res)
3234 {
3235         /* Looks like the unsol event is incompatible with the standard
3236          * definition.  4bit tag is placed at 28 bit!
3237          */
3238         if ((res >> 28) == ALC880_HP_EVENT)
3239                 alc880_medion_rim_automute(codec);
3240 }
3241
3242 static void alc880_medion_rim_setup(struct hda_codec *codec)
3243 {
3244         struct alc_spec *spec = codec->spec;
3245
3246         spec->autocfg.hp_pins[0] = 0x14;
3247         spec->autocfg.speaker_pins[0] = 0x1b;
3248 }
3249
3250 #ifdef CONFIG_SND_HDA_POWER_SAVE
3251 static struct hda_amp_list alc880_loopbacks[] = {
3252         { 0x0b, HDA_INPUT, 0 },
3253         { 0x0b, HDA_INPUT, 1 },
3254         { 0x0b, HDA_INPUT, 2 },
3255         { 0x0b, HDA_INPUT, 3 },
3256         { 0x0b, HDA_INPUT, 4 },
3257         { } /* end */
3258 };
3259
3260 static struct hda_amp_list alc880_lg_loopbacks[] = {
3261         { 0x0b, HDA_INPUT, 1 },
3262         { 0x0b, HDA_INPUT, 6 },
3263         { 0x0b, HDA_INPUT, 7 },
3264         { } /* end */
3265 };
3266 #endif
3267
3268 /*
3269  * Common callbacks
3270  */
3271
3272 static int alc_init(struct hda_codec *codec)
3273 {
3274         struct alc_spec *spec = codec->spec;
3275         unsigned int i;
3276
3277         alc_fix_pll(codec);
3278         alc_auto_init_amp(codec, spec->init_amp);
3279
3280         for (i = 0; i < spec->num_init_verbs; i++)
3281                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
3282
3283         if (spec->init_hook)
3284                 spec->init_hook(codec);
3285
3286         return 0;
3287 }
3288
3289 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
3290 {
3291         struct alc_spec *spec = codec->spec;
3292
3293         if (spec->unsol_event)
3294                 spec->unsol_event(codec, res);
3295 }
3296
3297 #ifdef CONFIG_SND_HDA_POWER_SAVE
3298 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
3299 {
3300         struct alc_spec *spec = codec->spec;
3301         return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
3302 }
3303 #endif
3304
3305 /*
3306  * Analog playback callbacks
3307  */
3308 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
3309                                     struct hda_codec *codec,
3310                                     struct snd_pcm_substream *substream)
3311 {
3312         struct alc_spec *spec = codec->spec;
3313         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
3314                                              hinfo);
3315 }
3316
3317 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3318                                        struct hda_codec *codec,
3319                                        unsigned int stream_tag,
3320                                        unsigned int format,
3321                                        struct snd_pcm_substream *substream)
3322 {
3323         struct alc_spec *spec = codec->spec;
3324         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
3325                                                 stream_tag, format, substream);
3326 }
3327
3328 static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
3329                                        struct hda_codec *codec,
3330                                        struct snd_pcm_substream *substream)
3331 {
3332         struct alc_spec *spec = codec->spec;
3333         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
3334 }
3335
3336 /*
3337  * Digital out
3338  */
3339 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
3340                                         struct hda_codec *codec,
3341                                         struct snd_pcm_substream *substream)
3342 {
3343         struct alc_spec *spec = codec->spec;
3344         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
3345 }
3346
3347 static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3348                                            struct hda_codec *codec,
3349                                            unsigned int stream_tag,
3350                                            unsigned int format,
3351                                            struct snd_pcm_substream *substream)
3352 {
3353         struct alc_spec *spec = codec->spec;
3354         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
3355                                              stream_tag, format, substream);
3356 }
3357
3358 static int alc880_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
3359                                            struct hda_codec *codec,
3360                                            struct snd_pcm_substream *substream)
3361 {
3362         struct alc_spec *spec = codec->spec;
3363         return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
3364 }
3365
3366 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
3367                                          struct hda_codec *codec,
3368                                          struct snd_pcm_substream *substream)
3369 {
3370         struct alc_spec *spec = codec->spec;
3371         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
3372 }
3373
3374 /*
3375  * Analog capture
3376  */
3377 static int alc880_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3378                                       struct hda_codec *codec,
3379                                       unsigned int stream_tag,
3380                                       unsigned int format,
3381                                       struct snd_pcm_substream *substream)
3382 {
3383         struct alc_spec *spec = codec->spec;
3384
3385         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
3386                                    stream_tag, 0, format);
3387         return 0;
3388 }
3389
3390 static int alc880_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3391                                       struct hda_codec *codec,
3392                                       struct snd_pcm_substream *substream)
3393 {
3394         struct alc_spec *spec = codec->spec;
3395
3396         snd_hda_codec_cleanup_stream(codec,
3397                                      spec->adc_nids[substream->number + 1]);
3398         return 0;
3399 }
3400
3401
3402 /*
3403  */
3404 static struct hda_pcm_stream alc880_pcm_analog_playback = {
3405         .substreams = 1,
3406         .channels_min = 2,
3407         .channels_max = 8,
3408         /* NID is set in alc_build_pcms */
3409         .ops = {
3410                 .open = alc880_playback_pcm_open,
3411                 .prepare = alc880_playback_pcm_prepare,
3412                 .cleanup = alc880_playback_pcm_cleanup
3413         },
3414 };
3415
3416 static struct hda_pcm_stream alc880_pcm_analog_capture = {
3417         .substreams = 1,
3418         .channels_min = 2,
3419         .channels_max = 2,
3420         /* NID is set in alc_build_pcms */
3421 };
3422
3423 static struct hda_pcm_stream alc880_pcm_analog_alt_playback = {
3424         .substreams = 1,
3425         .channels_min = 2,
3426         .channels_max = 2,
3427         /* NID is set in alc_build_pcms */
3428 };
3429
3430 static struct hda_pcm_stream alc880_pcm_analog_alt_capture = {
3431         .substreams = 2, /* can be overridden */
3432         .channels_min = 2,
3433         .channels_max = 2,
3434         /* NID is set in alc_build_pcms */
3435         .ops = {
3436                 .prepare = alc880_alt_capture_pcm_prepare,
3437                 .cleanup = alc880_alt_capture_pcm_cleanup
3438         },
3439 };
3440
3441 static struct hda_pcm_stream alc880_pcm_digital_playback = {
3442         .substreams = 1,
3443         .channels_min = 2,
3444         .channels_max = 2,
3445         /* NID is set in alc_build_pcms */
3446         .ops = {
3447                 .open = alc880_dig_playback_pcm_open,
3448                 .close = alc880_dig_playback_pcm_close,
3449                 .prepare = alc880_dig_playback_pcm_prepare,
3450                 .cleanup = alc880_dig_playback_pcm_cleanup
3451         },
3452 };
3453
3454 static struct hda_pcm_stream alc880_pcm_digital_capture = {
3455         .substreams = 1,
3456         .channels_min = 2,
3457         .channels_max = 2,
3458         /* NID is set in alc_build_pcms */
3459 };
3460
3461 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
3462 static struct hda_pcm_stream alc_pcm_null_stream = {
3463         .substreams = 0,
3464         .channels_min = 0,
3465         .channels_max = 0,
3466 };
3467
3468 static int alc_build_pcms(struct hda_codec *codec)
3469 {
3470         struct alc_spec *spec = codec->spec;
3471         struct hda_pcm *info = spec->pcm_rec;
3472         int i;
3473
3474         codec->num_pcms = 1;
3475         codec->pcm_info = info;
3476
3477         if (spec->no_analog)
3478                 goto skip_analog;
3479
3480         snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
3481                  "%s Analog", codec->chip_name);
3482         info->name = spec->stream_name_analog;
3483         
3484         if (spec->stream_analog_playback) {
3485                 if (snd_BUG_ON(!spec->multiout.dac_nids))
3486                         return -EINVAL;
3487                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
3488                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
3489         }
3490         if (spec->stream_analog_capture) {
3491                 if (snd_BUG_ON(!spec->adc_nids))
3492                         return -EINVAL;
3493                 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
3494                 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
3495         }
3496
3497         if (spec->channel_mode) {
3498                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
3499                 for (i = 0; i < spec->num_channel_mode; i++) {
3500                         if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
3501                                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
3502                         }
3503                 }
3504         }
3505
3506  skip_analog:
3507         /* SPDIF for stream index #1 */
3508         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
3509                 snprintf(spec->stream_name_digital,
3510                          sizeof(spec->stream_name_digital),
3511                          "%s Digital", codec->chip_name);
3512                 codec->num_pcms = 2;
3513                 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
3514                 info = spec->pcm_rec + 1;
3515                 info->name = spec->stream_name_digital;
3516                 if (spec->dig_out_type)
3517                         info->pcm_type = spec->dig_out_type;
3518                 else
3519                         info->pcm_type = HDA_PCM_TYPE_SPDIF;
3520                 if (spec->multiout.dig_out_nid &&
3521                     spec->stream_digital_playback) {
3522                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
3523                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
3524                 }
3525                 if (spec->dig_in_nid &&
3526                     spec->stream_digital_capture) {
3527                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
3528                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
3529                 }
3530                 /* FIXME: do we need this for all Realtek codec models? */
3531                 codec->spdif_status_reset = 1;
3532         }
3533
3534         if (spec->no_analog)
3535                 return 0;
3536
3537         /* If the use of more than one ADC is requested for the current
3538          * model, configure a second analog capture-only PCM.
3539          */
3540         /* Additional Analaog capture for index #2 */
3541         if ((spec->alt_dac_nid && spec->stream_analog_alt_playback) ||
3542             (spec->num_adc_nids > 1 && spec->stream_analog_alt_capture)) {
3543                 codec->num_pcms = 3;
3544                 info = spec->pcm_rec + 2;
3545                 info->name = spec->stream_name_analog;
3546                 if (spec->alt_dac_nid) {
3547                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
3548                                 *spec->stream_analog_alt_playback;
3549                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
3550                                 spec->alt_dac_nid;
3551                 } else {
3552                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
3553                                 alc_pcm_null_stream;
3554                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
3555                 }
3556                 if (spec->num_adc_nids > 1) {
3557                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
3558                                 *spec->stream_analog_alt_capture;
3559                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
3560                                 spec->adc_nids[1];
3561                         info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
3562                                 spec->num_adc_nids - 1;
3563                 } else {
3564                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
3565                                 alc_pcm_null_stream;
3566                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
3567                 }
3568         }
3569
3570         return 0;
3571 }
3572
3573 static void alc_free_kctls(struct hda_codec *codec)
3574 {
3575         struct alc_spec *spec = codec->spec;
3576
3577         if (spec->kctls.list) {
3578                 struct snd_kcontrol_new *kctl = spec->kctls.list;
3579                 int i;
3580                 for (i = 0; i < spec->kctls.used; i++)
3581                         kfree(kctl[i].name);
3582         }
3583         snd_array_free(&spec->kctls);
3584 }
3585
3586 static void alc_free(struct hda_codec *codec)
3587 {
3588         struct alc_spec *spec = codec->spec;
3589
3590         if (!spec)
3591                 return;
3592
3593         alc_free_kctls(codec);
3594         kfree(spec);
3595         snd_hda_detach_beep_device(codec);
3596 }
3597
3598 #ifdef SND_HDA_NEEDS_RESUME
3599 static int alc_resume(struct hda_codec *codec)
3600 {
3601         codec->patch_ops.init(codec);
3602         snd_hda_codec_resume_amp(codec);
3603         snd_hda_codec_resume_cache(codec);
3604         return 0;
3605 }
3606 #endif
3607
3608 /*
3609  */
3610 static struct hda_codec_ops alc_patch_ops = {
3611         .build_controls = alc_build_controls,
3612         .build_pcms = alc_build_pcms,
3613         .init = alc_init,
3614         .free = alc_free,
3615         .unsol_event = alc_unsol_event,
3616 #ifdef SND_HDA_NEEDS_RESUME
3617         .resume = alc_resume,
3618 #endif
3619 #ifdef CONFIG_SND_HDA_POWER_SAVE
3620         .check_power_status = alc_check_power_status,
3621 #endif
3622 };
3623
3624
3625 /*
3626  * Test configuration for debugging
3627  *
3628  * Almost all inputs/outputs are enabled.  I/O pins can be configured via
3629  * enum controls.
3630  */
3631 #ifdef CONFIG_SND_DEBUG
3632 static hda_nid_t alc880_test_dac_nids[4] = {
3633         0x02, 0x03, 0x04, 0x05
3634 };
3635
3636 static struct hda_input_mux alc880_test_capture_source = {
3637         .num_items = 7,
3638         .items = {
3639                 { "In-1", 0x0 },
3640                 { "In-2", 0x1 },
3641                 { "In-3", 0x2 },
3642                 { "In-4", 0x3 },
3643                 { "CD", 0x4 },
3644                 { "Front", 0x5 },
3645                 { "Surround", 0x6 },
3646         },
3647 };
3648
3649 static struct hda_channel_mode alc880_test_modes[4] = {
3650         { 2, NULL },
3651         { 4, NULL },
3652         { 6, NULL },
3653         { 8, NULL },
3654 };
3655
3656 static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
3657                                  struct snd_ctl_elem_info *uinfo)
3658 {
3659         static char *texts[] = {
3660                 "N/A", "Line Out", "HP Out",
3661                 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
3662         };
3663         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3664         uinfo->count = 1;
3665         uinfo->value.enumerated.items = 8;
3666         if (uinfo->value.enumerated.item >= 8)
3667                 uinfo->value.enumerated.item = 7;
3668         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3669         return 0;
3670 }
3671
3672 static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
3673                                 struct snd_ctl_elem_value *ucontrol)
3674 {
3675         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3676         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3677         unsigned int pin_ctl, item = 0;
3678
3679         pin_ctl = snd_hda_codec_read(codec, nid, 0,
3680                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3681         if (pin_ctl & AC_PINCTL_OUT_EN) {
3682                 if (pin_ctl & AC_PINCTL_HP_EN)
3683                         item = 2;
3684                 else
3685                         item = 1;
3686         } else if (pin_ctl & AC_PINCTL_IN_EN) {
3687                 switch (pin_ctl & AC_PINCTL_VREFEN) {
3688                 case AC_PINCTL_VREF_HIZ: item = 3; break;
3689                 case AC_PINCTL_VREF_50:  item = 4; break;
3690                 case AC_PINCTL_VREF_GRD: item = 5; break;
3691                 case AC_PINCTL_VREF_80:  item = 6; break;
3692                 case AC_PINCTL_VREF_100: item = 7; break;
3693                 }
3694         }
3695         ucontrol->value.enumerated.item[0] = item;
3696         return 0;
3697 }
3698
3699 static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
3700                                 struct snd_ctl_elem_value *ucontrol)
3701 {
3702         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3703         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3704         static unsigned int ctls[] = {
3705                 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
3706                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
3707                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
3708                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
3709                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
3710                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
3711         };
3712         unsigned int old_ctl, new_ctl;
3713
3714         old_ctl = snd_hda_codec_read(codec, nid, 0,
3715                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3716         new_ctl = ctls[ucontrol->value.enumerated.item[0]];
3717         if (old_ctl != new_ctl) {
3718                 int val;
3719                 snd_hda_codec_write_cache(codec, nid, 0,
3720                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
3721                                           new_ctl);
3722                 val = ucontrol->value.enumerated.item[0] >= 3 ?
3723                         HDA_AMP_MUTE : 0;
3724                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3725                                          HDA_AMP_MUTE, val);
3726                 return 1;
3727         }
3728         return 0;
3729 }
3730
3731 static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
3732                                  struct snd_ctl_elem_info *uinfo)
3733 {
3734         static char *texts[] = {
3735                 "Front", "Surround", "CLFE", "Side"
3736         };
3737         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3738         uinfo->count = 1;
3739         uinfo->value.enumerated.items = 4;
3740         if (uinfo->value.enumerated.item >= 4)
3741                 uinfo->value.enumerated.item = 3;
3742         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3743         return 0;
3744 }
3745
3746 static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
3747                                 struct snd_ctl_elem_value *ucontrol)
3748 {
3749         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3750         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3751         unsigned int sel;
3752
3753         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
3754         ucontrol->value.enumerated.item[0] = sel & 3;
3755         return 0;
3756 }
3757
3758 static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
3759                                 struct snd_ctl_elem_value *ucontrol)
3760 {
3761         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3762         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3763         unsigned int sel;
3764
3765         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
3766         if (ucontrol->value.enumerated.item[0] != sel) {
3767                 sel = ucontrol->value.enumerated.item[0] & 3;
3768                 snd_hda_codec_write_cache(codec, nid, 0,
3769                                           AC_VERB_SET_CONNECT_SEL, sel);
3770                 return 1;
3771         }
3772         return 0;
3773 }
3774
3775 #define PIN_CTL_TEST(xname,nid) {                       \
3776                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3777                         .name = xname,                 \
3778                         .info = alc_test_pin_ctl_info, \
3779                         .get = alc_test_pin_ctl_get,   \
3780                         .put = alc_test_pin_ctl_put,   \
3781                         .private_value = nid           \
3782                         }
3783
3784 #define PIN_SRC_TEST(xname,nid) {                       \
3785                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3786                         .name = xname,                 \
3787                         .info = alc_test_pin_src_info, \
3788                         .get = alc_test_pin_src_get,   \
3789                         .put = alc_test_pin_src_put,   \
3790                         .private_value = nid           \
3791                         }
3792
3793 static struct snd_kcontrol_new alc880_test_mixer[] = {
3794         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3795         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
3796         HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
3797         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3798         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
3799         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
3800         HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
3801         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
3802         PIN_CTL_TEST("Front Pin Mode", 0x14),
3803         PIN_CTL_TEST("Surround Pin Mode", 0x15),
3804         PIN_CTL_TEST("CLFE Pin Mode", 0x16),
3805         PIN_CTL_TEST("Side Pin Mode", 0x17),
3806         PIN_CTL_TEST("In-1 Pin Mode", 0x18),
3807         PIN_CTL_TEST("In-2 Pin Mode", 0x19),
3808         PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
3809         PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
3810         PIN_SRC_TEST("In-1 Pin Source", 0x18),
3811         PIN_SRC_TEST("In-2 Pin Source", 0x19),
3812         PIN_SRC_TEST("In-3 Pin Source", 0x1a),
3813         PIN_SRC_TEST("In-4 Pin Source", 0x1b),
3814         HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
3815         HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
3816         HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
3817         HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
3818         HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
3819         HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
3820         HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
3821         HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
3822         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
3823         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
3824         {
3825                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3826                 .name = "Channel Mode",
3827                 .info = alc_ch_mode_info,
3828                 .get = alc_ch_mode_get,
3829                 .put = alc_ch_mode_put,
3830         },
3831         { } /* end */
3832 };
3833
3834 static struct hda_verb alc880_test_init_verbs[] = {
3835         /* Unmute inputs of 0x0c - 0x0f */
3836         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3837         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3838         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3839         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3840         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3841         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3842         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3843         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3844         /* Vol output for 0x0c-0x0f */
3845         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3846         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3847         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3848         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3849         /* Set output pins 0x14-0x17 */
3850         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3851         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3852         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3853         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3854         /* Unmute output pins 0x14-0x17 */
3855         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3856         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3857         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3858         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3859         /* Set input pins 0x18-0x1c */
3860         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3861         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3862         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3863         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3864         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3865         /* Mute input pins 0x18-0x1b */
3866         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3867         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3868         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3869         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3870         /* ADC set up */
3871         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3872         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
3873         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3874         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
3875         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3876         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
3877         /* Analog input/passthru */
3878         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3879         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3880         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3881         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3882         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3883         { }
3884 };
3885 #endif
3886
3887 /*
3888  */
3889
3890 static const char *alc880_models[ALC880_MODEL_LAST] = {
3891         [ALC880_3ST]            = "3stack",
3892         [ALC880_TCL_S700]       = "tcl",
3893         [ALC880_3ST_DIG]        = "3stack-digout",
3894         [ALC880_CLEVO]          = "clevo",
3895         [ALC880_5ST]            = "5stack",
3896         [ALC880_5ST_DIG]        = "5stack-digout",
3897         [ALC880_W810]           = "w810",
3898         [ALC880_Z71V]           = "z71v",
3899         [ALC880_6ST]            = "6stack",
3900         [ALC880_6ST_DIG]        = "6stack-digout",
3901         [ALC880_ASUS]           = "asus",
3902         [ALC880_ASUS_W1V]       = "asus-w1v",
3903         [ALC880_ASUS_DIG]       = "asus-dig",
3904         [ALC880_ASUS_DIG2]      = "asus-dig2",
3905         [ALC880_UNIWILL_DIG]    = "uniwill",
3906         [ALC880_UNIWILL_P53]    = "uniwill-p53",
3907         [ALC880_FUJITSU]        = "fujitsu",
3908         [ALC880_F1734]          = "F1734",
3909         [ALC880_LG]             = "lg",
3910         [ALC880_LG_LW]          = "lg-lw",
3911         [ALC880_MEDION_RIM]     = "medion",
3912 #ifdef CONFIG_SND_DEBUG
3913         [ALC880_TEST]           = "test",
3914 #endif
3915         [ALC880_AUTO]           = "auto",
3916 };
3917
3918 static struct snd_pci_quirk alc880_cfg_tbl[] = {
3919         SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
3920         SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
3921         SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
3922         SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
3923         SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
3924         SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
3925         SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
3926         SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
3927         SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
3928         SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
3929         SND_PCI_QUIRK(0x103c, 0x2a09, "HP", ALC880_5ST),
3930         SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
3931         SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
3932         SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
3933         SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
3934         SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
3935         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
3936         SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
3937         /* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
3938         SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
3939         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
3940         SND_PCI_QUIRK(0x1043, 0x814e, "ASUS P5GD1 w/SPDIF", ALC880_6ST_DIG),
3941         SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
3942         SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
3943         SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
3944         SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_ASUS), /* default ASUS */
3945         SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
3946         SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
3947         SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
3948         SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
3949         SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
3950         SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
3951         SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
3952         SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
3953         SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
3954         SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
3955         SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
3956         SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
3957         SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
3958         SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
3959         SND_PCI_QUIRK(0x1584, 0x9054, "Uniwlll", ALC880_F1734),
3960         SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
3961         SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
3962         SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
3963         SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_MEDION_RIM),
3964         SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
3965         SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
3966         SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
3967         SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FUJITSU),
3968         SND_PCI_QUIRK(0x1734, 0x10ac, "FSC", ALC880_UNIWILL),
3969         SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
3970         SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
3971         SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
3972         SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
3973         SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
3974         SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
3975         SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG), /* broken BIOS */
3976         SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
3977         SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
3978         SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
3979         SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
3980         SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
3981         SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
3982         SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
3983         SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
3984         SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
3985         SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
3986         SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
3987         /* default Intel */
3988         SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_3ST),
3989         SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
3990         SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
3991         {}
3992 };
3993
3994 /*
3995  * ALC880 codec presets
3996  */
3997 static struct alc_config_preset alc880_presets[] = {
3998         [ALC880_3ST] = {
3999                 .mixers = { alc880_three_stack_mixer },
4000                 .init_verbs = { alc880_volume_init_verbs,
4001                                 alc880_pin_3stack_init_verbs },
4002                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4003                 .dac_nids = alc880_dac_nids,
4004                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
4005                 .channel_mode = alc880_threestack_modes,
4006                 .need_dac_fix = 1,
4007                 .input_mux = &alc880_capture_source,
4008         },
4009         [ALC880_3ST_DIG] = {
4010                 .mixers = { alc880_three_stack_mixer },
4011                 .init_verbs = { alc880_volume_init_verbs,
4012                                 alc880_pin_3stack_init_verbs },
4013                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4014                 .dac_nids = alc880_dac_nids,
4015                 .dig_out_nid = ALC880_DIGOUT_NID,
4016                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
4017                 .channel_mode = alc880_threestack_modes,
4018                 .need_dac_fix = 1,
4019                 .input_mux = &alc880_capture_source,
4020         },
4021         [ALC880_TCL_S700] = {
4022                 .mixers = { alc880_tcl_s700_mixer },
4023                 .init_verbs = { alc880_volume_init_verbs,
4024                                 alc880_pin_tcl_S700_init_verbs,
4025                                 alc880_gpio2_init_verbs },
4026                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4027                 .dac_nids = alc880_dac_nids,
4028                 .adc_nids = alc880_adc_nids_alt, /* FIXME: correct? */
4029                 .num_adc_nids = 1, /* single ADC */
4030                 .hp_nid = 0x03,
4031                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4032                 .channel_mode = alc880_2_jack_modes,
4033                 .input_mux = &alc880_capture_source,
4034         },
4035         [ALC880_5ST] = {
4036                 .mixers = { alc880_three_stack_mixer,
4037                             alc880_five_stack_mixer},
4038                 .init_verbs = { alc880_volume_init_verbs,
4039                                 alc880_pin_5stack_init_verbs },
4040                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4041                 .dac_nids = alc880_dac_nids,
4042                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
4043                 .channel_mode = alc880_fivestack_modes,
4044                 .input_mux = &alc880_capture_source,
4045         },
4046         [ALC880_5ST_DIG] = {
4047                 .mixers = { alc880_three_stack_mixer,
4048                             alc880_five_stack_mixer },
4049                 .init_verbs = { alc880_volume_init_verbs,
4050                                 alc880_pin_5stack_init_verbs },
4051                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4052                 .dac_nids = alc880_dac_nids,
4053                 .dig_out_nid = ALC880_DIGOUT_NID,
4054                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
4055                 .channel_mode = alc880_fivestack_modes,
4056                 .input_mux = &alc880_capture_source,
4057         },
4058         [ALC880_6ST] = {
4059                 .mixers = { alc880_six_stack_mixer },
4060                 .init_verbs = { alc880_volume_init_verbs,
4061                                 alc880_pin_6stack_init_verbs },
4062                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
4063                 .dac_nids = alc880_6st_dac_nids,
4064                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
4065                 .channel_mode = alc880_sixstack_modes,
4066                 .input_mux = &alc880_6stack_capture_source,
4067         },
4068         [ALC880_6ST_DIG] = {
4069                 .mixers = { alc880_six_stack_mixer },
4070                 .init_verbs = { alc880_volume_init_verbs,
4071                                 alc880_pin_6stack_init_verbs },
4072                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
4073                 .dac_nids = alc880_6st_dac_nids,
4074                 .dig_out_nid = ALC880_DIGOUT_NID,
4075                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
4076                 .channel_mode = alc880_sixstack_modes,
4077                 .input_mux = &alc880_6stack_capture_source,
4078         },
4079         [ALC880_W810] = {
4080                 .mixers = { alc880_w810_base_mixer },
4081                 .init_verbs = { alc880_volume_init_verbs,
4082                                 alc880_pin_w810_init_verbs,
4083                                 alc880_gpio2_init_verbs },
4084                 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
4085                 .dac_nids = alc880_w810_dac_nids,
4086                 .dig_out_nid = ALC880_DIGOUT_NID,
4087                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
4088                 .channel_mode = alc880_w810_modes,
4089                 .input_mux = &alc880_capture_source,
4090         },
4091         [ALC880_Z71V] = {
4092                 .mixers = { alc880_z71v_mixer },
4093                 .init_verbs = { alc880_volume_init_verbs,
4094                                 alc880_pin_z71v_init_verbs },
4095                 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
4096                 .dac_nids = alc880_z71v_dac_nids,
4097                 .dig_out_nid = ALC880_DIGOUT_NID,
4098                 .hp_nid = 0x03,
4099                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4100                 .channel_mode = alc880_2_jack_modes,
4101                 .input_mux = &alc880_capture_source,
4102         },
4103         [ALC880_F1734] = {
4104                 .mixers = { alc880_f1734_mixer },
4105                 .init_verbs = { alc880_volume_init_verbs,
4106                                 alc880_pin_f1734_init_verbs },
4107                 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
4108                 .dac_nids = alc880_f1734_dac_nids,
4109                 .hp_nid = 0x02,
4110                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4111                 .channel_mode = alc880_2_jack_modes,
4112                 .input_mux = &alc880_f1734_capture_source,
4113                 .unsol_event = alc880_uniwill_p53_unsol_event,
4114                 .setup = alc880_uniwill_p53_setup,
4115                 .init_hook = alc_automute_amp,
4116         },
4117         [ALC880_ASUS] = {
4118                 .mixers = { alc880_asus_mixer },
4119                 .init_verbs = { alc880_volume_init_verbs,
4120                                 alc880_pin_asus_init_verbs,
4121                                 alc880_gpio1_init_verbs },
4122                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4123                 .dac_nids = alc880_asus_dac_nids,
4124                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4125                 .channel_mode = alc880_asus_modes,
4126                 .need_dac_fix = 1,
4127                 .input_mux = &alc880_capture_source,
4128         },
4129         [ALC880_ASUS_DIG] = {
4130                 .mixers = { alc880_asus_mixer },
4131                 .init_verbs = { alc880_volume_init_verbs,
4132                                 alc880_pin_asus_init_verbs,
4133                                 alc880_gpio1_init_verbs },
4134                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4135                 .dac_nids = alc880_asus_dac_nids,
4136                 .dig_out_nid = ALC880_DIGOUT_NID,
4137                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4138                 .channel_mode = alc880_asus_modes,
4139                 .need_dac_fix = 1,
4140                 .input_mux = &alc880_capture_source,
4141         },
4142         [ALC880_ASUS_DIG2] = {
4143                 .mixers = { alc880_asus_mixer },
4144                 .init_verbs = { alc880_volume_init_verbs,
4145                                 alc880_pin_asus_init_verbs,
4146                                 alc880_gpio2_init_verbs }, /* use GPIO2 */
4147                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4148                 .dac_nids = alc880_asus_dac_nids,
4149                 .dig_out_nid = ALC880_DIGOUT_NID,
4150                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4151                 .channel_mode = alc880_asus_modes,
4152                 .need_dac_fix = 1,
4153                 .input_mux = &alc880_capture_source,
4154         },
4155         [ALC880_ASUS_W1V] = {
4156                 .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
4157                 .init_verbs = { alc880_volume_init_verbs,
4158                                 alc880_pin_asus_init_verbs,
4159                                 alc880_gpio1_init_verbs },
4160                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4161                 .dac_nids = alc880_asus_dac_nids,
4162                 .dig_out_nid = ALC880_DIGOUT_NID,
4163                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4164                 .channel_mode = alc880_asus_modes,
4165                 .need_dac_fix = 1,
4166                 .input_mux = &alc880_capture_source,
4167         },
4168         [ALC880_UNIWILL_DIG] = {
4169                 .mixers = { alc880_asus_mixer },
4170                 .init_verbs = { alc880_volume_init_verbs,
4171                                 alc880_pin_asus_init_verbs },
4172                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4173                 .dac_nids = alc880_asus_dac_nids,
4174                 .dig_out_nid = ALC880_DIGOUT_NID,
4175                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4176                 .channel_mode = alc880_asus_modes,
4177                 .need_dac_fix = 1,
4178                 .input_mux = &alc880_capture_source,
4179         },
4180         [ALC880_UNIWILL] = {
4181                 .mixers = { alc880_uniwill_mixer },
4182                 .init_verbs = { alc880_volume_init_verbs,
4183                                 alc880_uniwill_init_verbs },
4184                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4185                 .dac_nids = alc880_asus_dac_nids,
4186                 .dig_out_nid = ALC880_DIGOUT_NID,
4187                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
4188                 .channel_mode = alc880_threestack_modes,
4189                 .need_dac_fix = 1,
4190                 .input_mux = &alc880_capture_source,
4191                 .unsol_event = alc880_uniwill_unsol_event,
4192                 .setup = alc880_uniwill_setup,
4193                 .init_hook = alc880_uniwill_init_hook,
4194         },
4195         [ALC880_UNIWILL_P53] = {
4196                 .mixers = { alc880_uniwill_p53_mixer },
4197                 .init_verbs = { alc880_volume_init_verbs,
4198                                 alc880_uniwill_p53_init_verbs },
4199                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4200                 .dac_nids = alc880_asus_dac_nids,
4201                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
4202                 .channel_mode = alc880_threestack_modes,
4203                 .input_mux = &alc880_capture_source,
4204                 .unsol_event = alc880_uniwill_p53_unsol_event,
4205                 .setup = alc880_uniwill_p53_setup,
4206                 .init_hook = alc_automute_amp,
4207         },
4208         [ALC880_FUJITSU] = {
4209                 .mixers = { alc880_fujitsu_mixer },
4210                 .init_verbs = { alc880_volume_init_verbs,
4211                                 alc880_uniwill_p53_init_verbs,
4212                                 alc880_beep_init_verbs },
4213                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4214                 .dac_nids = alc880_dac_nids,
4215                 .dig_out_nid = ALC880_DIGOUT_NID,
4216                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4217                 .channel_mode = alc880_2_jack_modes,
4218                 .input_mux = &alc880_capture_source,
4219                 .unsol_event = alc880_uniwill_p53_unsol_event,
4220                 .setup = alc880_uniwill_p53_setup,
4221                 .init_hook = alc_automute_amp,
4222         },
4223         [ALC880_CLEVO] = {
4224                 .mixers = { alc880_three_stack_mixer },
4225                 .init_verbs = { alc880_volume_init_verbs,
4226                                 alc880_pin_clevo_init_verbs },
4227                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4228                 .dac_nids = alc880_dac_nids,
4229                 .hp_nid = 0x03,
4230                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
4231                 .channel_mode = alc880_threestack_modes,
4232                 .need_dac_fix = 1,
4233                 .input_mux = &alc880_capture_source,
4234         },
4235         [ALC880_LG] = {
4236                 .mixers = { alc880_lg_mixer },
4237                 .init_verbs = { alc880_volume_init_verbs,
4238                                 alc880_lg_init_verbs },
4239                 .num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
4240                 .dac_nids = alc880_lg_dac_nids,
4241                 .dig_out_nid = ALC880_DIGOUT_NID,
4242                 .num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
4243                 .channel_mode = alc880_lg_ch_modes,
4244                 .need_dac_fix = 1,
4245                 .input_mux = &alc880_lg_capture_source,
4246                 .unsol_event = alc_automute_amp_unsol_event,
4247                 .setup = alc880_lg_setup,
4248                 .init_hook = alc_automute_amp,
4249 #ifdef CONFIG_SND_HDA_POWER_SAVE
4250                 .loopbacks = alc880_lg_loopbacks,
4251 #endif
4252         },
4253         [ALC880_LG_LW] = {
4254                 .mixers = { alc880_lg_lw_mixer },
4255                 .init_verbs = { alc880_volume_init_verbs,
4256                                 alc880_lg_lw_init_verbs },
4257                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4258                 .dac_nids = alc880_dac_nids,
4259                 .dig_out_nid = ALC880_DIGOUT_NID,
4260                 .num_channel_mode = ARRAY_SIZE(alc880_lg_lw_modes),
4261                 .channel_mode = alc880_lg_lw_modes,
4262                 .input_mux = &alc880_lg_lw_capture_source,
4263                 .unsol_event = alc_automute_amp_unsol_event,
4264                 .setup = alc880_lg_lw_setup,
4265                 .init_hook = alc_automute_amp,
4266         },
4267         [ALC880_MEDION_RIM] = {
4268                 .mixers = { alc880_medion_rim_mixer },
4269                 .init_verbs = { alc880_volume_init_verbs,
4270                                 alc880_medion_rim_init_verbs,
4271                                 alc_gpio2_init_verbs },
4272                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4273                 .dac_nids = alc880_dac_nids,
4274                 .dig_out_nid = ALC880_DIGOUT_NID,
4275                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4276                 .channel_mode = alc880_2_jack_modes,
4277                 .input_mux = &alc880_medion_rim_capture_source,
4278                 .unsol_event = alc880_medion_rim_unsol_event,
4279                 .setup = alc880_medion_rim_setup,
4280                 .init_hook = alc880_medion_rim_automute,
4281         },
4282 #ifdef CONFIG_SND_DEBUG
4283         [ALC880_TEST] = {
4284                 .mixers = { alc880_test_mixer },
4285                 .init_verbs = { alc880_test_init_verbs },
4286                 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
4287                 .dac_nids = alc880_test_dac_nids,
4288                 .dig_out_nid = ALC880_DIGOUT_NID,
4289                 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
4290                 .channel_mode = alc880_test_modes,
4291                 .input_mux = &alc880_test_capture_source,
4292         },
4293 #endif
4294 };
4295
4296 /*
4297  * Automatic parse of I/O pins from the BIOS configuration
4298  */
4299
4300 enum {
4301         ALC_CTL_WIDGET_VOL,
4302         ALC_CTL_WIDGET_MUTE,
4303         ALC_CTL_BIND_MUTE,
4304 };
4305 static struct snd_kcontrol_new alc880_control_templates[] = {
4306         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
4307         HDA_CODEC_MUTE(NULL, 0, 0, 0),
4308         HDA_BIND_MUTE(NULL, 0, 0, 0),
4309 };
4310
4311 /* add dynamic controls */
4312 static int add_control(struct alc_spec *spec, int type, const char *name,
4313                        unsigned long val)
4314 {
4315         struct snd_kcontrol_new *knew;
4316
4317         snd_array_init(&spec->kctls, sizeof(*knew), 32);
4318         knew = snd_array_new(&spec->kctls);
4319         if (!knew)
4320                 return -ENOMEM;
4321         *knew = alc880_control_templates[type];
4322         knew->name = kstrdup(name, GFP_KERNEL);
4323         if (!knew->name)
4324                 return -ENOMEM;
4325         knew->private_value = val;
4326         return 0;
4327 }
4328
4329 static int add_control_with_pfx(struct alc_spec *spec, int type,
4330                                 const char *pfx, const char *dir,
4331                                 const char *sfx, unsigned long val)
4332 {
4333         char name[32];
4334         snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
4335         return add_control(spec, type, name, val);
4336 }
4337
4338 #define add_pb_vol_ctrl(spec, type, pfx, val) \
4339         add_control_with_pfx(spec, type, pfx, "Playback", "Volume", val)
4340 #define add_pb_sw_ctrl(spec, type, pfx, val) \
4341         add_control_with_pfx(spec, type, pfx, "Playback", "Switch", val)
4342
4343 #define alc880_is_fixed_pin(nid)        ((nid) >= 0x14 && (nid) <= 0x17)
4344 #define alc880_fixed_pin_idx(nid)       ((nid) - 0x14)
4345 #define alc880_is_multi_pin(nid)        ((nid) >= 0x18)
4346 #define alc880_multi_pin_idx(nid)       ((nid) - 0x18)
4347 #define alc880_idx_to_dac(nid)          ((nid) + 0x02)
4348 #define alc880_dac_to_idx(nid)          ((nid) - 0x02)
4349 #define alc880_idx_to_mixer(nid)        ((nid) + 0x0c)
4350 #define alc880_idx_to_selector(nid)     ((nid) + 0x10)
4351 #define ALC880_PIN_CD_NID               0x1c
4352
4353 /* fill in the dac_nids table from the parsed pin configuration */
4354 static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
4355                                      const struct auto_pin_cfg *cfg)
4356 {
4357         hda_nid_t nid;
4358         int assigned[4];
4359         int i, j;
4360
4361         memset(assigned, 0, sizeof(assigned));
4362         spec->multiout.dac_nids = spec->private_dac_nids;
4363
4364         /* check the pins hardwired to audio widget */
4365         for (i = 0; i < cfg->line_outs; i++) {
4366                 nid = cfg->line_out_pins[i];
4367                 if (alc880_is_fixed_pin(nid)) {
4368                         int idx = alc880_fixed_pin_idx(nid);
4369                         spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
4370                         assigned[idx] = 1;
4371                 }
4372         }
4373         /* left pins can be connect to any audio widget */
4374         for (i = 0; i < cfg->line_outs; i++) {
4375                 nid = cfg->line_out_pins[i];
4376                 if (alc880_is_fixed_pin(nid))
4377                         continue;
4378                 /* search for an empty channel */
4379                 for (j = 0; j < cfg->line_outs; j++) {
4380                         if (!assigned[j]) {
4381                                 spec->multiout.dac_nids[i] =
4382                                         alc880_idx_to_dac(j);
4383                                 assigned[j] = 1;
4384                                 break;
4385                         }
4386                 }
4387         }
4388         spec->multiout.num_dacs = cfg->line_outs;
4389         return 0;
4390 }
4391
4392 /* add playback controls from the parsed DAC table */
4393 static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
4394                                              const struct auto_pin_cfg *cfg)
4395 {
4396         static const char *chname[4] = {
4397                 "Front", "Surround", NULL /*CLFE*/, "Side"
4398         };
4399         hda_nid_t nid;
4400         int i, err;
4401
4402         for (i = 0; i < cfg->line_outs; i++) {
4403                 if (!spec->multiout.dac_nids[i])
4404                         continue;
4405                 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
4406                 if (i == 2) {
4407                         /* Center/LFE */
4408                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
4409                                               "Center",
4410                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
4411                                                               HDA_OUTPUT));
4412                         if (err < 0)
4413                                 return err;
4414                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
4415                                               "LFE",
4416                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
4417                                                               HDA_OUTPUT));
4418                         if (err < 0)
4419                                 return err;
4420                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
4421                                              "Center",
4422                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
4423                                                               HDA_INPUT));
4424                         if (err < 0)
4425                                 return err;
4426                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
4427                                              "LFE",
4428                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
4429                                                               HDA_INPUT));
4430                         if (err < 0)
4431                                 return err;
4432                 } else {
4433                         const char *pfx;
4434                         if (cfg->line_outs == 1 &&
4435                             cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
4436                                 pfx = "Speaker";
4437                         else
4438                                 pfx = chname[i];
4439                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
4440                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
4441                                                               HDA_OUTPUT));
4442                         if (err < 0)
4443                                 return err;
4444                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE, pfx,
4445                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
4446                                                               HDA_INPUT));
4447                         if (err < 0)
4448                                 return err;
4449                 }
4450         }
4451         return 0;
4452 }
4453
4454 /* add playback controls for speaker and HP outputs */
4455 static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
4456                                         const char *pfx)
4457 {
4458         hda_nid_t nid;
4459         int err;
4460
4461         if (!pin)
4462                 return 0;
4463
4464         if (alc880_is_fixed_pin(pin)) {
4465                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
4466                 /* specify the DAC as the extra output */
4467                 if (!spec->multiout.hp_nid)
4468                         spec->multiout.hp_nid = nid;
4469                 else
4470                         spec->multiout.extra_out_nid[0] = nid;
4471                 /* control HP volume/switch on the output mixer amp */
4472                 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
4473                 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
4474                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
4475                 if (err < 0)
4476                         return err;
4477                 err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE, pfx,
4478                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
4479                 if (err < 0)
4480                         return err;
4481         } else if (alc880_is_multi_pin(pin)) {
4482                 /* set manual connection */
4483                 /* we have only a switch on HP-out PIN */
4484                 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
4485                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4486                 if (err < 0)
4487                         return err;
4488         }
4489         return 0;
4490 }
4491
4492 /* create input playback/capture controls for the given pin */
4493 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
4494                             const char *ctlname,
4495                             int idx, hda_nid_t mix_nid)
4496 {
4497         int err;
4498
4499         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname,
4500                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
4501         if (err < 0)
4502                 return err;
4503         err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname,
4504                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
4505         if (err < 0)
4506                 return err;
4507         return 0;
4508 }
4509
4510 static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
4511 {
4512         unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
4513         return (pincap & AC_PINCAP_IN) != 0;
4514 }
4515
4516 /* create playback/capture controls for input pins */
4517 static int alc_auto_create_input_ctls(struct hda_codec *codec,
4518                                       const struct auto_pin_cfg *cfg,
4519                                       hda_nid_t mixer,
4520                                       hda_nid_t cap1, hda_nid_t cap2)
4521 {
4522         struct alc_spec *spec = codec->spec;
4523         struct hda_input_mux *imux = &spec->private_imux[0];
4524         int i, err, idx;
4525
4526         for (i = 0; i < AUTO_PIN_LAST; i++) {
4527                 hda_nid_t pin;
4528
4529                 pin = cfg->input_pins[i];
4530                 if (!alc_is_input_pin(codec, pin))
4531                         continue;
4532
4533                 if (mixer) {
4534                         idx = get_connection_index(codec, mixer, pin);
4535                         if (idx >= 0) {
4536                                 err = new_analog_input(spec, pin,
4537                                                        auto_pin_cfg_labels[i],
4538                                                        idx, mixer);
4539                                 if (err < 0)
4540                                         return err;
4541                         }
4542                 }
4543
4544                 if (!cap1)
4545                         continue;
4546                 idx = get_connection_index(codec, cap1, pin);
4547                 if (idx < 0 && cap2)
4548                         idx = get_connection_index(codec, cap2, pin);
4549                 if (idx >= 0) {
4550                         imux->items[imux->num_items].label =
4551                                 auto_pin_cfg_labels[i];
4552                         imux->items[imux->num_items].index = idx;
4553                         imux->num_items++;
4554                 }
4555         }
4556         return 0;
4557 }
4558
4559 static int alc880_auto_create_input_ctls(struct hda_codec *codec,
4560                                                 const struct auto_pin_cfg *cfg)
4561 {
4562         return alc_auto_create_input_ctls(codec, cfg, 0x0b, 0x08, 0x09);
4563 }
4564
4565 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
4566                                unsigned int pin_type)
4567 {
4568         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4569                             pin_type);
4570         /* unmute pin */
4571         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4572                             AMP_OUT_UNMUTE);
4573 }
4574
4575 static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
4576                                               hda_nid_t nid, int pin_type,
4577                                               int dac_idx)
4578 {
4579         alc_set_pin_output(codec, nid, pin_type);
4580         /* need the manual connection? */
4581         if (alc880_is_multi_pin(nid)) {
4582                 struct alc_spec *spec = codec->spec;
4583                 int idx = alc880_multi_pin_idx(nid);
4584                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
4585                                     AC_VERB_SET_CONNECT_SEL,
4586                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
4587         }
4588 }
4589
4590 static int get_pin_type(int line_out_type)
4591 {
4592         if (line_out_type == AUTO_PIN_HP_OUT)
4593                 return PIN_HP;
4594         else
4595                 return PIN_OUT;
4596 }
4597
4598 static void alc880_auto_init_multi_out(struct hda_codec *codec)
4599 {
4600         struct alc_spec *spec = codec->spec;
4601         int i;
4602
4603         for (i = 0; i < spec->autocfg.line_outs; i++) {
4604                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
4605                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
4606                 alc880_auto_set_output_and_unmute(codec, nid, pin_type, i);
4607         }
4608 }
4609
4610 static void alc880_auto_init_extra_out(struct hda_codec *codec)
4611 {
4612         struct alc_spec *spec = codec->spec;
4613         hda_nid_t pin;
4614
4615         pin = spec->autocfg.speaker_pins[0];
4616         if (pin) /* connect to front */
4617                 alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
4618         pin = spec->autocfg.hp_pins[0];
4619         if (pin) /* connect to front */
4620                 alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
4621 }
4622
4623 static void alc880_auto_init_analog_input(struct hda_codec *codec)
4624 {
4625         struct alc_spec *spec = codec->spec;
4626         int i;
4627
4628         for (i = 0; i < AUTO_PIN_LAST; i++) {
4629                 hda_nid_t nid = spec->autocfg.input_pins[i];
4630                 if (alc_is_input_pin(codec, nid)) {
4631                         alc_set_input_pin(codec, nid, i);
4632                         if (nid != ALC880_PIN_CD_NID &&
4633                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
4634                                 snd_hda_codec_write(codec, nid, 0,
4635                                                     AC_VERB_SET_AMP_GAIN_MUTE,
4636                                                     AMP_OUT_MUTE);
4637                 }
4638         }
4639 }
4640
4641 /* parse the BIOS configuration and set up the alc_spec */
4642 /* return 1 if successful, 0 if the proper config is not found,
4643  * or a negative error code
4644  */
4645 static int alc880_parse_auto_config(struct hda_codec *codec)
4646 {
4647         struct alc_spec *spec = codec->spec;
4648         int i, err;
4649         static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4650
4651         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
4652                                            alc880_ignore);
4653         if (err < 0)
4654                 return err;
4655         if (!spec->autocfg.line_outs)
4656                 return 0; /* can't find valid BIOS pin config */
4657
4658         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
4659         if (err < 0)
4660                 return err;
4661         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
4662         if (err < 0)
4663                 return err;
4664         err = alc880_auto_create_extra_out(spec,
4665                                            spec->autocfg.speaker_pins[0],
4666                                            "Speaker");
4667         if (err < 0)
4668                 return err;
4669         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
4670                                            "Headphone");
4671         if (err < 0)
4672                 return err;
4673         err = alc880_auto_create_input_ctls(codec, &spec->autocfg);
4674         if (err < 0)
4675                 return err;
4676
4677         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4678
4679         /* check multiple SPDIF-out (for recent codecs) */
4680         for (i = 0; i < spec->autocfg.dig_outs; i++) {
4681                 hda_nid_t dig_nid;
4682                 err = snd_hda_get_connections(codec,
4683                                               spec->autocfg.dig_out_pins[i],
4684                                               &dig_nid, 1);
4685                 if (err < 0)
4686                         continue;
4687                 if (!i)
4688                         spec->multiout.dig_out_nid = dig_nid;
4689                 else {
4690                         spec->multiout.slave_dig_outs = spec->slave_dig_outs;
4691                         if (i >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
4692                                 break;
4693                         spec->slave_dig_outs[i - 1] = dig_nid;
4694                 }
4695         }
4696         if (spec->autocfg.dig_in_pin)
4697                 spec->dig_in_nid = ALC880_DIGIN_NID;
4698
4699         if (spec->kctls.list)
4700                 add_mixer(spec, spec->kctls.list);
4701
4702         add_verb(spec, alc880_volume_init_verbs);
4703
4704         spec->num_mux_defs = 1;
4705         spec->input_mux = &spec->private_imux[0];
4706
4707         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
4708
4709         return 1;
4710 }
4711
4712 /* additional initialization for auto-configuration model */
4713 static void alc880_auto_init(struct hda_codec *codec)
4714 {
4715         struct alc_spec *spec = codec->spec;
4716         alc880_auto_init_multi_out(codec);
4717         alc880_auto_init_extra_out(codec);
4718         alc880_auto_init_analog_input(codec);
4719         if (spec->unsol_event)
4720                 alc_inithook(codec);
4721 }
4722
4723 /* check the ADC/MUX contains all input pins; some ADC/MUX contains only
4724  * one of two digital mic pins, e.g. on ALC272
4725  */
4726 static void fixup_automic_adc(struct hda_codec *codec)
4727 {
4728         struct alc_spec *spec = codec->spec;
4729         int i;
4730
4731         for (i = 0; i < spec->num_adc_nids; i++) {
4732                 hda_nid_t cap = spec->capsrc_nids ?
4733                         spec->capsrc_nids[i] : spec->adc_nids[i];
4734                 int iidx, eidx;
4735
4736                 iidx = get_connection_index(codec, cap, spec->int_mic.pin);
4737                 if (iidx < 0)
4738                         continue;
4739                 eidx = get_connection_index(codec, cap, spec->ext_mic.pin);
4740                 if (eidx < 0)
4741                         continue;
4742                 spec->int_mic.mux_idx = iidx;
4743                 spec->ext_mic.mux_idx = eidx;
4744                 if (spec->capsrc_nids)
4745                         spec->capsrc_nids += i;
4746                 spec->adc_nids += i;
4747                 spec->num_adc_nids = 1;
4748                 return;
4749         }
4750         snd_printd(KERN_INFO "hda_codec: %s: "
4751                    "No ADC/MUX containing both 0x%x and 0x%x pins\n",
4752                    codec->chip_name, spec->int_mic.pin, spec->ext_mic.pin);
4753         spec->auto_mic = 0; /* disable auto-mic to be sure */
4754 }
4755
4756 static void set_capture_mixer(struct hda_codec *codec)
4757 {
4758         struct alc_spec *spec = codec->spec;
4759         static struct snd_kcontrol_new *caps[2][3] = {
4760                 { alc_capture_mixer_nosrc1,
4761                   alc_capture_mixer_nosrc2,
4762                   alc_capture_mixer_nosrc3 },
4763                 { alc_capture_mixer1,
4764                   alc_capture_mixer2,
4765                   alc_capture_mixer3 },
4766         };
4767         if (spec->num_adc_nids > 0 && spec->num_adc_nids <= 3) {
4768                 int mux;
4769                 if (spec->auto_mic) {
4770                         mux = 0;
4771                         fixup_automic_adc(codec);
4772                 } else if (spec->input_mux && spec->input_mux->num_items > 1)
4773                         mux = 1;
4774                 else
4775                         mux = 0;
4776                 spec->cap_mixer = caps[mux][spec->num_adc_nids - 1];
4777         }
4778 }
4779
4780 #define set_beep_amp(spec, nid, idx, dir) \
4781         ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4782
4783 /*
4784  * OK, here we have finally the patch for ALC880
4785  */
4786
4787 static int patch_alc880(struct hda_codec *codec)
4788 {
4789         struct alc_spec *spec;
4790         int board_config;
4791         int err;
4792
4793         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4794         if (spec == NULL)
4795                 return -ENOMEM;
4796
4797         codec->spec = spec;
4798
4799         board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
4800                                                   alc880_models,
4801                                                   alc880_cfg_tbl);
4802         if (board_config < 0) {
4803                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4804                        codec->chip_name);
4805                 board_config = ALC880_AUTO;
4806         }
4807
4808         if (board_config == ALC880_AUTO) {
4809                 /* automatic parse from the BIOS config */
4810                 err = alc880_parse_auto_config(codec);
4811                 if (err < 0) {
4812                         alc_free(codec);
4813                         return err;
4814                 } else if (!err) {
4815                         printk(KERN_INFO
4816                                "hda_codec: Cannot set up configuration "
4817                                "from BIOS.  Using 3-stack mode...\n");
4818                         board_config = ALC880_3ST;
4819                 }
4820         }
4821
4822         err = snd_hda_attach_beep_device(codec, 0x1);
4823         if (err < 0) {
4824                 alc_free(codec);
4825                 return err;
4826         }
4827
4828         if (board_config != ALC880_AUTO)
4829                 setup_preset(codec, &alc880_presets[board_config]);
4830
4831         spec->stream_analog_playback = &alc880_pcm_analog_playback;
4832         spec->stream_analog_capture = &alc880_pcm_analog_capture;
4833         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
4834
4835         spec->stream_digital_playback = &alc880_pcm_digital_playback;
4836         spec->stream_digital_capture = &alc880_pcm_digital_capture;
4837
4838         if (!spec->adc_nids && spec->input_mux) {
4839                 /* check whether NID 0x07 is valid */
4840                 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
4841                 /* get type */
4842                 wcap = get_wcaps_type(wcap);
4843                 if (wcap != AC_WID_AUD_IN) {
4844                         spec->adc_nids = alc880_adc_nids_alt;
4845                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
4846                 } else {
4847                         spec->adc_nids = alc880_adc_nids;
4848                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
4849                 }
4850         }
4851         set_capture_mixer(codec);
4852         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4853
4854         spec->vmaster_nid = 0x0c;
4855
4856         codec->patch_ops = alc_patch_ops;
4857         if (board_config == ALC880_AUTO)
4858                 spec->init_hook = alc880_auto_init;
4859 #ifdef CONFIG_SND_HDA_POWER_SAVE
4860         if (!spec->loopback.amplist)
4861                 spec->loopback.amplist = alc880_loopbacks;
4862 #endif
4863         codec->proc_widget_hook = print_realtek_coef;
4864
4865         return 0;
4866 }
4867
4868
4869 /*
4870  * ALC260 support
4871  */
4872
4873 static hda_nid_t alc260_dac_nids[1] = {
4874         /* front */
4875         0x02,
4876 };
4877
4878 static hda_nid_t alc260_adc_nids[1] = {
4879         /* ADC0 */
4880         0x04,
4881 };
4882
4883 static hda_nid_t alc260_adc_nids_alt[1] = {
4884         /* ADC1 */
4885         0x05,
4886 };
4887
4888 /* NIDs used when simultaneous access to both ADCs makes sense.  Note that
4889  * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
4890  */
4891 static hda_nid_t alc260_dual_adc_nids[2] = {
4892         /* ADC0, ADC1 */
4893         0x04, 0x05
4894 };
4895
4896 #define ALC260_DIGOUT_NID       0x03
4897 #define ALC260_DIGIN_NID        0x06
4898
4899 static struct hda_input_mux alc260_capture_source = {
4900         .num_items = 4,
4901         .items = {
4902                 { "Mic", 0x0 },
4903                 { "Front Mic", 0x1 },
4904                 { "Line", 0x2 },
4905                 { "CD", 0x4 },
4906         },
4907 };
4908
4909 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
4910  * headphone jack and the internal CD lines since these are the only pins at
4911  * which audio can appear.  For flexibility, also allow the option of
4912  * recording the mixer output on the second ADC (ADC0 doesn't have a
4913  * connection to the mixer output).
4914  */
4915 static struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
4916         {
4917                 .num_items = 3,
4918                 .items = {
4919                         { "Mic/Line", 0x0 },
4920                         { "CD", 0x4 },
4921                         { "Headphone", 0x2 },
4922                 },
4923         },
4924         {
4925                 .num_items = 4,
4926                 .items = {
4927                         { "Mic/Line", 0x0 },
4928                         { "CD", 0x4 },
4929                         { "Headphone", 0x2 },
4930                         { "Mixer", 0x5 },
4931                 },
4932         },
4933
4934 };
4935
4936 /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
4937  * the Fujitsu S702x, but jacks are marked differently.
4938  */
4939 static struct hda_input_mux alc260_acer_capture_sources[2] = {
4940         {
4941                 .num_items = 4,
4942                 .items = {
4943                         { "Mic", 0x0 },
4944                         { "Line", 0x2 },
4945                         { "CD", 0x4 },
4946                         { "Headphone", 0x5 },
4947                 },
4948         },
4949         {
4950                 .num_items = 5,
4951                 .items = {
4952                         { "Mic", 0x0 },
4953                         { "Line", 0x2 },
4954                         { "CD", 0x4 },
4955                         { "Headphone", 0x6 },
4956                         { "Mixer", 0x5 },
4957                 },
4958         },
4959 };
4960
4961 /* Maxdata Favorit 100XS */
4962 static struct hda_input_mux alc260_favorit100_capture_sources[2] = {
4963         {
4964                 .num_items = 2,
4965                 .items = {
4966                         { "Line/Mic", 0x0 },
4967                         { "CD", 0x4 },
4968                 },
4969         },
4970         {
4971                 .num_items = 3,
4972                 .items = {
4973                         { "Line/Mic", 0x0 },
4974                         { "CD", 0x4 },
4975                         { "Mixer", 0x5 },
4976                 },
4977         },
4978 };
4979
4980 /*
4981  * This is just place-holder, so there's something for alc_build_pcms to look
4982  * at when it calculates the maximum number of channels. ALC260 has no mixer
4983  * element which allows changing the channel mode, so the verb list is
4984  * never used.
4985  */
4986 static struct hda_channel_mode alc260_modes[1] = {
4987         { 2, NULL },
4988 };
4989
4990
4991 /* Mixer combinations
4992  *
4993  * basic: base_output + input + pc_beep + capture
4994  * HP: base_output + input + capture_alt
4995  * HP_3013: hp_3013 + input + capture
4996  * fujitsu: fujitsu + capture
4997  * acer: acer + capture
4998  */
4999
5000 static struct snd_kcontrol_new alc260_base_output_mixer[] = {
5001         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5002         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
5003         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5004         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
5005         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
5006         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
5007         { } /* end */
5008 };
5009
5010 static struct snd_kcontrol_new alc260_input_mixer[] = {
5011         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5012         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5013         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
5014         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
5015         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
5016         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
5017         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
5018         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
5019         { } /* end */
5020 };
5021
5022 /* update HP, line and mono out pins according to the master switch */
5023 static void alc260_hp_master_update(struct hda_codec *codec,
5024                                     hda_nid_t hp, hda_nid_t line,
5025                                     hda_nid_t mono)
5026 {
5027         struct alc_spec *spec = codec->spec;
5028         unsigned int val = spec->master_sw ? PIN_HP : 0;
5029         /* change HP and line-out pins */
5030         snd_hda_codec_write(codec, hp, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5031                             val);
5032         snd_hda_codec_write(codec, line, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5033                             val);
5034         /* mono (speaker) depending on the HP jack sense */
5035         val = (val && !spec->jack_present) ? PIN_OUT : 0;
5036         snd_hda_codec_write(codec, mono, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5037                             val);
5038 }
5039
5040 static int alc260_hp_master_sw_get(struct snd_kcontrol *kcontrol,
5041                                    struct snd_ctl_elem_value *ucontrol)
5042 {
5043         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5044         struct alc_spec *spec = codec->spec;
5045         *ucontrol->value.integer.value = spec->master_sw;
5046         return 0;
5047 }
5048
5049 static int alc260_hp_master_sw_put(struct snd_kcontrol *kcontrol,
5050                                    struct snd_ctl_elem_value *ucontrol)
5051 {
5052         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5053         struct alc_spec *spec = codec->spec;
5054         int val = !!*ucontrol->value.integer.value;
5055         hda_nid_t hp, line, mono;
5056
5057         if (val == spec->master_sw)
5058                 return 0;
5059         spec->master_sw = val;
5060         hp = (kcontrol->private_value >> 16) & 0xff;
5061         line = (kcontrol->private_value >> 8) & 0xff;
5062         mono = kcontrol->private_value & 0xff;
5063         alc260_hp_master_update(codec, hp, line, mono);
5064         return 1;
5065 }
5066
5067 static struct snd_kcontrol_new alc260_hp_output_mixer[] = {
5068         {
5069                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5070                 .name = "Master Playback Switch",
5071                 .info = snd_ctl_boolean_mono_info,
5072                 .get = alc260_hp_master_sw_get,
5073                 .put = alc260_hp_master_sw_put,
5074                 .private_value = (0x0f << 16) | (0x10 << 8) | 0x11
5075         },
5076         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5077         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
5078         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5079         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
5080         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
5081                               HDA_OUTPUT),
5082         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2, HDA_INPUT),
5083         { } /* end */
5084 };
5085
5086 static struct hda_verb alc260_hp_unsol_verbs[] = {
5087         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5088         {},
5089 };
5090
5091 static void alc260_hp_automute(struct hda_codec *codec)
5092 {
5093         struct alc_spec *spec = codec->spec;
5094         unsigned int present;
5095
5096         present = snd_hda_codec_read(codec, 0x10, 0,
5097                                      AC_VERB_GET_PIN_SENSE, 0);
5098         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
5099         alc260_hp_master_update(codec, 0x0f, 0x10, 0x11);
5100 }
5101
5102 static void alc260_hp_unsol_event(struct hda_codec *codec, unsigned int res)
5103 {
5104         if ((res >> 26) == ALC880_HP_EVENT)
5105                 alc260_hp_automute(codec);
5106 }
5107
5108 static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
5109         {
5110                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5111                 .name = "Master Playback Switch",
5112                 .info = snd_ctl_boolean_mono_info,
5113                 .get = alc260_hp_master_sw_get,
5114                 .put = alc260_hp_master_sw_put,
5115                 .private_value = (0x15 << 16) | (0x10 << 8) | 0x11
5116         },
5117         HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5118         HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
5119         HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
5120         HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
5121         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5122         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5123         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
5124         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
5125         { } /* end */
5126 };
5127
5128 static struct hda_bind_ctls alc260_dc7600_bind_master_vol = {
5129         .ops = &snd_hda_bind_vol,
5130         .values = {
5131                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_OUTPUT),
5132                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
5133                 HDA_COMPOSE_AMP_VAL(0x0a, 3, 0, HDA_OUTPUT),
5134                 0
5135         },
5136 };
5137
5138 static struct hda_bind_ctls alc260_dc7600_bind_switch = {
5139         .ops = &snd_hda_bind_sw,
5140         .values = {
5141                 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
5142                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
5143                 0
5144         },
5145 };
5146
5147 static struct snd_kcontrol_new alc260_hp_dc7600_mixer[] = {
5148         HDA_BIND_VOL("Master Playback Volume", &alc260_dc7600_bind_master_vol),
5149         HDA_BIND_SW("LineOut Playback Switch", &alc260_dc7600_bind_switch),
5150         HDA_CODEC_MUTE("Speaker Playback Switch", 0x0f, 0x0, HDA_OUTPUT),
5151         HDA_CODEC_MUTE("Headphone Playback Switch", 0x10, 0x0, HDA_OUTPUT),
5152         { } /* end */
5153 };
5154
5155 static struct hda_verb alc260_hp_3013_unsol_verbs[] = {
5156         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5157         {},
5158 };
5159
5160 static void alc260_hp_3013_automute(struct hda_codec *codec)
5161 {
5162         struct alc_spec *spec = codec->spec;
5163         unsigned int present;
5164
5165         present = snd_hda_codec_read(codec, 0x15, 0,
5166                                      AC_VERB_GET_PIN_SENSE, 0);
5167         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
5168         alc260_hp_master_update(codec, 0x15, 0x10, 0x11);
5169 }
5170
5171 static void alc260_hp_3013_unsol_event(struct hda_codec *codec,
5172                                        unsigned int res)
5173 {
5174         if ((res >> 26) == ALC880_HP_EVENT)
5175                 alc260_hp_3013_automute(codec);
5176 }
5177
5178 static void alc260_hp_3012_automute(struct hda_codec *codec)
5179 {
5180         unsigned int present, bits;
5181
5182         present = snd_hda_codec_read(codec, 0x10, 0,
5183                         AC_VERB_GET_PIN_SENSE, 0) & AC_PINSENSE_PRESENCE;
5184
5185         bits = present ? 0 : PIN_OUT;
5186         snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5187                             bits);
5188         snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5189                             bits);
5190         snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5191                             bits);
5192 }
5193
5194 static void alc260_hp_3012_unsol_event(struct hda_codec *codec,
5195                                        unsigned int res)
5196 {
5197         if ((res >> 26) == ALC880_HP_EVENT)
5198                 alc260_hp_3012_automute(codec);
5199 }
5200
5201 /* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12,
5202  * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
5203  */
5204 static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
5205         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5206         HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
5207         ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
5208         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5209         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5210         HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
5211         HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
5212         ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
5213         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5214         HDA_BIND_MUTE("Speaker Playback Switch", 0x09, 2, HDA_INPUT),
5215         { } /* end */
5216 };
5217
5218 /* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks.  Note that current
5219  * versions of the ALC260 don't act on requests to enable mic bias from NID
5220  * 0x0f (used to drive the headphone jack in these laptops).  The ALC260
5221  * datasheet doesn't mention this restriction.  At this stage it's not clear
5222  * whether this behaviour is intentional or is a hardware bug in chip
5223  * revisions available in early 2006.  Therefore for now allow the
5224  * "Headphone Jack Mode" control to span all choices, but if it turns out
5225  * that the lack of mic bias for this NID is intentional we could change the
5226  * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
5227  *
5228  * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
5229  * don't appear to make the mic bias available from the "line" jack, even
5230  * though the NID used for this jack (0x14) can supply it.  The theory is
5231  * that perhaps Acer have included blocking capacitors between the ALC260
5232  * and the output jack.  If this turns out to be the case for all such
5233  * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
5234  * to ALC_PIN_DIR_INOUT_NOMICBIAS.
5235  *
5236  * The C20x Tablet series have a mono internal speaker which is controlled
5237  * via the chip's Mono sum widget and pin complex, so include the necessary
5238  * controls for such models.  On models without a "mono speaker" the control
5239  * won't do anything.
5240  */
5241 static struct snd_kcontrol_new alc260_acer_mixer[] = {
5242         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5243         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
5244         ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
5245         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
5246                               HDA_OUTPUT),
5247         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2,
5248                            HDA_INPUT),
5249         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5250         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5251         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
5252         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
5253         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
5254         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
5255         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
5256         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
5257         { } /* end */
5258 };
5259
5260 /* Maxdata Favorit 100XS: one output and one input (0x12) jack
5261  */
5262 static struct snd_kcontrol_new alc260_favorit100_mixer[] = {
5263         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5264         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
5265         ALC_PIN_MODE("Output Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
5266         HDA_CODEC_VOLUME("Line/Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
5267         HDA_CODEC_MUTE("Line/Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
5268         ALC_PIN_MODE("Line/Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
5269         { } /* end */
5270 };
5271
5272 /* Packard bell V7900  ALC260 pin usage: HP = 0x0f, Mic jack = 0x12,
5273  * Line In jack = 0x14, CD audio =  0x16, pc beep = 0x17.
5274  */
5275 static struct snd_kcontrol_new alc260_will_mixer[] = {
5276         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5277         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
5278         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
5279         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
5280         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
5281         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
5282         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
5283         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
5284         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5285         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5286         { } /* end */
5287 };
5288
5289 /* Replacer 672V ALC260 pin usage: Mic jack = 0x12,
5290  * Line In jack = 0x14, ATAPI Mic = 0x13, speaker = 0x0f.
5291  */
5292 static struct snd_kcontrol_new alc260_replacer_672v_mixer[] = {
5293         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5294         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
5295         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
5296         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
5297         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
5298         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x07, 0x1, HDA_INPUT),
5299         HDA_CODEC_MUTE("ATATI Mic Playback Switch", 0x07, 0x1, HDA_INPUT),
5300         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
5301         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
5302         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
5303         { } /* end */
5304 };
5305
5306 /*
5307  * initialization verbs
5308  */
5309 static struct hda_verb alc260_init_verbs[] = {
5310         /* Line In pin widget for input */
5311         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5312         /* CD pin widget for input */
5313         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5314         /* Mic1 (rear panel) pin widget for input and vref at 80% */
5315         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5316         /* Mic2 (front panel) pin widget for input and vref at 80% */
5317         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5318         /* LINE-2 is used for line-out in rear */
5319         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5320         /* select line-out */
5321         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
5322         /* LINE-OUT pin */
5323         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5324         /* enable HP */
5325         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5326         /* enable Mono */
5327         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5328         /* mute capture amp left and right */
5329         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5330         /* set connection select to line in (default select for this ADC) */
5331         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
5332         /* mute capture amp left and right */
5333         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5334         /* set connection select to line in (default select for this ADC) */
5335         {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
5336         /* set vol=0 Line-Out mixer amp left and right */
5337         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5338         /* unmute pin widget amp left and right (no gain on this amp) */
5339         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5340         /* set vol=0 HP mixer amp left and right */
5341         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5342         /* unmute pin widget amp left and right (no gain on this amp) */
5343         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5344         /* set vol=0 Mono mixer amp left and right */
5345         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5346         /* unmute pin widget amp left and right (no gain on this amp) */
5347         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5348         /* unmute LINE-2 out pin */
5349         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5350         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
5351          * Line In 2 = 0x03
5352          */
5353         /* mute analog inputs */
5354         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5355         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5356         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5357         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5358         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5359         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
5360         /* mute Front out path */
5361         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5362         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5363         /* mute Headphone out path */
5364         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5365         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5366         /* mute Mono out path */
5367         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5368         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5369         { }
5370 };
5371
5372 #if 0 /* should be identical with alc260_init_verbs? */
5373 static struct hda_verb alc260_hp_init_verbs[] = {
5374         /* Headphone and output */
5375         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
5376         /* mono output */
5377         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5378         /* Mic1 (rear panel) pin widget for input and vref at 80% */
5379         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
5380         /* Mic2 (front panel) pin widget for input and vref at 80% */
5381         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
5382         /* Line In pin widget for input */
5383         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
5384         /* Line-2 pin widget for output */
5385         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5386         /* CD pin widget for input */
5387         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
5388         /* unmute amp left and right */
5389         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
5390         /* set connection select to line in (default select for this ADC) */
5391         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
5392         /* unmute Line-Out mixer amp left and right (volume = 0) */
5393         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5394         /* mute pin widget amp left and right (no gain on this amp) */
5395         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5396         /* unmute HP mixer amp left and right (volume = 0) */
5397         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5398         /* mute pin widget amp left and right (no gain on this amp) */
5399         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5400         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
5401          * Line In 2 = 0x03
5402          */
5403         /* mute analog inputs */
5404         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5405         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5406         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5407         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5408         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5409         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
5410         /* Unmute Front out path */
5411         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5412         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5413         /* Unmute Headphone out path */
5414         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5415         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5416         /* Unmute Mono out path */
5417         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5418         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5419         { }
5420 };
5421 #endif
5422
5423 static struct hda_verb alc260_hp_3013_init_verbs[] = {
5424         /* Line out and output */
5425         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5426         /* mono output */
5427         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5428         /* Mic1 (rear panel) pin widget for input and vref at 80% */
5429         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
5430         /* Mic2 (front panel) pin widget for input and vref at 80% */
5431         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
5432         /* Line In pin widget for input */
5433         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
5434         /* Headphone pin widget for output */
5435         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
5436         /* CD pin widget for input */
5437         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
5438         /* unmute amp left and right */
5439         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
5440         /* set connection select to line in (default select for this ADC) */
5441         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
5442         /* unmute Line-Out mixer amp left and right (volume = 0) */
5443         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5444         /* mute pin widget amp left and right (no gain on this amp) */
5445         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5446         /* unmute HP mixer amp left and right (volume = 0) */
5447         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5448         /* mute pin widget amp left and right (no gain on this amp) */
5449         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5450         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
5451          * Line In 2 = 0x03
5452          */
5453         /* mute analog inputs */
5454         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5455         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5456         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5457         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5458         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5459         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
5460         /* Unmute Front out path */
5461         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5462         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5463         /* Unmute Headphone out path */
5464         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5465         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5466         /* Unmute Mono out path */
5467         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5468         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5469         { }
5470 };
5471
5472 /* Initialisation sequence for ALC260 as configured in Fujitsu S702x
5473  * laptops.  ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
5474  * audio = 0x16, internal speaker = 0x10.
5475  */
5476 static struct hda_verb alc260_fujitsu_init_verbs[] = {
5477         /* Disable all GPIOs */
5478         {0x01, AC_VERB_SET_GPIO_MASK, 0},
5479         /* Internal speaker is connected to headphone pin */
5480         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5481         /* Headphone/Line-out jack connects to Line1 pin; make it an output */
5482         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5483         /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
5484         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5485         /* Ensure all other unused pins are disabled and muted. */
5486         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5487         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5488         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5489         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5490         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5491         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5492         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5493         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5494
5495         /* Disable digital (SPDIF) pins */
5496         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5497         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5498
5499         /* Ensure Line1 pin widget takes its input from the OUT1 sum bus
5500          * when acting as an output.
5501          */
5502         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5503
5504         /* Start with output sum widgets muted and their output gains at min */
5505         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5506         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5507         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5508         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5509         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5510         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5511         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5512         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5513         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5514
5515         /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
5516         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5517         /* Unmute Line1 pin widget output buffer since it starts as an output.
5518          * If the pin mode is changed by the user the pin mode control will
5519          * take care of enabling the pin's input/output buffers as needed.
5520          * Therefore there's no need to enable the input buffer at this
5521          * stage.
5522          */
5523         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5524         /* Unmute input buffer of pin widget used for Line-in (no equiv
5525          * mixer ctrl)
5526          */
5527         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5528
5529         /* Mute capture amp left and right */
5530         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5531         /* Set ADC connection select to match default mixer setting - line
5532          * in (on mic1 pin)
5533          */
5534         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5535
5536         /* Do the same for the second ADC: mute capture input amp and
5537          * set ADC connection to line in (on mic1 pin)
5538          */
5539         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5540         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5541
5542         /* Mute all inputs to mixer widget (even unconnected ones) */
5543         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5544         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5545         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5546         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5547         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5548         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5549         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5550         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5551
5552         { }
5553 };
5554
5555 /* Initialisation sequence for ALC260 as configured in Acer TravelMate and
5556  * similar laptops (adapted from Fujitsu init verbs).
5557  */
5558 static struct hda_verb alc260_acer_init_verbs[] = {
5559         /* On TravelMate laptops, GPIO 0 enables the internal speaker and
5560          * the headphone jack.  Turn this on and rely on the standard mute
5561          * methods whenever the user wants to turn these outputs off.
5562          */
5563         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5564         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5565         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5566         /* Internal speaker/Headphone jack is connected to Line-out pin */
5567         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5568         /* Internal microphone/Mic jack is connected to Mic1 pin */
5569         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
5570         /* Line In jack is connected to Line1 pin */
5571         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5572         /* Some Acers (eg: C20x Tablets) use Mono pin for internal speaker */
5573         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5574         /* Ensure all other unused pins are disabled and muted. */
5575         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5576         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5577         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5578         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5579         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5580         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5581         /* Disable digital (SPDIF) pins */
5582         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5583         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5584
5585         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
5586          * bus when acting as outputs.
5587          */
5588         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5589         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5590
5591         /* Start with output sum widgets muted and their output gains at min */
5592         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5593         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5594         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5595         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5596         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5597         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5598         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5599         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5600         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5601
5602         /* Unmute Line-out pin widget amp left and right
5603          * (no equiv mixer ctrl)
5604          */
5605         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5606         /* Unmute mono pin widget amp output (no equiv mixer ctrl) */
5607         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5608         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
5609          * inputs. If the pin mode is changed by the user the pin mode control
5610          * will take care of enabling the pin's input/output buffers as needed.
5611          * Therefore there's no need to enable the input buffer at this
5612          * stage.
5613          */
5614         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5615         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5616
5617         /* Mute capture amp left and right */
5618         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5619         /* Set ADC connection select to match default mixer setting - mic
5620          * (on mic1 pin)
5621          */
5622         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5623
5624         /* Do similar with the second ADC: mute capture input amp and
5625          * set ADC connection to mic to match ALSA's default state.
5626          */
5627         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5628         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5629
5630         /* Mute all inputs to mixer widget (even unconnected ones) */
5631         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5632         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5633         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5634         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5635         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5636         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5637         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5638         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5639
5640         { }
5641 };
5642
5643 /* Initialisation sequence for Maxdata Favorit 100XS
5644  * (adapted from Acer init verbs).
5645  */
5646 static struct hda_verb alc260_favorit100_init_verbs[] = {
5647         /* GPIO 0 enables the output jack.
5648          * Turn this on and rely on the standard mute
5649          * methods whenever the user wants to turn these outputs off.
5650          */
5651         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5652         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5653         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5654         /* Line/Mic input jack is connected to Mic1 pin */
5655         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
5656         /* Ensure all other unused pins are disabled and muted. */
5657         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5658         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5659         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5660         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5661         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5662         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5663         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5664         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5665         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5666         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5667         /* Disable digital (SPDIF) pins */
5668         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5669         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5670
5671         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
5672          * bus when acting as outputs.
5673          */
5674         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5675         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5676
5677         /* Start with output sum widgets muted and their output gains at min */
5678         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5679         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5680         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5681         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5682         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5683         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5684         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5685         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5686         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5687
5688         /* Unmute Line-out pin widget amp left and right
5689          * (no equiv mixer ctrl)
5690          */
5691         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5692         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
5693          * inputs. If the pin mode is changed by the user the pin mode control
5694          * will take care of enabling the pin's input/output buffers as needed.
5695          * Therefore there's no need to enable the input buffer at this
5696          * stage.
5697          */
5698         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5699
5700         /* Mute capture amp left and right */
5701         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5702         /* Set ADC connection select to match default mixer setting - mic
5703          * (on mic1 pin)
5704          */
5705         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5706
5707         /* Do similar with the second ADC: mute capture input amp and
5708          * set ADC connection to mic to match ALSA's default state.
5709          */
5710         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5711         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5712
5713         /* Mute all inputs to mixer widget (even unconnected ones) */
5714         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5715         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5716         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5717         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5718         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5719         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5720         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5721         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5722
5723         { }
5724 };
5725
5726 static struct hda_verb alc260_will_verbs[] = {
5727         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5728         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x00},
5729         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
5730         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
5731         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
5732         {0x1a, AC_VERB_SET_PROC_COEF, 0x3040},
5733         {}
5734 };
5735
5736 static struct hda_verb alc260_replacer_672v_verbs[] = {
5737         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
5738         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
5739         {0x1a, AC_VERB_SET_PROC_COEF, 0x3050},
5740
5741         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5742         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5743         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5744
5745         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5746         {}
5747 };
5748
5749 /* toggle speaker-output according to the hp-jack state */
5750 static void alc260_replacer_672v_automute(struct hda_codec *codec)
5751 {
5752         unsigned int present;
5753
5754         /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
5755         present = snd_hda_codec_read(codec, 0x0f, 0,
5756                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5757         if (present) {
5758                 snd_hda_codec_write_cache(codec, 0x01, 0,
5759                                           AC_VERB_SET_GPIO_DATA, 1);
5760                 snd_hda_codec_write_cache(codec, 0x0f, 0,
5761                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
5762                                           PIN_HP);
5763         } else {
5764                 snd_hda_codec_write_cache(codec, 0x01, 0,
5765                                           AC_VERB_SET_GPIO_DATA, 0);
5766                 snd_hda_codec_write_cache(codec, 0x0f, 0,
5767                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
5768                                           PIN_OUT);
5769         }
5770 }
5771
5772 static void alc260_replacer_672v_unsol_event(struct hda_codec *codec,
5773                                        unsigned int res)
5774 {
5775         if ((res >> 26) == ALC880_HP_EVENT)
5776                 alc260_replacer_672v_automute(codec);
5777 }
5778
5779 static struct hda_verb alc260_hp_dc7600_verbs[] = {
5780         {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
5781         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
5782         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5783         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5784         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5785         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5786         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5787         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5788         {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5789         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5790         {}
5791 };
5792
5793 /* Test configuration for debugging, modelled after the ALC880 test
5794  * configuration.
5795  */
5796 #ifdef CONFIG_SND_DEBUG
5797 static hda_nid_t alc260_test_dac_nids[1] = {
5798         0x02,
5799 };
5800 static hda_nid_t alc260_test_adc_nids[2] = {
5801         0x04, 0x05,
5802 };
5803 /* For testing the ALC260, each input MUX needs its own definition since
5804  * the signal assignments are different.  This assumes that the first ADC
5805  * is NID 0x04.
5806  */
5807 static struct hda_input_mux alc260_test_capture_sources[2] = {
5808         {
5809                 .num_items = 7,
5810                 .items = {
5811                         { "MIC1 pin", 0x0 },
5812                         { "MIC2 pin", 0x1 },
5813                         { "LINE1 pin", 0x2 },
5814                         { "LINE2 pin", 0x3 },
5815                         { "CD pin", 0x4 },
5816                         { "LINE-OUT pin", 0x5 },
5817                         { "HP-OUT pin", 0x6 },
5818                 },
5819         },
5820         {
5821                 .num_items = 8,
5822                 .items = {
5823                         { "MIC1 pin", 0x0 },
5824                         { "MIC2 pin", 0x1 },
5825                         { "LINE1 pin", 0x2 },
5826                         { "LINE2 pin", 0x3 },
5827                         { "CD pin", 0x4 },
5828                         { "Mixer", 0x5 },
5829                         { "LINE-OUT pin", 0x6 },
5830                         { "HP-OUT pin", 0x7 },
5831                 },
5832         },
5833 };
5834 static struct snd_kcontrol_new alc260_test_mixer[] = {
5835         /* Output driver widgets */
5836         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
5837         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
5838         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5839         HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
5840         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5841         HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),
5842
5843         /* Modes for retasking pin widgets
5844          * Note: the ALC260 doesn't seem to act on requests to enable mic
5845          * bias from NIDs 0x0f and 0x10.  The ALC260 datasheet doesn't
5846          * mention this restriction.  At this stage it's not clear whether
5847          * this behaviour is intentional or is a hardware bug in chip
5848          * revisions available at least up until early 2006.  Therefore for
5849          * now allow the "HP-OUT" and "LINE-OUT" Mode controls to span all
5850          * choices, but if it turns out that the lack of mic bias for these
5851          * NIDs is intentional we could change their modes from
5852          * ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
5853          */
5854         ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
5855         ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
5856         ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
5857         ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
5858         ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
5859         ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),
5860
5861         /* Loopback mixer controls */
5862         HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
5863         HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
5864         HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
5865         HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
5866         HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
5867         HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
5868         HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
5869         HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
5870         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5871         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5872         HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
5873         HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
5874         HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
5875         HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
5876
5877         /* Controls for GPIO pins, assuming they are configured as outputs */
5878         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
5879         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
5880         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
5881         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
5882
5883         /* Switches to allow the digital IO pins to be enabled.  The datasheet
5884          * is ambigious as to which NID is which; testing on laptops which
5885          * make this output available should provide clarification.
5886          */
5887         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
5888         ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),
5889
5890         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
5891          * this output to turn on an external amplifier.
5892          */
5893         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
5894         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
5895
5896         { } /* end */
5897 };
5898 static struct hda_verb alc260_test_init_verbs[] = {
5899         /* Enable all GPIOs as outputs with an initial value of 0 */
5900         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
5901         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5902         {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
5903
5904         /* Enable retasking pins as output, initially without power amp */
5905         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5906         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5907         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5908         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5909         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5910         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5911
5912         /* Disable digital (SPDIF) pins initially, but users can enable
5913          * them via a mixer switch.  In the case of SPDIF-out, this initverb
5914          * payload also sets the generation to 0, output to be in "consumer"
5915          * PCM format, copyright asserted, no pre-emphasis and no validity
5916          * control.
5917          */
5918         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5919         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5920
5921         /* Ensure mic1, mic2, line1 and line2 pin widgets take input from the
5922          * OUT1 sum bus when acting as an output.
5923          */
5924         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5925         {0x0c, AC_VERB_SET_CONNECT_SEL, 0},
5926         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5927         {0x0e, AC_VERB_SET_CONNECT_SEL, 0},
5928
5929         /* Start with output sum widgets muted and their output gains at min */
5930         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5931         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5932         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5933         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5934         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5935         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5936         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5937         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5938         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5939
5940         /* Unmute retasking pin widget output buffers since the default
5941          * state appears to be output.  As the pin mode is changed by the
5942          * user the pin mode control will take care of enabling the pin's
5943          * input/output buffers as needed.
5944          */
5945         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5946         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5947         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5948         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5949         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5950         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5951         /* Also unmute the mono-out pin widget */
5952         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5953
5954         /* Mute capture amp left and right */
5955         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5956         /* Set ADC connection select to match default mixer setting (mic1
5957          * pin)
5958          */
5959         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5960
5961         /* Do the same for the second ADC: mute capture input amp and
5962          * set ADC connection to mic1 pin
5963          */
5964         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5965         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5966
5967         /* Mute all inputs to mixer widget (even unconnected ones) */
5968         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5969         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5970         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5971         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5972         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5973         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5974         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5975         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5976
5977         { }
5978 };
5979 #endif
5980
5981 #define alc260_pcm_analog_playback      alc880_pcm_analog_alt_playback
5982 #define alc260_pcm_analog_capture       alc880_pcm_analog_capture
5983
5984 #define alc260_pcm_digital_playback     alc880_pcm_digital_playback
5985 #define alc260_pcm_digital_capture      alc880_pcm_digital_capture
5986
5987 /*
5988  * for BIOS auto-configuration
5989  */
5990
5991 static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
5992                                         const char *pfx, int *vol_bits)
5993 {
5994         hda_nid_t nid_vol;
5995         unsigned long vol_val, sw_val;
5996         int err;
5997
5998         if (nid >= 0x0f && nid < 0x11) {
5999                 nid_vol = nid - 0x7;
6000                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
6001                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
6002         } else if (nid == 0x11) {
6003                 nid_vol = nid - 0x7;
6004                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT);
6005                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
6006         } else if (nid >= 0x12 && nid <= 0x15) {
6007                 nid_vol = 0x08;
6008                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
6009                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
6010         } else
6011                 return 0; /* N/A */
6012
6013         if (!(*vol_bits & (1 << nid_vol))) {
6014                 /* first control for the volume widget */
6015                 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx, vol_val);
6016                 if (err < 0)
6017                         return err;
6018                 *vol_bits |= (1 << nid_vol);
6019         }
6020         err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, sw_val);
6021         if (err < 0)
6022                 return err;
6023         return 1;
6024 }
6025
6026 /* add playback controls from the parsed DAC table */
6027 static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
6028                                              const struct auto_pin_cfg *cfg)
6029 {
6030         hda_nid_t nid;
6031         int err;
6032         int vols = 0;
6033
6034         spec->multiout.num_dacs = 1;
6035         spec->multiout.dac_nids = spec->private_dac_nids;
6036         spec->multiout.dac_nids[0] = 0x02;
6037
6038         nid = cfg->line_out_pins[0];
6039         if (nid) {
6040                 const char *pfx;
6041                 if (!cfg->speaker_pins[0] && !cfg->hp_pins[0])
6042                         pfx = "Master";
6043                 else if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
6044                         pfx = "Speaker";
6045                 else
6046                         pfx = "Front";
6047                 err = alc260_add_playback_controls(spec, nid, pfx, &vols);
6048                 if (err < 0)
6049                         return err;
6050         }
6051
6052         nid = cfg->speaker_pins[0];
6053         if (nid) {
6054                 err = alc260_add_playback_controls(spec, nid, "Speaker", &vols);
6055                 if (err < 0)
6056                         return err;
6057         }
6058
6059         nid = cfg->hp_pins[0];
6060         if (nid) {
6061                 err = alc260_add_playback_controls(spec, nid, "Headphone",
6062                                                    &vols);
6063                 if (err < 0)
6064                         return err;
6065         }
6066         return 0;
6067 }
6068
6069 /* create playback/capture controls for input pins */
6070 static int alc260_auto_create_input_ctls(struct hda_codec *codec,
6071                                                 const struct auto_pin_cfg *cfg)
6072 {
6073         return alc_auto_create_input_ctls(codec, cfg, 0x07, 0x04, 0x05);
6074 }
6075
6076 static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
6077                                               hda_nid_t nid, int pin_type,
6078                                               int sel_idx)
6079 {
6080         alc_set_pin_output(codec, nid, pin_type);
6081         /* need the manual connection? */
6082         if (nid >= 0x12) {
6083                 int idx = nid - 0x12;
6084                 snd_hda_codec_write(codec, idx + 0x0b, 0,
6085                                     AC_VERB_SET_CONNECT_SEL, sel_idx);
6086         }
6087 }
6088
6089 static void alc260_auto_init_multi_out(struct hda_codec *codec)
6090 {
6091         struct alc_spec *spec = codec->spec;
6092         hda_nid_t nid;
6093
6094         nid = spec->autocfg.line_out_pins[0];
6095         if (nid) {
6096                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
6097                 alc260_auto_set_output_and_unmute(codec, nid, pin_type, 0);
6098         }
6099
6100         nid = spec->autocfg.speaker_pins[0];
6101         if (nid)
6102                 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
6103
6104         nid = spec->autocfg.hp_pins[0];
6105         if (nid)
6106                 alc260_auto_set_output_and_unmute(codec, nid, PIN_HP, 0);
6107 }
6108
6109 #define ALC260_PIN_CD_NID               0x16
6110 static void alc260_auto_init_analog_input(struct hda_codec *codec)
6111 {
6112         struct alc_spec *spec = codec->spec;
6113         int i;
6114
6115         for (i = 0; i < AUTO_PIN_LAST; i++) {
6116                 hda_nid_t nid = spec->autocfg.input_pins[i];
6117                 if (nid >= 0x12) {
6118                         alc_set_input_pin(codec, nid, i);
6119                         if (nid != ALC260_PIN_CD_NID &&
6120                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
6121                                 snd_hda_codec_write(codec, nid, 0,
6122                                                     AC_VERB_SET_AMP_GAIN_MUTE,
6123                                                     AMP_OUT_MUTE);
6124                 }
6125         }
6126 }
6127
6128 /*
6129  * generic initialization of ADC, input mixers and output mixers
6130  */
6131 static struct hda_verb alc260_volume_init_verbs[] = {
6132         /*
6133          * Unmute ADC0-1 and set the default input to mic-in
6134          */
6135         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
6136         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6137         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
6138         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6139
6140         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
6141          * mixer widget
6142          * Note: PASD motherboards uses the Line In 2 as the input for
6143          * front panel mic (mic 2)
6144          */
6145         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
6146         /* mute analog inputs */
6147         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6148         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6149         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6150         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6151         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6152
6153         /*
6154          * Set up output mixers (0x08 - 0x0a)
6155          */
6156         /* set vol=0 to output mixers */
6157         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6158         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6159         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6160         /* set up input amps for analog loopback */
6161         /* Amp Indices: DAC = 0, mixer = 1 */
6162         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6163         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6164         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6165         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6166         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6167         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6168
6169         { }
6170 };
6171
6172 static int alc260_parse_auto_config(struct hda_codec *codec)
6173 {
6174         struct alc_spec *spec = codec->spec;
6175         int err;
6176         static hda_nid_t alc260_ignore[] = { 0x17, 0 };
6177
6178         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
6179                                            alc260_ignore);
6180         if (err < 0)
6181                 return err;
6182         err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg);
6183         if (err < 0)
6184                 return err;
6185         if (!spec->kctls.list)
6186                 return 0; /* can't find valid BIOS pin config */
6187         err = alc260_auto_create_input_ctls(codec, &spec->autocfg);
6188         if (err < 0)
6189                 return err;
6190
6191         spec->multiout.max_channels = 2;
6192
6193         if (spec->autocfg.dig_outs)
6194                 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
6195         if (spec->kctls.list)
6196                 add_mixer(spec, spec->kctls.list);
6197
6198         add_verb(spec, alc260_volume_init_verbs);
6199
6200         spec->num_mux_defs = 1;
6201         spec->input_mux = &spec->private_imux[0];
6202
6203         alc_ssid_check(codec, 0x10, 0x15, 0x0f);
6204
6205         return 1;
6206 }
6207
6208 /* additional initialization for auto-configuration model */
6209 static void alc260_auto_init(struct hda_codec *codec)
6210 {
6211         struct alc_spec *spec = codec->spec;
6212         alc260_auto_init_multi_out(codec);
6213         alc260_auto_init_analog_input(codec);
6214         if (spec->unsol_event)
6215                 alc_inithook(codec);
6216 }
6217
6218 #ifdef CONFIG_SND_HDA_POWER_SAVE
6219 static struct hda_amp_list alc260_loopbacks[] = {
6220         { 0x07, HDA_INPUT, 0 },
6221         { 0x07, HDA_INPUT, 1 },
6222         { 0x07, HDA_INPUT, 2 },
6223         { 0x07, HDA_INPUT, 3 },
6224         { 0x07, HDA_INPUT, 4 },
6225         { } /* end */
6226 };
6227 #endif
6228
6229 /*
6230  * ALC260 configurations
6231  */
6232 static const char *alc260_models[ALC260_MODEL_LAST] = {
6233         [ALC260_BASIC]          = "basic",
6234         [ALC260_HP]             = "hp",
6235         [ALC260_HP_3013]        = "hp-3013",
6236         [ALC260_HP_DC7600]      = "hp-dc7600",
6237         [ALC260_FUJITSU_S702X]  = "fujitsu",
6238         [ALC260_ACER]           = "acer",
6239         [ALC260_WILL]           = "will",
6240         [ALC260_REPLACER_672V]  = "replacer",
6241         [ALC260_FAVORIT100]     = "favorit100",
6242 #ifdef CONFIG_SND_DEBUG
6243         [ALC260_TEST]           = "test",
6244 #endif
6245         [ALC260_AUTO]           = "auto",
6246 };
6247
6248 static struct snd_pci_quirk alc260_cfg_tbl[] = {
6249         SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER),
6250         SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
6251         SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FAVORIT100),
6252         SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
6253         SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_AUTO), /* no quirk */
6254         SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
6255         SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP_3013),
6256         SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_DC7600),
6257         SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
6258         SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
6259         SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP),
6260         SND_PCI_QUIRK(0x103c, 0x3016, "HP", ALC260_HP),
6261         SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_BASIC),
6262         SND_PCI_QUIRK(0x104d, 0x81cc, "Sony VAIO", ALC260_BASIC),
6263         SND_PCI_QUIRK(0x104d, 0x81cd, "Sony VAIO", ALC260_BASIC),
6264         SND_PCI_QUIRK(0x10cf, 0x1326, "Fujitsu S702X", ALC260_FUJITSU_S702X),
6265         SND_PCI_QUIRK(0x152d, 0x0729, "CTL U553W", ALC260_BASIC),
6266         SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_REPLACER_672V),
6267         SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_WILL),
6268         {}
6269 };
6270
6271 static struct alc_config_preset alc260_presets[] = {
6272         [ALC260_BASIC] = {
6273                 .mixers = { alc260_base_output_mixer,
6274                             alc260_input_mixer },
6275                 .init_verbs = { alc260_init_verbs },
6276                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6277                 .dac_nids = alc260_dac_nids,
6278                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
6279                 .adc_nids = alc260_adc_nids,
6280                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6281                 .channel_mode = alc260_modes,
6282                 .input_mux = &alc260_capture_source,
6283         },
6284         [ALC260_HP] = {
6285                 .mixers = { alc260_hp_output_mixer,
6286                             alc260_input_mixer },
6287                 .init_verbs = { alc260_init_verbs,
6288                                 alc260_hp_unsol_verbs },
6289                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6290                 .dac_nids = alc260_dac_nids,
6291                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
6292                 .adc_nids = alc260_adc_nids_alt,
6293                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6294                 .channel_mode = alc260_modes,
6295                 .input_mux = &alc260_capture_source,
6296                 .unsol_event = alc260_hp_unsol_event,
6297                 .init_hook = alc260_hp_automute,
6298         },
6299         [ALC260_HP_DC7600] = {
6300                 .mixers = { alc260_hp_dc7600_mixer,
6301                             alc260_input_mixer },
6302                 .init_verbs = { alc260_init_verbs,
6303                                 alc260_hp_dc7600_verbs },
6304                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6305                 .dac_nids = alc260_dac_nids,
6306                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
6307                 .adc_nids = alc260_adc_nids_alt,
6308                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6309                 .channel_mode = alc260_modes,
6310                 .input_mux = &alc260_capture_source,
6311                 .unsol_event = alc260_hp_3012_unsol_event,
6312                 .init_hook = alc260_hp_3012_automute,
6313         },
6314         [ALC260_HP_3013] = {
6315                 .mixers = { alc260_hp_3013_mixer,
6316                             alc260_input_mixer },
6317                 .init_verbs = { alc260_hp_3013_init_verbs,
6318                                 alc260_hp_3013_unsol_verbs },
6319                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6320                 .dac_nids = alc260_dac_nids,
6321                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
6322                 .adc_nids = alc260_adc_nids_alt,
6323                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6324                 .channel_mode = alc260_modes,
6325                 .input_mux = &alc260_capture_source,
6326                 .unsol_event = alc260_hp_3013_unsol_event,
6327                 .init_hook = alc260_hp_3013_automute,
6328         },
6329         [ALC260_FUJITSU_S702X] = {
6330                 .mixers = { alc260_fujitsu_mixer },
6331                 .init_verbs = { alc260_fujitsu_init_verbs },
6332                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6333                 .dac_nids = alc260_dac_nids,
6334                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
6335                 .adc_nids = alc260_dual_adc_nids,
6336                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6337                 .channel_mode = alc260_modes,
6338                 .num_mux_defs = ARRAY_SIZE(alc260_fujitsu_capture_sources),
6339                 .input_mux = alc260_fujitsu_capture_sources,
6340         },
6341         [ALC260_ACER] = {
6342                 .mixers = { alc260_acer_mixer },
6343                 .init_verbs = { alc260_acer_init_verbs },
6344                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6345                 .dac_nids = alc260_dac_nids,
6346                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
6347                 .adc_nids = alc260_dual_adc_nids,
6348                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6349                 .channel_mode = alc260_modes,
6350                 .num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources),
6351                 .input_mux = alc260_acer_capture_sources,
6352         },
6353         [ALC260_FAVORIT100] = {
6354                 .mixers = { alc260_favorit100_mixer },
6355                 .init_verbs = { alc260_favorit100_init_verbs },
6356                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6357                 .dac_nids = alc260_dac_nids,
6358                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
6359                 .adc_nids = alc260_dual_adc_nids,
6360                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6361                 .channel_mode = alc260_modes,
6362                 .num_mux_defs = ARRAY_SIZE(alc260_favorit100_capture_sources),
6363                 .input_mux = alc260_favorit100_capture_sources,
6364         },
6365         [ALC260_WILL] = {
6366                 .mixers = { alc260_will_mixer },
6367                 .init_verbs = { alc260_init_verbs, alc260_will_verbs },
6368                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6369                 .dac_nids = alc260_dac_nids,
6370                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
6371                 .adc_nids = alc260_adc_nids,
6372                 .dig_out_nid = ALC260_DIGOUT_NID,
6373                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6374                 .channel_mode = alc260_modes,
6375                 .input_mux = &alc260_capture_source,
6376         },
6377         [ALC260_REPLACER_672V] = {
6378                 .mixers = { alc260_replacer_672v_mixer },
6379                 .init_verbs = { alc260_init_verbs, alc260_replacer_672v_verbs },
6380                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6381                 .dac_nids = alc260_dac_nids,
6382                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
6383                 .adc_nids = alc260_adc_nids,
6384                 .dig_out_nid = ALC260_DIGOUT_NID,
6385                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6386                 .channel_mode = alc260_modes,
6387                 .input_mux = &alc260_capture_source,
6388                 .unsol_event = alc260_replacer_672v_unsol_event,
6389                 .init_hook = alc260_replacer_672v_automute,
6390         },
6391 #ifdef CONFIG_SND_DEBUG
6392         [ALC260_TEST] = {
6393                 .mixers = { alc260_test_mixer },
6394                 .init_verbs = { alc260_test_init_verbs },
6395                 .num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
6396                 .dac_nids = alc260_test_dac_nids,
6397                 .num_adc_nids = ARRAY_SIZE(alc260_test_adc_nids),
6398                 .adc_nids = alc260_test_adc_nids,
6399                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6400                 .channel_mode = alc260_modes,
6401                 .num_mux_defs = ARRAY_SIZE(alc260_test_capture_sources),
6402                 .input_mux = alc260_test_capture_sources,
6403         },
6404 #endif
6405 };
6406
6407 static int patch_alc260(struct hda_codec *codec)
6408 {
6409         struct alc_spec *spec;
6410         int err, board_config;
6411
6412         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6413         if (spec == NULL)
6414                 return -ENOMEM;
6415
6416         codec->spec = spec;
6417
6418         board_config = snd_hda_check_board_config(codec, ALC260_MODEL_LAST,
6419                                                   alc260_models,
6420                                                   alc260_cfg_tbl);
6421         if (board_config < 0) {
6422                 snd_printd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6423                            codec->chip_name);
6424                 board_config = ALC260_AUTO;
6425         }
6426
6427         if (board_config == ALC260_AUTO) {
6428                 /* automatic parse from the BIOS config */
6429                 err = alc260_parse_auto_config(codec);
6430                 if (err < 0) {
6431                         alc_free(codec);
6432                         return err;
6433                 } else if (!err) {
6434                         printk(KERN_INFO
6435                                "hda_codec: Cannot set up configuration "
6436                                "from BIOS.  Using base mode...\n");
6437                         board_config = ALC260_BASIC;
6438                 }
6439         }
6440
6441         err = snd_hda_attach_beep_device(codec, 0x1);
6442         if (err < 0) {
6443                 alc_free(codec);
6444                 return err;
6445         }
6446
6447         if (board_config != ALC260_AUTO)
6448                 setup_preset(codec, &alc260_presets[board_config]);
6449
6450         spec->stream_analog_playback = &alc260_pcm_analog_playback;
6451         spec->stream_analog_capture = &alc260_pcm_analog_capture;
6452
6453         spec->stream_digital_playback = &alc260_pcm_digital_playback;
6454         spec->stream_digital_capture = &alc260_pcm_digital_capture;
6455
6456         if (!spec->adc_nids && spec->input_mux) {
6457                 /* check whether NID 0x04 is valid */
6458                 unsigned int wcap = get_wcaps(codec, 0x04);
6459                 wcap = get_wcaps_type(wcap);
6460                 /* get type */
6461                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
6462                         spec->adc_nids = alc260_adc_nids_alt;
6463                         spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
6464                 } else {
6465                         spec->adc_nids = alc260_adc_nids;
6466                         spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
6467                 }
6468         }
6469         set_capture_mixer(codec);
6470         set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
6471
6472         spec->vmaster_nid = 0x08;
6473
6474         codec->patch_ops = alc_patch_ops;
6475         if (board_config == ALC260_AUTO)
6476                 spec->init_hook = alc260_auto_init;
6477 #ifdef CONFIG_SND_HDA_POWER_SAVE
6478         if (!spec->loopback.amplist)
6479                 spec->loopback.amplist = alc260_loopbacks;
6480 #endif
6481         codec->proc_widget_hook = print_realtek_coef;
6482
6483         return 0;
6484 }
6485
6486
6487 /*
6488  * ALC882/883/885/888/889 support
6489  *
6490  * ALC882 is almost identical with ALC880 but has cleaner and more flexible
6491  * configuration.  Each pin widget can choose any input DACs and a mixer.
6492  * Each ADC is connected from a mixer of all inputs.  This makes possible
6493  * 6-channel independent captures.
6494  *
6495  * In addition, an independent DAC for the multi-playback (not used in this
6496  * driver yet).
6497  */
6498 #define ALC882_DIGOUT_NID       0x06
6499 #define ALC882_DIGIN_NID        0x0a
6500 #define ALC883_DIGOUT_NID       ALC882_DIGOUT_NID
6501 #define ALC883_DIGIN_NID        ALC882_DIGIN_NID
6502 #define ALC1200_DIGOUT_NID      0x10
6503
6504
6505 static struct hda_channel_mode alc882_ch_modes[1] = {
6506         { 8, NULL }
6507 };
6508
6509 /* DACs */
6510 static hda_nid_t alc882_dac_nids[4] = {
6511         /* front, rear, clfe, rear_surr */
6512         0x02, 0x03, 0x04, 0x05
6513 };
6514 #define alc883_dac_nids         alc882_dac_nids
6515
6516 /* ADCs */
6517 #define alc882_adc_nids         alc880_adc_nids
6518 #define alc882_adc_nids_alt     alc880_adc_nids_alt
6519 #define alc883_adc_nids         alc882_adc_nids_alt
6520 static hda_nid_t alc883_adc_nids_alt[1] = { 0x08 };
6521 static hda_nid_t alc883_adc_nids_rev[2] = { 0x09, 0x08 };
6522 #define alc889_adc_nids         alc880_adc_nids
6523
6524 static hda_nid_t alc882_capsrc_nids[3] = { 0x24, 0x23, 0x22 };
6525 static hda_nid_t alc882_capsrc_nids_alt[2] = { 0x23, 0x22 };
6526 #define alc883_capsrc_nids      alc882_capsrc_nids_alt
6527 static hda_nid_t alc883_capsrc_nids_rev[2] = { 0x22, 0x23 };
6528 #define alc889_capsrc_nids      alc882_capsrc_nids
6529
6530 /* input MUX */
6531 /* FIXME: should be a matrix-type input source selection */
6532
6533 static struct hda_input_mux alc882_capture_source = {
6534         .num_items = 4,
6535         .items = {
6536                 { "Mic", 0x0 },
6537                 { "Front Mic", 0x1 },
6538                 { "Line", 0x2 },
6539                 { "CD", 0x4 },
6540         },
6541 };
6542
6543 #define alc883_capture_source   alc882_capture_source
6544
6545 static struct hda_input_mux alc889_capture_source = {
6546         .num_items = 3,
6547         .items = {
6548                 { "Front Mic", 0x0 },
6549                 { "Mic", 0x3 },
6550                 { "Line", 0x2 },
6551         },
6552 };
6553
6554 static struct hda_input_mux mb5_capture_source = {
6555         .num_items = 3,
6556         .items = {
6557                 { "Mic", 0x1 },
6558                 { "Line", 0x2 },
6559                 { "CD", 0x4 },
6560         },
6561 };
6562
6563 static struct hda_input_mux alc883_3stack_6ch_intel = {
6564         .num_items = 4,
6565         .items = {
6566                 { "Mic", 0x1 },
6567                 { "Front Mic", 0x0 },
6568                 { "Line", 0x2 },
6569                 { "CD", 0x4 },
6570         },
6571 };
6572
6573 static struct hda_input_mux alc883_lenovo_101e_capture_source = {
6574         .num_items = 2,
6575         .items = {
6576                 { "Mic", 0x1 },
6577                 { "Line", 0x2 },
6578         },
6579 };
6580
6581 static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
6582         .num_items = 4,
6583         .items = {
6584                 { "Mic", 0x0 },
6585                 { "iMic", 0x1 },
6586                 { "Line", 0x2 },
6587                 { "CD", 0x4 },
6588         },
6589 };
6590
6591 static struct hda_input_mux alc883_fujitsu_pi2515_capture_source = {
6592         .num_items = 2,
6593         .items = {
6594                 { "Mic", 0x0 },
6595                 { "Int Mic", 0x1 },
6596         },
6597 };
6598
6599 static struct hda_input_mux alc883_lenovo_sky_capture_source = {
6600         .num_items = 3,
6601         .items = {
6602                 { "Mic", 0x0 },
6603                 { "Front Mic", 0x1 },
6604                 { "Line", 0x4 },
6605         },
6606 };
6607
6608 static struct hda_input_mux alc883_asus_eee1601_capture_source = {
6609         .num_items = 2,
6610         .items = {
6611                 { "Mic", 0x0 },
6612                 { "Line", 0x2 },
6613         },
6614 };
6615
6616 static struct hda_input_mux alc889A_mb31_capture_source = {
6617         .num_items = 2,
6618         .items = {
6619                 { "Mic", 0x0 },
6620                 /* Front Mic (0x01) unused */
6621                 { "Line", 0x2 },
6622                 /* Line 2 (0x03) unused */
6623                 /* CD (0x04) unsused? */
6624         },
6625 };
6626
6627 /*
6628  * 2ch mode
6629  */
6630 static struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
6631         { 2, NULL }
6632 };
6633
6634 /*
6635  * 2ch mode
6636  */
6637 static struct hda_verb alc882_3ST_ch2_init[] = {
6638         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6639         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6640         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6641         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6642         { } /* end */
6643 };
6644
6645 /*
6646  * 4ch mode
6647  */
6648 static struct hda_verb alc882_3ST_ch4_init[] = {
6649         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6650         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6651         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6652         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6653         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6654         { } /* end */
6655 };
6656
6657 /*
6658  * 6ch mode
6659  */
6660 static struct hda_verb alc882_3ST_ch6_init[] = {
6661         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6662         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6663         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6664         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6665         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6666         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6667         { } /* end */
6668 };
6669
6670 static struct hda_channel_mode alc882_3ST_6ch_modes[3] = {
6671         { 2, alc882_3ST_ch2_init },
6672         { 4, alc882_3ST_ch4_init },
6673         { 6, alc882_3ST_ch6_init },
6674 };
6675
6676 #define alc883_3ST_6ch_modes    alc882_3ST_6ch_modes
6677
6678 /*
6679  * 2ch mode
6680  */
6681 static struct hda_verb alc883_3ST_ch2_clevo_init[] = {
6682         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
6683         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6684         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6685         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6686         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6687         { } /* end */
6688 };
6689
6690 /*
6691  * 4ch mode
6692  */
6693 static struct hda_verb alc883_3ST_ch4_clevo_init[] = {
6694         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6695         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6696         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6697         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6698         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6699         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6700         { } /* end */
6701 };
6702
6703 /*
6704  * 6ch mode
6705  */
6706 static struct hda_verb alc883_3ST_ch6_clevo_init[] = {
6707         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6708         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6709         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6710         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6711         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6712         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6713         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6714         { } /* end */
6715 };
6716
6717 static struct hda_channel_mode alc883_3ST_6ch_clevo_modes[3] = {
6718         { 2, alc883_3ST_ch2_clevo_init },
6719         { 4, alc883_3ST_ch4_clevo_init },
6720         { 6, alc883_3ST_ch6_clevo_init },
6721 };
6722
6723
6724 /*
6725  * 6ch mode
6726  */
6727 static struct hda_verb alc882_sixstack_ch6_init[] = {
6728         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
6729         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6730         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6731         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6732         { } /* end */
6733 };
6734
6735 /*
6736  * 8ch mode
6737  */
6738 static struct hda_verb alc882_sixstack_ch8_init[] = {
6739         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6740         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6741         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6742         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6743         { } /* end */
6744 };
6745
6746 static struct hda_channel_mode alc882_sixstack_modes[2] = {
6747         { 6, alc882_sixstack_ch6_init },
6748         { 8, alc882_sixstack_ch8_init },
6749 };
6750
6751 /*
6752  * macbook pro ALC885 can switch LineIn to LineOut without losing Mic
6753  */
6754
6755 /*
6756  * 2ch mode
6757  */
6758 static struct hda_verb alc885_mbp_ch2_init[] = {
6759         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6760         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6761         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6762         { } /* end */
6763 };
6764
6765 /*
6766  * 4ch mode
6767  */
6768 static struct hda_verb alc885_mbp_ch4_init[] = {
6769         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6770         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6771         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6772         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6773         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6774         { } /* end */
6775 };
6776
6777 static struct hda_channel_mode alc885_mbp_4ch_modes[2] = {
6778         { 2, alc885_mbp_ch2_init },
6779         { 4, alc885_mbp_ch4_init },
6780 };
6781
6782 /*
6783  * 2ch
6784  * Speakers/Woofer/HP = Front
6785  * LineIn = Input
6786  */
6787 static struct hda_verb alc885_mb5_ch2_init[] = {
6788         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6789         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6790         { } /* end */
6791 };
6792
6793 /*
6794  * 6ch mode
6795  * Speakers/HP = Front
6796  * Woofer = LFE
6797  * LineIn = Surround
6798  */
6799 static struct hda_verb alc885_mb5_ch6_init[] = {
6800         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6801         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6802         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
6803         { } /* end */
6804 };
6805
6806 static struct hda_channel_mode alc885_mb5_6ch_modes[2] = {
6807         { 2, alc885_mb5_ch2_init },
6808         { 6, alc885_mb5_ch6_init },
6809 };
6810
6811
6812 /*
6813  * 2ch mode
6814  */
6815 static struct hda_verb alc883_4ST_ch2_init[] = {
6816         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6817         { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6818         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6819         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6820         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6821         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6822         { } /* end */
6823 };
6824
6825 /*
6826  * 4ch mode
6827  */
6828 static struct hda_verb alc883_4ST_ch4_init[] = {
6829         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6830         { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6831         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6832         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6833         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6834         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6835         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6836         { } /* end */
6837 };
6838
6839 /*
6840  * 6ch mode
6841  */
6842 static struct hda_verb alc883_4ST_ch6_init[] = {
6843         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6844         { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6845         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6846         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6847         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6848         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6849         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6850         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6851         { } /* end */
6852 };
6853
6854 /*
6855  * 8ch mode
6856  */
6857 static struct hda_verb alc883_4ST_ch8_init[] = {
6858         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6859         { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6860         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03 },
6861         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6862         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6863         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6864         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6865         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6866         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6867         { } /* end */
6868 };
6869
6870 static struct hda_channel_mode alc883_4ST_8ch_modes[4] = {
6871         { 2, alc883_4ST_ch2_init },
6872         { 4, alc883_4ST_ch4_init },
6873         { 6, alc883_4ST_ch6_init },
6874         { 8, alc883_4ST_ch8_init },
6875 };
6876
6877
6878 /*
6879  * 2ch mode
6880  */
6881 static struct hda_verb alc883_3ST_ch2_intel_init[] = {
6882         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6883         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6884         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6885         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6886         { } /* end */
6887 };
6888
6889 /*
6890  * 4ch mode
6891  */
6892 static struct hda_verb alc883_3ST_ch4_intel_init[] = {
6893         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6894         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6895         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6896         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6897         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6898         { } /* end */
6899 };
6900
6901 /*
6902  * 6ch mode
6903  */
6904 static struct hda_verb alc883_3ST_ch6_intel_init[] = {
6905         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6906         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6907         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x02 },
6908         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6909         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6910         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6911         { } /* end */
6912 };
6913
6914 static struct hda_channel_mode alc883_3ST_6ch_intel_modes[3] = {
6915         { 2, alc883_3ST_ch2_intel_init },
6916         { 4, alc883_3ST_ch4_intel_init },
6917         { 6, alc883_3ST_ch6_intel_init },
6918 };
6919
6920 /*
6921  * 2ch mode
6922  */
6923 static struct hda_verb alc889_ch2_intel_init[] = {
6924         { 0x14, AC_VERB_SET_CONNECT_SEL, 0x00 },
6925         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x00 },
6926         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x00 },
6927         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00 },
6928         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6929         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6930         { } /* end */
6931 };
6932
6933 /*
6934  * 6ch mode
6935  */
6936 static struct hda_verb alc889_ch6_intel_init[] = {
6937         { 0x14, AC_VERB_SET_CONNECT_SEL, 0x00 },
6938         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x01 },
6939         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x02 },
6940         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03 },
6941         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6942         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6943         { } /* end */
6944 };
6945
6946 /*
6947  * 8ch mode
6948  */
6949 static struct hda_verb alc889_ch8_intel_init[] = {
6950         { 0x14, AC_VERB_SET_CONNECT_SEL, 0x00 },
6951         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x01 },
6952         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x02 },
6953         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03 },
6954         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x03 },
6955         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6956         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6957         { } /* end */
6958 };
6959
6960 static struct hda_channel_mode alc889_8ch_intel_modes[3] = {
6961         { 2, alc889_ch2_intel_init },
6962         { 6, alc889_ch6_intel_init },
6963         { 8, alc889_ch8_intel_init },
6964 };
6965
6966 /*
6967  * 6ch mode
6968  */
6969 static struct hda_verb alc883_sixstack_ch6_init[] = {
6970         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
6971         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6972         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6973         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6974         { } /* end */
6975 };
6976
6977 /*
6978  * 8ch mode
6979  */
6980 static struct hda_verb alc883_sixstack_ch8_init[] = {
6981         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6982         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6983         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6984         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6985         { } /* end */
6986 };
6987
6988 static struct hda_channel_mode alc883_sixstack_modes[2] = {
6989         { 6, alc883_sixstack_ch6_init },
6990         { 8, alc883_sixstack_ch8_init },
6991 };
6992
6993
6994 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
6995  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
6996  */
6997 static struct snd_kcontrol_new alc882_base_mixer[] = {
6998         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6999         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7000         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7001         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7002         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7003         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7004         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7005         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7006         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7007         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7008         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7009         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7010         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7011         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7012         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7013         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7014         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7015         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7016         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7017         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7018         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7019         { } /* end */
7020 };
7021
7022 static struct snd_kcontrol_new alc885_mbp3_mixer[] = {
7023         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
7024         HDA_BIND_MUTE   ("Speaker Playback Switch", 0x0c, 0x02, HDA_INPUT),
7025         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0e, 0x00, HDA_OUTPUT),
7026         HDA_BIND_MUTE   ("Headphone Playback Switch", 0x0e, 0x02, HDA_INPUT),
7027         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
7028         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7029         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7030         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
7031         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
7032         HDA_CODEC_VOLUME("Line Boost", 0x1a, 0x00, HDA_INPUT),
7033         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
7034         { } /* end */
7035 };
7036
7037 static struct snd_kcontrol_new alc885_mb5_mixer[] = {
7038         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
7039         HDA_BIND_MUTE   ("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
7040         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
7041         HDA_BIND_MUTE   ("Surround Playback Switch", 0x0d, 0x02, HDA_INPUT),
7042         HDA_CODEC_VOLUME("LFE Playback Volume", 0x0e, 0x00, HDA_OUTPUT),
7043         HDA_BIND_MUTE   ("LFE Playback Switch", 0x0e, 0x02, HDA_INPUT),
7044         HDA_CODEC_VOLUME("HP Playback Volume", 0x0f, 0x00, HDA_OUTPUT),
7045         HDA_BIND_MUTE   ("HP Playback Switch", 0x0f, 0x02, HDA_INPUT),
7046         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7047         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7048         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
7049         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
7050         HDA_CODEC_VOLUME("Line Boost", 0x15, 0x00, HDA_INPUT),
7051         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0x00, HDA_INPUT),
7052         { } /* end */
7053 };
7054
7055 static struct snd_kcontrol_new alc882_w2jc_mixer[] = {
7056         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7057         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7058         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7059         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7060         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7061         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7062         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7063         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7064         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7065         { } /* end */
7066 };
7067
7068 static struct snd_kcontrol_new alc882_targa_mixer[] = {
7069         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7070         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7071         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7072         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7073         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7074         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7075         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7076         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7077         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7078         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7079         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7080         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7081         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7082         { } /* end */
7083 };
7084
7085 /* Pin assignment: Front=0x14, HP = 0x15, Front = 0x16, ???
7086  *                 Front Mic=0x18, Line In = 0x1a, Line In = 0x1b, CD = 0x1c
7087  */
7088 static struct snd_kcontrol_new alc882_asus_a7j_mixer[] = {
7089         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7090         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7091         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7092         HDA_CODEC_MUTE("Mobile Front Playback Switch", 0x16, 0x0, HDA_OUTPUT),
7093         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7094         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7095         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7096         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7097         HDA_CODEC_VOLUME("Mobile Line Playback Volume", 0x0b, 0x03, HDA_INPUT),
7098         HDA_CODEC_MUTE("Mobile Line Playback Switch", 0x0b, 0x03, HDA_INPUT),
7099         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7100         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7101         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7102         { } /* end */
7103 };
7104
7105 static struct snd_kcontrol_new alc882_asus_a7m_mixer[] = {
7106         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7107         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7108         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7109         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7110         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7111         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7112         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7113         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7114         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7115         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7116         { } /* end */
7117 };
7118
7119 static struct snd_kcontrol_new alc882_chmode_mixer[] = {
7120         {
7121                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7122                 .name = "Channel Mode",
7123                 .info = alc_ch_mode_info,
7124                 .get = alc_ch_mode_get,
7125                 .put = alc_ch_mode_put,
7126         },
7127         { } /* end */
7128 };
7129
7130 static struct hda_verb alc882_base_init_verbs[] = {
7131         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7132         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7133         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7134         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7135         /* Rear mixer */
7136         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7137         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7138         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7139         /* CLFE mixer */
7140         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7141         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7142         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7143         /* Side mixer */
7144         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7145         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7146         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7147
7148         /* mute analog input loopbacks */
7149         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7150         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7151         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7152         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7153         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7154
7155         /* Front Pin: output 0 (0x0c) */
7156         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7157         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7158         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7159         /* Rear Pin: output 1 (0x0d) */
7160         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7161         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7162         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7163         /* CLFE Pin: output 2 (0x0e) */
7164         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7165         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7166         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
7167         /* Side Pin: output 3 (0x0f) */
7168         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7169         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7170         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
7171         /* Mic (rear) pin: input vref at 80% */
7172         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7173         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7174         /* Front Mic pin: input vref at 80% */
7175         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7176         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7177         /* Line In pin: input */
7178         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7179         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7180         /* Line-2 In: Headphone output (output 0 - 0x0c) */
7181         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7182         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7183         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7184         /* CD pin widget for input */
7185         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7186
7187         /* FIXME: use matrix-type input source selection */
7188         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7189         /* Input mixer2 */
7190         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7191         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7192         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7193         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7194         /* Input mixer3 */
7195         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7196         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7197         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7198         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7199         /* ADC2: mute amp left and right */
7200         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7201         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7202         /* ADC3: mute amp left and right */
7203         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7204         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7205
7206         { }
7207 };
7208
7209 static struct hda_verb alc882_adc1_init_verbs[] = {
7210         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
7211         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7212         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7213         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7214         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7215         /* ADC1: mute amp left and right */
7216         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7217         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
7218         { }
7219 };
7220
7221 static struct hda_verb alc882_eapd_verbs[] = {
7222         /* change to EAPD mode */
7223         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7224         {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
7225         { }
7226 };
7227
7228 static struct hda_verb alc889_eapd_verbs[] = {
7229         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
7230         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
7231         { }
7232 };
7233
7234 static struct hda_verb alc_hp15_unsol_verbs[] = {
7235         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
7236         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7237         {}
7238 };
7239
7240 static struct hda_verb alc885_init_verbs[] = {
7241         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7242         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7243         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7244         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7245         /* Rear mixer */
7246         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7247         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7248         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7249         /* CLFE mixer */
7250         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7251         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7252         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7253         /* Side mixer */
7254         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7255         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7256         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7257
7258         /* mute analog input loopbacks */
7259         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7260         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7261         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7262
7263         /* Front HP Pin: output 0 (0x0c) */
7264         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7265         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7266         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7267         /* Front Pin: output 0 (0x0c) */
7268         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7269         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7270         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7271         /* Rear Pin: output 1 (0x0d) */
7272         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7273         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7274         {0x19, AC_VERB_SET_CONNECT_SEL, 0x01},
7275         /* CLFE Pin: output 2 (0x0e) */
7276         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7277         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7278         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
7279         /* Side Pin: output 3 (0x0f) */
7280         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7281         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7282         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
7283         /* Mic (rear) pin: input vref at 80% */
7284         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7285         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7286         /* Front Mic pin: input vref at 80% */
7287         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7288         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7289         /* Line In pin: input */
7290         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7291         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7292
7293         /* Mixer elements: 0x18, , 0x1a, 0x1b */
7294         /* Input mixer1 */
7295         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
7296         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7297         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7298         /* Input mixer2 */
7299         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7300         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7301         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7302         /* Input mixer3 */
7303         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7304         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7305         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7306         /* ADC2: mute amp left and right */
7307         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7308         /* ADC3: mute amp left and right */
7309         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7310
7311         { }
7312 };
7313
7314 static struct hda_verb alc885_init_input_verbs[] = {
7315         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7316         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7317         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
7318         { }
7319 };
7320
7321
7322 /* Unmute Selector 24h and set the default input to front mic */
7323 static struct hda_verb alc889_init_input_verbs[] = {
7324         {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
7325         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7326         { }
7327 };
7328
7329
7330 #define alc883_init_verbs       alc882_base_init_verbs
7331
7332 /* Mac Pro test */
7333 static struct snd_kcontrol_new alc882_macpro_mixer[] = {
7334         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7335         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7336         HDA_CODEC_MUTE("Headphone Playback Switch", 0x18, 0x0, HDA_OUTPUT),
7337         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
7338         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
7339         /* FIXME: this looks suspicious...
7340         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x02, HDA_INPUT),
7341         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x02, HDA_INPUT),
7342         */
7343         { } /* end */
7344 };
7345
7346 static struct hda_verb alc882_macpro_init_verbs[] = {
7347         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7348         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7349         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7350         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7351         /* Front Pin: output 0 (0x0c) */
7352         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7353         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7354         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7355         /* Front Mic pin: input vref at 80% */
7356         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7357         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7358         /* Speaker:  output */
7359         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7360         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7361         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x04},
7362         /* Headphone output (output 0 - 0x0c) */
7363         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7364         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7365         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
7366
7367         /* FIXME: use matrix-type input source selection */
7368         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7369         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
7370         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7371         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7372         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7373         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7374         /* Input mixer2 */
7375         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7376         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7377         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7378         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7379         /* Input mixer3 */
7380         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7381         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7382         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7383         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7384         /* ADC1: mute amp left and right */
7385         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7386         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
7387         /* ADC2: mute amp left and right */
7388         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7389         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7390         /* ADC3: mute amp left and right */
7391         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7392         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7393
7394         { }
7395 };
7396
7397 /* Macbook 5,1 */
7398 static struct hda_verb alc885_mb5_init_verbs[] = {
7399         /* DACs */
7400         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7401         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7402         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7403         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7404         /* Front mixer */
7405         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7406         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7407         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7408         /* Surround mixer */
7409         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7410         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7411         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7412         /* LFE mixer */
7413         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7414         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7415         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7416         /* HP mixer */
7417         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7418         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7419         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7420         /* Front Pin (0x0c) */
7421         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x01},
7422         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7423         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
7424         /* LFE Pin (0x0e) */
7425         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x01},
7426         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7427         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x02},
7428         /* HP Pin (0x0f) */
7429         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7430         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7431         {0x14, AC_VERB_SET_CONNECT_SEL, 0x03},
7432         /* Front Mic pin: input vref at 80% */
7433         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7434         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7435         /* Line In pin */
7436         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7437         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7438
7439         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7440         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7441         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7442         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7443         { }
7444 };
7445
7446 /* Macbook Pro rev3 */
7447 static struct hda_verb alc885_mbp3_init_verbs[] = {
7448         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7449         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7450         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7451         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7452         /* Rear mixer */
7453         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7454         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7455         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7456         /* HP mixer */
7457         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7458         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7459         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7460         /* Front Pin: output 0 (0x0c) */
7461         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7462         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7463         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7464         /* HP Pin: output 0 (0x0e) */
7465         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},
7466         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7467         {0x15, AC_VERB_SET_CONNECT_SEL, 0x02},
7468         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7469         /* Mic (rear) pin: input vref at 80% */
7470         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7471         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7472         /* Front Mic pin: input vref at 80% */
7473         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7474         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7475         /* Line In pin: use output 1 when in LineOut mode */
7476         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7477         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7478         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
7479
7480         /* FIXME: use matrix-type input source selection */
7481         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7482         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
7483         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7484         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7485         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7486         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7487         /* Input mixer2 */
7488         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7489         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7490         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7491         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7492         /* Input mixer3 */
7493         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7494         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7495         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7496         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7497         /* ADC1: mute amp left and right */
7498         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7499         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
7500         /* ADC2: mute amp left and right */
7501         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7502         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7503         /* ADC3: mute amp left and right */
7504         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7505         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7506
7507         { }
7508 };
7509
7510 /* iMac 24 mixer. */
7511 static struct snd_kcontrol_new alc885_imac24_mixer[] = {
7512         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
7513         HDA_CODEC_MUTE("Master Playback Switch", 0x0c, 0x00, HDA_INPUT),
7514         { } /* end */
7515 };
7516
7517 /* iMac 24 init verbs. */
7518 static struct hda_verb alc885_imac24_init_verbs[] = {
7519         /* Internal speakers: output 0 (0x0c) */
7520         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7521         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7522         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
7523         /* Internal speakers: output 0 (0x0c) */
7524         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7525         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7526         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
7527         /* Headphone: output 0 (0x0c) */
7528         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7529         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7530         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7531         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7532         /* Front Mic: input vref at 80% */
7533         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7534         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7535         { }
7536 };
7537
7538 /* Toggle speaker-output according to the hp-jack state */
7539 static void alc885_imac24_setup(struct hda_codec *codec)
7540 {
7541         struct alc_spec *spec = codec->spec;
7542
7543         spec->autocfg.hp_pins[0] = 0x14;
7544         spec->autocfg.speaker_pins[0] = 0x18;
7545         spec->autocfg.speaker_pins[1] = 0x1a;
7546 }
7547
7548 static void alc885_mbp3_setup(struct hda_codec *codec)
7549 {
7550         struct alc_spec *spec = codec->spec;
7551
7552         spec->autocfg.hp_pins[0] = 0x15;
7553         spec->autocfg.speaker_pins[0] = 0x14;
7554 }
7555
7556
7557 static struct hda_verb alc882_targa_verbs[] = {
7558         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7559         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7560
7561         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7562         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7563
7564         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
7565         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
7566         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7567
7568         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7569         { } /* end */
7570 };
7571
7572 /* toggle speaker-output according to the hp-jack state */
7573 static void alc882_targa_automute(struct hda_codec *codec)
7574 {
7575         struct alc_spec *spec = codec->spec;
7576         alc_automute_amp(codec);
7577         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
7578                                   spec->jack_present ? 1 : 3);
7579 }
7580
7581 static void alc882_targa_setup(struct hda_codec *codec)
7582 {
7583         struct alc_spec *spec = codec->spec;
7584
7585         spec->autocfg.hp_pins[0] = 0x14;
7586         spec->autocfg.speaker_pins[0] = 0x1b;
7587 }
7588
7589 static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res)
7590 {
7591         if ((res >> 26) == ALC880_HP_EVENT)
7592                 alc882_targa_automute(codec);
7593 }
7594
7595 static struct hda_verb alc882_asus_a7j_verbs[] = {
7596         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7597         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7598
7599         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7600         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7601         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7602
7603         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
7604         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7605         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
7606
7607         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
7608         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
7609         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7610         { } /* end */
7611 };
7612
7613 static struct hda_verb alc882_asus_a7m_verbs[] = {
7614         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7615         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7616
7617         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7618         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7619         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7620
7621         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
7622         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7623         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
7624
7625         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
7626         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
7627         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7628         { } /* end */
7629 };
7630
7631 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
7632 {
7633         unsigned int gpiostate, gpiomask, gpiodir;
7634
7635         gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
7636                                        AC_VERB_GET_GPIO_DATA, 0);
7637
7638         if (!muted)
7639                 gpiostate |= (1 << pin);
7640         else
7641                 gpiostate &= ~(1 << pin);
7642
7643         gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
7644                                       AC_VERB_GET_GPIO_MASK, 0);
7645         gpiomask |= (1 << pin);
7646
7647         gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
7648                                      AC_VERB_GET_GPIO_DIRECTION, 0);
7649         gpiodir |= (1 << pin);
7650
7651
7652         snd_hda_codec_write(codec, codec->afg, 0,
7653                             AC_VERB_SET_GPIO_MASK, gpiomask);
7654         snd_hda_codec_write(codec, codec->afg, 0,
7655                             AC_VERB_SET_GPIO_DIRECTION, gpiodir);
7656
7657         msleep(1);
7658
7659         snd_hda_codec_write(codec, codec->afg, 0,
7660                             AC_VERB_SET_GPIO_DATA, gpiostate);
7661 }
7662
7663 /* set up GPIO at initialization */
7664 static void alc885_macpro_init_hook(struct hda_codec *codec)
7665 {
7666         alc882_gpio_mute(codec, 0, 0);
7667         alc882_gpio_mute(codec, 1, 0);
7668 }
7669
7670 /* set up GPIO and update auto-muting at initialization */
7671 static void alc885_imac24_init_hook(struct hda_codec *codec)
7672 {
7673         alc885_macpro_init_hook(codec);
7674         alc_automute_amp(codec);
7675 }
7676
7677 /*
7678  * generic initialization of ADC, input mixers and output mixers
7679  */
7680 static struct hda_verb alc883_auto_init_verbs[] = {
7681         /*
7682          * Unmute ADC0-2 and set the default input to mic-in
7683          */
7684         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7685         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7686         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7687         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7688
7689         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
7690          * mixer widget
7691          * Note: PASD motherboards uses the Line In 2 as the input for
7692          * front panel mic (mic 2)
7693          */
7694         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
7695         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7696         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7697         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7698         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7699         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7700
7701         /*
7702          * Set up output mixers (0x0c - 0x0f)
7703          */
7704         /* set vol=0 to output mixers */
7705         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7706         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7707         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7708         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7709         /* set up input amps for analog loopback */
7710         /* Amp Indices: DAC = 0, mixer = 1 */
7711         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7712         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7713         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7714         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7715         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7716         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7717         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7718         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7719         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7720         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7721
7722         /* FIXME: use matrix-type input source selection */
7723         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7724         /* Input mixer2 */
7725         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7726         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7727         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
7728         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
7729         /* Input mixer3 */
7730         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7731         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7732         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
7733         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
7734
7735         { }
7736 };
7737
7738 /* 2ch mode (Speaker:front, Subwoofer:CLFE, Line:input, Headphones:front) */
7739 static struct hda_verb alc889A_mb31_ch2_init[] = {
7740         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},             /* HP as front */
7741         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Subwoofer on */
7742         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},    /* Line as input */
7743         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},   /* Line off */
7744         { } /* end */
7745 };
7746
7747 /* 4ch mode (Speaker:front, Subwoofer:CLFE, Line:CLFE, Headphones:front) */
7748 static struct hda_verb alc889A_mb31_ch4_init[] = {
7749         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},             /* HP as front */
7750         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Subwoofer on */
7751         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},   /* Line as output */
7752         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Line on */
7753         { } /* end */
7754 };
7755
7756 /* 5ch mode (Speaker:front, Subwoofer:CLFE, Line:input, Headphones:rear) */
7757 static struct hda_verb alc889A_mb31_ch5_init[] = {
7758         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},             /* HP as rear */
7759         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Subwoofer on */
7760         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},    /* Line as input */
7761         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},   /* Line off */
7762         { } /* end */
7763 };
7764
7765 /* 6ch mode (Speaker:front, Subwoofer:off, Line:CLFE, Headphones:Rear) */
7766 static struct hda_verb alc889A_mb31_ch6_init[] = {
7767         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},             /* HP as front */
7768         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},   /* Subwoofer off */
7769         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},   /* Line as output */
7770         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Line on */
7771         { } /* end */
7772 };
7773
7774 static struct hda_channel_mode alc889A_mb31_6ch_modes[4] = {
7775         { 2, alc889A_mb31_ch2_init },
7776         { 4, alc889A_mb31_ch4_init },
7777         { 5, alc889A_mb31_ch5_init },
7778         { 6, alc889A_mb31_ch6_init },
7779 };
7780
7781 static struct hda_verb alc883_medion_eapd_verbs[] = {
7782         /* eanable EAPD on medion laptop */
7783         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7784         {0x20, AC_VERB_SET_PROC_COEF, 0x3070},
7785         { }
7786 };
7787
7788 #define alc883_base_mixer       alc882_base_mixer
7789
7790 static struct snd_kcontrol_new alc883_mitac_mixer[] = {
7791         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7792         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7793         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7794         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7795         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7796         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7797         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7798         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7799         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7800         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7801         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7802         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7803         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7804         { } /* end */
7805 };
7806
7807 static struct snd_kcontrol_new alc883_clevo_m720_mixer[] = {
7808         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7809         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7810         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7811         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7812         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7813         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7814         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7815         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7816         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7817         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7818         { } /* end */
7819 };
7820
7821 static struct snd_kcontrol_new alc883_2ch_fujitsu_pi2515_mixer[] = {
7822         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7823         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7824         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7825         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7826         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7827         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7828         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7829         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7830         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7831         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7832         { } /* end */
7833 };
7834
7835 static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
7836         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7837         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7838         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7839         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7840         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7841         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7842         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7843         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7844         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7845         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7846         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7847         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7848         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7849         { } /* end */
7850 };
7851
7852 static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
7853         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7854         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7855         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7856         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7857         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7858         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7859         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7860         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7861         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7862         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7863         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7864         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7865         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7866         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7867         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7868         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7869         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7870         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7871         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7872         { } /* end */
7873 };
7874
7875 static struct snd_kcontrol_new alc883_3ST_6ch_intel_mixer[] = {
7876         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7877         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7878         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7879         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7880         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
7881                               HDA_OUTPUT),
7882         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7883         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7884         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7885         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7886         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7887         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7888         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7889         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7890         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7891         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
7892         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7893         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7894         HDA_CODEC_VOLUME("Front Mic Boost", 0x18, 0, HDA_INPUT),
7895         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7896         { } /* end */
7897 };
7898
7899 static struct snd_kcontrol_new alc885_8ch_intel_mixer[] = {
7900         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7901         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7902         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7903         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7904         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
7905                               HDA_OUTPUT),
7906         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7907         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7908         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7909         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7910         HDA_BIND_MUTE("Speaker Playback Switch", 0x0f, 2, HDA_INPUT),
7911         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7912         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7913         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7914         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
7915         HDA_CODEC_VOLUME("Mic Boost", 0x1b, 0, HDA_INPUT),
7916         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
7917         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7918         HDA_CODEC_VOLUME("Front Mic Boost", 0x18, 0, HDA_INPUT),
7919         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7920         { } /* end */
7921 };
7922
7923 static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
7924         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7925         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7926         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7927         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7928         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7929         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7930         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7931         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7932         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7933         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7934         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7935         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7936         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7937         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7938         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7939         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7940         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7941         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7942         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7943         { } /* end */
7944 };
7945
7946 static struct snd_kcontrol_new alc883_targa_mixer[] = {
7947         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7948         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7949         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7950         HDA_CODEC_MUTE("Speaker Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7951         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7952         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7953         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7954         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7955         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7956         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7957         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7958         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7959         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7960         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7961         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7962         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7963         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7964         { } /* end */
7965 };
7966
7967 static struct snd_kcontrol_new alc883_targa_2ch_mixer[] = {
7968         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7969         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7970         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7971         HDA_CODEC_MUTE("Speaker Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7972         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7973         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7974         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7975         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7976         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7977         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7978         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7979         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7980         { } /* end */
7981 };
7982
7983 static struct snd_kcontrol_new alc883_targa_8ch_mixer[] = {
7984         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7985         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7986         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7987         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7988         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7989         { } /* end */
7990 };
7991
7992 static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
7993         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7994         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7995         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7996         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7997         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7998         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7999         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8000         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8001         { } /* end */
8002 };
8003
8004 static struct snd_kcontrol_new alc883_lenovo_nb0763_mixer[] = {
8005         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8006         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
8007         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8008         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8009         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8010         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8011         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8012         HDA_CODEC_VOLUME("iMic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8013         HDA_CODEC_MUTE("iMic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8014         { } /* end */
8015 };
8016
8017 static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
8018         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8019         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8020         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8021         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8022         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8023         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8024         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8025         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8026         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8027         { } /* end */
8028 };
8029
8030 static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
8031         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8032         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8033         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8034         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8035         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8036         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8037         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8038         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8039         { } /* end */
8040 };
8041
8042 static struct snd_kcontrol_new alc888_acer_aspire_6530_mixer[] = {
8043         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8044         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8045         HDA_CODEC_VOLUME("LFE Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
8046         HDA_BIND_MUTE("LFE Playback Switch", 0x0f, 2, HDA_INPUT),
8047         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8048         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8049         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8050         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8051         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8052         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8053         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8054         { } /* end */
8055 };
8056
8057 static struct snd_kcontrol_new alc888_lenovo_sky_mixer[] = {
8058         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8059         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8060         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
8061         HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
8062         HDA_CODEC_VOLUME_MONO("Center Playback Volume",
8063                                                 0x0d, 1, 0x0, HDA_OUTPUT),
8064         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
8065         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
8066         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
8067         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
8068         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
8069         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8070         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8071         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8072         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8073         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8074         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8075         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8076         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8077         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8078         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8079         { } /* end */
8080 };
8081
8082 static struct snd_kcontrol_new alc889A_mb31_mixer[] = {
8083         /* Output mixers */
8084         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
8085         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
8086         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
8087         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 0x02, HDA_INPUT),
8088         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x00,
8089                 HDA_OUTPUT),
8090         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x02, HDA_INPUT),
8091         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x00, HDA_OUTPUT),
8092         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x02, HDA_INPUT),
8093         /* Output switches */
8094         HDA_CODEC_MUTE("Enable Speaker", 0x14, 0x00, HDA_OUTPUT),
8095         HDA_CODEC_MUTE("Enable Headphones", 0x15, 0x00, HDA_OUTPUT),
8096         HDA_CODEC_MUTE_MONO("Enable LFE", 0x16, 2, 0x00, HDA_OUTPUT),
8097         /* Boost mixers */
8098         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
8099         HDA_CODEC_VOLUME("Line Boost", 0x1a, 0x00, HDA_INPUT),
8100         /* Input mixers */
8101         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
8102         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
8103         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8104         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8105         { } /* end */
8106 };
8107
8108 static struct snd_kcontrol_new alc883_vaiott_mixer[] = {
8109         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8110         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8111         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8112         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8113         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
8114         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8115         { } /* end */
8116 };
8117
8118 static struct hda_bind_ctls alc883_bind_cap_vol = {
8119         .ops = &snd_hda_bind_vol,
8120         .values = {
8121                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
8122                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
8123                 0
8124         },
8125 };
8126
8127 static struct hda_bind_ctls alc883_bind_cap_switch = {
8128         .ops = &snd_hda_bind_sw,
8129         .values = {
8130                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
8131                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
8132                 0
8133         },
8134 };
8135
8136 static struct snd_kcontrol_new alc883_asus_eee1601_mixer[] = {
8137         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8138         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8139         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8140         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8141         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8142         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8143         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8144         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8145         { } /* end */
8146 };
8147
8148 static struct snd_kcontrol_new alc883_asus_eee1601_cap_mixer[] = {
8149         HDA_BIND_VOL("Capture Volume", &alc883_bind_cap_vol),
8150         HDA_BIND_SW("Capture Switch", &alc883_bind_cap_switch),
8151         {
8152                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8153                 /* .name = "Capture Source", */
8154                 .name = "Input Source",
8155                 .count = 1,
8156                 .info = alc_mux_enum_info,
8157                 .get = alc_mux_enum_get,
8158                 .put = alc_mux_enum_put,
8159         },
8160         { } /* end */
8161 };
8162
8163 static struct snd_kcontrol_new alc883_chmode_mixer[] = {
8164         {
8165                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8166                 .name = "Channel Mode",
8167                 .info = alc_ch_mode_info,
8168                 .get = alc_ch_mode_get,
8169                 .put = alc_ch_mode_put,
8170         },
8171         { } /* end */
8172 };
8173
8174 /* toggle speaker-output according to the hp-jack state */
8175 static void alc883_mitac_setup(struct hda_codec *codec)
8176 {
8177         struct alc_spec *spec = codec->spec;
8178
8179         spec->autocfg.hp_pins[0] = 0x15;
8180         spec->autocfg.speaker_pins[0] = 0x14;
8181         spec->autocfg.speaker_pins[1] = 0x17;
8182 }
8183
8184 /* auto-toggle front mic */
8185 /*
8186 static void alc883_mitac_mic_automute(struct hda_codec *codec)
8187 {
8188         unsigned int present;
8189         unsigned char bits;
8190
8191         present = snd_hda_codec_read(codec, 0x18, 0,
8192                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8193         bits = present ? HDA_AMP_MUTE : 0;
8194         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
8195 }
8196 */
8197
8198 static struct hda_verb alc883_mitac_verbs[] = {
8199         /* HP */
8200         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8201         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8202         /* Subwoofer */
8203         {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
8204         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8205
8206         /* enable unsolicited event */
8207         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8208         /* {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN}, */
8209
8210         { } /* end */
8211 };
8212
8213 static struct hda_verb alc883_clevo_m540r_verbs[] = {
8214         /* HP */
8215         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8216         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8217         /* Int speaker */
8218         /*{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},*/
8219
8220         /* enable unsolicited event */
8221         /*
8222         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8223         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
8224         */
8225
8226         { } /* end */
8227 };
8228
8229 static struct hda_verb alc883_clevo_m720_verbs[] = {
8230         /* HP */
8231         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8232         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8233         /* Int speaker */
8234         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
8235         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8236
8237         /* enable unsolicited event */
8238         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8239         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
8240
8241         { } /* end */
8242 };
8243
8244 static struct hda_verb alc883_2ch_fujitsu_pi2515_verbs[] = {
8245         /* HP */
8246         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8247         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8248         /* Subwoofer */
8249         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
8250         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8251
8252         /* enable unsolicited event */
8253         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8254
8255         { } /* end */
8256 };
8257
8258 static struct hda_verb alc883_targa_verbs[] = {
8259         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8260         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8261
8262         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8263         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8264
8265 /* Connect Line-Out side jack (SPDIF) to Side */
8266         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8267         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8268         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
8269 /* Connect Mic jack to CLFE */
8270         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8271         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8272         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},
8273 /* Connect Line-in jack to Surround */
8274         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8275         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8276         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
8277 /* Connect HP out jack to Front */
8278         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8279         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8280         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8281
8282         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8283
8284         { } /* end */
8285 };
8286
8287 static struct hda_verb alc883_lenovo_101e_verbs[] = {
8288         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8289         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT|AC_USRSP_EN},
8290         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT|AC_USRSP_EN},
8291         { } /* end */
8292 };
8293
8294 static struct hda_verb alc883_lenovo_nb0763_verbs[] = {
8295         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8296         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8297         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8298         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8299         { } /* end */
8300 };
8301
8302 static struct hda_verb alc888_lenovo_ms7195_verbs[] = {
8303         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8304         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8305         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8306         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT | AC_USRSP_EN},
8307         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT    | AC_USRSP_EN},
8308         { } /* end */
8309 };
8310
8311 static struct hda_verb alc883_haier_w66_verbs[] = {
8312         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8313         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8314
8315         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8316
8317         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8318         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8319         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8320         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8321         { } /* end */
8322 };
8323
8324 static struct hda_verb alc888_lenovo_sky_verbs[] = {
8325         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8326         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8327         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8328         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8329         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8330         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8331         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
8332         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8333         { } /* end */
8334 };
8335
8336 static struct hda_verb alc888_6st_dell_verbs[] = {
8337         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8338         { }
8339 };
8340
8341 static struct hda_verb alc883_vaiott_verbs[] = {
8342         /* HP */
8343         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8344         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8345
8346         /* enable unsolicited event */
8347         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8348
8349         { } /* end */
8350 };
8351
8352 static void alc888_3st_hp_setup(struct hda_codec *codec)
8353 {
8354         struct alc_spec *spec = codec->spec;
8355
8356         spec->autocfg.hp_pins[0] = 0x1b;
8357         spec->autocfg.speaker_pins[0] = 0x14;
8358         spec->autocfg.speaker_pins[1] = 0x16;
8359         spec->autocfg.speaker_pins[2] = 0x18;
8360 }
8361
8362 static struct hda_verb alc888_3st_hp_verbs[] = {
8363         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
8364         {0x16, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Rear : output 1 (0x0d) */
8365         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},  /* CLFE : output 2 (0x0e) */
8366         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8367         { } /* end */
8368 };
8369
8370 /*
8371  * 2ch mode
8372  */
8373 static struct hda_verb alc888_3st_hp_2ch_init[] = {
8374         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
8375         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8376         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
8377         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8378         { } /* end */
8379 };
8380
8381 /*
8382  * 4ch mode
8383  */
8384 static struct hda_verb alc888_3st_hp_4ch_init[] = {
8385         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
8386         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8387         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8388         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8389         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x01 },
8390         { } /* end */
8391 };
8392
8393 /*
8394  * 6ch mode
8395  */
8396 static struct hda_verb alc888_3st_hp_6ch_init[] = {
8397         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8398         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8399         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
8400         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8401         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8402         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x01 },
8403         { } /* end */
8404 };
8405
8406 static struct hda_channel_mode alc888_3st_hp_modes[3] = {
8407         { 2, alc888_3st_hp_2ch_init },
8408         { 4, alc888_3st_hp_4ch_init },
8409         { 6, alc888_3st_hp_6ch_init },
8410 };
8411
8412 /* toggle front-jack and RCA according to the hp-jack state */
8413 static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
8414 {
8415         unsigned int present;
8416
8417         present = snd_hda_codec_read(codec, 0x1b, 0,
8418                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8419         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8420                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8421         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8422                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8423 }
8424
8425 /* toggle RCA according to the front-jack state */
8426 static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
8427 {
8428         unsigned int present;
8429
8430         present = snd_hda_codec_read(codec, 0x14, 0,
8431                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8432         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8433                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8434 }
8435
8436 static void alc883_lenovo_ms7195_unsol_event(struct hda_codec *codec,
8437                                              unsigned int res)
8438 {
8439         if ((res >> 26) == ALC880_HP_EVENT)
8440                 alc888_lenovo_ms7195_front_automute(codec);
8441         if ((res >> 26) == ALC880_FRONT_EVENT)
8442                 alc888_lenovo_ms7195_rca_automute(codec);
8443 }
8444
8445 static struct hda_verb alc883_medion_md2_verbs[] = {
8446         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8447         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8448
8449         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8450
8451         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8452         { } /* end */
8453 };
8454
8455 /* toggle speaker-output according to the hp-jack state */
8456 static void alc883_medion_md2_setup(struct hda_codec *codec)
8457 {
8458         struct alc_spec *spec = codec->spec;
8459
8460         spec->autocfg.hp_pins[0] = 0x14;
8461         spec->autocfg.speaker_pins[0] = 0x15;
8462 }
8463
8464 /* toggle speaker-output according to the hp-jack state */
8465 #define alc883_targa_init_hook          alc882_targa_init_hook
8466 #define alc883_targa_unsol_event        alc882_targa_unsol_event
8467
8468 static void alc883_clevo_m720_mic_automute(struct hda_codec *codec)
8469 {
8470         unsigned int present;
8471
8472         present = snd_hda_codec_read(codec, 0x18, 0,
8473                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8474         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
8475                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8476 }
8477
8478 static void alc883_clevo_m720_setup(struct hda_codec *codec)
8479 {
8480         struct alc_spec *spec = codec->spec;
8481
8482         spec->autocfg.hp_pins[0] = 0x15;
8483         spec->autocfg.speaker_pins[0] = 0x14;
8484 }
8485
8486 static void alc883_clevo_m720_init_hook(struct hda_codec *codec)
8487 {
8488         alc_automute_amp(codec);
8489         alc883_clevo_m720_mic_automute(codec);
8490 }
8491
8492 static void alc883_clevo_m720_unsol_event(struct hda_codec *codec,
8493                                            unsigned int res)
8494 {
8495         switch (res >> 26) {
8496         case ALC880_MIC_EVENT:
8497                 alc883_clevo_m720_mic_automute(codec);
8498                 break;
8499         default:
8500                 alc_automute_amp_unsol_event(codec, res);
8501                 break;
8502         }
8503 }
8504
8505 /* toggle speaker-output according to the hp-jack state */
8506 static void alc883_2ch_fujitsu_pi2515_setup(struct hda_codec *codec)
8507 {
8508         struct alc_spec *spec = codec->spec;
8509
8510         spec->autocfg.hp_pins[0] = 0x14;
8511         spec->autocfg.speaker_pins[0] = 0x15;
8512 }
8513
8514 static void alc883_haier_w66_setup(struct hda_codec *codec)
8515 {
8516         struct alc_spec *spec = codec->spec;
8517
8518         spec->autocfg.hp_pins[0] = 0x1b;
8519         spec->autocfg.speaker_pins[0] = 0x14;
8520 }
8521
8522 static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
8523 {
8524         unsigned int present;
8525         unsigned char bits;
8526
8527         present = snd_hda_codec_read(codec, 0x14, 0, AC_VERB_GET_PIN_SENSE, 0)
8528                 & AC_PINSENSE_PRESENCE;
8529         bits = present ? HDA_AMP_MUTE : 0;
8530         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8531                                  HDA_AMP_MUTE, bits);
8532 }
8533
8534 static void alc883_lenovo_101e_all_automute(struct hda_codec *codec)
8535 {
8536         unsigned int present;
8537         unsigned char bits;
8538
8539         present = snd_hda_codec_read(codec, 0x1b, 0,
8540                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8541         bits = present ? HDA_AMP_MUTE : 0;
8542         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8543                                  HDA_AMP_MUTE, bits);
8544         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8545                                  HDA_AMP_MUTE, bits);
8546 }
8547
8548 static void alc883_lenovo_101e_unsol_event(struct hda_codec *codec,
8549                                            unsigned int res)
8550 {
8551         if ((res >> 26) == ALC880_HP_EVENT)
8552                 alc883_lenovo_101e_all_automute(codec);
8553         if ((res >> 26) == ALC880_FRONT_EVENT)
8554                 alc883_lenovo_101e_ispeaker_automute(codec);
8555 }
8556
8557 /* toggle speaker-output according to the hp-jack state */
8558 static void alc883_acer_aspire_setup(struct hda_codec *codec)
8559 {
8560         struct alc_spec *spec = codec->spec;
8561
8562         spec->autocfg.hp_pins[0] = 0x14;
8563         spec->autocfg.speaker_pins[0] = 0x15;
8564         spec->autocfg.speaker_pins[1] = 0x16;
8565 }
8566
8567 static struct hda_verb alc883_acer_eapd_verbs[] = {
8568         /* HP Pin: output 0 (0x0c) */
8569         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8570         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8571         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8572         /* Front Pin: output 0 (0x0c) */
8573         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8574         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8575         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8576         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
8577         /* eanable EAPD on medion laptop */
8578         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
8579         {0x20, AC_VERB_SET_PROC_COEF, 0x3050},
8580         /* enable unsolicited event */
8581         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8582         { }
8583 };
8584
8585 static struct hda_verb alc888_acer_aspire_7730G_verbs[] = {
8586         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8587         {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
8588         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8589         { } /* end */
8590 };
8591
8592 static void alc888_6st_dell_setup(struct hda_codec *codec)
8593 {
8594         struct alc_spec *spec = codec->spec;
8595
8596         spec->autocfg.hp_pins[0] = 0x1b;
8597         spec->autocfg.speaker_pins[0] = 0x14;
8598         spec->autocfg.speaker_pins[1] = 0x15;
8599         spec->autocfg.speaker_pins[2] = 0x16;
8600         spec->autocfg.speaker_pins[3] = 0x17;
8601 }
8602
8603 static void alc888_lenovo_sky_setup(struct hda_codec *codec)
8604 {
8605         struct alc_spec *spec = codec->spec;
8606
8607         spec->autocfg.hp_pins[0] = 0x1b;
8608         spec->autocfg.speaker_pins[0] = 0x14;
8609         spec->autocfg.speaker_pins[1] = 0x15;
8610         spec->autocfg.speaker_pins[2] = 0x16;
8611         spec->autocfg.speaker_pins[3] = 0x17;
8612         spec->autocfg.speaker_pins[4] = 0x1a;
8613 }
8614
8615 static void alc883_vaiott_setup(struct hda_codec *codec)
8616 {
8617         struct alc_spec *spec = codec->spec;
8618
8619         spec->autocfg.hp_pins[0] = 0x15;
8620         spec->autocfg.speaker_pins[0] = 0x14;
8621         spec->autocfg.speaker_pins[1] = 0x17;
8622 }
8623
8624 static struct hda_verb alc888_asus_m90v_verbs[] = {
8625         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8626         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8627         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8628         /* enable unsolicited event */
8629         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8630         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
8631         { } /* end */
8632 };
8633
8634 static void alc883_mode2_setup(struct hda_codec *codec)
8635 {
8636         struct alc_spec *spec = codec->spec;
8637
8638         spec->autocfg.hp_pins[0] = 0x1b;
8639         spec->autocfg.speaker_pins[0] = 0x14;
8640         spec->autocfg.speaker_pins[1] = 0x15;
8641         spec->autocfg.speaker_pins[2] = 0x16;
8642         spec->ext_mic.pin = 0x18;
8643         spec->int_mic.pin = 0x19;
8644         spec->ext_mic.mux_idx = 0;
8645         spec->int_mic.mux_idx = 1;
8646         spec->auto_mic = 1;
8647 }
8648
8649 static struct hda_verb alc888_asus_eee1601_verbs[] = {
8650         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8651         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8652         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8653         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8654         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8655         {0x20, AC_VERB_SET_COEF_INDEX, 0x0b},
8656         {0x20, AC_VERB_SET_PROC_COEF,  0x0838},
8657         /* enable unsolicited event */
8658         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8659         { } /* end */
8660 };
8661
8662 static void alc883_eee1601_inithook(struct hda_codec *codec)
8663 {
8664         struct alc_spec *spec = codec->spec;
8665
8666         spec->autocfg.hp_pins[0] = 0x14;
8667         spec->autocfg.speaker_pins[0] = 0x1b;
8668         alc_automute_pin(codec);
8669 }
8670
8671 static struct hda_verb alc889A_mb31_verbs[] = {
8672         /* Init rear pin (used as headphone output) */
8673         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},    /* Apple Headphones */
8674         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},           /* Connect to front */
8675         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8676         /* Init line pin (used as output in 4ch and 6ch mode) */
8677         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x02},           /* Connect to CLFE */
8678         /* Init line 2 pin (used as headphone out by default) */
8679         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},  /* Use as input */
8680         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Mute output */
8681         { } /* end */
8682 };
8683
8684 /* Mute speakers according to the headphone jack state */
8685 static void alc889A_mb31_automute(struct hda_codec *codec)
8686 {
8687         unsigned int present;
8688
8689         /* Mute only in 2ch or 4ch mode */
8690         if (snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_CONNECT_SEL, 0)
8691             == 0x00) {
8692                 present = snd_hda_codec_read(codec, 0x15, 0,
8693                         AC_VERB_GET_PIN_SENSE, 0) & AC_PINSENSE_PRESENCE;
8694                 snd_hda_codec_amp_stereo(codec, 0x14,  HDA_OUTPUT, 0,
8695                         HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8696                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8697                         HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8698         }
8699 }
8700
8701 static void alc889A_mb31_unsol_event(struct hda_codec *codec, unsigned int res)
8702 {
8703         if ((res >> 26) == ALC880_HP_EVENT)
8704                 alc889A_mb31_automute(codec);
8705 }
8706
8707
8708 #ifdef CONFIG_SND_HDA_POWER_SAVE
8709 #define alc882_loopbacks        alc880_loopbacks
8710 #endif
8711
8712 /* pcm configuration: identical with ALC880 */
8713 #define alc882_pcm_analog_playback      alc880_pcm_analog_playback
8714 #define alc882_pcm_analog_capture       alc880_pcm_analog_capture
8715 #define alc882_pcm_digital_playback     alc880_pcm_digital_playback
8716 #define alc882_pcm_digital_capture      alc880_pcm_digital_capture
8717
8718 static hda_nid_t alc883_slave_dig_outs[] = {
8719         ALC1200_DIGOUT_NID, 0,
8720 };
8721
8722 static hda_nid_t alc1200_slave_dig_outs[] = {
8723         ALC883_DIGOUT_NID, 0,
8724 };
8725
8726 /*
8727  * configuration and preset
8728  */
8729 static const char *alc882_models[ALC882_MODEL_LAST] = {
8730         [ALC882_3ST_DIG]        = "3stack-dig",
8731         [ALC882_6ST_DIG]        = "6stack-dig",
8732         [ALC882_ARIMA]          = "arima",
8733         [ALC882_W2JC]           = "w2jc",
8734         [ALC882_TARGA]          = "targa",
8735         [ALC882_ASUS_A7J]       = "asus-a7j",
8736         [ALC882_ASUS_A7M]       = "asus-a7m",
8737         [ALC885_MACPRO]         = "macpro",
8738         [ALC885_MB5]            = "mb5",
8739         [ALC885_MBP3]           = "mbp3",
8740         [ALC885_IMAC24]         = "imac24",
8741         [ALC883_3ST_2ch_DIG]    = "3stack-2ch-dig",
8742         [ALC883_3ST_6ch_DIG]    = "3stack-6ch-dig",
8743         [ALC883_3ST_6ch]        = "3stack-6ch",
8744         [ALC883_6ST_DIG]        = "alc883-6stack-dig",
8745         [ALC883_TARGA_DIG]      = "targa-dig",
8746         [ALC883_TARGA_2ch_DIG]  = "targa-2ch-dig",
8747         [ALC883_TARGA_8ch_DIG]  = "targa-8ch-dig",
8748         [ALC883_ACER]           = "acer",
8749         [ALC883_ACER_ASPIRE]    = "acer-aspire",
8750         [ALC888_ACER_ASPIRE_4930G]      = "acer-aspire-4930g",
8751         [ALC888_ACER_ASPIRE_6530G]      = "acer-aspire-6530g",
8752         [ALC888_ACER_ASPIRE_8930G]      = "acer-aspire-8930g",
8753         [ALC888_ACER_ASPIRE_7730G]      = "acer-aspire-7730g",
8754         [ALC883_MEDION]         = "medion",
8755         [ALC883_MEDION_MD2]     = "medion-md2",
8756         [ALC883_LAPTOP_EAPD]    = "laptop-eapd",
8757         [ALC883_LENOVO_101E_2ch] = "lenovo-101e",
8758         [ALC883_LENOVO_NB0763]  = "lenovo-nb0763",
8759         [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
8760         [ALC888_LENOVO_SKY] = "lenovo-sky",
8761         [ALC883_HAIER_W66]      = "haier-w66",
8762         [ALC888_3ST_HP]         = "3stack-hp",
8763         [ALC888_6ST_DELL]       = "6stack-dell",
8764         [ALC883_MITAC]          = "mitac",
8765         [ALC883_CLEVO_M540R]    = "clevo-m540r",
8766         [ALC883_CLEVO_M720]     = "clevo-m720",
8767         [ALC883_FUJITSU_PI2515] = "fujitsu-pi2515",
8768         [ALC888_FUJITSU_XA3530] = "fujitsu-xa3530",
8769         [ALC883_3ST_6ch_INTEL]  = "3stack-6ch-intel",
8770         [ALC889A_INTEL]         = "intel-alc889a",
8771         [ALC889_INTEL]          = "intel-x58",
8772         [ALC1200_ASUS_P5Q]      = "asus-p5q",
8773         [ALC889A_MB31]          = "mb31",
8774         [ALC883_SONY_VAIO_TT]   = "sony-vaio-tt",
8775         [ALC882_AUTO]           = "auto",
8776 };
8777
8778 static struct snd_pci_quirk alc882_cfg_tbl[] = {
8779         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),
8780
8781         SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE),
8782         SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_ACER_ASPIRE),
8783         SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_ACER_ASPIRE),
8784         SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE),
8785         SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE),
8786         SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_ACER_ASPIRE),
8787         SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
8788                 ALC888_ACER_ASPIRE_4930G),
8789         SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
8790                 ALC888_ACER_ASPIRE_4930G),
8791         SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
8792                 ALC888_ACER_ASPIRE_8930G),
8793         SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
8794                 ALC888_ACER_ASPIRE_8930G),
8795         SND_PCI_QUIRK(0x1025, 0x0157, "Acer X3200", ALC882_AUTO),
8796         SND_PCI_QUIRK(0x1025, 0x0158, "Acer AX1700-U3700A", ALC882_AUTO),
8797         SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
8798                 ALC888_ACER_ASPIRE_6530G),
8799         SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
8800                 ALC888_ACER_ASPIRE_6530G),
8801         SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
8802                 ALC888_ACER_ASPIRE_7730G),
8803         /* default Acer -- disabled as it causes more problems.
8804          *    model=auto should work fine now
8805          */
8806         /* SND_PCI_QUIRK_VENDOR(0x1025, "Acer laptop", ALC883_ACER), */
8807
8808         SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL),
8809
8810         SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
8811         SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
8812         SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
8813         SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG),
8814         SND_PCI_QUIRK(0x103c, 0x2a66, "HP Acacia", ALC888_3ST_HP),
8815         SND_PCI_QUIRK(0x103c, 0x2a72, "HP Educ.ar", ALC888_3ST_HP),
8816
8817         SND_PCI_QUIRK(0x1043, 0x060d, "Asus A7J", ALC882_ASUS_A7J),
8818         SND_PCI_QUIRK(0x1043, 0x1243, "Asus A7J", ALC882_ASUS_A7J),
8819         SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_ASUS_A7M),
8820         SND_PCI_QUIRK(0x1043, 0x1873, "Asus M90V", ALC888_ASUS_M90V),
8821         SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_W2JC),
8822         SND_PCI_QUIRK(0x1043, 0x817f, "Asus P5LD2", ALC882_6ST_DIG),
8823         SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
8824         SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG),
8825         SND_PCI_QUIRK(0x1043, 0x8284, "Asus Z37E", ALC883_6ST_DIG),
8826         SND_PCI_QUIRK(0x1043, 0x82fe, "Asus P5Q-EM HDMI", ALC1200_ASUS_P5Q),
8827         SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_ASUS_EEE1601),
8828
8829         SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC883_SONY_VAIO_TT),
8830         SND_PCI_QUIRK(0x105b, 0x0ce8, "Foxconn P35AX-S", ALC883_6ST_DIG),
8831         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
8832         SND_PCI_QUIRK(0x1071, 0x8227, "Mitac 82801H", ALC883_MITAC),
8833         SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC),
8834         SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
8835         SND_PCI_QUIRK(0x10f1, 0x2350, "TYAN-S2350", ALC888_6ST_DELL),
8836         SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
8837         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte P35 DS3R", ALC882_6ST_DIG),
8838
8839         SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
8840         SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG),
8841         SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
8842         SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8  */
8843         SND_PCI_QUIRK(0x1462, 0x2fb3, "MSI", ALC883_TARGA_2ch_DIG),
8844         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
8845         SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
8846         SND_PCI_QUIRK(0x1462, 0x3783, "NEC S970", ALC883_TARGA_DIG),
8847         SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
8848         SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
8849         SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
8850         SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG),
8851         SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG),
8852         SND_PCI_QUIRK(0x1462, 0x3fdf, "MSI", ALC883_TARGA_DIG),
8853         SND_PCI_QUIRK(0x1462, 0x42cd, "MSI", ALC883_TARGA_DIG),
8854         SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
8855         SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
8856         SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
8857         SND_PCI_QUIRK(0x1462, 0x6510, "MSI GX620", ALC883_TARGA_8ch_DIG),
8858         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
8859         SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
8860         SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
8861         SND_PCI_QUIRK(0x1462, 0x7260, "MSI 7260", ALC883_TARGA_DIG),
8862         SND_PCI_QUIRK(0x1462, 0x7267, "MSI", ALC883_3ST_6ch_DIG),
8863         SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
8864         SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
8865         SND_PCI_QUIRK(0x1462, 0x7350, "MSI", ALC883_6ST_DIG),
8866         SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
8867         SND_PCI_QUIRK(0x1462, 0xaa08, "MSI", ALC883_TARGA_2ch_DIG),
8868
8869         SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG),
8870         SND_PCI_QUIRK(0x1558, 0x0721, "Clevo laptop M720R", ALC883_CLEVO_M720),
8871         SND_PCI_QUIRK(0x1558, 0x0722, "Clevo laptop M720SR", ALC883_CLEVO_M720),
8872         SND_PCI_QUIRK(0x1558, 0x5409, "Clevo laptop M540R", ALC883_CLEVO_M540R),
8873         SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC883_LAPTOP_EAPD),
8874         SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
8875         /* SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA), */
8876         SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
8877         SND_PCI_QUIRK_MASK(0x1734, 0xfff0, 0x1100, "FSC AMILO Xi/Pi25xx",
8878                       ALC883_FUJITSU_PI2515),
8879         SND_PCI_QUIRK_MASK(0x1734, 0xfff0, 0x1130, "Fujitsu AMILO Xa35xx",
8880                 ALC888_FUJITSU_XA3530),
8881         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
8882         SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8883         SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8884         SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8885         SND_PCI_QUIRK(0x17aa, 0x101d, "Lenovo Sky", ALC888_LENOVO_SKY),
8886         SND_PCI_QUIRK(0x17c0, 0x4071, "MEDION MD2", ALC883_MEDION_MD2),
8887         SND_PCI_QUIRK(0x17c0, 0x4085, "MEDION MD96630", ALC888_LENOVO_MS7195_DIG),
8888         SND_PCI_QUIRK(0x17f2, 0x5000, "Albatron KI690-AM2", ALC883_6ST_DIG),
8889         SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66),
8890
8891         SND_PCI_QUIRK(0x8086, 0x0001, "DG33BUC", ALC883_3ST_6ch_INTEL),
8892         SND_PCI_QUIRK(0x8086, 0x0002, "DG33FBC", ALC883_3ST_6ch_INTEL),
8893         SND_PCI_QUIRK(0x8086, 0x2503, "82801H", ALC883_MITAC),
8894         SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_INTEL),
8895         SND_PCI_QUIRK(0x8086, 0x0021, "Intel IbexPeak", ALC889A_INTEL),
8896         SND_PCI_QUIRK(0x8086, 0x3b56, "Intel IbexPeak", ALC889A_INTEL),
8897         SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch),
8898
8899         {}
8900 };
8901
8902 /* codec SSID table for Intel Mac */
8903 static struct snd_pci_quirk alc882_ssid_cfg_tbl[] = {
8904         SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC885_MBP3),
8905         SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC885_MBP3),
8906         SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC885_MBP3),
8907         SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_MACPRO),
8908         SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_IMAC24),
8909         SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_IMAC24),
8910         SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC885_MBP3),
8911         SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889A_MB31),
8912         SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC885_MBP3),
8913         SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_IMAC24),
8914         SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC885_MB5),
8915         /* FIXME: HP jack sense seems not working for MBP 5,1 or 5,2,
8916          * so apparently no perfect solution yet
8917          */
8918         SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC885_MB5),
8919         SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC885_MB5),
8920         {} /* terminator */
8921 };
8922
8923 static struct alc_config_preset alc882_presets[] = {
8924         [ALC882_3ST_DIG] = {
8925                 .mixers = { alc882_base_mixer },
8926                 .init_verbs = { alc882_base_init_verbs,
8927                                 alc882_adc1_init_verbs },
8928                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
8929                 .dac_nids = alc882_dac_nids,
8930                 .dig_out_nid = ALC882_DIGOUT_NID,
8931                 .dig_in_nid = ALC882_DIGIN_NID,
8932                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
8933                 .channel_mode = alc882_ch_modes,
8934                 .need_dac_fix = 1,
8935                 .input_mux = &alc882_capture_source,
8936         },
8937         [ALC882_6ST_DIG] = {
8938                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
8939                 .init_verbs = { alc882_base_init_verbs,
8940                                 alc882_adc1_init_verbs },
8941                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
8942                 .dac_nids = alc882_dac_nids,
8943                 .dig_out_nid = ALC882_DIGOUT_NID,
8944                 .dig_in_nid = ALC882_DIGIN_NID,
8945                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
8946                 .channel_mode = alc882_sixstack_modes,
8947                 .input_mux = &alc882_capture_source,
8948         },
8949         [ALC882_ARIMA] = {
8950                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
8951                 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
8952                                 alc882_eapd_verbs },
8953                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
8954                 .dac_nids = alc882_dac_nids,
8955                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
8956                 .channel_mode = alc882_sixstack_modes,
8957                 .input_mux = &alc882_capture_source,
8958         },
8959         [ALC882_W2JC] = {
8960                 .mixers = { alc882_w2jc_mixer, alc882_chmode_mixer },
8961                 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
8962                                 alc882_eapd_verbs, alc880_gpio1_init_verbs },
8963                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
8964                 .dac_nids = alc882_dac_nids,
8965                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
8966                 .channel_mode = alc880_threestack_modes,
8967                 .need_dac_fix = 1,
8968                 .input_mux = &alc882_capture_source,
8969                 .dig_out_nid = ALC882_DIGOUT_NID,
8970         },
8971         [ALC885_MBP3] = {
8972                 .mixers = { alc885_mbp3_mixer, alc882_chmode_mixer },
8973                 .init_verbs = { alc885_mbp3_init_verbs,
8974                                 alc880_gpio1_init_verbs },
8975                 .num_dacs = 2,
8976                 .dac_nids = alc882_dac_nids,
8977                 .hp_nid = 0x04,
8978                 .channel_mode = alc885_mbp_4ch_modes,
8979                 .num_channel_mode = ARRAY_SIZE(alc885_mbp_4ch_modes),
8980                 .input_mux = &alc882_capture_source,
8981                 .dig_out_nid = ALC882_DIGOUT_NID,
8982                 .dig_in_nid = ALC882_DIGIN_NID,
8983                 .unsol_event = alc_automute_amp_unsol_event,
8984                 .setup = alc885_mbp3_setup,
8985                 .init_hook = alc_automute_amp,
8986         },
8987         [ALC885_MB5] = {
8988                 .mixers = { alc885_mb5_mixer, alc882_chmode_mixer },
8989                 .init_verbs = { alc885_mb5_init_verbs,
8990                                 alc880_gpio1_init_verbs },
8991                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
8992                 .dac_nids = alc882_dac_nids,
8993                 .channel_mode = alc885_mb5_6ch_modes,
8994                 .num_channel_mode = ARRAY_SIZE(alc885_mb5_6ch_modes),
8995                 .input_mux = &mb5_capture_source,
8996                 .dig_out_nid = ALC882_DIGOUT_NID,
8997                 .dig_in_nid = ALC882_DIGIN_NID,
8998         },
8999         [ALC885_MACPRO] = {
9000                 .mixers = { alc882_macpro_mixer },
9001                 .init_verbs = { alc882_macpro_init_verbs },
9002                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
9003                 .dac_nids = alc882_dac_nids,
9004                 .dig_out_nid = ALC882_DIGOUT_NID,
9005                 .dig_in_nid = ALC882_DIGIN_NID,
9006                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
9007                 .channel_mode = alc882_ch_modes,
9008                 .input_mux = &alc882_capture_source,
9009                 .init_hook = alc885_macpro_init_hook,
9010         },
9011         [ALC885_IMAC24] = {
9012                 .mixers = { alc885_imac24_mixer },
9013                 .init_verbs = { alc885_imac24_init_verbs },
9014                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
9015                 .dac_nids = alc882_dac_nids,
9016                 .dig_out_nid = ALC882_DIGOUT_NID,
9017                 .dig_in_nid = ALC882_DIGIN_NID,
9018                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
9019                 .channel_mode = alc882_ch_modes,
9020                 .input_mux = &alc882_capture_source,
9021                 .unsol_event = alc_automute_amp_unsol_event,
9022                 .setup = alc885_imac24_setup,
9023                 .init_hook = alc885_imac24_init_hook,
9024         },
9025         [ALC882_TARGA] = {
9026                 .mixers = { alc882_targa_mixer, alc882_chmode_mixer },
9027                 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
9028                                 alc880_gpio3_init_verbs, alc882_targa_verbs},
9029                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
9030                 .dac_nids = alc882_dac_nids,
9031                 .dig_out_nid = ALC882_DIGOUT_NID,
9032                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
9033                 .adc_nids = alc882_adc_nids,
9034                 .capsrc_nids = alc882_capsrc_nids,
9035                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
9036                 .channel_mode = alc882_3ST_6ch_modes,
9037                 .need_dac_fix = 1,
9038                 .input_mux = &alc882_capture_source,
9039                 .unsol_event = alc882_targa_unsol_event,
9040                 .setup = alc882_targa_setup,
9041                 .init_hook = alc882_targa_automute,
9042         },
9043         [ALC882_ASUS_A7J] = {
9044                 .mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer },
9045                 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
9046                                 alc882_asus_a7j_verbs},
9047                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
9048                 .dac_nids = alc882_dac_nids,
9049                 .dig_out_nid = ALC882_DIGOUT_NID,
9050                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
9051                 .adc_nids = alc882_adc_nids,
9052                 .capsrc_nids = alc882_capsrc_nids,
9053                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
9054                 .channel_mode = alc882_3ST_6ch_modes,
9055                 .need_dac_fix = 1,
9056                 .input_mux = &alc882_capture_source,
9057         },
9058         [ALC882_ASUS_A7M] = {
9059                 .mixers = { alc882_asus_a7m_mixer, alc882_chmode_mixer },
9060                 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
9061                                 alc882_eapd_verbs, alc880_gpio1_init_verbs,
9062                                 alc882_asus_a7m_verbs },
9063                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
9064                 .dac_nids = alc882_dac_nids,
9065                 .dig_out_nid = ALC882_DIGOUT_NID,
9066                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
9067                 .channel_mode = alc880_threestack_modes,
9068                 .need_dac_fix = 1,
9069                 .input_mux = &alc882_capture_source,
9070         },
9071         [ALC883_3ST_2ch_DIG] = {
9072                 .mixers = { alc883_3ST_2ch_mixer },
9073                 .init_verbs = { alc883_init_verbs },
9074                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9075                 .dac_nids = alc883_dac_nids,
9076                 .dig_out_nid = ALC883_DIGOUT_NID,
9077                 .dig_in_nid = ALC883_DIGIN_NID,
9078                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9079                 .channel_mode = alc883_3ST_2ch_modes,
9080                 .input_mux = &alc883_capture_source,
9081         },
9082         [ALC883_3ST_6ch_DIG] = {
9083                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_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_6ch_modes),
9090                 .channel_mode = alc883_3ST_6ch_modes,
9091                 .need_dac_fix = 1,
9092                 .input_mux = &alc883_capture_source,
9093         },
9094         [ALC883_3ST_6ch] = {
9095                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9096                 .init_verbs = { alc883_init_verbs },
9097                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9098                 .dac_nids = alc883_dac_nids,
9099                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9100                 .channel_mode = alc883_3ST_6ch_modes,
9101                 .need_dac_fix = 1,
9102                 .input_mux = &alc883_capture_source,
9103         },
9104         [ALC883_3ST_6ch_INTEL] = {
9105                 .mixers = { alc883_3ST_6ch_intel_mixer, alc883_chmode_mixer },
9106                 .init_verbs = { alc883_init_verbs },
9107                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9108                 .dac_nids = alc883_dac_nids,
9109                 .dig_out_nid = ALC883_DIGOUT_NID,
9110                 .dig_in_nid = ALC883_DIGIN_NID,
9111                 .slave_dig_outs = alc883_slave_dig_outs,
9112                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_intel_modes),
9113                 .channel_mode = alc883_3ST_6ch_intel_modes,
9114                 .need_dac_fix = 1,
9115                 .input_mux = &alc883_3stack_6ch_intel,
9116         },
9117         [ALC889A_INTEL] = {
9118                 .mixers = { alc885_8ch_intel_mixer, alc883_chmode_mixer },
9119                 .init_verbs = { alc885_init_verbs, alc885_init_input_verbs,
9120                                 alc_hp15_unsol_verbs },
9121                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9122                 .dac_nids = alc883_dac_nids,
9123                 .num_adc_nids = ARRAY_SIZE(alc889_adc_nids),
9124                 .adc_nids = alc889_adc_nids,
9125                 .dig_out_nid = ALC883_DIGOUT_NID,
9126                 .dig_in_nid = ALC883_DIGIN_NID,
9127                 .slave_dig_outs = alc883_slave_dig_outs,
9128                 .num_channel_mode = ARRAY_SIZE(alc889_8ch_intel_modes),
9129                 .channel_mode = alc889_8ch_intel_modes,
9130                 .capsrc_nids = alc889_capsrc_nids,
9131                 .input_mux = &alc889_capture_source,
9132                 .setup = alc889_automute_setup,
9133                 .init_hook = alc_automute_amp,
9134                 .unsol_event = alc_automute_amp_unsol_event,
9135                 .need_dac_fix = 1,
9136         },
9137         [ALC889_INTEL] = {
9138                 .mixers = { alc885_8ch_intel_mixer, alc883_chmode_mixer },
9139                 .init_verbs = { alc885_init_verbs, alc889_init_input_verbs,
9140                                 alc889_eapd_verbs, alc_hp15_unsol_verbs},
9141                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9142                 .dac_nids = alc883_dac_nids,
9143                 .num_adc_nids = ARRAY_SIZE(alc889_adc_nids),
9144                 .adc_nids = alc889_adc_nids,
9145                 .dig_out_nid = ALC883_DIGOUT_NID,
9146                 .dig_in_nid = ALC883_DIGIN_NID,
9147                 .slave_dig_outs = alc883_slave_dig_outs,
9148                 .num_channel_mode = ARRAY_SIZE(alc889_8ch_intel_modes),
9149                 .channel_mode = alc889_8ch_intel_modes,
9150                 .capsrc_nids = alc889_capsrc_nids,
9151                 .input_mux = &alc889_capture_source,
9152                 .setup = alc889_automute_setup,
9153                 .init_hook = alc889_intel_init_hook,
9154                 .unsol_event = alc_automute_amp_unsol_event,
9155                 .need_dac_fix = 1,
9156         },
9157         [ALC883_6ST_DIG] = {
9158                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
9159                 .init_verbs = { alc883_init_verbs },
9160                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9161                 .dac_nids = alc883_dac_nids,
9162                 .dig_out_nid = ALC883_DIGOUT_NID,
9163                 .dig_in_nid = ALC883_DIGIN_NID,
9164                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9165                 .channel_mode = alc883_sixstack_modes,
9166                 .input_mux = &alc883_capture_source,
9167         },
9168         [ALC883_TARGA_DIG] = {
9169                 .mixers = { alc883_targa_mixer, alc883_chmode_mixer },
9170                 .init_verbs = { alc883_init_verbs, alc880_gpio3_init_verbs,
9171                                 alc883_targa_verbs},
9172                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9173                 .dac_nids = alc883_dac_nids,
9174                 .dig_out_nid = ALC883_DIGOUT_NID,
9175                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9176                 .channel_mode = alc883_3ST_6ch_modes,
9177                 .need_dac_fix = 1,
9178                 .input_mux = &alc883_capture_source,
9179                 .unsol_event = alc883_targa_unsol_event,
9180                 .setup = alc882_targa_setup,
9181                 .init_hook = alc882_targa_automute,
9182         },
9183         [ALC883_TARGA_2ch_DIG] = {
9184                 .mixers = { alc883_targa_2ch_mixer},
9185                 .init_verbs = { alc883_init_verbs, alc880_gpio3_init_verbs,
9186                                 alc883_targa_verbs},
9187                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9188                 .dac_nids = alc883_dac_nids,
9189                 .adc_nids = alc883_adc_nids_alt,
9190                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
9191                 .dig_out_nid = ALC883_DIGOUT_NID,
9192                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9193                 .channel_mode = alc883_3ST_2ch_modes,
9194                 .input_mux = &alc883_capture_source,
9195                 .unsol_event = alc883_targa_unsol_event,
9196                 .setup = alc882_targa_setup,
9197                 .init_hook = alc882_targa_automute,
9198         },
9199         [ALC883_TARGA_8ch_DIG] = {
9200                 .mixers = { alc883_targa_mixer, alc883_targa_8ch_mixer,
9201                             alc883_chmode_mixer },
9202                 .init_verbs = { alc883_init_verbs, alc880_gpio3_init_verbs,
9203                                 alc883_targa_verbs },
9204                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9205                 .dac_nids = alc883_dac_nids,
9206                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
9207                 .adc_nids = alc883_adc_nids_rev,
9208                 .capsrc_nids = alc883_capsrc_nids_rev,
9209                 .dig_out_nid = ALC883_DIGOUT_NID,
9210                 .dig_in_nid = ALC883_DIGIN_NID,
9211                 .num_channel_mode = ARRAY_SIZE(alc883_4ST_8ch_modes),
9212                 .channel_mode = alc883_4ST_8ch_modes,
9213                 .need_dac_fix = 1,
9214                 .input_mux = &alc883_capture_source,
9215                 .unsol_event = alc883_targa_unsol_event,
9216                 .setup = alc882_targa_setup,
9217                 .init_hook = alc882_targa_automute,
9218         },
9219         [ALC883_ACER] = {
9220                 .mixers = { alc883_base_mixer },
9221                 /* On TravelMate laptops, GPIO 0 enables the internal speaker
9222                  * and the headphone jack.  Turn this on and rely on the
9223                  * standard mute methods whenever the user wants to turn
9224                  * these outputs off.
9225                  */
9226                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
9227                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9228                 .dac_nids = alc883_dac_nids,
9229                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9230                 .channel_mode = alc883_3ST_2ch_modes,
9231                 .input_mux = &alc883_capture_source,
9232         },
9233         [ALC883_ACER_ASPIRE] = {
9234                 .mixers = { alc883_acer_aspire_mixer },
9235                 .init_verbs = { alc883_init_verbs, alc883_acer_eapd_verbs },
9236                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9237                 .dac_nids = alc883_dac_nids,
9238                 .dig_out_nid = ALC883_DIGOUT_NID,
9239                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9240                 .channel_mode = alc883_3ST_2ch_modes,
9241                 .input_mux = &alc883_capture_source,
9242                 .unsol_event = alc_automute_amp_unsol_event,
9243                 .setup = alc883_acer_aspire_setup,
9244                 .init_hook = alc_automute_amp,
9245         },
9246         [ALC888_ACER_ASPIRE_4930G] = {
9247                 .mixers = { alc888_base_mixer,
9248                                 alc883_chmode_mixer },
9249                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
9250                                 alc888_acer_aspire_4930g_verbs },
9251                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9252                 .dac_nids = alc883_dac_nids,
9253                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
9254                 .adc_nids = alc883_adc_nids_rev,
9255                 .capsrc_nids = alc883_capsrc_nids_rev,
9256                 .dig_out_nid = ALC883_DIGOUT_NID,
9257                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9258                 .channel_mode = alc883_3ST_6ch_modes,
9259                 .need_dac_fix = 1,
9260                 .num_mux_defs =
9261                         ARRAY_SIZE(alc888_2_capture_sources),
9262                 .input_mux = alc888_2_capture_sources,
9263                 .unsol_event = alc_automute_amp_unsol_event,
9264                 .setup = alc888_acer_aspire_4930g_setup,
9265                 .init_hook = alc_automute_amp,
9266         },
9267         [ALC888_ACER_ASPIRE_6530G] = {
9268                 .mixers = { alc888_acer_aspire_6530_mixer },
9269                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
9270                                 alc888_acer_aspire_6530g_verbs },
9271                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9272                 .dac_nids = alc883_dac_nids,
9273                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
9274                 .adc_nids = alc883_adc_nids_rev,
9275                 .capsrc_nids = alc883_capsrc_nids_rev,
9276                 .dig_out_nid = ALC883_DIGOUT_NID,
9277                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9278                 .channel_mode = alc883_3ST_2ch_modes,
9279                 .num_mux_defs =
9280                         ARRAY_SIZE(alc888_2_capture_sources),
9281                 .input_mux = alc888_acer_aspire_6530_sources,
9282                 .unsol_event = alc_automute_amp_unsol_event,
9283                 .setup = alc888_acer_aspire_6530g_setup,
9284                 .init_hook = alc_automute_amp,
9285         },
9286         [ALC888_ACER_ASPIRE_8930G] = {
9287                 .mixers = { alc888_base_mixer,
9288                                 alc883_chmode_mixer },
9289                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
9290                                 alc889_acer_aspire_8930g_verbs },
9291                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9292                 .dac_nids = alc883_dac_nids,
9293                 .num_adc_nids = ARRAY_SIZE(alc889_adc_nids),
9294                 .adc_nids = alc889_adc_nids,
9295                 .capsrc_nids = alc889_capsrc_nids,
9296                 .dig_out_nid = ALC883_DIGOUT_NID,
9297                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9298                 .channel_mode = alc883_3ST_6ch_modes,
9299                 .need_dac_fix = 1,
9300                 .const_channel_count = 6,
9301                 .num_mux_defs =
9302                         ARRAY_SIZE(alc889_capture_sources),
9303                 .input_mux = alc889_capture_sources,
9304                 .unsol_event = alc_automute_amp_unsol_event,
9305                 .setup = alc889_acer_aspire_8930g_setup,
9306                 .init_hook = alc_automute_amp,
9307         },
9308         [ALC888_ACER_ASPIRE_7730G] = {
9309                 .mixers = { alc883_3ST_6ch_mixer,
9310                                 alc883_chmode_mixer },
9311                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
9312                                 alc888_acer_aspire_7730G_verbs },
9313                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9314                 .dac_nids = alc883_dac_nids,
9315                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
9316                 .adc_nids = alc883_adc_nids_rev,
9317                 .capsrc_nids = alc883_capsrc_nids_rev,
9318                 .dig_out_nid = ALC883_DIGOUT_NID,
9319                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9320                 .channel_mode = alc883_3ST_6ch_modes,
9321                 .need_dac_fix = 1,
9322                 .const_channel_count = 6,
9323                 .input_mux = &alc883_capture_source,
9324                 .unsol_event = alc_automute_amp_unsol_event,
9325                 .setup = alc888_acer_aspire_6530g_setup,
9326                 .init_hook = alc_automute_amp,
9327         },
9328         [ALC883_MEDION] = {
9329                 .mixers = { alc883_fivestack_mixer,
9330                             alc883_chmode_mixer },
9331                 .init_verbs = { alc883_init_verbs,
9332                                 alc883_medion_eapd_verbs },
9333                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9334                 .dac_nids = alc883_dac_nids,
9335                 .adc_nids = alc883_adc_nids_alt,
9336                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
9337                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9338                 .channel_mode = alc883_sixstack_modes,
9339                 .input_mux = &alc883_capture_source,
9340         },
9341         [ALC883_MEDION_MD2] = {
9342                 .mixers = { alc883_medion_md2_mixer},
9343                 .init_verbs = { alc883_init_verbs, alc883_medion_md2_verbs},
9344                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9345                 .dac_nids = alc883_dac_nids,
9346                 .dig_out_nid = ALC883_DIGOUT_NID,
9347                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9348                 .channel_mode = alc883_3ST_2ch_modes,
9349                 .input_mux = &alc883_capture_source,
9350                 .unsol_event = alc_automute_amp_unsol_event,
9351                 .setup = alc883_medion_md2_setup,
9352                 .init_hook = alc_automute_amp,
9353         },
9354         [ALC883_LAPTOP_EAPD] = {
9355                 .mixers = { alc883_base_mixer },
9356                 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
9357                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9358                 .dac_nids = alc883_dac_nids,
9359                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9360                 .channel_mode = alc883_3ST_2ch_modes,
9361                 .input_mux = &alc883_capture_source,
9362         },
9363         [ALC883_CLEVO_M540R] = {
9364                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9365                 .init_verbs = { alc883_init_verbs, alc883_clevo_m540r_verbs },
9366                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9367                 .dac_nids = alc883_dac_nids,
9368                 .dig_out_nid = ALC883_DIGOUT_NID,
9369                 .dig_in_nid = ALC883_DIGIN_NID,
9370                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_clevo_modes),
9371                 .channel_mode = alc883_3ST_6ch_clevo_modes,
9372                 .need_dac_fix = 1,
9373                 .input_mux = &alc883_capture_source,
9374                 /* This machine has the hardware HP auto-muting, thus
9375                  * we need no software mute via unsol event
9376                  */
9377         },
9378         [ALC883_CLEVO_M720] = {
9379                 .mixers = { alc883_clevo_m720_mixer },
9380                 .init_verbs = { alc883_init_verbs, alc883_clevo_m720_verbs },
9381                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9382                 .dac_nids = alc883_dac_nids,
9383                 .dig_out_nid = ALC883_DIGOUT_NID,
9384                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9385                 .channel_mode = alc883_3ST_2ch_modes,
9386                 .input_mux = &alc883_capture_source,
9387                 .unsol_event = alc883_clevo_m720_unsol_event,
9388                 .setup = alc883_clevo_m720_setup,
9389                 .init_hook = alc883_clevo_m720_init_hook,
9390         },
9391         [ALC883_LENOVO_101E_2ch] = {
9392                 .mixers = { alc883_lenovo_101e_2ch_mixer},
9393                 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
9394                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9395                 .dac_nids = alc883_dac_nids,
9396                 .adc_nids = alc883_adc_nids_alt,
9397                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
9398                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9399                 .channel_mode = alc883_3ST_2ch_modes,
9400                 .input_mux = &alc883_lenovo_101e_capture_source,
9401                 .unsol_event = alc883_lenovo_101e_unsol_event,
9402                 .init_hook = alc883_lenovo_101e_all_automute,
9403         },
9404         [ALC883_LENOVO_NB0763] = {
9405                 .mixers = { alc883_lenovo_nb0763_mixer },
9406                 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs},
9407                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9408                 .dac_nids = alc883_dac_nids,
9409                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9410                 .channel_mode = alc883_3ST_2ch_modes,
9411                 .need_dac_fix = 1,
9412                 .input_mux = &alc883_lenovo_nb0763_capture_source,
9413                 .unsol_event = alc_automute_amp_unsol_event,
9414                 .setup = alc883_medion_md2_setup,
9415                 .init_hook = alc_automute_amp,
9416         },
9417         [ALC888_LENOVO_MS7195_DIG] = {
9418                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9419                 .init_verbs = { alc883_init_verbs, alc888_lenovo_ms7195_verbs},
9420                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9421                 .dac_nids = alc883_dac_nids,
9422                 .dig_out_nid = ALC883_DIGOUT_NID,
9423                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9424                 .channel_mode = alc883_3ST_6ch_modes,
9425                 .need_dac_fix = 1,
9426                 .input_mux = &alc883_capture_source,
9427                 .unsol_event = alc883_lenovo_ms7195_unsol_event,
9428                 .init_hook = alc888_lenovo_ms7195_front_automute,
9429         },
9430         [ALC883_HAIER_W66] = {
9431                 .mixers = { alc883_targa_2ch_mixer},
9432                 .init_verbs = { alc883_init_verbs, alc883_haier_w66_verbs},
9433                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9434                 .dac_nids = alc883_dac_nids,
9435                 .dig_out_nid = ALC883_DIGOUT_NID,
9436                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9437                 .channel_mode = alc883_3ST_2ch_modes,
9438                 .input_mux = &alc883_capture_source,
9439                 .unsol_event = alc_automute_amp_unsol_event,
9440                 .setup = alc883_haier_w66_setup,
9441                 .init_hook = alc_automute_amp,
9442         },
9443         [ALC888_3ST_HP] = {
9444                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9445                 .init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs },
9446                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9447                 .dac_nids = alc883_dac_nids,
9448                 .num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes),
9449                 .channel_mode = alc888_3st_hp_modes,
9450                 .need_dac_fix = 1,
9451                 .input_mux = &alc883_capture_source,
9452                 .unsol_event = alc_automute_amp_unsol_event,
9453                 .setup = alc888_3st_hp_setup,
9454                 .init_hook = alc_automute_amp,
9455         },
9456         [ALC888_6ST_DELL] = {
9457                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
9458                 .init_verbs = { alc883_init_verbs, alc888_6st_dell_verbs },
9459                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9460                 .dac_nids = alc883_dac_nids,
9461                 .dig_out_nid = ALC883_DIGOUT_NID,
9462                 .dig_in_nid = ALC883_DIGIN_NID,
9463                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9464                 .channel_mode = alc883_sixstack_modes,
9465                 .input_mux = &alc883_capture_source,
9466                 .unsol_event = alc_automute_amp_unsol_event,
9467                 .setup = alc888_6st_dell_setup,
9468                 .init_hook = alc_automute_amp,
9469         },
9470         [ALC883_MITAC] = {
9471                 .mixers = { alc883_mitac_mixer },
9472                 .init_verbs = { alc883_init_verbs, alc883_mitac_verbs },
9473                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9474                 .dac_nids = alc883_dac_nids,
9475                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9476                 .channel_mode = alc883_3ST_2ch_modes,
9477                 .input_mux = &alc883_capture_source,
9478                 .unsol_event = alc_automute_amp_unsol_event,
9479                 .setup = alc883_mitac_setup,
9480                 .init_hook = alc_automute_amp,
9481         },
9482         [ALC883_FUJITSU_PI2515] = {
9483                 .mixers = { alc883_2ch_fujitsu_pi2515_mixer },
9484                 .init_verbs = { alc883_init_verbs,
9485                                 alc883_2ch_fujitsu_pi2515_verbs},
9486                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9487                 .dac_nids = alc883_dac_nids,
9488                 .dig_out_nid = ALC883_DIGOUT_NID,
9489                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9490                 .channel_mode = alc883_3ST_2ch_modes,
9491                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
9492                 .unsol_event = alc_automute_amp_unsol_event,
9493                 .setup = alc883_2ch_fujitsu_pi2515_setup,
9494                 .init_hook = alc_automute_amp,
9495         },
9496         [ALC888_FUJITSU_XA3530] = {
9497                 .mixers = { alc888_base_mixer, alc883_chmode_mixer },
9498                 .init_verbs = { alc883_init_verbs,
9499                         alc888_fujitsu_xa3530_verbs },
9500                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9501                 .dac_nids = alc883_dac_nids,
9502                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
9503                 .adc_nids = alc883_adc_nids_rev,
9504                 .capsrc_nids = alc883_capsrc_nids_rev,
9505                 .dig_out_nid = ALC883_DIGOUT_NID,
9506                 .num_channel_mode = ARRAY_SIZE(alc888_4ST_8ch_intel_modes),
9507                 .channel_mode = alc888_4ST_8ch_intel_modes,
9508                 .num_mux_defs =
9509                         ARRAY_SIZE(alc888_2_capture_sources),
9510                 .input_mux = alc888_2_capture_sources,
9511                 .unsol_event = alc_automute_amp_unsol_event,
9512                 .setup = alc888_fujitsu_xa3530_setup,
9513                 .init_hook = alc_automute_amp,
9514         },
9515         [ALC888_LENOVO_SKY] = {
9516                 .mixers = { alc888_lenovo_sky_mixer, alc883_chmode_mixer },
9517                 .init_verbs = { alc883_init_verbs, alc888_lenovo_sky_verbs},
9518                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9519                 .dac_nids = alc883_dac_nids,
9520                 .dig_out_nid = ALC883_DIGOUT_NID,
9521                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9522                 .channel_mode = alc883_sixstack_modes,
9523                 .need_dac_fix = 1,
9524                 .input_mux = &alc883_lenovo_sky_capture_source,
9525                 .unsol_event = alc_automute_amp_unsol_event,
9526                 .setup = alc888_lenovo_sky_setup,
9527                 .init_hook = alc_automute_amp,
9528         },
9529         [ALC888_ASUS_M90V] = {
9530                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9531                 .init_verbs = { alc883_init_verbs, alc888_asus_m90v_verbs },
9532                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9533                 .dac_nids = alc883_dac_nids,
9534                 .dig_out_nid = ALC883_DIGOUT_NID,
9535                 .dig_in_nid = ALC883_DIGIN_NID,
9536                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9537                 .channel_mode = alc883_3ST_6ch_modes,
9538                 .need_dac_fix = 1,
9539                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
9540                 .unsol_event = alc_sku_unsol_event,
9541                 .setup = alc883_mode2_setup,
9542                 .init_hook = alc_inithook,
9543         },
9544         [ALC888_ASUS_EEE1601] = {
9545                 .mixers = { alc883_asus_eee1601_mixer },
9546                 .cap_mixer = alc883_asus_eee1601_cap_mixer,
9547                 .init_verbs = { alc883_init_verbs, alc888_asus_eee1601_verbs },
9548                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9549                 .dac_nids = alc883_dac_nids,
9550                 .dig_out_nid = ALC883_DIGOUT_NID,
9551                 .dig_in_nid = ALC883_DIGIN_NID,
9552                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9553                 .channel_mode = alc883_3ST_2ch_modes,
9554                 .need_dac_fix = 1,
9555                 .input_mux = &alc883_asus_eee1601_capture_source,
9556                 .unsol_event = alc_sku_unsol_event,
9557                 .init_hook = alc883_eee1601_inithook,
9558         },
9559         [ALC1200_ASUS_P5Q] = {
9560                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
9561                 .init_verbs = { alc883_init_verbs },
9562                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9563                 .dac_nids = alc883_dac_nids,
9564                 .dig_out_nid = ALC1200_DIGOUT_NID,
9565                 .dig_in_nid = ALC883_DIGIN_NID,
9566                 .slave_dig_outs = alc1200_slave_dig_outs,
9567                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9568                 .channel_mode = alc883_sixstack_modes,
9569                 .input_mux = &alc883_capture_source,
9570         },
9571         [ALC889A_MB31] = {
9572                 .mixers = { alc889A_mb31_mixer, alc883_chmode_mixer},
9573                 .init_verbs = { alc883_init_verbs, alc889A_mb31_verbs,
9574                         alc880_gpio1_init_verbs },
9575                 .adc_nids = alc883_adc_nids,
9576                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
9577                 .dac_nids = alc883_dac_nids,
9578                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9579                 .channel_mode = alc889A_mb31_6ch_modes,
9580                 .num_channel_mode = ARRAY_SIZE(alc889A_mb31_6ch_modes),
9581                 .input_mux = &alc889A_mb31_capture_source,
9582                 .dig_out_nid = ALC883_DIGOUT_NID,
9583                 .unsol_event = alc889A_mb31_unsol_event,
9584                 .init_hook = alc889A_mb31_automute,
9585         },
9586         [ALC883_SONY_VAIO_TT] = {
9587                 .mixers = { alc883_vaiott_mixer },
9588                 .init_verbs = { alc883_init_verbs, alc883_vaiott_verbs },
9589                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9590                 .dac_nids = alc883_dac_nids,
9591                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9592                 .channel_mode = alc883_3ST_2ch_modes,
9593                 .input_mux = &alc883_capture_source,
9594                 .unsol_event = alc_automute_amp_unsol_event,
9595                 .setup = alc883_vaiott_setup,
9596                 .init_hook = alc_automute_amp,
9597         },
9598 };
9599
9600
9601 /*
9602  * Pin config fixes
9603  */
9604 enum {
9605         PINFIX_ABIT_AW9D_MAX
9606 };
9607
9608 static struct alc_pincfg alc882_abit_aw9d_pinfix[] = {
9609         { 0x15, 0x01080104 }, /* side */
9610         { 0x16, 0x01011012 }, /* rear */
9611         { 0x17, 0x01016011 }, /* clfe */
9612         { }
9613 };
9614
9615 static const struct alc_fixup alc882_fixups[] = {
9616         [PINFIX_ABIT_AW9D_MAX] = {
9617                 .pins = alc882_abit_aw9d_pinfix
9618         },
9619 };
9620
9621 static struct snd_pci_quirk alc882_fixup_tbl[] = {
9622         SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
9623         {}
9624 };
9625
9626 /*
9627  * BIOS auto configuration
9628  */
9629 static int alc882_auto_create_input_ctls(struct hda_codec *codec,
9630                                                 const struct auto_pin_cfg *cfg)
9631 {
9632         return alc_auto_create_input_ctls(codec, cfg, 0x0b, 0x23, 0x22);
9633 }
9634
9635 static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
9636                                               hda_nid_t nid, int pin_type,
9637                                               int dac_idx)
9638 {
9639         /* set as output */
9640         struct alc_spec *spec = codec->spec;
9641         int idx;
9642
9643         alc_set_pin_output(codec, nid, pin_type);
9644         if (spec->multiout.dac_nids[dac_idx] == 0x25)
9645                 idx = 4;
9646         else
9647                 idx = spec->multiout.dac_nids[dac_idx] - 2;
9648         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
9649
9650 }
9651
9652 static void alc882_auto_init_multi_out(struct hda_codec *codec)
9653 {
9654         struct alc_spec *spec = codec->spec;
9655         int i;
9656
9657         for (i = 0; i <= HDA_SIDE; i++) {
9658                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
9659                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
9660                 if (nid)
9661                         alc882_auto_set_output_and_unmute(codec, nid, pin_type,
9662                                                           i);
9663         }
9664 }
9665
9666 static void alc882_auto_init_hp_out(struct hda_codec *codec)
9667 {
9668         struct alc_spec *spec = codec->spec;
9669         hda_nid_t pin;
9670
9671         pin = spec->autocfg.hp_pins[0];
9672         if (pin) /* connect to front */
9673                 /* use dac 0 */
9674                 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
9675         pin = spec->autocfg.speaker_pins[0];
9676         if (pin)
9677                 alc882_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
9678 }
9679
9680 static void alc882_auto_init_analog_input(struct hda_codec *codec)
9681 {
9682         struct alc_spec *spec = codec->spec;
9683         int i;
9684
9685         for (i = 0; i < AUTO_PIN_LAST; i++) {
9686                 hda_nid_t nid = spec->autocfg.input_pins[i];
9687                 if (!nid)
9688                         continue;
9689                 alc_set_input_pin(codec, nid, i);
9690                 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
9691                         snd_hda_codec_write(codec, nid, 0,
9692                                             AC_VERB_SET_AMP_GAIN_MUTE,
9693                                             AMP_OUT_MUTE);
9694         }
9695 }
9696
9697 static void alc882_auto_init_input_src(struct hda_codec *codec)
9698 {
9699         struct alc_spec *spec = codec->spec;
9700         int c;
9701
9702         for (c = 0; c < spec->num_adc_nids; c++) {
9703                 hda_nid_t conn_list[HDA_MAX_NUM_INPUTS];
9704                 hda_nid_t nid = spec->capsrc_nids[c];
9705                 unsigned int mux_idx;
9706                 const struct hda_input_mux *imux;
9707                 int conns, mute, idx, item;
9708
9709                 conns = snd_hda_get_connections(codec, nid, conn_list,
9710                                                 ARRAY_SIZE(conn_list));
9711                 if (conns < 0)
9712                         continue;
9713                 mux_idx = c >= spec->num_mux_defs ? 0 : c;
9714                 imux = &spec->input_mux[mux_idx];
9715                 for (idx = 0; idx < conns; idx++) {
9716                         /* if the current connection is the selected one,
9717                          * unmute it as default - otherwise mute it
9718                          */
9719                         mute = AMP_IN_MUTE(idx);
9720                         for (item = 0; item < imux->num_items; item++) {
9721                                 if (imux->items[item].index == idx) {
9722                                         if (spec->cur_mux[c] == item)
9723                                                 mute = AMP_IN_UNMUTE(idx);
9724                                         break;
9725                                 }
9726                         }
9727                         /* check if we have a selector or mixer
9728                          * we could check for the widget type instead, but
9729                          * just check for Amp-In presence (in case of mixer
9730                          * without amp-in there is something wrong, this
9731                          * function shouldn't be used or capsrc nid is wrong)
9732                          */
9733                         if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)
9734                                 snd_hda_codec_write(codec, nid, 0,
9735                                                     AC_VERB_SET_AMP_GAIN_MUTE,
9736                                                     mute);
9737                         else if (mute != AMP_IN_MUTE(idx))
9738                                 snd_hda_codec_write(codec, nid, 0,
9739                                                     AC_VERB_SET_CONNECT_SEL,
9740                                                     idx);
9741                 }
9742         }
9743 }
9744
9745 /* add mic boosts if needed */
9746 static int alc_auto_add_mic_boost(struct hda_codec *codec)
9747 {
9748         struct alc_spec *spec = codec->spec;
9749         int err;
9750         hda_nid_t nid;
9751
9752         nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
9753         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
9754                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
9755                                   "Mic Boost",
9756                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
9757                 if (err < 0)
9758                         return err;
9759         }
9760         nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
9761         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
9762                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
9763                                   "Front Mic Boost",
9764                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
9765                 if (err < 0)
9766                         return err;
9767         }
9768         return 0;
9769 }
9770
9771 /* almost identical with ALC880 parser... */
9772 static int alc882_parse_auto_config(struct hda_codec *codec)
9773 {
9774         struct alc_spec *spec = codec->spec;
9775         static hda_nid_t alc882_ignore[] = { 0x1d, 0 };
9776         int i, err;
9777
9778         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
9779                                            alc882_ignore);
9780         if (err < 0)
9781                 return err;
9782         if (!spec->autocfg.line_outs)
9783                 return 0; /* can't find valid BIOS pin config */
9784
9785         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
9786         if (err < 0)
9787                 return err;
9788         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
9789         if (err < 0)
9790                 return err;
9791         err = alc880_auto_create_extra_out(spec,
9792                                            spec->autocfg.speaker_pins[0],
9793                                            "Speaker");
9794         if (err < 0)
9795                 return err;
9796         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
9797                                            "Headphone");
9798         if (err < 0)
9799                 return err;
9800         err = alc882_auto_create_input_ctls(codec, &spec->autocfg);
9801         if (err < 0)
9802                 return err;
9803
9804         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
9805
9806         /* check multiple SPDIF-out (for recent codecs) */
9807         for (i = 0; i < spec->autocfg.dig_outs; i++) {
9808                 hda_nid_t dig_nid;
9809                 err = snd_hda_get_connections(codec,
9810                                               spec->autocfg.dig_out_pins[i],
9811                                               &dig_nid, 1);
9812                 if (err < 0)
9813                         continue;
9814                 if (!i)
9815                         spec->multiout.dig_out_nid = dig_nid;
9816                 else {
9817                         spec->multiout.slave_dig_outs = spec->slave_dig_outs;
9818                         if (i >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
9819                                 break;
9820                         spec->slave_dig_outs[i - 1] = dig_nid;
9821                 }
9822         }
9823         if (spec->autocfg.dig_in_pin)
9824                 spec->dig_in_nid = ALC880_DIGIN_NID;
9825
9826         if (spec->kctls.list)
9827                 add_mixer(spec, spec->kctls.list);
9828
9829         add_verb(spec, alc883_auto_init_verbs);
9830         /* if ADC 0x07 is available, initialize it, too */
9831         if (get_wcaps_type(get_wcaps(codec, 0x07)) == AC_WID_AUD_IN)
9832                 add_verb(spec, alc882_adc1_init_verbs);
9833
9834         spec->num_mux_defs = 1;
9835         spec->input_mux = &spec->private_imux[0];
9836
9837         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
9838
9839         err = alc_auto_add_mic_boost(codec);
9840         if (err < 0)
9841                 return err;
9842
9843         return 1; /* config found */
9844 }
9845
9846 /* additional initialization for auto-configuration model */
9847 static void alc882_auto_init(struct hda_codec *codec)
9848 {
9849         struct alc_spec *spec = codec->spec;
9850         alc882_auto_init_multi_out(codec);
9851         alc882_auto_init_hp_out(codec);
9852         alc882_auto_init_analog_input(codec);
9853         alc882_auto_init_input_src(codec);
9854         if (spec->unsol_event)
9855                 alc_inithook(codec);
9856 }
9857
9858 static int patch_alc882(struct hda_codec *codec)
9859 {
9860         struct alc_spec *spec;
9861         int err, board_config;
9862
9863         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
9864         if (spec == NULL)
9865                 return -ENOMEM;
9866
9867         codec->spec = spec;
9868
9869         switch (codec->vendor_id) {
9870         case 0x10ec0882:
9871         case 0x10ec0885:
9872                 break;
9873         default:
9874                 /* ALC883 and variants */
9875                 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
9876                 break;
9877         }
9878
9879         board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
9880                                                   alc882_models,
9881                                                   alc882_cfg_tbl);
9882
9883         if (board_config < 0 || board_config >= ALC882_MODEL_LAST)
9884                 board_config = snd_hda_check_board_codec_sid_config(codec,
9885                         ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl);
9886
9887         if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
9888                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
9889                        codec->chip_name);
9890                 board_config = ALC882_AUTO;
9891         }
9892
9893         alc_pick_fixup(codec, alc882_fixup_tbl, alc882_fixups);
9894
9895         if (board_config == ALC882_AUTO) {
9896                 /* automatic parse from the BIOS config */
9897                 err = alc882_parse_auto_config(codec);
9898                 if (err < 0) {
9899                         alc_free(codec);
9900                         return err;
9901                 } else if (!err) {
9902                         printk(KERN_INFO
9903                                "hda_codec: Cannot set up configuration "
9904                                "from BIOS.  Using base mode...\n");
9905                         board_config = ALC882_3ST_DIG;
9906                 }
9907         }
9908
9909         err = snd_hda_attach_beep_device(codec, 0x1);
9910         if (err < 0) {
9911                 alc_free(codec);
9912                 return err;
9913         }
9914
9915         if (board_config != ALC882_AUTO)
9916                 setup_preset(codec, &alc882_presets[board_config]);
9917
9918         spec->stream_analog_playback = &alc882_pcm_analog_playback;
9919         spec->stream_analog_capture = &alc882_pcm_analog_capture;
9920         /* FIXME: setup DAC5 */
9921         /*spec->stream_analog_alt_playback = &alc880_pcm_analog_alt_playback;*/
9922         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
9923
9924         spec->stream_digital_playback = &alc882_pcm_digital_playback;
9925         spec->stream_digital_capture = &alc882_pcm_digital_capture;
9926
9927         if (codec->vendor_id == 0x10ec0888)
9928                 spec->init_amp = ALC_INIT_DEFAULT; /* always initialize */
9929
9930         if (!spec->adc_nids && spec->input_mux) {
9931                 int i;
9932                 spec->num_adc_nids = 0;
9933                 for (i = 0; i < ARRAY_SIZE(alc882_adc_nids); i++) {
9934                         hda_nid_t cap;
9935                         hda_nid_t nid = alc882_adc_nids[i];
9936                         unsigned int wcap = get_wcaps(codec, nid);
9937                         /* get type */
9938                         wcap = get_wcaps_type(wcap);
9939                         if (wcap != AC_WID_AUD_IN)
9940                                 continue;
9941                         spec->private_adc_nids[spec->num_adc_nids] = nid;
9942                         err = snd_hda_get_connections(codec, nid, &cap, 1);
9943                         if (err < 0)
9944                                 continue;
9945                         spec->private_capsrc_nids[spec->num_adc_nids] = cap;
9946                         spec->num_adc_nids++;
9947                 }
9948                 spec->adc_nids = spec->private_adc_nids;
9949                 spec->capsrc_nids = spec->private_capsrc_nids;
9950         }
9951
9952         set_capture_mixer(codec);
9953         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
9954
9955         spec->vmaster_nid = 0x0c;
9956
9957         codec->patch_ops = alc_patch_ops;
9958         if (board_config == ALC882_AUTO)
9959                 spec->init_hook = alc882_auto_init;
9960 #ifdef CONFIG_SND_HDA_POWER_SAVE
9961         if (!spec->loopback.amplist)
9962                 spec->loopback.amplist = alc882_loopbacks;
9963 #endif
9964         codec->proc_widget_hook = print_realtek_coef;
9965
9966         return 0;
9967 }
9968
9969
9970 /*
9971  * ALC262 support
9972  */
9973
9974 #define ALC262_DIGOUT_NID       ALC880_DIGOUT_NID
9975 #define ALC262_DIGIN_NID        ALC880_DIGIN_NID
9976
9977 #define alc262_dac_nids         alc260_dac_nids
9978 #define alc262_adc_nids         alc882_adc_nids
9979 #define alc262_adc_nids_alt     alc882_adc_nids_alt
9980 #define alc262_capsrc_nids      alc882_capsrc_nids
9981 #define alc262_capsrc_nids_alt  alc882_capsrc_nids_alt
9982
9983 #define alc262_modes            alc260_modes
9984 #define alc262_capture_source   alc882_capture_source
9985
9986 static hda_nid_t alc262_dmic_adc_nids[1] = {
9987         /* ADC0 */
9988         0x09
9989 };
9990
9991 static hda_nid_t alc262_dmic_capsrc_nids[1] = { 0x22 };
9992
9993 static struct snd_kcontrol_new alc262_base_mixer[] = {
9994         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9995         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9996         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9997         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9998         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9999         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10000         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10001         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10002         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10003         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10004         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10005         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10006         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
10007         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10008         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
10009         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
10010         { } /* end */
10011 };
10012
10013 /* update HP, line and mono-out pins according to the master switch */
10014 static void alc262_hp_master_update(struct hda_codec *codec)
10015 {
10016         struct alc_spec *spec = codec->spec;
10017         int val = spec->master_sw;
10018
10019         /* HP & line-out */
10020         snd_hda_codec_write_cache(codec, 0x1b, 0,
10021                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
10022                                   val ? PIN_HP : 0);
10023         snd_hda_codec_write_cache(codec, 0x15, 0,
10024                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
10025                                   val ? PIN_HP : 0);
10026         /* mono (speaker) depending on the HP jack sense */
10027         val = val && !spec->jack_present;
10028         snd_hda_codec_write_cache(codec, 0x16, 0,
10029                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
10030                                   val ? PIN_OUT : 0);
10031 }
10032
10033 static void alc262_hp_bpc_automute(struct hda_codec *codec)
10034 {
10035         struct alc_spec *spec = codec->spec;
10036         unsigned int presence;
10037         presence = snd_hda_codec_read(codec, 0x1b, 0,
10038                                       AC_VERB_GET_PIN_SENSE, 0);
10039         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
10040         alc262_hp_master_update(codec);
10041 }
10042
10043 static void alc262_hp_bpc_unsol_event(struct hda_codec *codec, unsigned int res)
10044 {
10045         if ((res >> 26) != ALC880_HP_EVENT)
10046                 return;
10047         alc262_hp_bpc_automute(codec);
10048 }
10049
10050 static void alc262_hp_wildwest_automute(struct hda_codec *codec)
10051 {
10052         struct alc_spec *spec = codec->spec;
10053         unsigned int presence;
10054         presence = snd_hda_codec_read(codec, 0x15, 0,
10055                                       AC_VERB_GET_PIN_SENSE, 0);
10056         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
10057         alc262_hp_master_update(codec);
10058 }
10059
10060 static void alc262_hp_wildwest_unsol_event(struct hda_codec *codec,
10061                                            unsigned int res)
10062 {
10063         if ((res >> 26) != ALC880_HP_EVENT)
10064                 return;
10065         alc262_hp_wildwest_automute(codec);
10066 }
10067
10068 #define alc262_hp_master_sw_get         alc260_hp_master_sw_get
10069
10070 static int alc262_hp_master_sw_put(struct snd_kcontrol *kcontrol,
10071                                    struct snd_ctl_elem_value *ucontrol)
10072 {
10073         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10074         struct alc_spec *spec = codec->spec;
10075         int val = !!*ucontrol->value.integer.value;
10076
10077         if (val == spec->master_sw)
10078                 return 0;
10079         spec->master_sw = val;
10080         alc262_hp_master_update(codec);
10081         return 1;
10082 }
10083
10084 #define ALC262_HP_MASTER_SWITCH                                 \
10085         {                                                       \
10086                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,            \
10087                 .name = "Master Playback Switch",               \
10088                 .info = snd_ctl_boolean_mono_info,              \
10089                 .get = alc262_hp_master_sw_get,                 \
10090                 .put = alc262_hp_master_sw_put,                 \
10091         }
10092
10093 static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
10094         ALC262_HP_MASTER_SWITCH,
10095         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10096         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10097         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
10098         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
10099                               HDA_OUTPUT),
10100         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
10101                             HDA_OUTPUT),
10102         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10103         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10104         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10105         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10106         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10107         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10108         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10109         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10110         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10111         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10112         HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
10113         HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
10114         { } /* end */
10115 };
10116
10117 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
10118         ALC262_HP_MASTER_SWITCH,
10119         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10120         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
10121         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
10122         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10123         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
10124                               HDA_OUTPUT),
10125         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
10126                             HDA_OUTPUT),
10127         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
10128         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
10129         HDA_CODEC_VOLUME("Front Mic Boost", 0x1a, 0, HDA_INPUT),
10130         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
10131         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
10132         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10133         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10134         { } /* end */
10135 };
10136
10137 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
10138         HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10139         HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10140         HDA_CODEC_VOLUME("Rear Mic Boost", 0x18, 0, HDA_INPUT),
10141         { } /* end */
10142 };
10143
10144 /* mute/unmute internal speaker according to the hp jack and mute state */
10145 static void alc262_hp_t5735_setup(struct hda_codec *codec)
10146 {
10147         struct alc_spec *spec = codec->spec;
10148
10149         spec->autocfg.hp_pins[0] = 0x15;
10150         spec->autocfg.speaker_pins[0] = 0x0c; /* HACK: not actually a pin */
10151 }
10152
10153 static struct snd_kcontrol_new alc262_hp_t5735_mixer[] = {
10154         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10155         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10156         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
10157         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10158         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10159         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10160         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10161         { } /* end */
10162 };
10163
10164 static struct hda_verb alc262_hp_t5735_verbs[] = {
10165         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10166         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10167
10168         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10169         { }
10170 };
10171
10172 static struct snd_kcontrol_new alc262_hp_rp5700_mixer[] = {
10173         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10174         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
10175         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
10176         HDA_CODEC_MUTE("Speaker Playback Switch", 0x16, 0x0, HDA_OUTPUT),
10177         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
10178         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
10179         { } /* end */
10180 };
10181
10182 static struct hda_verb alc262_hp_rp5700_verbs[] = {
10183         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10184         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10185         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10186         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10187         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10188         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10189         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10190         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10191         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
10192         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
10193         {}
10194 };
10195
10196 static struct hda_input_mux alc262_hp_rp5700_capture_source = {
10197         .num_items = 1,
10198         .items = {
10199                 { "Line", 0x1 },
10200         },
10201 };
10202
10203 /* bind hp and internal speaker mute (with plug check) as master switch */
10204 static void alc262_hippo_master_update(struct hda_codec *codec)
10205 {
10206         struct alc_spec *spec = codec->spec;
10207         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
10208         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
10209         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
10210         unsigned int mute;
10211
10212         /* HP */
10213         mute = spec->master_sw ? 0 : HDA_AMP_MUTE;
10214         snd_hda_codec_amp_stereo(codec, hp_nid, HDA_OUTPUT, 0,
10215                                  HDA_AMP_MUTE, mute);
10216         /* mute internal speaker per jack sense */
10217         if (spec->jack_present)
10218                 mute = HDA_AMP_MUTE;
10219         if (line_nid)
10220                 snd_hda_codec_amp_stereo(codec, line_nid, HDA_OUTPUT, 0,
10221                                          HDA_AMP_MUTE, mute);
10222         if (speaker_nid && speaker_nid != line_nid)
10223                 snd_hda_codec_amp_stereo(codec, speaker_nid, HDA_OUTPUT, 0,
10224                                          HDA_AMP_MUTE, mute);
10225 }
10226
10227 #define alc262_hippo_master_sw_get      alc262_hp_master_sw_get
10228
10229 static int alc262_hippo_master_sw_put(struct snd_kcontrol *kcontrol,
10230                                       struct snd_ctl_elem_value *ucontrol)
10231 {
10232         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10233         struct alc_spec *spec = codec->spec;
10234         int val = !!*ucontrol->value.integer.value;
10235
10236         if (val == spec->master_sw)
10237                 return 0;
10238         spec->master_sw = val;
10239         alc262_hippo_master_update(codec);
10240         return 1;
10241 }
10242
10243 #define ALC262_HIPPO_MASTER_SWITCH                              \
10244         {                                                       \
10245                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,            \
10246                 .name = "Master Playback Switch",               \
10247                 .info = snd_ctl_boolean_mono_info,              \
10248                 .get = alc262_hippo_master_sw_get,              \
10249                 .put = alc262_hippo_master_sw_put,              \
10250         }
10251
10252 static struct snd_kcontrol_new alc262_hippo_mixer[] = {
10253         ALC262_HIPPO_MASTER_SWITCH,
10254         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10255         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10256         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10257         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10258         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10259         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10260         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10261         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10262         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10263         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10264         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10265         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
10266         { } /* end */
10267 };
10268
10269 static struct snd_kcontrol_new alc262_hippo1_mixer[] = {
10270         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10271         ALC262_HIPPO_MASTER_SWITCH,
10272         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10273         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10274         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10275         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10276         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10277         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10278         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10279         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10280         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10281         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10282         { } /* end */
10283 };
10284
10285 /* mute/unmute internal speaker according to the hp jack and mute state */
10286 static void alc262_hippo_automute(struct hda_codec *codec)
10287 {
10288         struct alc_spec *spec = codec->spec;
10289         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
10290         unsigned int present;
10291
10292         /* need to execute and sync at first */
10293         snd_hda_codec_read(codec, hp_nid, 0, AC_VERB_SET_PIN_SENSE, 0);
10294         present = snd_hda_codec_read(codec, hp_nid, 0,
10295                                      AC_VERB_GET_PIN_SENSE, 0);
10296         spec->jack_present = (present & 0x80000000) != 0;
10297         alc262_hippo_master_update(codec);
10298 }
10299
10300 static void alc262_hippo_unsol_event(struct hda_codec *codec, unsigned int res)
10301 {
10302         if ((res >> 26) != ALC880_HP_EVENT)
10303                 return;
10304         alc262_hippo_automute(codec);
10305 }
10306
10307 static void alc262_hippo_setup(struct hda_codec *codec)
10308 {
10309         struct alc_spec *spec = codec->spec;
10310
10311         spec->autocfg.hp_pins[0] = 0x15;
10312         spec->autocfg.speaker_pins[0] = 0x14;
10313 }
10314
10315 static void alc262_hippo1_setup(struct hda_codec *codec)
10316 {
10317         struct alc_spec *spec = codec->spec;
10318
10319         spec->autocfg.hp_pins[0] = 0x1b;
10320         spec->autocfg.speaker_pins[0] = 0x14;
10321 }
10322
10323
10324 static struct snd_kcontrol_new alc262_sony_mixer[] = {
10325         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10326         ALC262_HIPPO_MASTER_SWITCH,
10327         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10328         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10329         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10330         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10331         { } /* end */
10332 };
10333
10334 static struct snd_kcontrol_new alc262_benq_t31_mixer[] = {
10335         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10336         ALC262_HIPPO_MASTER_SWITCH,
10337         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
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_tyan_mixer[] = {
10346         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10347         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
10348         HDA_CODEC_VOLUME("Aux Playback Volume", 0x0b, 0x06, HDA_INPUT),
10349         HDA_CODEC_MUTE("Aux Playback Switch", 0x0b, 0x06, HDA_INPUT),
10350         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10351         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10352         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10353         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10354         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10355         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10356         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10357         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10358         { } /* end */
10359 };
10360
10361 static struct hda_verb alc262_tyan_verbs[] = {
10362         /* Headphone automute */
10363         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10364         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10365         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10366
10367         /* P11 AUX_IN, white 4-pin connector */
10368         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10369         {0x14, AC_VERB_SET_CONFIG_DEFAULT_BYTES_1, 0xe1},
10370         {0x14, AC_VERB_SET_CONFIG_DEFAULT_BYTES_2, 0x93},
10371         {0x14, AC_VERB_SET_CONFIG_DEFAULT_BYTES_3, 0x19},
10372
10373         {}
10374 };
10375
10376 /* unsolicited event for HP jack sensing */
10377 static void alc262_tyan_setup(struct hda_codec *codec)
10378 {
10379         struct alc_spec *spec = codec->spec;
10380
10381         spec->autocfg.hp_pins[0] = 0x1b;
10382         spec->autocfg.speaker_pins[0] = 0x15;
10383 }
10384
10385
10386 #define alc262_capture_mixer            alc882_capture_mixer
10387 #define alc262_capture_alt_mixer        alc882_capture_alt_mixer
10388
10389 /*
10390  * generic initialization of ADC, input mixers and output mixers
10391  */
10392 static struct hda_verb alc262_init_verbs[] = {
10393         /*
10394          * Unmute ADC0-2 and set the default input to mic-in
10395          */
10396         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10397         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10398         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10399         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10400         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10401         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10402
10403         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10404          * mixer widget
10405          * Note: PASD motherboards uses the Line In 2 as the input for
10406          * front panel mic (mic 2)
10407          */
10408         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10409         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10410         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10411         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10412         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10413         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10414
10415         /*
10416          * Set up output mixers (0x0c - 0x0e)
10417          */
10418         /* set vol=0 to output mixers */
10419         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10420         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10421         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10422         /* set up input amps for analog loopback */
10423         /* Amp Indices: DAC = 0, mixer = 1 */
10424         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10425         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10426         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10427         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10428         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10429         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10430
10431         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
10432         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
10433         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
10434         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10435         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10436         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10437
10438         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10439         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10440         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10441         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10442         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10443
10444         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
10445         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
10446
10447         /* FIXME: use matrix-type input source selection */
10448         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10449         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10450         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10451         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10452         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10453         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10454         /* Input mixer2 */
10455         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10456         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10457         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10458         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10459         /* Input mixer3 */
10460         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10461         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10462         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10463         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10464
10465         { }
10466 };
10467
10468 static struct hda_verb alc262_eapd_verbs[] = {
10469         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
10470         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
10471         { }
10472 };
10473
10474 static struct hda_verb alc262_hippo1_unsol_verbs[] = {
10475         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
10476         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10477         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10478
10479         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10480         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10481         {}
10482 };
10483
10484 static struct hda_verb alc262_sony_unsol_verbs[] = {
10485         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
10486         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10487         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},   // Front Mic
10488
10489         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10490         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10491         {}
10492 };
10493
10494 static struct snd_kcontrol_new alc262_toshiba_s06_mixer[] = {
10495         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10496         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10497         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10498         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10499         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10500         { } /* end */
10501 };
10502
10503 static struct hda_verb alc262_toshiba_s06_verbs[] = {
10504         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10505         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10506         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10507         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10508         {0x22, AC_VERB_SET_CONNECT_SEL, 0x09},
10509         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10510         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
10511         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10512         {}
10513 };
10514
10515 static void alc262_toshiba_s06_setup(struct hda_codec *codec)
10516 {
10517         struct alc_spec *spec = codec->spec;
10518
10519         spec->autocfg.hp_pins[0] = 0x15;
10520         spec->autocfg.speaker_pins[0] = 0x14;
10521         spec->ext_mic.pin = 0x18;
10522         spec->ext_mic.mux_idx = 0;
10523         spec->int_mic.pin = 0x12;
10524         spec->int_mic.mux_idx = 9;
10525         spec->auto_mic = 1;
10526 }
10527
10528 /*
10529  * nec model
10530  *  0x15 = headphone
10531  *  0x16 = internal speaker
10532  *  0x18 = external mic
10533  */
10534
10535 static struct snd_kcontrol_new alc262_nec_mixer[] = {
10536         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
10537         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 0, 0x0, HDA_OUTPUT),
10538
10539         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10540         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10541         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10542
10543         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
10544         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10545         { } /* end */
10546 };
10547
10548 static struct hda_verb alc262_nec_verbs[] = {
10549         /* Unmute Speaker */
10550         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10551
10552         /* Headphone */
10553         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10554         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10555
10556         /* External mic to headphone */
10557         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10558         /* External mic to speaker */
10559         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10560         {}
10561 };
10562
10563 /*
10564  * fujitsu model
10565  *  0x14 = headphone/spdif-out, 0x15 = internal speaker,
10566  *  0x1b = port replicator headphone out
10567  */
10568
10569 #define ALC_HP_EVENT    0x37
10570
10571 static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
10572         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
10573         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10574         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
10575         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10576         {}
10577 };
10578
10579 static struct hda_verb alc262_lenovo_3000_unsol_verbs[] = {
10580         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
10581         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10582         {}
10583 };
10584
10585 static struct hda_input_mux alc262_fujitsu_capture_source = {
10586         .num_items = 3,
10587         .items = {
10588                 { "Mic", 0x0 },
10589                 { "Int Mic", 0x1 },
10590                 { "CD", 0x4 },
10591         },
10592 };
10593
10594 static struct hda_input_mux alc262_HP_capture_source = {
10595         .num_items = 5,
10596         .items = {
10597                 { "Mic", 0x0 },
10598                 { "Front Mic", 0x1 },
10599                 { "Line", 0x2 },
10600                 { "CD", 0x4 },
10601                 { "AUX IN", 0x6 },
10602         },
10603 };
10604
10605 static struct hda_input_mux alc262_HP_D7000_capture_source = {
10606         .num_items = 4,
10607         .items = {
10608                 { "Mic", 0x0 },
10609                 { "Front Mic", 0x2 },
10610                 { "Line", 0x1 },
10611                 { "CD", 0x4 },
10612         },
10613 };
10614
10615 /* mute/unmute internal speaker according to the hp jacks and mute state */
10616 static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
10617 {
10618         struct alc_spec *spec = codec->spec;
10619         unsigned int mute;
10620
10621         if (force || !spec->sense_updated) {
10622                 unsigned int present;
10623                 /* need to execute and sync at first */
10624                 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
10625                 /* check laptop HP jack */
10626                 present = snd_hda_codec_read(codec, 0x14, 0,
10627                                              AC_VERB_GET_PIN_SENSE, 0);
10628                 /* need to execute and sync at first */
10629                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
10630                 /* check docking HP jack */
10631                 present |= snd_hda_codec_read(codec, 0x1b, 0,
10632                                               AC_VERB_GET_PIN_SENSE, 0);
10633                 if (present & AC_PINSENSE_PRESENCE)
10634                         spec->jack_present = 1;
10635                 else
10636                         spec->jack_present = 0;
10637                 spec->sense_updated = 1;
10638         }
10639         /* unmute internal speaker only if both HPs are unplugged and
10640          * master switch is on
10641          */
10642         if (spec->jack_present)
10643                 mute = HDA_AMP_MUTE;
10644         else
10645                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
10646         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
10647                                  HDA_AMP_MUTE, mute);
10648 }
10649
10650 /* unsolicited event for HP jack sensing */
10651 static void alc262_fujitsu_unsol_event(struct hda_codec *codec,
10652                                        unsigned int res)
10653 {
10654         if ((res >> 26) != ALC_HP_EVENT)
10655                 return;
10656         alc262_fujitsu_automute(codec, 1);
10657 }
10658
10659 static void alc262_fujitsu_init_hook(struct hda_codec *codec)
10660 {
10661         alc262_fujitsu_automute(codec, 1);
10662 }
10663
10664 /* bind volumes of both NID 0x0c and 0x0d */
10665 static struct hda_bind_ctls alc262_fujitsu_bind_master_vol = {
10666         .ops = &snd_hda_bind_vol,
10667         .values = {
10668                 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
10669                 HDA_COMPOSE_AMP_VAL(0x0d, 3, 0, HDA_OUTPUT),
10670                 0
10671         },
10672 };
10673
10674 /* mute/unmute internal speaker according to the hp jack and mute state */
10675 static void alc262_lenovo_3000_automute(struct hda_codec *codec, int force)
10676 {
10677         struct alc_spec *spec = codec->spec;
10678         unsigned int mute;
10679
10680         if (force || !spec->sense_updated) {
10681                 unsigned int present_int_hp;
10682                 /* need to execute and sync at first */
10683                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
10684                 present_int_hp = snd_hda_codec_read(codec, 0x1b, 0,
10685                                         AC_VERB_GET_PIN_SENSE, 0);
10686                 spec->jack_present = (present_int_hp & 0x80000000) != 0;
10687                 spec->sense_updated = 1;
10688         }
10689         if (spec->jack_present) {
10690                 /* mute internal speaker */
10691                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10692                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
10693                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
10694                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
10695         } else {
10696                 /* unmute internal speaker if necessary */
10697                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
10698                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10699                                          HDA_AMP_MUTE, mute);
10700                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
10701                                          HDA_AMP_MUTE, mute);
10702         }
10703 }
10704
10705 /* unsolicited event for HP jack sensing */
10706 static void alc262_lenovo_3000_unsol_event(struct hda_codec *codec,
10707                                        unsigned int res)
10708 {
10709         if ((res >> 26) != ALC_HP_EVENT)
10710                 return;
10711         alc262_lenovo_3000_automute(codec, 1);
10712 }
10713
10714 static int amp_stereo_mute_update(struct hda_codec *codec, hda_nid_t nid,
10715                                   int dir, int idx, long *valp)
10716 {
10717         int i, change = 0;
10718
10719         for (i = 0; i < 2; i++, valp++)
10720                 change |= snd_hda_codec_amp_update(codec, nid, i, dir, idx,
10721                                                    HDA_AMP_MUTE,
10722                                                    *valp ? 0 : HDA_AMP_MUTE);
10723         return change;
10724 }
10725
10726 /* bind hp and internal speaker mute (with plug check) */
10727 static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
10728                                          struct snd_ctl_elem_value *ucontrol)
10729 {
10730         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10731         long *valp = ucontrol->value.integer.value;
10732         int change;
10733
10734         change = amp_stereo_mute_update(codec, 0x14, HDA_OUTPUT, 0, valp);
10735         change |= amp_stereo_mute_update(codec, 0x1b, HDA_OUTPUT, 0, valp);
10736         if (change)
10737                 alc262_fujitsu_automute(codec, 0);
10738         return change;
10739 }
10740
10741 static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
10742         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
10743         {
10744                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10745                 .name = "Master Playback Switch",
10746                 .info = snd_hda_mixer_amp_switch_info,
10747                 .get = snd_hda_mixer_amp_switch_get,
10748                 .put = alc262_fujitsu_master_sw_put,
10749                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
10750         },
10751         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10752         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10753         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10754         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10755         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10756         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
10757         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
10758         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
10759         { } /* end */
10760 };
10761
10762 /* bind hp and internal speaker mute (with plug check) */
10763 static int alc262_lenovo_3000_master_sw_put(struct snd_kcontrol *kcontrol,
10764                                          struct snd_ctl_elem_value *ucontrol)
10765 {
10766         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10767         long *valp = ucontrol->value.integer.value;
10768         int change;
10769
10770         change = amp_stereo_mute_update(codec, 0x1b, HDA_OUTPUT, 0, valp);
10771         if (change)
10772                 alc262_lenovo_3000_automute(codec, 0);
10773         return change;
10774 }
10775
10776 static struct snd_kcontrol_new alc262_lenovo_3000_mixer[] = {
10777         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
10778         {
10779                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10780                 .name = "Master Playback Switch",
10781                 .info = snd_hda_mixer_amp_switch_info,
10782                 .get = snd_hda_mixer_amp_switch_get,
10783                 .put = alc262_lenovo_3000_master_sw_put,
10784                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
10785         },
10786         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10787         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10788         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10789         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10790         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10791         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
10792         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
10793         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
10794         { } /* end */
10795 };
10796
10797 static struct snd_kcontrol_new alc262_toshiba_rx1_mixer[] = {
10798         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
10799         ALC262_HIPPO_MASTER_SWITCH,
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("Mic Boost", 0x18, 0, HDA_INPUT),
10803         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10804         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10805         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10806         { } /* end */
10807 };
10808
10809 /* additional init verbs for Benq laptops */
10810 static struct hda_verb alc262_EAPD_verbs[] = {
10811         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
10812         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
10813         {}
10814 };
10815
10816 static struct hda_verb alc262_benq_t31_EAPD_verbs[] = {
10817         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10818         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10819
10820         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
10821         {0x20, AC_VERB_SET_PROC_COEF,  0x3050},
10822         {}
10823 };
10824
10825 /* Samsung Q1 Ultra Vista model setup */
10826 static struct snd_kcontrol_new alc262_ultra_mixer[] = {
10827         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10828         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
10829         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10830         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10831         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
10832         HDA_CODEC_VOLUME("Headphone Mic Boost", 0x15, 0, HDA_INPUT),
10833         { } /* end */
10834 };
10835
10836 static struct hda_verb alc262_ultra_verbs[] = {
10837         /* output mixer */
10838         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10839         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10840         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10841         /* speaker */
10842         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10843         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10844         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10845         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
10846         /* HP */
10847         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10848         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10849         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10850         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10851         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10852         /* internal mic */
10853         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10854         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10855         /* ADC, choose mic */
10856         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10857         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10858         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10859         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10860         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10861         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10862         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10863         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10864         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
10865         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(8)},
10866         {}
10867 };
10868
10869 /* mute/unmute internal speaker according to the hp jack and mute state */
10870 static void alc262_ultra_automute(struct hda_codec *codec)
10871 {
10872         struct alc_spec *spec = codec->spec;
10873         unsigned int mute;
10874
10875         mute = 0;
10876         /* auto-mute only when HP is used as HP */
10877         if (!spec->cur_mux[0]) {
10878                 unsigned int present;
10879                 /* need to execute and sync at first */
10880                 snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
10881                 present = snd_hda_codec_read(codec, 0x15, 0,
10882                                              AC_VERB_GET_PIN_SENSE, 0);
10883                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
10884                 if (spec->jack_present)
10885                         mute = HDA_AMP_MUTE;
10886         }
10887         /* mute/unmute internal speaker */
10888         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10889                                  HDA_AMP_MUTE, mute);
10890         /* mute/unmute HP */
10891         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
10892                                  HDA_AMP_MUTE, mute ? 0 : HDA_AMP_MUTE);
10893 }
10894
10895 /* unsolicited event for HP jack sensing */
10896 static void alc262_ultra_unsol_event(struct hda_codec *codec,
10897                                        unsigned int res)
10898 {
10899         if ((res >> 26) != ALC880_HP_EVENT)
10900                 return;
10901         alc262_ultra_automute(codec);
10902 }
10903
10904 static struct hda_input_mux alc262_ultra_capture_source = {
10905         .num_items = 2,
10906         .items = {
10907                 { "Mic", 0x1 },
10908                 { "Headphone", 0x7 },
10909         },
10910 };
10911
10912 static int alc262_ultra_mux_enum_put(struct snd_kcontrol *kcontrol,
10913                                      struct snd_ctl_elem_value *ucontrol)
10914 {
10915         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10916         struct alc_spec *spec = codec->spec;
10917         int ret;
10918
10919         ret = alc_mux_enum_put(kcontrol, ucontrol);
10920         if (!ret)
10921                 return 0;
10922         /* reprogram the HP pin as mic or HP according to the input source */
10923         snd_hda_codec_write_cache(codec, 0x15, 0,
10924                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
10925                                   spec->cur_mux[0] ? PIN_VREF80 : PIN_HP);
10926         alc262_ultra_automute(codec); /* mute/unmute HP */
10927         return ret;
10928 }
10929
10930 static struct snd_kcontrol_new alc262_ultra_capture_mixer[] = {
10931         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
10932         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
10933         {
10934                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10935                 .name = "Capture Source",
10936                 .info = alc_mux_enum_info,
10937                 .get = alc_mux_enum_get,
10938                 .put = alc262_ultra_mux_enum_put,
10939         },
10940         { } /* end */
10941 };
10942
10943 /* We use two mixers depending on the output pin; 0x16 is a mono output
10944  * and thus it's bound with a different mixer.
10945  * This function returns which mixer amp should be used.
10946  */
10947 static int alc262_check_volbit(hda_nid_t nid)
10948 {
10949         if (!nid)
10950                 return 0;
10951         else if (nid == 0x16)
10952                 return 2;
10953         else
10954                 return 1;
10955 }
10956
10957 static int alc262_add_out_vol_ctl(struct alc_spec *spec, hda_nid_t nid,
10958                                   const char *pfx, int *vbits)
10959 {
10960         unsigned long val;
10961         int vbit;
10962
10963         vbit = alc262_check_volbit(nid);
10964         if (!vbit)
10965                 return 0;
10966         if (*vbits & vbit) /* a volume control for this mixer already there */
10967                 return 0;
10968         *vbits |= vbit;
10969         if (vbit == 2)
10970                 val = HDA_COMPOSE_AMP_VAL(0x0e, 2, 0, HDA_OUTPUT);
10971         else
10972                 val = HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT);
10973         return add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx, val);
10974 }
10975
10976 static int alc262_add_out_sw_ctl(struct alc_spec *spec, hda_nid_t nid,
10977                                  const char *pfx)
10978 {
10979         unsigned long val;
10980
10981         if (!nid)
10982                 return 0;
10983         if (nid == 0x16)
10984                 val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
10985         else
10986                 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
10987         return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, val);
10988 }
10989
10990 /* add playback controls from the parsed DAC table */
10991 static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
10992                                              const struct auto_pin_cfg *cfg)
10993 {
10994         const char *pfx;
10995         int vbits;
10996         int err;
10997
10998         spec->multiout.num_dacs = 1;    /* only use one dac */
10999         spec->multiout.dac_nids = spec->private_dac_nids;
11000         spec->multiout.dac_nids[0] = 2;
11001
11002         if (!cfg->speaker_pins[0] && !cfg->hp_pins[0])
11003                 pfx = "Master";
11004         else if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
11005                 pfx = "Speaker";
11006         else
11007                 pfx = "Front";
11008         err = alc262_add_out_sw_ctl(spec, cfg->line_out_pins[0], pfx);
11009         if (err < 0)
11010                 return err;
11011         err = alc262_add_out_sw_ctl(spec, cfg->speaker_pins[0], "Speaker");
11012         if (err < 0)
11013                 return err;
11014         err = alc262_add_out_sw_ctl(spec, cfg->hp_pins[0], "Headphone");
11015         if (err < 0)
11016                 return err;
11017
11018         vbits = alc262_check_volbit(cfg->line_out_pins[0]) |
11019                 alc262_check_volbit(cfg->speaker_pins[0]) |
11020                 alc262_check_volbit(cfg->hp_pins[0]);
11021         if (vbits == 1 || vbits == 2)
11022                 pfx = "Master"; /* only one mixer is used */
11023         else if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
11024                 pfx = "Speaker";
11025         else
11026                 pfx = "Front";
11027         vbits = 0;
11028         err = alc262_add_out_vol_ctl(spec, cfg->line_out_pins[0], pfx, &vbits);
11029         if (err < 0)
11030                 return err;
11031         err = alc262_add_out_vol_ctl(spec, cfg->speaker_pins[0], "Speaker",
11032                                      &vbits);
11033         if (err < 0)
11034                 return err;
11035         err = alc262_add_out_vol_ctl(spec, cfg->hp_pins[0], "Headphone",
11036                                      &vbits);
11037         if (err < 0)
11038                 return err;
11039         return 0;
11040 }
11041
11042 #define alc262_auto_create_input_ctls \
11043         alc880_auto_create_input_ctls
11044
11045 /*
11046  * generic initialization of ADC, input mixers and output mixers
11047  */
11048 static struct hda_verb alc262_volume_init_verbs[] = {
11049         /*
11050          * Unmute ADC0-2 and set the default input to mic-in
11051          */
11052         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
11053         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11054         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11055         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11056         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
11057         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11058
11059         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
11060          * mixer widget
11061          * Note: PASD motherboards uses the Line In 2 as the input for
11062          * front panel mic (mic 2)
11063          */
11064         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
11065         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11066         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11067         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11068         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11069         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
11070
11071         /*
11072          * Set up output mixers (0x0c - 0x0f)
11073          */
11074         /* set vol=0 to output mixers */
11075         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11076         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11077         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11078
11079         /* set up input amps for analog loopback */
11080         /* Amp Indices: DAC = 0, mixer = 1 */
11081         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11082         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11083         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11084         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11085         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11086         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11087
11088         /* FIXME: use matrix-type input source selection */
11089         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
11090         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
11091         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11092         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11093         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11094         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11095         /* Input mixer2 */
11096         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11097         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11098         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11099         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11100         /* Input mixer3 */
11101         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11102         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11103         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11104         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11105
11106         { }
11107 };
11108
11109 static struct hda_verb alc262_HP_BPC_init_verbs[] = {
11110         /*
11111          * Unmute ADC0-2 and set the default input to mic-in
11112          */
11113         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
11114         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11115         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11116         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11117         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
11118         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11119
11120         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
11121          * mixer widget
11122          * Note: PASD motherboards uses the Line In 2 as the input for
11123          * front panel mic (mic 2)
11124          */
11125         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
11126         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11127         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11128         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11129         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11130         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
11131         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
11132         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
11133
11134         /*
11135          * Set up output mixers (0x0c - 0x0e)
11136          */
11137         /* set vol=0 to output mixers */
11138         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11139         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11140         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11141
11142         /* set up input amps for analog loopback */
11143         /* Amp Indices: DAC = 0, mixer = 1 */
11144         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11145         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11146         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11147         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11148         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11149         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11150
11151         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11152         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11153         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11154
11155         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11156         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11157
11158         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
11159         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
11160
11161         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11162         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11163         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11164         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11165         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11166
11167         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11168         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11169         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11170         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11171         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11172         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11173
11174
11175         /* FIXME: use matrix-type input source selection */
11176         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 0b, 12 */
11177         /* Input mixer1: only unmute Mic */
11178         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11179         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8))},
11180         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11181         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11182         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11183         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x05 << 8))},
11184         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x06 << 8))},
11185         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x07 << 8))},
11186         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x08 << 8))},
11187         /* Input mixer2 */
11188         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11189         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8))},
11190         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11191         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11192         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11193         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x05 << 8))},
11194         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x06 << 8))},
11195         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x07 << 8))},
11196         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x08 << 8))},
11197         /* Input mixer3 */
11198         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11199         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8))},
11200         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11201         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11202         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11203         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x05 << 8))},
11204         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x06 << 8))},
11205         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x07 << 8))},
11206         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x08 << 8))},
11207
11208         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11209
11210         { }
11211 };
11212
11213 static struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
11214         /*
11215          * Unmute ADC0-2 and set the default input to mic-in
11216          */
11217         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
11218         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11219         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11220         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11221         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
11222         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11223
11224         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
11225          * mixer widget
11226          * Note: PASD motherboards uses the Line In 2 as the input for front
11227          * panel mic (mic 2)
11228          */
11229         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
11230         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11231         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11232         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11233         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11234         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
11235         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
11236         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
11237         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
11238         /*
11239          * Set up output mixers (0x0c - 0x0e)
11240          */
11241         /* set vol=0 to output mixers */
11242         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11243         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11244         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11245
11246         /* set up input amps for analog loopback */
11247         /* Amp Indices: DAC = 0, mixer = 1 */
11248         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11249         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11250         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11251         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11252         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11253         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11254
11255
11256         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP */
11257         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Mono */
11258         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* rear MIC */
11259         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* Line in */
11260         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
11261         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Line out */
11262         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* CD in */
11263
11264         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11265         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11266
11267         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
11268         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
11269
11270         /* {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 }, */
11271         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11272         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11273         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
11274         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11275         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11276
11277         /* FIXME: use matrix-type input source selection */
11278         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
11279         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
11280         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, /*rear MIC*/
11281         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, /*Line in*/
11282         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))}, /*F MIC*/
11283         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))}, /*Front*/
11284         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))}, /*CD*/
11285         /* {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))},  */
11286         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))}, /*HP*/
11287         /* Input mixer2 */
11288         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11289         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
11290         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
11291         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
11292         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
11293         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
11294         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
11295         /* Input mixer3 */
11296         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11297         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
11298         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
11299         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
11300         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
11301         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
11302         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
11303
11304         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11305
11306         { }
11307 };
11308
11309 static struct hda_verb alc262_toshiba_rx1_unsol_verbs[] = {
11310
11311         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Front Speaker */
11312         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11313         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
11314
11315         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* MIC jack */
11316         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
11317         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
11318         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
11319
11320         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP  jack */
11321         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
11322         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
11323         {}
11324 };
11325
11326
11327 #ifdef CONFIG_SND_HDA_POWER_SAVE
11328 #define alc262_loopbacks        alc880_loopbacks
11329 #endif
11330
11331 /* pcm configuration: identical with ALC880 */
11332 #define alc262_pcm_analog_playback      alc880_pcm_analog_playback
11333 #define alc262_pcm_analog_capture       alc880_pcm_analog_capture
11334 #define alc262_pcm_digital_playback     alc880_pcm_digital_playback
11335 #define alc262_pcm_digital_capture      alc880_pcm_digital_capture
11336
11337 /*
11338  * BIOS auto configuration
11339  */
11340 static int alc262_parse_auto_config(struct hda_codec *codec)
11341 {
11342         struct alc_spec *spec = codec->spec;
11343         int err;
11344         static hda_nid_t alc262_ignore[] = { 0x1d, 0 };
11345
11346         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
11347                                            alc262_ignore);
11348         if (err < 0)
11349                 return err;
11350         if (!spec->autocfg.line_outs) {
11351                 if (spec->autocfg.dig_outs || spec->autocfg.dig_in_pin) {
11352                         spec->multiout.max_channels = 2;
11353                         spec->no_analog = 1;
11354                         goto dig_only;
11355                 }
11356                 return 0; /* can't find valid BIOS pin config */
11357         }
11358         err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
11359         if (err < 0)
11360                 return err;
11361         err = alc262_auto_create_input_ctls(codec, &spec->autocfg);
11362         if (err < 0)
11363                 return err;
11364
11365         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
11366
11367  dig_only:
11368         if (spec->autocfg.dig_outs) {
11369                 spec->multiout.dig_out_nid = ALC262_DIGOUT_NID;
11370                 spec->dig_out_type = spec->autocfg.dig_out_type[0];
11371         }
11372         if (spec->autocfg.dig_in_pin)
11373                 spec->dig_in_nid = ALC262_DIGIN_NID;
11374
11375         if (spec->kctls.list)
11376                 add_mixer(spec, spec->kctls.list);
11377
11378         add_verb(spec, alc262_volume_init_verbs);
11379         spec->num_mux_defs = 1;
11380         spec->input_mux = &spec->private_imux[0];
11381
11382         err = alc_auto_add_mic_boost(codec);
11383         if (err < 0)
11384                 return err;
11385
11386         alc_ssid_check(codec, 0x15, 0x14, 0x1b);
11387
11388         return 1;
11389 }
11390
11391 #define alc262_auto_init_multi_out      alc882_auto_init_multi_out
11392 #define alc262_auto_init_hp_out         alc882_auto_init_hp_out
11393 #define alc262_auto_init_analog_input   alc882_auto_init_analog_input
11394 #define alc262_auto_init_input_src      alc882_auto_init_input_src
11395
11396
11397 /* init callback for auto-configuration model -- overriding the default init */
11398 static void alc262_auto_init(struct hda_codec *codec)
11399 {
11400         struct alc_spec *spec = codec->spec;
11401         alc262_auto_init_multi_out(codec);
11402         alc262_auto_init_hp_out(codec);
11403         alc262_auto_init_analog_input(codec);
11404         alc262_auto_init_input_src(codec);
11405         if (spec->unsol_event)
11406                 alc_inithook(codec);
11407 }
11408
11409 /*
11410  * configuration and preset
11411  */
11412 static const char *alc262_models[ALC262_MODEL_LAST] = {
11413         [ALC262_BASIC]          = "basic",
11414         [ALC262_HIPPO]          = "hippo",
11415         [ALC262_HIPPO_1]        = "hippo_1",
11416         [ALC262_FUJITSU]        = "fujitsu",
11417         [ALC262_HP_BPC]         = "hp-bpc",
11418         [ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000",
11419         [ALC262_HP_TC_T5735]    = "hp-tc-t5735",
11420         [ALC262_HP_RP5700]      = "hp-rp5700",
11421         [ALC262_BENQ_ED8]       = "benq",
11422         [ALC262_BENQ_T31]       = "benq-t31",
11423         [ALC262_SONY_ASSAMD]    = "sony-assamd",
11424         [ALC262_TOSHIBA_S06]    = "toshiba-s06",
11425         [ALC262_TOSHIBA_RX1]    = "toshiba-rx1",
11426         [ALC262_ULTRA]          = "ultra",
11427         [ALC262_LENOVO_3000]    = "lenovo-3000",
11428         [ALC262_NEC]            = "nec",
11429         [ALC262_TYAN]           = "tyan",
11430         [ALC262_AUTO]           = "auto",
11431 };
11432
11433 static struct snd_pci_quirk alc262_cfg_tbl[] = {
11434         SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
11435         SND_PCI_QUIRK(0x1033, 0x8895, "NEC Versa S9100", ALC262_NEC),
11436         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1200, "HP xw series",
11437                            ALC262_HP_BPC),
11438         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1300, "HP xw series",
11439                            ALC262_HP_BPC),
11440         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1700, "HP xw series",
11441                            ALC262_HP_BPC),
11442         SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
11443         SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
11444         SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
11445         SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF),
11446         SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL),
11447         SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF),
11448         SND_PCI_QUIRK(0x103c, 0x2806, "HP D7000", ALC262_HP_BPC_D7000_WL),
11449         SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF),
11450         SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC),
11451         SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC),
11452         SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC),
11453         SND_PCI_QUIRK(0x103c, 0x302f, "HP Thin Client T5735",
11454                       ALC262_HP_TC_T5735),
11455         SND_PCI_QUIRK(0x103c, 0x2817, "HP RP5700", ALC262_HP_RP5700),
11456         SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD),
11457         SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
11458         SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
11459         SND_PCI_QUIRK(0x104d, 0x9016, "Sony VAIO", ALC262_AUTO), /* dig-only */
11460         SND_PCI_QUIRK(0x104d, 0x9025, "Sony VAIO Z21MN", ALC262_TOSHIBA_S06),
11461         SND_PCI_QUIRK(0x104d, 0x9035, "Sony VAIO VGN-FW170J", ALC262_AUTO),
11462         SND_PCI_QUIRK_MASK(0x104d, 0xff00, 0x9000, "Sony VAIO",
11463                            ALC262_SONY_ASSAMD),
11464         SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
11465                       ALC262_TOSHIBA_RX1),
11466         SND_PCI_QUIRK(0x1179, 0xff7b, "Toshiba S06", ALC262_TOSHIBA_S06),
11467         SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
11468         SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU),
11469         SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_TYAN),
11470         SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc032, "Samsung Q1",
11471                            ALC262_ULTRA),
11472         SND_PCI_QUIRK(0x144d, 0xc510, "Samsung Q45", ALC262_HIPPO),
11473         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 y410", ALC262_LENOVO_3000),
11474         SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
11475         SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
11476         SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
11477         {}
11478 };
11479
11480 static struct alc_config_preset alc262_presets[] = {
11481         [ALC262_BASIC] = {
11482                 .mixers = { alc262_base_mixer },
11483                 .init_verbs = { alc262_init_verbs },
11484                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11485                 .dac_nids = alc262_dac_nids,
11486                 .hp_nid = 0x03,
11487                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11488                 .channel_mode = alc262_modes,
11489                 .input_mux = &alc262_capture_source,
11490         },
11491         [ALC262_HIPPO] = {
11492                 .mixers = { alc262_hippo_mixer },
11493                 .init_verbs = { alc262_init_verbs, alc_hp15_unsol_verbs},
11494                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11495                 .dac_nids = alc262_dac_nids,
11496                 .hp_nid = 0x03,
11497                 .dig_out_nid = ALC262_DIGOUT_NID,
11498                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11499                 .channel_mode = alc262_modes,
11500                 .input_mux = &alc262_capture_source,
11501                 .unsol_event = alc262_hippo_unsol_event,
11502                 .setup = alc262_hippo_setup,
11503                 .init_hook = alc262_hippo_automute,
11504         },
11505         [ALC262_HIPPO_1] = {
11506                 .mixers = { alc262_hippo1_mixer },
11507                 .init_verbs = { alc262_init_verbs, alc262_hippo1_unsol_verbs},
11508                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11509                 .dac_nids = alc262_dac_nids,
11510                 .hp_nid = 0x02,
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_hippo1_setup,
11517                 .init_hook = alc262_hippo_automute,
11518         },
11519         [ALC262_FUJITSU] = {
11520                 .mixers = { alc262_fujitsu_mixer },
11521                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
11522                                 alc262_fujitsu_unsol_verbs },
11523                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11524                 .dac_nids = alc262_dac_nids,
11525                 .hp_nid = 0x03,
11526                 .dig_out_nid = ALC262_DIGOUT_NID,
11527                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11528                 .channel_mode = alc262_modes,
11529                 .input_mux = &alc262_fujitsu_capture_source,
11530                 .unsol_event = alc262_fujitsu_unsol_event,
11531                 .init_hook = alc262_fujitsu_init_hook,
11532         },
11533         [ALC262_HP_BPC] = {
11534                 .mixers = { alc262_HP_BPC_mixer },
11535                 .init_verbs = { alc262_HP_BPC_init_verbs },
11536                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11537                 .dac_nids = alc262_dac_nids,
11538                 .hp_nid = 0x03,
11539                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11540                 .channel_mode = alc262_modes,
11541                 .input_mux = &alc262_HP_capture_source,
11542                 .unsol_event = alc262_hp_bpc_unsol_event,
11543                 .init_hook = alc262_hp_bpc_automute,
11544         },
11545         [ALC262_HP_BPC_D7000_WF] = {
11546                 .mixers = { alc262_HP_BPC_WildWest_mixer },
11547                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
11548                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11549                 .dac_nids = alc262_dac_nids,
11550                 .hp_nid = 0x03,
11551                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11552                 .channel_mode = alc262_modes,
11553                 .input_mux = &alc262_HP_D7000_capture_source,
11554                 .unsol_event = alc262_hp_wildwest_unsol_event,
11555                 .init_hook = alc262_hp_wildwest_automute,
11556         },
11557         [ALC262_HP_BPC_D7000_WL] = {
11558                 .mixers = { alc262_HP_BPC_WildWest_mixer,
11559                             alc262_HP_BPC_WildWest_option_mixer },
11560                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
11561                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11562                 .dac_nids = alc262_dac_nids,
11563                 .hp_nid = 0x03,
11564                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11565                 .channel_mode = alc262_modes,
11566                 .input_mux = &alc262_HP_D7000_capture_source,
11567                 .unsol_event = alc262_hp_wildwest_unsol_event,
11568                 .init_hook = alc262_hp_wildwest_automute,
11569         },
11570         [ALC262_HP_TC_T5735] = {
11571                 .mixers = { alc262_hp_t5735_mixer },
11572                 .init_verbs = { alc262_init_verbs, alc262_hp_t5735_verbs },
11573                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11574                 .dac_nids = alc262_dac_nids,
11575                 .hp_nid = 0x03,
11576                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11577                 .channel_mode = alc262_modes,
11578                 .input_mux = &alc262_capture_source,
11579                 .unsol_event = alc_automute_amp_unsol_event,
11580                 .setup = alc262_hp_t5735_setup,
11581                 .init_hook = alc_automute_amp,
11582         },
11583         [ALC262_HP_RP5700] = {
11584                 .mixers = { alc262_hp_rp5700_mixer },
11585                 .init_verbs = { alc262_init_verbs, alc262_hp_rp5700_verbs },
11586                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11587                 .dac_nids = alc262_dac_nids,
11588                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11589                 .channel_mode = alc262_modes,
11590                 .input_mux = &alc262_hp_rp5700_capture_source,
11591         },
11592         [ALC262_BENQ_ED8] = {
11593                 .mixers = { alc262_base_mixer },
11594                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs },
11595                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11596                 .dac_nids = alc262_dac_nids,
11597                 .hp_nid = 0x03,
11598                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11599                 .channel_mode = alc262_modes,
11600                 .input_mux = &alc262_capture_source,
11601         },
11602         [ALC262_SONY_ASSAMD] = {
11603                 .mixers = { alc262_sony_mixer },
11604                 .init_verbs = { alc262_init_verbs, alc262_sony_unsol_verbs},
11605                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11606                 .dac_nids = alc262_dac_nids,
11607                 .hp_nid = 0x02,
11608                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11609                 .channel_mode = alc262_modes,
11610                 .input_mux = &alc262_capture_source,
11611                 .unsol_event = alc262_hippo_unsol_event,
11612                 .setup = alc262_hippo_setup,
11613                 .init_hook = alc262_hippo_automute,
11614         },
11615         [ALC262_BENQ_T31] = {
11616                 .mixers = { alc262_benq_t31_mixer },
11617                 .init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs,
11618                                 alc_hp15_unsol_verbs },
11619                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11620                 .dac_nids = alc262_dac_nids,
11621                 .hp_nid = 0x03,
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_ULTRA] = {
11630                 .mixers = { alc262_ultra_mixer },
11631                 .cap_mixer = alc262_ultra_capture_mixer,
11632                 .init_verbs = { alc262_ultra_verbs },
11633                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11634                 .dac_nids = alc262_dac_nids,
11635                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11636                 .channel_mode = alc262_modes,
11637                 .input_mux = &alc262_ultra_capture_source,
11638                 .adc_nids = alc262_adc_nids, /* ADC0 */
11639                 .capsrc_nids = alc262_capsrc_nids,
11640                 .num_adc_nids = 1, /* single ADC */
11641                 .unsol_event = alc262_ultra_unsol_event,
11642                 .init_hook = alc262_ultra_automute,
11643         },
11644         [ALC262_LENOVO_3000] = {
11645                 .mixers = { alc262_lenovo_3000_mixer },
11646                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
11647                                 alc262_lenovo_3000_unsol_verbs },
11648                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11649                 .dac_nids = alc262_dac_nids,
11650                 .hp_nid = 0x03,
11651                 .dig_out_nid = ALC262_DIGOUT_NID,
11652                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11653                 .channel_mode = alc262_modes,
11654                 .input_mux = &alc262_fujitsu_capture_source,
11655                 .unsol_event = alc262_lenovo_3000_unsol_event,
11656         },
11657         [ALC262_NEC] = {
11658                 .mixers = { alc262_nec_mixer },
11659                 .init_verbs = { alc262_nec_verbs },
11660                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11661                 .dac_nids = alc262_dac_nids,
11662                 .hp_nid = 0x03,
11663                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11664                 .channel_mode = alc262_modes,
11665                 .input_mux = &alc262_capture_source,
11666         },
11667         [ALC262_TOSHIBA_S06] = {
11668                 .mixers = { alc262_toshiba_s06_mixer },
11669                 .init_verbs = { alc262_init_verbs, alc262_toshiba_s06_verbs,
11670                                                         alc262_eapd_verbs },
11671                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11672                 .capsrc_nids = alc262_dmic_capsrc_nids,
11673                 .dac_nids = alc262_dac_nids,
11674                 .adc_nids = alc262_dmic_adc_nids, /* ADC0 */
11675                 .num_adc_nids = 1, /* single ADC */
11676                 .dig_out_nid = ALC262_DIGOUT_NID,
11677                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11678                 .channel_mode = alc262_modes,
11679                 .unsol_event = alc_sku_unsol_event,
11680                 .setup = alc262_toshiba_s06_setup,
11681                 .init_hook = alc_inithook,
11682         },
11683         [ALC262_TOSHIBA_RX1] = {
11684                 .mixers = { alc262_toshiba_rx1_mixer },
11685                 .init_verbs = { alc262_init_verbs, alc262_toshiba_rx1_unsol_verbs },
11686                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11687                 .dac_nids = alc262_dac_nids,
11688                 .hp_nid = 0x03,
11689                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11690                 .channel_mode = alc262_modes,
11691                 .input_mux = &alc262_capture_source,
11692                 .unsol_event = alc262_hippo_unsol_event,
11693                 .setup = alc262_hippo_setup,
11694                 .init_hook = alc262_hippo_automute,
11695         },
11696         [ALC262_TYAN] = {
11697                 .mixers = { alc262_tyan_mixer },
11698                 .init_verbs = { alc262_init_verbs, alc262_tyan_verbs},
11699                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11700                 .dac_nids = alc262_dac_nids,
11701                 .hp_nid = 0x02,
11702                 .dig_out_nid = ALC262_DIGOUT_NID,
11703                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11704                 .channel_mode = alc262_modes,
11705                 .input_mux = &alc262_capture_source,
11706                 .unsol_event = alc_automute_amp_unsol_event,
11707                 .setup = alc262_tyan_setup,
11708                 .init_hook = alc_automute_amp,
11709         },
11710 };
11711
11712 static int patch_alc262(struct hda_codec *codec)
11713 {
11714         struct alc_spec *spec;
11715         int board_config;
11716         int err;
11717
11718         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
11719         if (spec == NULL)
11720                 return -ENOMEM;
11721
11722         codec->spec = spec;
11723 #if 0
11724         /* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is
11725          * under-run
11726          */
11727         {
11728         int tmp;
11729         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
11730         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
11731         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
11732         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
11733         }
11734 #endif
11735
11736         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
11737
11738         board_config = snd_hda_check_board_config(codec, ALC262_MODEL_LAST,
11739                                                   alc262_models,
11740                                                   alc262_cfg_tbl);
11741
11742         if (board_config < 0) {
11743                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
11744                        codec->chip_name);
11745                 board_config = ALC262_AUTO;
11746         }
11747
11748         if (board_config == ALC262_AUTO) {
11749                 /* automatic parse from the BIOS config */
11750                 err = alc262_parse_auto_config(codec);
11751                 if (err < 0) {
11752                         alc_free(codec);
11753                         return err;
11754                 } else if (!err) {
11755                         printk(KERN_INFO
11756                                "hda_codec: Cannot set up configuration "
11757                                "from BIOS.  Using base mode...\n");
11758                         board_config = ALC262_BASIC;
11759                 }
11760         }
11761
11762         if (!spec->no_analog) {
11763                 err = snd_hda_attach_beep_device(codec, 0x1);
11764                 if (err < 0) {
11765                         alc_free(codec);
11766                         return err;
11767                 }
11768         }
11769
11770         if (board_config != ALC262_AUTO)
11771                 setup_preset(codec, &alc262_presets[board_config]);
11772
11773         spec->stream_analog_playback = &alc262_pcm_analog_playback;
11774         spec->stream_analog_capture = &alc262_pcm_analog_capture;
11775
11776         spec->stream_digital_playback = &alc262_pcm_digital_playback;
11777         spec->stream_digital_capture = &alc262_pcm_digital_capture;
11778
11779         if (!spec->adc_nids && spec->input_mux) {
11780                 int i;
11781                 /* check whether the digital-mic has to be supported */
11782                 for (i = 0; i < spec->input_mux->num_items; i++) {
11783                         if (spec->input_mux->items[i].index >= 9)
11784                                 break;
11785                 }
11786                 if (i < spec->input_mux->num_items) {
11787                         /* use only ADC0 */
11788                         spec->adc_nids = alc262_dmic_adc_nids;
11789                         spec->num_adc_nids = 1;
11790                         spec->capsrc_nids = alc262_dmic_capsrc_nids;
11791                 } else {
11792                         /* all analog inputs */
11793                         /* check whether NID 0x07 is valid */
11794                         unsigned int wcap = get_wcaps(codec, 0x07);
11795
11796                         /* get type */
11797                         wcap = get_wcaps_type(wcap);
11798                         if (wcap != AC_WID_AUD_IN) {
11799                                 spec->adc_nids = alc262_adc_nids_alt;
11800                                 spec->num_adc_nids =
11801                                         ARRAY_SIZE(alc262_adc_nids_alt);
11802                                 spec->capsrc_nids = alc262_capsrc_nids_alt;
11803                         } else {
11804                                 spec->adc_nids = alc262_adc_nids;
11805                                 spec->num_adc_nids =
11806                                         ARRAY_SIZE(alc262_adc_nids);
11807                                 spec->capsrc_nids = alc262_capsrc_nids;
11808                         }
11809                 }
11810         }
11811         if (!spec->cap_mixer && !spec->no_analog)
11812                 set_capture_mixer(codec);
11813         if (!spec->no_analog)
11814                 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
11815
11816         spec->vmaster_nid = 0x0c;
11817
11818         codec->patch_ops = alc_patch_ops;
11819         if (board_config == ALC262_AUTO)
11820                 spec->init_hook = alc262_auto_init;
11821 #ifdef CONFIG_SND_HDA_POWER_SAVE
11822         if (!spec->loopback.amplist)
11823                 spec->loopback.amplist = alc262_loopbacks;
11824 #endif
11825         codec->proc_widget_hook = print_realtek_coef;
11826
11827         return 0;
11828 }
11829
11830 /*
11831  *  ALC268 channel source setting (2 channel)
11832  */
11833 #define ALC268_DIGOUT_NID       ALC880_DIGOUT_NID
11834 #define alc268_modes            alc260_modes
11835
11836 static hda_nid_t alc268_dac_nids[2] = {
11837         /* front, hp */
11838         0x02, 0x03
11839 };
11840
11841 static hda_nid_t alc268_adc_nids[2] = {
11842         /* ADC0-1 */
11843         0x08, 0x07
11844 };
11845
11846 static hda_nid_t alc268_adc_nids_alt[1] = {
11847         /* ADC0 */
11848         0x08
11849 };
11850
11851 static hda_nid_t alc268_capsrc_nids[2] = { 0x23, 0x24 };
11852
11853 static struct snd_kcontrol_new alc268_base_mixer[] = {
11854         /* output mixer control */
11855         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
11856         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11857         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
11858         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11859         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11860         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
11861         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11862         { }
11863 };
11864
11865 static struct snd_kcontrol_new alc268_toshiba_mixer[] = {
11866         /* output mixer control */
11867         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
11868         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
11869         ALC262_HIPPO_MASTER_SWITCH,
11870         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11871         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
11872         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11873         { }
11874 };
11875
11876 /* bind Beep switches of both NID 0x0f and 0x10 */
11877 static struct hda_bind_ctls alc268_bind_beep_sw = {
11878         .ops = &snd_hda_bind_sw,
11879         .values = {
11880                 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
11881                 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
11882                 0
11883         },
11884 };
11885
11886 static struct snd_kcontrol_new alc268_beep_mixer[] = {
11887         HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
11888         HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
11889         { }
11890 };
11891
11892 static struct hda_verb alc268_eapd_verbs[] = {
11893         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
11894         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
11895         { }
11896 };
11897
11898 /* Toshiba specific */
11899 static struct hda_verb alc268_toshiba_verbs[] = {
11900         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11901         { } /* end */
11902 };
11903
11904 /* Acer specific */
11905 /* bind volumes of both NID 0x02 and 0x03 */
11906 static struct hda_bind_ctls alc268_acer_bind_master_vol = {
11907         .ops = &snd_hda_bind_vol,
11908         .values = {
11909                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
11910                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
11911                 0
11912         },
11913 };
11914
11915 /* mute/unmute internal speaker according to the hp jack and mute state */
11916 static void alc268_acer_automute(struct hda_codec *codec, int force)
11917 {
11918         struct alc_spec *spec = codec->spec;
11919         unsigned int mute;
11920
11921         if (force || !spec->sense_updated) {
11922                 unsigned int present;
11923                 present = snd_hda_codec_read(codec, 0x14, 0,
11924                                          AC_VERB_GET_PIN_SENSE, 0);
11925                 spec->jack_present = (present & 0x80000000) != 0;
11926                 spec->sense_updated = 1;
11927         }
11928         if (spec->jack_present)
11929                 mute = HDA_AMP_MUTE; /* mute internal speaker */
11930         else /* unmute internal speaker if necessary */
11931                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
11932         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
11933                                  HDA_AMP_MUTE, mute);
11934 }
11935
11936
11937 /* bind hp and internal speaker mute (with plug check) */
11938 static int alc268_acer_master_sw_put(struct snd_kcontrol *kcontrol,
11939                                      struct snd_ctl_elem_value *ucontrol)
11940 {
11941         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
11942         long *valp = ucontrol->value.integer.value;
11943         int change;
11944
11945         change = amp_stereo_mute_update(codec, 0x14, HDA_OUTPUT, 0, valp);
11946         if (change)
11947                 alc268_acer_automute(codec, 0);
11948         return change;
11949 }
11950
11951 static struct snd_kcontrol_new alc268_acer_aspire_one_mixer[] = {
11952         /* output mixer control */
11953         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11954         {
11955                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11956                 .name = "Master Playback Switch",
11957                 .info = snd_hda_mixer_amp_switch_info,
11958                 .get = snd_hda_mixer_amp_switch_get,
11959                 .put = alc268_acer_master_sw_put,
11960                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11961         },
11962         HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x18, 0, HDA_INPUT),
11963         { }
11964 };
11965
11966 static struct snd_kcontrol_new alc268_acer_mixer[] = {
11967         /* output mixer control */
11968         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11969         {
11970                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11971                 .name = "Master Playback Switch",
11972                 .info = snd_hda_mixer_amp_switch_info,
11973                 .get = snd_hda_mixer_amp_switch_get,
11974                 .put = alc268_acer_master_sw_put,
11975                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11976         },
11977         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11978         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
11979         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11980         { }
11981 };
11982
11983 static struct snd_kcontrol_new alc268_acer_dmic_mixer[] = {
11984         /* output mixer control */
11985         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11986         {
11987                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11988                 .name = "Master Playback Switch",
11989                 .info = snd_hda_mixer_amp_switch_info,
11990                 .get = snd_hda_mixer_amp_switch_get,
11991                 .put = alc268_acer_master_sw_put,
11992                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11993         },
11994         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11995         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11996         { }
11997 };
11998
11999 static struct hda_verb alc268_acer_aspire_one_verbs[] = {
12000         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12001         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12002         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12003         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12004         {0x23, AC_VERB_SET_CONNECT_SEL, 0x06},
12005         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, 0xa017},
12006         { }
12007 };
12008
12009 static struct hda_verb alc268_acer_verbs[] = {
12010         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* internal dmic? */
12011         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12012         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12013         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12014         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12015         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12016         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12017         { }
12018 };
12019
12020 /* unsolicited event for HP jack sensing */
12021 #define alc268_toshiba_unsol_event      alc262_hippo_unsol_event
12022 #define alc268_toshiba_setup            alc262_hippo_setup
12023 #define alc268_toshiba_automute         alc262_hippo_automute
12024
12025 static void alc268_acer_unsol_event(struct hda_codec *codec,
12026                                        unsigned int res)
12027 {
12028         if ((res >> 26) != ALC880_HP_EVENT)
12029                 return;
12030         alc268_acer_automute(codec, 1);
12031 }
12032
12033 static void alc268_acer_init_hook(struct hda_codec *codec)
12034 {
12035         alc268_acer_automute(codec, 1);
12036 }
12037
12038 /* toggle speaker-output according to the hp-jack state */
12039 static void alc268_aspire_one_speaker_automute(struct hda_codec *codec)
12040 {
12041         unsigned int present;
12042         unsigned char bits;
12043
12044         present = snd_hda_codec_read(codec, 0x15, 0,
12045                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12046         bits = present ? AMP_IN_MUTE(0) : 0;
12047         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 0,
12048                                 AMP_IN_MUTE(0), bits);
12049         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 1,
12050                                 AMP_IN_MUTE(0), bits);
12051 }
12052
12053 static void alc268_acer_lc_unsol_event(struct hda_codec *codec,
12054                                     unsigned int res)
12055 {
12056         switch (res >> 26) {
12057         case ALC880_HP_EVENT:
12058                 alc268_aspire_one_speaker_automute(codec);
12059                 break;
12060         case ALC880_MIC_EVENT:
12061                 alc_mic_automute(codec);
12062                 break;
12063         }
12064 }
12065
12066 static void alc268_acer_lc_setup(struct hda_codec *codec)
12067 {
12068         struct alc_spec *spec = codec->spec;
12069         spec->ext_mic.pin = 0x18;
12070         spec->ext_mic.mux_idx = 0;
12071         spec->int_mic.pin = 0x12;
12072         spec->int_mic.mux_idx = 6;
12073         spec->auto_mic = 1;
12074 }
12075
12076 static void alc268_acer_lc_init_hook(struct hda_codec *codec)
12077 {
12078         alc268_aspire_one_speaker_automute(codec);
12079         alc_mic_automute(codec);
12080 }
12081
12082 static struct snd_kcontrol_new alc268_dell_mixer[] = {
12083         /* output mixer control */
12084         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12085         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12086         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12087         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12088         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12089         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
12090         { }
12091 };
12092
12093 static struct hda_verb alc268_dell_verbs[] = {
12094         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12095         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12096         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12097         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
12098         { }
12099 };
12100
12101 /* mute/unmute internal speaker according to the hp jack and mute state */
12102 static void alc268_dell_setup(struct hda_codec *codec)
12103 {
12104         struct alc_spec *spec = codec->spec;
12105
12106         spec->autocfg.hp_pins[0] = 0x15;
12107         spec->autocfg.speaker_pins[0] = 0x14;
12108         spec->ext_mic.pin = 0x18;
12109         spec->ext_mic.mux_idx = 0;
12110         spec->int_mic.pin = 0x19;
12111         spec->int_mic.mux_idx = 1;
12112         spec->auto_mic = 1;
12113 }
12114
12115 static struct snd_kcontrol_new alc267_quanta_il1_mixer[] = {
12116         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x2, 0x0, HDA_OUTPUT),
12117         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12118         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
12119         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12120         HDA_CODEC_VOLUME("Mic Capture Volume", 0x23, 0x0, HDA_OUTPUT),
12121         HDA_BIND_MUTE("Mic Capture Switch", 0x23, 2, HDA_OUTPUT),
12122         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
12123         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
12124         { }
12125 };
12126
12127 static struct hda_verb alc267_quanta_il1_verbs[] = {
12128         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12129         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
12130         { }
12131 };
12132
12133 static void alc267_quanta_il1_setup(struct hda_codec *codec)
12134 {
12135         struct alc_spec *spec = codec->spec;
12136         spec->autocfg.hp_pins[0] = 0x15;
12137         spec->autocfg.speaker_pins[0] = 0x14;
12138         spec->ext_mic.pin = 0x18;
12139         spec->ext_mic.mux_idx = 0;
12140         spec->int_mic.pin = 0x19;
12141         spec->int_mic.mux_idx = 1;
12142         spec->auto_mic = 1;
12143 }
12144
12145 /*
12146  * generic initialization of ADC, input mixers and output mixers
12147  */
12148 static struct hda_verb alc268_base_init_verbs[] = {
12149         /* Unmute DAC0-1 and set vol = 0 */
12150         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12151         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12152
12153         /*
12154          * Set up output mixers (0x0c - 0x0e)
12155          */
12156         /* set vol=0 to output mixers */
12157         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12158         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
12159
12160         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12161         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12162
12163         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
12164         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
12165         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
12166         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
12167         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
12168         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12169         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12170         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12171
12172         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12173         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12174         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12175         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12176         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12177
12178         /* set PCBEEP vol = 0, mute connections */
12179         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12180         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12181         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12182
12183         /* Unmute Selector 23h,24h and set the default input to mic-in */
12184
12185         {0x23, AC_VERB_SET_CONNECT_SEL, 0x00},
12186         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12187         {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
12188         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12189
12190         { }
12191 };
12192
12193 /*
12194  * generic initialization of ADC, input mixers and output mixers
12195  */
12196 static struct hda_verb alc268_volume_init_verbs[] = {
12197         /* set output DAC */
12198         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12199         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12200
12201         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
12202         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
12203         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12204         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12205         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12206
12207         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12208         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12209         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12210
12211         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12212         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12213
12214         /* set PCBEEP vol = 0, mute connections */
12215         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12216         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12217         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12218
12219         { }
12220 };
12221
12222 static struct snd_kcontrol_new alc268_capture_nosrc_mixer[] = {
12223         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
12224         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
12225         { } /* end */
12226 };
12227
12228 static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
12229         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
12230         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
12231         _DEFINE_CAPSRC(1),
12232         { } /* end */
12233 };
12234
12235 static struct snd_kcontrol_new alc268_capture_mixer[] = {
12236         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
12237         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
12238         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
12239         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
12240         _DEFINE_CAPSRC(2),
12241         { } /* end */
12242 };
12243
12244 static struct hda_input_mux alc268_capture_source = {
12245         .num_items = 4,
12246         .items = {
12247                 { "Mic", 0x0 },
12248                 { "Front Mic", 0x1 },
12249                 { "Line", 0x2 },
12250                 { "CD", 0x3 },
12251         },
12252 };
12253
12254 static struct hda_input_mux alc268_acer_capture_source = {
12255         .num_items = 3,
12256         .items = {
12257                 { "Mic", 0x0 },
12258                 { "Internal Mic", 0x1 },
12259                 { "Line", 0x2 },
12260         },
12261 };
12262
12263 static struct hda_input_mux alc268_acer_dmic_capture_source = {
12264         .num_items = 3,
12265         .items = {
12266                 { "Mic", 0x0 },
12267                 { "Internal Mic", 0x6 },
12268                 { "Line", 0x2 },
12269         },
12270 };
12271
12272 #ifdef CONFIG_SND_DEBUG
12273 static struct snd_kcontrol_new alc268_test_mixer[] = {
12274         /* Volume widgets */
12275         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12276         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12277         HDA_BIND_MUTE_MONO("Mono sum Playback Switch", 0x0e, 1, 2, HDA_INPUT),
12278         HDA_BIND_MUTE("LINE-OUT sum Playback Switch", 0x0f, 2, HDA_INPUT),
12279         HDA_BIND_MUTE("HP-OUT sum Playback Switch", 0x10, 2, HDA_INPUT),
12280         HDA_BIND_MUTE("LINE-OUT Playback Switch", 0x14, 2, HDA_OUTPUT),
12281         HDA_BIND_MUTE("HP-OUT Playback Switch", 0x15, 2, HDA_OUTPUT),
12282         HDA_BIND_MUTE("Mono Playback Switch", 0x16, 2, HDA_OUTPUT),
12283         HDA_CODEC_VOLUME("MIC1 Capture Volume", 0x18, 0x0, HDA_INPUT),
12284         HDA_BIND_MUTE("MIC1 Capture Switch", 0x18, 2, HDA_OUTPUT),
12285         HDA_CODEC_VOLUME("MIC2 Capture Volume", 0x19, 0x0, HDA_INPUT),
12286         HDA_CODEC_VOLUME("LINE1 Capture Volume", 0x1a, 0x0, HDA_INPUT),
12287         HDA_BIND_MUTE("LINE1 Capture Switch", 0x1a, 2, HDA_OUTPUT),
12288         /* The below appears problematic on some hardwares */
12289         /*HDA_CODEC_VOLUME("PCBEEP Playback Volume", 0x1d, 0x0, HDA_INPUT),*/
12290         HDA_CODEC_VOLUME("PCM-IN1 Capture Volume", 0x23, 0x0, HDA_OUTPUT),
12291         HDA_BIND_MUTE("PCM-IN1 Capture Switch", 0x23, 2, HDA_OUTPUT),
12292         HDA_CODEC_VOLUME("PCM-IN2 Capture Volume", 0x24, 0x0, HDA_OUTPUT),
12293         HDA_BIND_MUTE("PCM-IN2 Capture Switch", 0x24, 2, HDA_OUTPUT),
12294
12295         /* Modes for retasking pin widgets */
12296         ALC_PIN_MODE("LINE-OUT pin mode", 0x14, ALC_PIN_DIR_INOUT),
12297         ALC_PIN_MODE("HP-OUT pin mode", 0x15, ALC_PIN_DIR_INOUT),
12298         ALC_PIN_MODE("MIC1 pin mode", 0x18, ALC_PIN_DIR_INOUT),
12299         ALC_PIN_MODE("LINE1 pin mode", 0x1a, ALC_PIN_DIR_INOUT),
12300
12301         /* Controls for GPIO pins, assuming they are configured as outputs */
12302         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
12303         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
12304         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
12305         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
12306
12307         /* Switches to allow the digital SPDIF output pin to be enabled.
12308          * The ALC268 does not have an SPDIF input.
12309          */
12310         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x06, 0x01),
12311
12312         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
12313          * this output to turn on an external amplifier.
12314          */
12315         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
12316         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
12317
12318         { } /* end */
12319 };
12320 #endif
12321
12322 /* create input playback/capture controls for the given pin */
12323 static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
12324                                     const char *ctlname, int idx)
12325 {
12326         hda_nid_t dac;
12327         int err;
12328
12329         switch (nid) {
12330         case 0x14:
12331         case 0x16:
12332                 dac = 0x02;
12333                 break;
12334         case 0x15:
12335                 dac = 0x03;
12336                 break;
12337         default:
12338                 return 0;
12339         }
12340         if (spec->multiout.dac_nids[0] != dac &&
12341             spec->multiout.dac_nids[1] != dac) {
12342                 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname,
12343                                   HDA_COMPOSE_AMP_VAL(dac, 3, idx,
12344                                                       HDA_OUTPUT));
12345                 if (err < 0)
12346                         return err;
12347                 spec->multiout.dac_nids[spec->multiout.num_dacs++] = dac;
12348         }
12349
12350         if (nid != 0x16)
12351                 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname,
12352                           HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
12353         else /* mono */
12354                 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname,
12355                           HDA_COMPOSE_AMP_VAL(nid, 2, idx, HDA_OUTPUT));
12356         if (err < 0)
12357                 return err;
12358         return 0;
12359 }
12360
12361 /* add playback controls from the parsed DAC table */
12362 static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
12363                                              const struct auto_pin_cfg *cfg)
12364 {
12365         hda_nid_t nid;
12366         int err;
12367
12368         spec->multiout.dac_nids = spec->private_dac_nids;
12369
12370         nid = cfg->line_out_pins[0];
12371         if (nid) {
12372                 const char *name;
12373                 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
12374                         name = "Speaker";
12375                 else
12376                         name = "Front";
12377                 err = alc268_new_analog_output(spec, nid, name, 0);
12378                 if (err < 0)
12379                         return err;
12380         }
12381
12382         nid = cfg->speaker_pins[0];
12383         if (nid == 0x1d) {
12384                 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, "Speaker",
12385                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
12386                 if (err < 0)
12387                         return err;
12388         } else {
12389                 err = alc268_new_analog_output(spec, nid, "Speaker", 0);
12390                 if (err < 0)
12391                         return err;
12392         }
12393         nid = cfg->hp_pins[0];
12394         if (nid) {
12395                 err = alc268_new_analog_output(spec, nid, "Headphone", 0);
12396                 if (err < 0)
12397                         return err;
12398         }
12399
12400         nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
12401         if (nid == 0x16) {
12402                 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, "Mono",
12403                                   HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT));
12404                 if (err < 0)
12405                         return err;
12406         }
12407         return 0;
12408 }
12409
12410 /* create playback/capture controls for input pins */
12411 static int alc268_auto_create_input_ctls(struct hda_codec *codec,
12412                                                 const struct auto_pin_cfg *cfg)
12413 {
12414         return alc_auto_create_input_ctls(codec, cfg, 0, 0x23, 0x24);
12415 }
12416
12417 static void alc268_auto_set_output_and_unmute(struct hda_codec *codec,
12418                                               hda_nid_t nid, int pin_type)
12419 {
12420         int idx;
12421
12422         alc_set_pin_output(codec, nid, pin_type);
12423         if (nid == 0x14 || nid == 0x16)
12424                 idx = 0;
12425         else
12426                 idx = 1;
12427         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
12428 }
12429
12430 static void alc268_auto_init_multi_out(struct hda_codec *codec)
12431 {
12432         struct alc_spec *spec = codec->spec;
12433         hda_nid_t nid = spec->autocfg.line_out_pins[0];
12434         if (nid) {
12435                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
12436                 alc268_auto_set_output_and_unmute(codec, nid, pin_type);
12437         }
12438 }
12439
12440 static void alc268_auto_init_hp_out(struct hda_codec *codec)
12441 {
12442         struct alc_spec *spec = codec->spec;
12443         hda_nid_t pin;
12444
12445         pin = spec->autocfg.hp_pins[0];
12446         if (pin)
12447                 alc268_auto_set_output_and_unmute(codec, pin, PIN_HP);
12448         pin = spec->autocfg.speaker_pins[0];
12449         if (pin)
12450                 alc268_auto_set_output_and_unmute(codec, pin, PIN_OUT);
12451 }
12452
12453 static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
12454 {
12455         struct alc_spec *spec = codec->spec;
12456         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
12457         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
12458         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
12459         unsigned int    dac_vol1, dac_vol2;
12460
12461         if (line_nid == 0x1d || speaker_nid == 0x1d) {
12462                 snd_hda_codec_write(codec, speaker_nid, 0,
12463                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
12464                 /* mute mixer inputs from 0x1d */
12465                 snd_hda_codec_write(codec, 0x0f, 0,
12466                                     AC_VERB_SET_AMP_GAIN_MUTE,
12467                                     AMP_IN_UNMUTE(1));
12468                 snd_hda_codec_write(codec, 0x10, 0,
12469                                     AC_VERB_SET_AMP_GAIN_MUTE,
12470                                     AMP_IN_UNMUTE(1));
12471         } else {
12472                 /* unmute mixer inputs from 0x1d */
12473                 snd_hda_codec_write(codec, 0x0f, 0,
12474                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
12475                 snd_hda_codec_write(codec, 0x10, 0,
12476                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
12477         }
12478
12479         dac_vol1 = dac_vol2 = 0xb000 | 0x40;    /* set max volume  */
12480         if (line_nid == 0x14)
12481                 dac_vol2 = AMP_OUT_ZERO;
12482         else if (line_nid == 0x15)
12483                 dac_vol1 = AMP_OUT_ZERO;
12484         if (hp_nid == 0x14)
12485                 dac_vol2 = AMP_OUT_ZERO;
12486         else if (hp_nid == 0x15)
12487                 dac_vol1 = AMP_OUT_ZERO;
12488         if (line_nid != 0x16 || hp_nid != 0x16 ||
12489             spec->autocfg.line_out_pins[1] != 0x16 ||
12490             spec->autocfg.line_out_pins[2] != 0x16)
12491                 dac_vol1 = dac_vol2 = AMP_OUT_ZERO;
12492
12493         snd_hda_codec_write(codec, 0x02, 0,
12494                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol1);
12495         snd_hda_codec_write(codec, 0x03, 0,
12496                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol2);
12497 }
12498
12499 /* pcm configuration: identical with ALC880 */
12500 #define alc268_pcm_analog_playback      alc880_pcm_analog_playback
12501 #define alc268_pcm_analog_capture       alc880_pcm_analog_capture
12502 #define alc268_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
12503 #define alc268_pcm_digital_playback     alc880_pcm_digital_playback
12504
12505 /*
12506  * BIOS auto configuration
12507  */
12508 static int alc268_parse_auto_config(struct hda_codec *codec)
12509 {
12510         struct alc_spec *spec = codec->spec;
12511         int err;
12512         static hda_nid_t alc268_ignore[] = { 0 };
12513
12514         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
12515                                            alc268_ignore);
12516         if (err < 0)
12517                 return err;
12518         if (!spec->autocfg.line_outs) {
12519                 if (spec->autocfg.dig_outs || spec->autocfg.dig_in_pin) {
12520                         spec->multiout.max_channels = 2;
12521                         spec->no_analog = 1;
12522                         goto dig_only;
12523                 }
12524                 return 0; /* can't find valid BIOS pin config */
12525         }
12526         err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
12527         if (err < 0)
12528                 return err;
12529         err = alc268_auto_create_input_ctls(codec, &spec->autocfg);
12530         if (err < 0)
12531                 return err;
12532
12533         spec->multiout.max_channels = 2;
12534
12535  dig_only:
12536         /* digital only support output */
12537         if (spec->autocfg.dig_outs) {
12538                 spec->multiout.dig_out_nid = ALC268_DIGOUT_NID;
12539                 spec->dig_out_type = spec->autocfg.dig_out_type[0];
12540         }
12541         if (spec->kctls.list)
12542                 add_mixer(spec, spec->kctls.list);
12543
12544         if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d)
12545                 add_mixer(spec, alc268_beep_mixer);
12546
12547         add_verb(spec, alc268_volume_init_verbs);
12548         spec->num_mux_defs = 2;
12549         spec->input_mux = &spec->private_imux[0];
12550
12551         err = alc_auto_add_mic_boost(codec);
12552         if (err < 0)
12553                 return err;
12554
12555         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
12556
12557         return 1;
12558 }
12559
12560 #define alc268_auto_init_analog_input   alc882_auto_init_analog_input
12561
12562 /* init callback for auto-configuration model -- overriding the default init */
12563 static void alc268_auto_init(struct hda_codec *codec)
12564 {
12565         struct alc_spec *spec = codec->spec;
12566         alc268_auto_init_multi_out(codec);
12567         alc268_auto_init_hp_out(codec);
12568         alc268_auto_init_mono_speaker_out(codec);
12569         alc268_auto_init_analog_input(codec);
12570         if (spec->unsol_event)
12571                 alc_inithook(codec);
12572 }
12573
12574 /*
12575  * configuration and preset
12576  */
12577 static const char *alc268_models[ALC268_MODEL_LAST] = {
12578         [ALC267_QUANTA_IL1]     = "quanta-il1",
12579         [ALC268_3ST]            = "3stack",
12580         [ALC268_TOSHIBA]        = "toshiba",
12581         [ALC268_ACER]           = "acer",
12582         [ALC268_ACER_DMIC]      = "acer-dmic",
12583         [ALC268_ACER_ASPIRE_ONE]        = "acer-aspire",
12584         [ALC268_DELL]           = "dell",
12585         [ALC268_ZEPTO]          = "zepto",
12586 #ifdef CONFIG_SND_DEBUG
12587         [ALC268_TEST]           = "test",
12588 #endif
12589         [ALC268_AUTO]           = "auto",
12590 };
12591
12592 static struct snd_pci_quirk alc268_cfg_tbl[] = {
12593         SND_PCI_QUIRK(0x1025, 0x011e, "Acer Aspire 5720z", ALC268_ACER),
12594         SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
12595         SND_PCI_QUIRK(0x1025, 0x012e, "Acer Aspire 5310", ALC268_ACER),
12596         SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
12597         SND_PCI_QUIRK(0x1025, 0x0136, "Acer Aspire 5315", ALC268_ACER),
12598         SND_PCI_QUIRK(0x1025, 0x015b, "Acer Aspire One",
12599                                                 ALC268_ACER_ASPIRE_ONE),
12600         SND_PCI_QUIRK(0x1028, 0x0253, "Dell OEM", ALC268_DELL),
12601         SND_PCI_QUIRK_MASK(0x1028, 0xfff0, 0x02b0,
12602                         "Dell Inspiron Mini9/Vostro A90", ALC268_DELL),
12603         /* almost compatible with toshiba but with optional digital outs;
12604          * auto-probing seems working fine
12605          */
12606         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP TX25xx series",
12607                            ALC268_AUTO),
12608         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
12609         SND_PCI_QUIRK(0x1170, 0x0040, "ZEPTO", ALC268_ZEPTO),
12610         SND_PCI_QUIRK(0x14c0, 0x0025, "COMPAL IFL90/JFL-92", ALC268_TOSHIBA),
12611         SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER),
12612         SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1),
12613         SND_PCI_QUIRK(0x1854, 0x1775, "LG R510", ALC268_DELL),
12614         {}
12615 };
12616
12617 /* Toshiba laptops have no unique PCI SSID but only codec SSID */
12618 static struct snd_pci_quirk alc268_ssid_cfg_tbl[] = {
12619         SND_PCI_QUIRK(0x1179, 0xff0a, "TOSHIBA X-200", ALC268_AUTO),
12620         SND_PCI_QUIRK(0x1179, 0xff0e, "TOSHIBA X-200 HDMI", ALC268_AUTO),
12621         SND_PCI_QUIRK_MASK(0x1179, 0xff00, 0xff00, "TOSHIBA A/Lx05",
12622                            ALC268_TOSHIBA),
12623         {}
12624 };
12625
12626 static struct alc_config_preset alc268_presets[] = {
12627         [ALC267_QUANTA_IL1] = {
12628                 .mixers = { alc267_quanta_il1_mixer, alc268_beep_mixer,
12629                             alc268_capture_nosrc_mixer },
12630                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12631                                 alc267_quanta_il1_verbs },
12632                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12633                 .dac_nids = alc268_dac_nids,
12634                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12635                 .adc_nids = alc268_adc_nids_alt,
12636                 .hp_nid = 0x03,
12637                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12638                 .channel_mode = alc268_modes,
12639                 .unsol_event = alc_sku_unsol_event,
12640                 .setup = alc267_quanta_il1_setup,
12641                 .init_hook = alc_inithook,
12642         },
12643         [ALC268_3ST] = {
12644                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
12645                             alc268_beep_mixer },
12646                 .init_verbs = { alc268_base_init_verbs },
12647                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12648                 .dac_nids = alc268_dac_nids,
12649                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12650                 .adc_nids = alc268_adc_nids_alt,
12651                 .capsrc_nids = alc268_capsrc_nids,
12652                 .hp_nid = 0x03,
12653                 .dig_out_nid = ALC268_DIGOUT_NID,
12654                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12655                 .channel_mode = alc268_modes,
12656                 .input_mux = &alc268_capture_source,
12657         },
12658         [ALC268_TOSHIBA] = {
12659                 .mixers = { alc268_toshiba_mixer, alc268_capture_alt_mixer,
12660                             alc268_beep_mixer },
12661                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12662                                 alc268_toshiba_verbs },
12663                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12664                 .dac_nids = alc268_dac_nids,
12665                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12666                 .adc_nids = alc268_adc_nids_alt,
12667                 .capsrc_nids = alc268_capsrc_nids,
12668                 .hp_nid = 0x03,
12669                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12670                 .channel_mode = alc268_modes,
12671                 .input_mux = &alc268_capture_source,
12672                 .unsol_event = alc268_toshiba_unsol_event,
12673                 .setup = alc268_toshiba_setup,
12674                 .init_hook = alc268_toshiba_automute,
12675         },
12676         [ALC268_ACER] = {
12677                 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer,
12678                             alc268_beep_mixer },
12679                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12680                                 alc268_acer_verbs },
12681                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12682                 .dac_nids = alc268_dac_nids,
12683                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12684                 .adc_nids = alc268_adc_nids_alt,
12685                 .capsrc_nids = alc268_capsrc_nids,
12686                 .hp_nid = 0x02,
12687                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12688                 .channel_mode = alc268_modes,
12689                 .input_mux = &alc268_acer_capture_source,
12690                 .unsol_event = alc268_acer_unsol_event,
12691                 .init_hook = alc268_acer_init_hook,
12692         },
12693         [ALC268_ACER_DMIC] = {
12694                 .mixers = { alc268_acer_dmic_mixer, alc268_capture_alt_mixer,
12695                             alc268_beep_mixer },
12696                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12697                                 alc268_acer_verbs },
12698                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12699                 .dac_nids = alc268_dac_nids,
12700                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12701                 .adc_nids = alc268_adc_nids_alt,
12702                 .capsrc_nids = alc268_capsrc_nids,
12703                 .hp_nid = 0x02,
12704                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12705                 .channel_mode = alc268_modes,
12706                 .input_mux = &alc268_acer_dmic_capture_source,
12707                 .unsol_event = alc268_acer_unsol_event,
12708                 .init_hook = alc268_acer_init_hook,
12709         },
12710         [ALC268_ACER_ASPIRE_ONE] = {
12711                 .mixers = { alc268_acer_aspire_one_mixer,
12712                             alc268_beep_mixer,
12713                             alc268_capture_nosrc_mixer },
12714                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12715                                 alc268_acer_aspire_one_verbs },
12716                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12717                 .dac_nids = alc268_dac_nids,
12718                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12719                 .adc_nids = alc268_adc_nids_alt,
12720                 .capsrc_nids = alc268_capsrc_nids,
12721                 .hp_nid = 0x03,
12722                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12723                 .channel_mode = alc268_modes,
12724                 .unsol_event = alc268_acer_lc_unsol_event,
12725                 .setup = alc268_acer_lc_setup,
12726                 .init_hook = alc268_acer_lc_init_hook,
12727         },
12728         [ALC268_DELL] = {
12729                 .mixers = { alc268_dell_mixer, alc268_beep_mixer,
12730                             alc268_capture_nosrc_mixer },
12731                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12732                                 alc268_dell_verbs },
12733                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12734                 .dac_nids = alc268_dac_nids,
12735                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12736                 .adc_nids = alc268_adc_nids_alt,
12737                 .capsrc_nids = alc268_capsrc_nids,
12738                 .hp_nid = 0x02,
12739                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12740                 .channel_mode = alc268_modes,
12741                 .unsol_event = alc_sku_unsol_event,
12742                 .setup = alc268_dell_setup,
12743                 .init_hook = alc_inithook,
12744         },
12745         [ALC268_ZEPTO] = {
12746                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
12747                             alc268_beep_mixer },
12748                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12749                                 alc268_toshiba_verbs },
12750                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12751                 .dac_nids = alc268_dac_nids,
12752                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12753                 .adc_nids = alc268_adc_nids_alt,
12754                 .capsrc_nids = alc268_capsrc_nids,
12755                 .hp_nid = 0x03,
12756                 .dig_out_nid = ALC268_DIGOUT_NID,
12757                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12758                 .channel_mode = alc268_modes,
12759                 .input_mux = &alc268_capture_source,
12760                 .setup = alc268_toshiba_setup,
12761                 .init_hook = alc268_toshiba_automute,
12762         },
12763 #ifdef CONFIG_SND_DEBUG
12764         [ALC268_TEST] = {
12765                 .mixers = { alc268_test_mixer, alc268_capture_mixer },
12766                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12767                                 alc268_volume_init_verbs },
12768                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12769                 .dac_nids = alc268_dac_nids,
12770                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12771                 .adc_nids = alc268_adc_nids_alt,
12772                 .capsrc_nids = alc268_capsrc_nids,
12773                 .hp_nid = 0x03,
12774                 .dig_out_nid = ALC268_DIGOUT_NID,
12775                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12776                 .channel_mode = alc268_modes,
12777                 .input_mux = &alc268_capture_source,
12778         },
12779 #endif
12780 };
12781
12782 static int patch_alc268(struct hda_codec *codec)
12783 {
12784         struct alc_spec *spec;
12785         int board_config;
12786         int i, has_beep, err;
12787
12788         spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
12789         if (spec == NULL)
12790                 return -ENOMEM;
12791
12792         codec->spec = spec;
12793
12794         board_config = snd_hda_check_board_config(codec, ALC268_MODEL_LAST,
12795                                                   alc268_models,
12796                                                   alc268_cfg_tbl);
12797
12798         if (board_config < 0 || board_config >= ALC268_MODEL_LAST)
12799                 board_config = snd_hda_check_board_codec_sid_config(codec,
12800                         ALC882_MODEL_LAST, alc268_models, alc268_ssid_cfg_tbl);
12801
12802         if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
12803                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
12804                        codec->chip_name);
12805                 board_config = ALC268_AUTO;
12806         }
12807
12808         if (board_config == ALC268_AUTO) {
12809                 /* automatic parse from the BIOS config */
12810                 err = alc268_parse_auto_config(codec);
12811                 if (err < 0) {
12812                         alc_free(codec);
12813                         return err;
12814                 } else if (!err) {
12815                         printk(KERN_INFO
12816                                "hda_codec: Cannot set up configuration "
12817                                "from BIOS.  Using base mode...\n");
12818                         board_config = ALC268_3ST;
12819                 }
12820         }
12821
12822         if (board_config != ALC268_AUTO)
12823                 setup_preset(codec, &alc268_presets[board_config]);
12824
12825         spec->stream_analog_playback = &alc268_pcm_analog_playback;
12826         spec->stream_analog_capture = &alc268_pcm_analog_capture;
12827         spec->stream_analog_alt_capture = &alc268_pcm_analog_alt_capture;
12828
12829         spec->stream_digital_playback = &alc268_pcm_digital_playback;
12830
12831         has_beep = 0;
12832         for (i = 0; i < spec->num_mixers; i++) {
12833                 if (spec->mixers[i] == alc268_beep_mixer) {
12834                         has_beep = 1;
12835                         break;
12836                 }
12837         }
12838
12839         if (has_beep) {
12840                 err = snd_hda_attach_beep_device(codec, 0x1);
12841                 if (err < 0) {
12842                         alc_free(codec);
12843                         return err;
12844                 }
12845                 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
12846                         /* override the amp caps for beep generator */
12847                         snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
12848                                           (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
12849                                           (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
12850                                           (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
12851                                           (0 << AC_AMPCAP_MUTE_SHIFT));
12852         }
12853
12854         if (!spec->no_analog && !spec->adc_nids && spec->input_mux) {
12855                 /* check whether NID 0x07 is valid */
12856                 unsigned int wcap = get_wcaps(codec, 0x07);
12857                 int i;
12858
12859                 spec->capsrc_nids = alc268_capsrc_nids;
12860                 /* get type */
12861                 wcap = get_wcaps_type(wcap);
12862                 if (spec->auto_mic ||
12863                     wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
12864                         spec->adc_nids = alc268_adc_nids_alt;
12865                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt);
12866                         if (spec->auto_mic)
12867                                 fixup_automic_adc(codec);
12868                         if (spec->auto_mic || spec->input_mux->num_items == 1)
12869                                 add_mixer(spec, alc268_capture_nosrc_mixer);
12870                         else
12871                                 add_mixer(spec, alc268_capture_alt_mixer);
12872                 } else {
12873                         spec->adc_nids = alc268_adc_nids;
12874                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids);
12875                         add_mixer(spec, alc268_capture_mixer);
12876                 }
12877                 /* set default input source */
12878                 for (i = 0; i < spec->num_adc_nids; i++)
12879                         snd_hda_codec_write_cache(codec, alc268_capsrc_nids[i],
12880                                 0, AC_VERB_SET_CONNECT_SEL,
12881                                 i < spec->num_mux_defs ?
12882                                 spec->input_mux[i].items[0].index :
12883                                 spec->input_mux->items[0].index);
12884         }
12885
12886         spec->vmaster_nid = 0x02;
12887
12888         codec->patch_ops = alc_patch_ops;
12889         if (board_config == ALC268_AUTO)
12890                 spec->init_hook = alc268_auto_init;
12891
12892         codec->proc_widget_hook = print_realtek_coef;
12893
12894         return 0;
12895 }
12896
12897 /*
12898  *  ALC269 channel source setting (2 channel)
12899  */
12900 #define ALC269_DIGOUT_NID       ALC880_DIGOUT_NID
12901
12902 #define alc269_dac_nids         alc260_dac_nids
12903
12904 static hda_nid_t alc269_adc_nids[1] = {
12905         /* ADC1 */
12906         0x08,
12907 };
12908
12909 static hda_nid_t alc269_capsrc_nids[1] = {
12910         0x23,
12911 };
12912
12913 /* NOTE: ADC2 (0x07) is connected from a recording *MIXER* (0x24),
12914  *       not a mux!
12915  */
12916
12917 #define alc269_modes            alc260_modes
12918 #define alc269_capture_source   alc880_lg_lw_capture_source
12919
12920 static struct snd_kcontrol_new alc269_base_mixer[] = {
12921         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12922         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12923         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
12924         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
12925         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12926         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12927         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12928         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12929         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12930         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
12931         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12932         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
12933         { } /* end */
12934 };
12935
12936 static struct snd_kcontrol_new alc269_quanta_fl1_mixer[] = {
12937         /* output mixer control */
12938         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
12939         {
12940                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12941                 .name = "Master Playback Switch",
12942                 .info = snd_hda_mixer_amp_switch_info,
12943                 .get = snd_hda_mixer_amp_switch_get,
12944                 .put = alc268_acer_master_sw_put,
12945                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
12946         },
12947         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12948         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12949         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12950         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12951         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12952         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
12953         { }
12954 };
12955
12956 static struct snd_kcontrol_new alc269_lifebook_mixer[] = {
12957         /* output mixer control */
12958         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
12959         {
12960                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12961                 .name = "Master Playback Switch",
12962                 .info = snd_hda_mixer_amp_switch_info,
12963                 .get = snd_hda_mixer_amp_switch_get,
12964                 .put = alc268_acer_master_sw_put,
12965                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
12966         },
12967         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12968         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12969         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12970         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12971         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12972         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
12973         HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x0b, 0x03, HDA_INPUT),
12974         HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x0b, 0x03, HDA_INPUT),
12975         HDA_CODEC_VOLUME("Dock Mic Boost", 0x1b, 0, HDA_INPUT),
12976         { }
12977 };
12978
12979 static struct snd_kcontrol_new alc269_eeepc_mixer[] = {
12980         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12981         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12982         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12983         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12984         { } /* end */
12985 };
12986
12987 /* capture mixer elements */
12988 static struct snd_kcontrol_new alc269_epc_capture_mixer[] = {
12989         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
12990         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
12991         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12992         { } /* end */
12993 };
12994
12995 /* FSC amilo */
12996 #define alc269_fujitsu_mixer    alc269_eeepc_mixer
12997
12998 static struct hda_verb alc269_quanta_fl1_verbs[] = {
12999         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
13000         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13001         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13002         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
13003         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
13004         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13005         { }
13006 };
13007
13008 static struct hda_verb alc269_lifebook_verbs[] = {
13009         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
13010         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
13011         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13012         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13013         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
13014         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13015         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13016         {0x1a, 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 /* toggle speaker-output according to the hp-jack state */
13023 static void alc269_quanta_fl1_speaker_automute(struct hda_codec *codec)
13024 {
13025         unsigned int present;
13026         unsigned char bits;
13027
13028         present = snd_hda_codec_read(codec, 0x15, 0,
13029                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13030         bits = present ? AMP_IN_MUTE(0) : 0;
13031         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
13032                         AMP_IN_MUTE(0), bits);
13033         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
13034                         AMP_IN_MUTE(0), bits);
13035
13036         snd_hda_codec_write(codec, 0x20, 0,
13037                         AC_VERB_SET_COEF_INDEX, 0x0c);
13038         snd_hda_codec_write(codec, 0x20, 0,
13039                         AC_VERB_SET_PROC_COEF, 0x680);
13040
13041         snd_hda_codec_write(codec, 0x20, 0,
13042                         AC_VERB_SET_COEF_INDEX, 0x0c);
13043         snd_hda_codec_write(codec, 0x20, 0,
13044                         AC_VERB_SET_PROC_COEF, 0x480);
13045 }
13046
13047 /* toggle speaker-output according to the hp-jacks state */
13048 static void alc269_lifebook_speaker_automute(struct hda_codec *codec)
13049 {
13050         unsigned int present;
13051         unsigned char bits;
13052
13053         /* Check laptop headphone socket */
13054         present = snd_hda_codec_read(codec, 0x15, 0,
13055                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13056
13057         /* Check port replicator headphone socket */
13058         present |= snd_hda_codec_read(codec, 0x1a, 0,
13059                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13060
13061         bits = present ? AMP_IN_MUTE(0) : 0;
13062         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
13063                         AMP_IN_MUTE(0), bits);
13064         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
13065                         AMP_IN_MUTE(0), bits);
13066
13067         snd_hda_codec_write(codec, 0x20, 0,
13068                         AC_VERB_SET_COEF_INDEX, 0x0c);
13069         snd_hda_codec_write(codec, 0x20, 0,
13070                         AC_VERB_SET_PROC_COEF, 0x680);
13071
13072         snd_hda_codec_write(codec, 0x20, 0,
13073                         AC_VERB_SET_COEF_INDEX, 0x0c);
13074         snd_hda_codec_write(codec, 0x20, 0,
13075                         AC_VERB_SET_PROC_COEF, 0x480);
13076 }
13077
13078 static void alc269_lifebook_mic_autoswitch(struct hda_codec *codec)
13079 {
13080         unsigned int present_laptop;
13081         unsigned int present_dock;
13082
13083         present_laptop = snd_hda_codec_read(codec, 0x18, 0,
13084                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13085
13086         present_dock = snd_hda_codec_read(codec, 0x1b, 0,
13087                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13088
13089         /* Laptop mic port overrides dock mic port, design decision */
13090         if (present_dock)
13091                 snd_hda_codec_write(codec, 0x23, 0,
13092                                 AC_VERB_SET_CONNECT_SEL, 0x3);
13093         if (present_laptop)
13094                 snd_hda_codec_write(codec, 0x23, 0,
13095                                 AC_VERB_SET_CONNECT_SEL, 0x0);
13096         if (!present_dock && !present_laptop)
13097                 snd_hda_codec_write(codec, 0x23, 0,
13098                                 AC_VERB_SET_CONNECT_SEL, 0x1);
13099 }
13100
13101 static void alc269_quanta_fl1_unsol_event(struct hda_codec *codec,
13102                                     unsigned int res)
13103 {
13104         switch (res >> 26) {
13105         case ALC880_HP_EVENT:
13106                 alc269_quanta_fl1_speaker_automute(codec);
13107                 break;
13108         case ALC880_MIC_EVENT:
13109                 alc_mic_automute(codec);
13110                 break;
13111         }
13112 }
13113
13114 static void alc269_lifebook_unsol_event(struct hda_codec *codec,
13115                                         unsigned int res)
13116 {
13117         if ((res >> 26) == ALC880_HP_EVENT)
13118                 alc269_lifebook_speaker_automute(codec);
13119         if ((res >> 26) == ALC880_MIC_EVENT)
13120                 alc269_lifebook_mic_autoswitch(codec);
13121 }
13122
13123 static void alc269_quanta_fl1_setup(struct hda_codec *codec)
13124 {
13125         struct alc_spec *spec = codec->spec;
13126         spec->ext_mic.pin = 0x18;
13127         spec->ext_mic.mux_idx = 0;
13128         spec->int_mic.pin = 0x19;
13129         spec->int_mic.mux_idx = 1;
13130         spec->auto_mic = 1;
13131 }
13132
13133 static void alc269_quanta_fl1_init_hook(struct hda_codec *codec)
13134 {
13135         alc269_quanta_fl1_speaker_automute(codec);
13136         alc_mic_automute(codec);
13137 }
13138
13139 static void alc269_lifebook_init_hook(struct hda_codec *codec)
13140 {
13141         alc269_lifebook_speaker_automute(codec);
13142         alc269_lifebook_mic_autoswitch(codec);
13143 }
13144
13145 static struct hda_verb alc269_eeepc_dmic_init_verbs[] = {
13146         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
13147         {0x23, AC_VERB_SET_CONNECT_SEL, 0x05},
13148         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
13149         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))},
13150         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13151         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
13152         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13153         {}
13154 };
13155
13156 static struct hda_verb alc269_eeepc_amic_init_verbs[] = {
13157         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
13158         {0x23, AC_VERB_SET_CONNECT_SEL, 0x01},
13159         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
13160         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x701b | (0x00 << 8))},
13161         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
13162         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13163         {}
13164 };
13165
13166 /* toggle speaker-output according to the hp-jack state */
13167 static void alc269_speaker_automute(struct hda_codec *codec)
13168 {
13169         unsigned int present;
13170         unsigned char bits;
13171
13172         present = snd_hda_codec_read(codec, 0x15, 0,
13173                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13174         bits = present ? AMP_IN_MUTE(0) : 0;
13175         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
13176                                 AMP_IN_MUTE(0), bits);
13177         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
13178                                 AMP_IN_MUTE(0), bits);
13179 }
13180
13181 /* unsolicited event for HP jack sensing */
13182 static void alc269_eeepc_unsol_event(struct hda_codec *codec,
13183                                      unsigned int res)
13184 {
13185         switch (res >> 26) {
13186         case ALC880_HP_EVENT:
13187                 alc269_speaker_automute(codec);
13188                 break;
13189         case ALC880_MIC_EVENT:
13190                 alc_mic_automute(codec);
13191                 break;
13192         }
13193 }
13194
13195 static void alc269_eeepc_dmic_setup(struct hda_codec *codec)
13196 {
13197         struct alc_spec *spec = codec->spec;
13198         spec->ext_mic.pin = 0x18;
13199         spec->ext_mic.mux_idx = 0;
13200         spec->int_mic.pin = 0x12;
13201         spec->int_mic.mux_idx = 5;
13202         spec->auto_mic = 1;
13203 }
13204
13205 static void alc269_eeepc_amic_setup(struct hda_codec *codec)
13206 {
13207         struct alc_spec *spec = codec->spec;
13208         spec->ext_mic.pin = 0x18;
13209         spec->ext_mic.mux_idx = 0;
13210         spec->int_mic.pin = 0x19;
13211         spec->int_mic.mux_idx = 1;
13212         spec->auto_mic = 1;
13213 }
13214
13215 static void alc269_eeepc_inithook(struct hda_codec *codec)
13216 {
13217         alc269_speaker_automute(codec);
13218         alc_mic_automute(codec);
13219 }
13220
13221 /*
13222  * generic initialization of ADC, input mixers and output mixers
13223  */
13224 static struct hda_verb alc269_init_verbs[] = {
13225         /*
13226          * Unmute ADC0 and set the default input to mic-in
13227          */
13228         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13229
13230         /* Mute input amps (PCBeep, Line In, Mic 1 & Mic 2) of the
13231          * analog-loopback mixer widget
13232          * Note: PASD motherboards uses the Line In 2 as the input for
13233          * front panel mic (mic 2)
13234          */
13235         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
13236         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13237         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13238         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
13239         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
13240         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
13241
13242         /*
13243          * Set up output mixers (0x0c - 0x0e)
13244          */
13245         /* set vol=0 to output mixers */
13246         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13247         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13248
13249         /* set up input amps for analog loopback */
13250         /* Amp Indices: DAC = 0, mixer = 1 */
13251         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13252         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13253         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13254         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13255         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13256         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13257
13258         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13259         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13260         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13261         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13262         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13263         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13264         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13265
13266         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13267         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13268         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13269         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13270         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13271         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13272         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13273
13274         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
13275         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
13276
13277         /* FIXME: use matrix-type input source selection */
13278         /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
13279         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
13280         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13281         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13282         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
13283         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
13284
13285         /* set EAPD */
13286         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
13287         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
13288         { }
13289 };
13290
13291 #define alc269_auto_create_multi_out_ctls \
13292         alc268_auto_create_multi_out_ctls
13293 #define alc269_auto_create_input_ctls \
13294         alc268_auto_create_input_ctls
13295
13296 #ifdef CONFIG_SND_HDA_POWER_SAVE
13297 #define alc269_loopbacks        alc880_loopbacks
13298 #endif
13299
13300 /* pcm configuration: identical with ALC880 */
13301 #define alc269_pcm_analog_playback      alc880_pcm_analog_playback
13302 #define alc269_pcm_analog_capture       alc880_pcm_analog_capture
13303 #define alc269_pcm_digital_playback     alc880_pcm_digital_playback
13304 #define alc269_pcm_digital_capture      alc880_pcm_digital_capture
13305
13306 static struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
13307         .substreams = 1,
13308         .channels_min = 2,
13309         .channels_max = 8,
13310         .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
13311         /* NID is set in alc_build_pcms */
13312         .ops = {
13313                 .open = alc880_playback_pcm_open,
13314                 .prepare = alc880_playback_pcm_prepare,
13315                 .cleanup = alc880_playback_pcm_cleanup
13316         },
13317 };
13318
13319 static struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
13320         .substreams = 1,
13321         .channels_min = 2,
13322         .channels_max = 2,
13323         .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
13324         /* NID is set in alc_build_pcms */
13325 };
13326
13327 /*
13328  * BIOS auto configuration
13329  */
13330 static int alc269_parse_auto_config(struct hda_codec *codec)
13331 {
13332         struct alc_spec *spec = codec->spec;
13333         int err;
13334         static hda_nid_t alc269_ignore[] = { 0x1d, 0 };
13335
13336         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
13337                                            alc269_ignore);
13338         if (err < 0)
13339                 return err;
13340
13341         err = alc269_auto_create_multi_out_ctls(spec, &spec->autocfg);
13342         if (err < 0)
13343                 return err;
13344         err = alc269_auto_create_input_ctls(codec, &spec->autocfg);
13345         if (err < 0)
13346                 return err;
13347
13348         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
13349
13350         if (spec->autocfg.dig_outs)
13351                 spec->multiout.dig_out_nid = ALC269_DIGOUT_NID;
13352
13353         if (spec->kctls.list)
13354                 add_mixer(spec, spec->kctls.list);
13355
13356         add_verb(spec, alc269_init_verbs);
13357         spec->num_mux_defs = 1;
13358         spec->input_mux = &spec->private_imux[0];
13359         /* set default input source */
13360         snd_hda_codec_write_cache(codec, alc269_capsrc_nids[0],
13361                                   0, AC_VERB_SET_CONNECT_SEL,
13362                                   spec->input_mux->items[0].index);
13363
13364         err = alc_auto_add_mic_boost(codec);
13365         if (err < 0)
13366                 return err;
13367
13368         if (!spec->cap_mixer && !spec->no_analog)
13369                 set_capture_mixer(codec);
13370
13371         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
13372
13373         return 1;
13374 }
13375
13376 #define alc269_auto_init_multi_out      alc268_auto_init_multi_out
13377 #define alc269_auto_init_hp_out         alc268_auto_init_hp_out
13378 #define alc269_auto_init_analog_input   alc882_auto_init_analog_input
13379
13380
13381 /* init callback for auto-configuration model -- overriding the default init */
13382 static void alc269_auto_init(struct hda_codec *codec)
13383 {
13384         struct alc_spec *spec = codec->spec;
13385         alc269_auto_init_multi_out(codec);
13386         alc269_auto_init_hp_out(codec);
13387         alc269_auto_init_analog_input(codec);
13388         if (spec->unsol_event)
13389                 alc_inithook(codec);
13390 }
13391
13392 /*
13393  * configuration and preset
13394  */
13395 static const char *alc269_models[ALC269_MODEL_LAST] = {
13396         [ALC269_BASIC]                  = "basic",
13397         [ALC269_QUANTA_FL1]             = "quanta",
13398         [ALC269_ASUS_EEEPC_P703]        = "eeepc-p703",
13399         [ALC269_ASUS_EEEPC_P901]        = "eeepc-p901",
13400         [ALC269_FUJITSU]                = "fujitsu",
13401         [ALC269_LIFEBOOK]               = "lifebook",
13402         [ALC269_AUTO]                   = "auto",
13403 };
13404
13405 static struct snd_pci_quirk alc269_cfg_tbl[] = {
13406         SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_QUANTA_FL1),
13407         SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
13408                       ALC269_ASUS_EEEPC_P703),
13409         SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_ASUS_EEEPC_P703),
13410         SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_ASUS_EEEPC_P703),
13411         SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_ASUS_EEEPC_P703),
13412         SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_ASUS_EEEPC_P703),
13413         SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_ASUS_EEEPC_P703),
13414         SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_ASUS_EEEPC_P703),
13415         SND_PCI_QUIRK(0x1043, 0x831a, "ASUS Eeepc P901",
13416                       ALC269_ASUS_EEEPC_P901),
13417         SND_PCI_QUIRK(0x1043, 0x834a, "ASUS Eeepc S101",
13418                       ALC269_ASUS_EEEPC_P901),
13419         SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_ASUS_EEEPC_P901),
13420         SND_PCI_QUIRK(0x1734, 0x115d, "FSC Amilo", ALC269_FUJITSU),
13421         SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook ICH9M-based", ALC269_LIFEBOOK),
13422         {}
13423 };
13424
13425 static struct alc_config_preset alc269_presets[] = {
13426         [ALC269_BASIC] = {
13427                 .mixers = { alc269_base_mixer },
13428                 .init_verbs = { alc269_init_verbs },
13429                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13430                 .dac_nids = alc269_dac_nids,
13431                 .hp_nid = 0x03,
13432                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13433                 .channel_mode = alc269_modes,
13434                 .input_mux = &alc269_capture_source,
13435         },
13436         [ALC269_QUANTA_FL1] = {
13437                 .mixers = { alc269_quanta_fl1_mixer },
13438                 .init_verbs = { alc269_init_verbs, alc269_quanta_fl1_verbs },
13439                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13440                 .dac_nids = alc269_dac_nids,
13441                 .hp_nid = 0x03,
13442                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13443                 .channel_mode = alc269_modes,
13444                 .input_mux = &alc269_capture_source,
13445                 .unsol_event = alc269_quanta_fl1_unsol_event,
13446                 .setup = alc269_quanta_fl1_setup,
13447                 .init_hook = alc269_quanta_fl1_init_hook,
13448         },
13449         [ALC269_ASUS_EEEPC_P703] = {
13450                 .mixers = { alc269_eeepc_mixer },
13451                 .cap_mixer = alc269_epc_capture_mixer,
13452                 .init_verbs = { alc269_init_verbs,
13453                                 alc269_eeepc_amic_init_verbs },
13454                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13455                 .dac_nids = alc269_dac_nids,
13456                 .hp_nid = 0x03,
13457                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13458                 .channel_mode = alc269_modes,
13459                 .unsol_event = alc269_eeepc_unsol_event,
13460                 .setup = alc269_eeepc_amic_setup,
13461                 .init_hook = alc269_eeepc_inithook,
13462         },
13463         [ALC269_ASUS_EEEPC_P901] = {
13464                 .mixers = { alc269_eeepc_mixer },
13465                 .cap_mixer = alc269_epc_capture_mixer,
13466                 .init_verbs = { alc269_init_verbs,
13467                                 alc269_eeepc_dmic_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_dmic_setup,
13475                 .init_hook = alc269_eeepc_inithook,
13476         },
13477         [ALC269_FUJITSU] = {
13478                 .mixers = { alc269_fujitsu_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_LIFEBOOK] = {
13492                 .mixers = { alc269_lifebook_mixer },
13493                 .init_verbs = { alc269_init_verbs, alc269_lifebook_verbs },
13494                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13495                 .dac_nids = alc269_dac_nids,
13496                 .hp_nid = 0x03,
13497                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13498                 .channel_mode = alc269_modes,
13499                 .input_mux = &alc269_capture_source,
13500                 .unsol_event = alc269_lifebook_unsol_event,
13501                 .init_hook = alc269_lifebook_init_hook,
13502         },
13503 };
13504
13505 static int patch_alc269(struct hda_codec *codec)
13506 {
13507         struct alc_spec *spec;
13508         int board_config;
13509         int err;
13510
13511         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
13512         if (spec == NULL)
13513                 return -ENOMEM;
13514
13515         codec->spec = spec;
13516
13517         alc_fix_pll_init(codec, 0x20, 0x04, 15);
13518
13519         board_config = snd_hda_check_board_config(codec, ALC269_MODEL_LAST,
13520                                                   alc269_models,
13521                                                   alc269_cfg_tbl);
13522
13523         if (board_config < 0) {
13524                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
13525                        codec->chip_name);
13526                 board_config = ALC269_AUTO;
13527         }
13528
13529         if (board_config == ALC269_AUTO) {
13530                 /* automatic parse from the BIOS config */
13531                 err = alc269_parse_auto_config(codec);
13532                 if (err < 0) {
13533                         alc_free(codec);
13534                         return err;
13535                 } else if (!err) {
13536                         printk(KERN_INFO
13537                                "hda_codec: Cannot set up configuration "
13538                                "from BIOS.  Using base mode...\n");
13539                         board_config = ALC269_BASIC;
13540                 }
13541         }
13542
13543         err = snd_hda_attach_beep_device(codec, 0x1);
13544         if (err < 0) {
13545                 alc_free(codec);
13546                 return err;
13547         }
13548
13549         if (board_config != ALC269_AUTO)
13550                 setup_preset(codec, &alc269_presets[board_config]);
13551
13552         if (codec->subsystem_id == 0x17aa3bf8) {
13553                 /* Due to a hardware problem on Lenovo Ideadpad, we need to
13554                  * fix the sample rate of analog I/O to 44.1kHz
13555                  */
13556                 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
13557                 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
13558         } else {
13559                 spec->stream_analog_playback = &alc269_pcm_analog_playback;
13560                 spec->stream_analog_capture = &alc269_pcm_analog_capture;
13561         }
13562         spec->stream_digital_playback = &alc269_pcm_digital_playback;
13563         spec->stream_digital_capture = &alc269_pcm_digital_capture;
13564
13565         spec->adc_nids = alc269_adc_nids;
13566         spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids);
13567         spec->capsrc_nids = alc269_capsrc_nids;
13568         if (!spec->cap_mixer)
13569                 set_capture_mixer(codec);
13570         set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
13571
13572         spec->vmaster_nid = 0x02;
13573
13574         codec->patch_ops = alc_patch_ops;
13575         if (board_config == ALC269_AUTO)
13576                 spec->init_hook = alc269_auto_init;
13577 #ifdef CONFIG_SND_HDA_POWER_SAVE
13578         if (!spec->loopback.amplist)
13579                 spec->loopback.amplist = alc269_loopbacks;
13580 #endif
13581         codec->proc_widget_hook = print_realtek_coef;
13582
13583         return 0;
13584 }
13585
13586 /*
13587  *  ALC861 channel source setting (2/6 channel selection for 3-stack)
13588  */
13589
13590 /*
13591  * set the path ways for 2 channel output
13592  * need to set the codec line out and mic 1 pin widgets to inputs
13593  */
13594 static struct hda_verb alc861_threestack_ch2_init[] = {
13595         /* set pin widget 1Ah (line in) for input */
13596         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13597         /* set pin widget 18h (mic1/2) for input, for mic also enable
13598          * the vref
13599          */
13600         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13601
13602         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
13603 #if 0
13604         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
13605         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
13606 #endif
13607         { } /* end */
13608 };
13609 /*
13610  * 6ch mode
13611  * need to set the codec line out and mic 1 pin widgets to outputs
13612  */
13613 static struct hda_verb alc861_threestack_ch6_init[] = {
13614         /* set pin widget 1Ah (line in) for output (Back Surround)*/
13615         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13616         /* set pin widget 18h (mic1) for output (CLFE)*/
13617         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13618
13619         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
13620         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
13621
13622         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
13623 #if 0
13624         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
13625         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
13626 #endif
13627         { } /* end */
13628 };
13629
13630 static struct hda_channel_mode alc861_threestack_modes[2] = {
13631         { 2, alc861_threestack_ch2_init },
13632         { 6, alc861_threestack_ch6_init },
13633 };
13634 /* Set mic1 as input and unmute the mixer */
13635 static struct hda_verb alc861_uniwill_m31_ch2_init[] = {
13636         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13637         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
13638         { } /* end */
13639 };
13640 /* Set mic1 as output and mute mixer */
13641 static struct hda_verb alc861_uniwill_m31_ch4_init[] = {
13642         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13643         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
13644         { } /* end */
13645 };
13646
13647 static struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
13648         { 2, alc861_uniwill_m31_ch2_init },
13649         { 4, alc861_uniwill_m31_ch4_init },
13650 };
13651
13652 /* Set mic1 and line-in as input and unmute the mixer */
13653 static struct hda_verb alc861_asus_ch2_init[] = {
13654         /* set pin widget 1Ah (line in) for input */
13655         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13656         /* set pin widget 18h (mic1/2) for input, for mic also enable
13657          * the vref
13658          */
13659         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13660
13661         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
13662 #if 0
13663         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
13664         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
13665 #endif
13666         { } /* end */
13667 };
13668 /* Set mic1 nad line-in as output and mute mixer */
13669 static struct hda_verb alc861_asus_ch6_init[] = {
13670         /* set pin widget 1Ah (line in) for output (Back Surround)*/
13671         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13672         /* { 0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
13673         /* set pin widget 18h (mic1) for output (CLFE)*/
13674         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13675         /* { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
13676         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
13677         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
13678
13679         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
13680 #if 0
13681         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
13682         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
13683 #endif
13684         { } /* end */
13685 };
13686
13687 static struct hda_channel_mode alc861_asus_modes[2] = {
13688         { 2, alc861_asus_ch2_init },
13689         { 6, alc861_asus_ch6_init },
13690 };
13691
13692 /* patch-ALC861 */
13693
13694 static struct snd_kcontrol_new alc861_base_mixer[] = {
13695         /* output mixer control */
13696         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13697         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
13698         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
13699         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13700         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
13701
13702         /*Input mixer control */
13703         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13704            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
13705         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13706         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13707         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13708         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13709         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13710         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13711         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13712         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
13713
13714         { } /* end */
13715 };
13716
13717 static struct snd_kcontrol_new alc861_3ST_mixer[] = {
13718         /* output mixer control */
13719         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13720         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
13721         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
13722         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13723         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
13724
13725         /* Input mixer control */
13726         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13727            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
13728         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13729         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13730         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13731         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13732         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13733         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13734         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13735         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
13736
13737         {
13738                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13739                 .name = "Channel Mode",
13740                 .info = alc_ch_mode_info,
13741                 .get = alc_ch_mode_get,
13742                 .put = alc_ch_mode_put,
13743                 .private_value = ARRAY_SIZE(alc861_threestack_modes),
13744         },
13745         { } /* end */
13746 };
13747
13748 static struct snd_kcontrol_new alc861_toshiba_mixer[] = {
13749         /* output mixer control */
13750         HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13751         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13752         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13753
13754         { } /* end */
13755 };
13756
13757 static struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
13758         /* output mixer control */
13759         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13760         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
13761         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
13762         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13763         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
13764
13765         /* Input mixer control */
13766         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13767            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
13768         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13769         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13770         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13771         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13772         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13773         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13774         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13775         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
13776
13777         {
13778                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13779                 .name = "Channel Mode",
13780                 .info = alc_ch_mode_info,
13781                 .get = alc_ch_mode_get,
13782                 .put = alc_ch_mode_put,
13783                 .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
13784         },
13785         { } /* end */
13786 };
13787
13788 static struct snd_kcontrol_new alc861_asus_mixer[] = {
13789         /* output mixer control */
13790         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13791         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
13792         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
13793         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13794         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
13795
13796         /* Input mixer control */
13797         HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13798         HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT),
13799         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13800         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13801         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13802         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13803         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13804         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13805         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13806         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT),
13807
13808         {
13809                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13810                 .name = "Channel Mode",
13811                 .info = alc_ch_mode_info,
13812                 .get = alc_ch_mode_get,
13813                 .put = alc_ch_mode_put,
13814                 .private_value = ARRAY_SIZE(alc861_asus_modes),
13815         },
13816         { }
13817 };
13818
13819 /* additional mixer */
13820 static struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
13821         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13822         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13823         { }
13824 };
13825
13826 /*
13827  * generic initialization of ADC, input mixers and output mixers
13828  */
13829 static struct hda_verb alc861_base_init_verbs[] = {
13830         /*
13831          * Unmute ADC0 and set the default input to mic-in
13832          */
13833         /* port-A for surround (rear panel) */
13834         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13835         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
13836         /* port-B for mic-in (rear panel) with vref */
13837         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13838         /* port-C for line-in (rear panel) */
13839         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13840         /* port-D for Front */
13841         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13842         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13843         /* port-E for HP out (front panel) */
13844         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
13845         /* route front PCM to HP */
13846         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13847         /* port-F for mic-in (front panel) with vref */
13848         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13849         /* port-G for CLFE (rear panel) */
13850         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13851         { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13852         /* port-H for side (rear panel) */
13853         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13854         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
13855         /* CD-in */
13856         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13857         /* route front mic to ADC1*/
13858         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13859         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13860
13861         /* Unmute DAC0~3 & spdif out*/
13862         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13863         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13864         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13865         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13866         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13867
13868         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13869         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13870         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13871         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13872         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13873
13874         /* Unmute Stereo Mixer 15 */
13875         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13876         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13877         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13878         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13879
13880         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13881         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13882         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13883         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13884         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13885         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13886         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13887         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13888         /* hp used DAC 3 (Front) */
13889         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13890         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13891
13892         { }
13893 };
13894
13895 static struct hda_verb alc861_threestack_init_verbs[] = {
13896         /*
13897          * Unmute ADC0 and set the default input to mic-in
13898          */
13899         /* port-A for surround (rear panel) */
13900         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13901         /* port-B for mic-in (rear panel) with vref */
13902         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13903         /* port-C for line-in (rear panel) */
13904         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13905         /* port-D for Front */
13906         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13907         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13908         /* port-E for HP out (front panel) */
13909         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
13910         /* route front PCM to HP */
13911         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13912         /* port-F for mic-in (front panel) with vref */
13913         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13914         /* port-G for CLFE (rear panel) */
13915         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13916         /* port-H for side (rear panel) */
13917         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13918         /* CD-in */
13919         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13920         /* route front mic to ADC1*/
13921         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13922         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13923         /* Unmute DAC0~3 & spdif out*/
13924         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13925         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13926         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13927         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13928         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13929
13930         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13931         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13932         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13933         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13934         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13935
13936         /* Unmute Stereo Mixer 15 */
13937         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13938         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13939         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13940         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13941
13942         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13943         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13944         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13945         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13946         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13947         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13948         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13949         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13950         /* hp used DAC 3 (Front) */
13951         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13952         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13953         { }
13954 };
13955
13956 static struct hda_verb alc861_uniwill_m31_init_verbs[] = {
13957         /*
13958          * Unmute ADC0 and set the default input to mic-in
13959          */
13960         /* port-A for surround (rear panel) */
13961         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13962         /* port-B for mic-in (rear panel) with vref */
13963         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13964         /* port-C for line-in (rear panel) */
13965         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13966         /* port-D for Front */
13967         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13968         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13969         /* port-E for HP out (front panel) */
13970         /* this has to be set to VREF80 */
13971         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13972         /* route front PCM to HP */
13973         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13974         /* port-F for mic-in (front panel) with vref */
13975         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13976         /* port-G for CLFE (rear panel) */
13977         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13978         /* port-H for side (rear panel) */
13979         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13980         /* CD-in */
13981         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13982         /* route front mic to ADC1*/
13983         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13984         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13985         /* Unmute DAC0~3 & spdif out*/
13986         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13987         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13988         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13989         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13990         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13991
13992         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13993         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13994         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13995         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13996         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13997
13998         /* Unmute Stereo Mixer 15 */
13999         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14000         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14001         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14002         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
14003
14004         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14005         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14006         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14007         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14008         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14009         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14010         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14011         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14012         /* hp used DAC 3 (Front) */
14013         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
14014         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14015         { }
14016 };
14017
14018 static struct hda_verb alc861_asus_init_verbs[] = {
14019         /*
14020          * Unmute ADC0 and set the default input to mic-in
14021          */
14022         /* port-A for surround (rear panel)
14023          * according to codec#0 this is the HP jack
14024          */
14025         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, /* was 0x00 */
14026         /* route front PCM to HP */
14027         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x01 },
14028         /* port-B for mic-in (rear panel) with vref */
14029         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
14030         /* port-C for line-in (rear panel) */
14031         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
14032         /* port-D for Front */
14033         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
14034         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
14035         /* port-E for HP out (front panel) */
14036         /* this has to be set to VREF80 */
14037         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
14038         /* route front PCM to HP */
14039         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
14040         /* port-F for mic-in (front panel) with vref */
14041         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
14042         /* port-G for CLFE (rear panel) */
14043         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
14044         /* port-H for side (rear panel) */
14045         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
14046         /* CD-in */
14047         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
14048         /* route front mic to ADC1*/
14049         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
14050         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14051         /* Unmute DAC0~3 & spdif out*/
14052         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14053         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14054         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14055         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14056         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14057         /* Unmute Mixer 14 (mic) 1c (Line in)*/
14058         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14059         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14060         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14061         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14062
14063         /* Unmute Stereo Mixer 15 */
14064         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14065         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14066         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14067         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
14068
14069         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14070         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14071         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14072         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14073         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14074         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14075         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14076         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14077         /* hp used DAC 3 (Front) */
14078         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
14079         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14080         { }
14081 };
14082
14083 /* additional init verbs for ASUS laptops */
14084 static struct hda_verb alc861_asus_laptop_init_verbs[] = {
14085         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x45 }, /* HP-out */
14086         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2) }, /* mute line-in */
14087         { }
14088 };
14089
14090 /*
14091  * generic initialization of ADC, input mixers and output mixers
14092  */
14093 static struct hda_verb alc861_auto_init_verbs[] = {
14094         /*
14095          * Unmute ADC0 and set the default input to mic-in
14096          */
14097         /* {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, */
14098         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14099
14100         /* Unmute DAC0~3 & spdif out*/
14101         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14102         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14103         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14104         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14105         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14106
14107         /* Unmute Mixer 14 (mic) 1c (Line in)*/
14108         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14109         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14110         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14111         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14112
14113         /* Unmute Stereo Mixer 15 */
14114         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14115         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14116         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14117         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c},
14118
14119         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14120         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14121         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14122         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14123         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14124         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14125         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14126         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14127
14128         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14129         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14130         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14131         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14132         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14133         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14134         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14135         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14136
14137         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},  /* set Mic 1 */
14138
14139         { }
14140 };
14141
14142 static struct hda_verb alc861_toshiba_init_verbs[] = {
14143         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14144
14145         { }
14146 };
14147
14148 /* toggle speaker-output according to the hp-jack state */
14149 static void alc861_toshiba_automute(struct hda_codec *codec)
14150 {
14151         unsigned int present;
14152
14153         present = snd_hda_codec_read(codec, 0x0f, 0,
14154                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14155         snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
14156                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
14157         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
14158                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
14159 }
14160
14161 static void alc861_toshiba_unsol_event(struct hda_codec *codec,
14162                                        unsigned int res)
14163 {
14164         if ((res >> 26) == ALC880_HP_EVENT)
14165                 alc861_toshiba_automute(codec);
14166 }
14167
14168 /* pcm configuration: identical with ALC880 */
14169 #define alc861_pcm_analog_playback      alc880_pcm_analog_playback
14170 #define alc861_pcm_analog_capture       alc880_pcm_analog_capture
14171 #define alc861_pcm_digital_playback     alc880_pcm_digital_playback
14172 #define alc861_pcm_digital_capture      alc880_pcm_digital_capture
14173
14174
14175 #define ALC861_DIGOUT_NID       0x07
14176
14177 static struct hda_channel_mode alc861_8ch_modes[1] = {
14178         { 8, NULL }
14179 };
14180
14181 static hda_nid_t alc861_dac_nids[4] = {
14182         /* front, surround, clfe, side */
14183         0x03, 0x06, 0x05, 0x04
14184 };
14185
14186 static hda_nid_t alc660_dac_nids[3] = {
14187         /* front, clfe, surround */
14188         0x03, 0x05, 0x06
14189 };
14190
14191 static hda_nid_t alc861_adc_nids[1] = {
14192         /* ADC0-2 */
14193         0x08,
14194 };
14195
14196 static struct hda_input_mux alc861_capture_source = {
14197         .num_items = 5,
14198         .items = {
14199                 { "Mic", 0x0 },
14200                 { "Front Mic", 0x3 },
14201                 { "Line", 0x1 },
14202                 { "CD", 0x4 },
14203                 { "Mixer", 0x5 },
14204         },
14205 };
14206
14207 static hda_nid_t alc861_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
14208 {
14209         struct alc_spec *spec = codec->spec;
14210         hda_nid_t mix, srcs[5];
14211         int i, j, num;
14212
14213         if (snd_hda_get_connections(codec, pin, &mix, 1) != 1)
14214                 return 0;
14215         num = snd_hda_get_connections(codec, mix, srcs, ARRAY_SIZE(srcs));
14216         if (num < 0)
14217                 return 0;
14218         for (i = 0; i < num; i++) {
14219                 unsigned int type;
14220                 type = get_wcaps_type(get_wcaps(codec, srcs[i]));
14221                 if (type != AC_WID_AUD_OUT)
14222                         continue;
14223                 for (j = 0; j < spec->multiout.num_dacs; j++)
14224                         if (spec->multiout.dac_nids[j] == srcs[i])
14225                                 break;
14226                 if (j >= spec->multiout.num_dacs)
14227                         return srcs[i];
14228         }
14229         return 0;
14230 }
14231
14232 /* fill in the dac_nids table from the parsed pin configuration */
14233 static int alc861_auto_fill_dac_nids(struct hda_codec *codec,
14234                                      const struct auto_pin_cfg *cfg)
14235 {
14236         struct alc_spec *spec = codec->spec;
14237         int i;
14238         hda_nid_t nid, dac;
14239
14240         spec->multiout.dac_nids = spec->private_dac_nids;
14241         for (i = 0; i < cfg->line_outs; i++) {
14242                 nid = cfg->line_out_pins[i];
14243                 dac = alc861_look_for_dac(codec, nid);
14244                 if (!dac)
14245                         continue;
14246                 spec->multiout.dac_nids[spec->multiout.num_dacs++] = dac;
14247         }
14248         return 0;
14249 }
14250
14251 static int alc861_create_out_sw(struct hda_codec *codec, const char *pfx,
14252                                 hda_nid_t nid, unsigned int chs)
14253 {
14254         return add_pb_sw_ctrl(codec->spec, ALC_CTL_WIDGET_MUTE, pfx,
14255                            HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
14256 }
14257
14258 /* add playback controls from the parsed DAC table */
14259 static int alc861_auto_create_multi_out_ctls(struct hda_codec *codec,
14260                                              const struct auto_pin_cfg *cfg)
14261 {
14262         struct alc_spec *spec = codec->spec;
14263         static const char *chname[4] = {
14264                 "Front", "Surround", NULL /*CLFE*/, "Side"
14265         };
14266         hda_nid_t nid;
14267         int i, err;
14268
14269         if (cfg->line_outs == 1) {
14270                 const char *pfx = NULL;
14271                 if (!cfg->hp_outs)
14272                         pfx = "Master";
14273                 else if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
14274                         pfx = "Speaker";
14275                 if (pfx) {
14276                         nid = spec->multiout.dac_nids[0];
14277                         return alc861_create_out_sw(codec, pfx, nid, 3);
14278                 }
14279         }
14280
14281         for (i = 0; i < cfg->line_outs; i++) {
14282                 nid = spec->multiout.dac_nids[i];
14283                 if (!nid)
14284                         continue;
14285                 if (i == 2) {
14286                         /* Center/LFE */
14287                         err = alc861_create_out_sw(codec, "Center", nid, 1);
14288                         if (err < 0)
14289                                 return err;
14290                         err = alc861_create_out_sw(codec, "LFE", nid, 2);
14291                         if (err < 0)
14292                                 return err;
14293                 } else {
14294                         err = alc861_create_out_sw(codec, chname[i], nid, 3);
14295                         if (err < 0)
14296                                 return err;
14297                 }
14298         }
14299         return 0;
14300 }
14301
14302 static int alc861_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin)
14303 {
14304         struct alc_spec *spec = codec->spec;
14305         int err;
14306         hda_nid_t nid;
14307
14308         if (!pin)
14309                 return 0;
14310
14311         if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
14312                 nid = alc861_look_for_dac(codec, pin);
14313                 if (nid) {
14314                         err = alc861_create_out_sw(codec, "Headphone", nid, 3);
14315                         if (err < 0)
14316                                 return err;
14317                         spec->multiout.hp_nid = nid;
14318                 }
14319         }
14320         return 0;
14321 }
14322
14323 /* create playback/capture controls for input pins */
14324 static int alc861_auto_create_input_ctls(struct hda_codec *codec,
14325                                                 const struct auto_pin_cfg *cfg)
14326 {
14327         return alc_auto_create_input_ctls(codec, cfg, 0x15, 0x08, 0);
14328 }
14329
14330 static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
14331                                               hda_nid_t nid,
14332                                               int pin_type, hda_nid_t dac)
14333 {
14334         hda_nid_t mix, srcs[5];
14335         int i, num;
14336
14337         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
14338                             pin_type);
14339         snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14340                             AMP_OUT_UNMUTE);
14341         if (snd_hda_get_connections(codec, nid, &mix, 1) != 1)
14342                 return;
14343         num = snd_hda_get_connections(codec, mix, srcs, ARRAY_SIZE(srcs));
14344         if (num < 0)
14345                 return;
14346         for (i = 0; i < num; i++) {
14347                 unsigned int mute;
14348                 if (srcs[i] == dac || srcs[i] == 0x15)
14349                         mute = AMP_IN_UNMUTE(i);
14350                 else
14351                         mute = AMP_IN_MUTE(i);
14352                 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14353                                     mute);
14354         }
14355 }
14356
14357 static void alc861_auto_init_multi_out(struct hda_codec *codec)
14358 {
14359         struct alc_spec *spec = codec->spec;
14360         int i;
14361
14362         for (i = 0; i < spec->autocfg.line_outs; i++) {
14363                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
14364                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
14365                 if (nid)
14366                         alc861_auto_set_output_and_unmute(codec, nid, pin_type,
14367                                                           spec->multiout.dac_nids[i]);
14368         }
14369 }
14370
14371 static void alc861_auto_init_hp_out(struct hda_codec *codec)
14372 {
14373         struct alc_spec *spec = codec->spec;
14374
14375         if (spec->autocfg.hp_outs)
14376                 alc861_auto_set_output_and_unmute(codec,
14377                                                   spec->autocfg.hp_pins[0],
14378                                                   PIN_HP,
14379                                                   spec->multiout.hp_nid);
14380         if (spec->autocfg.speaker_outs)
14381                 alc861_auto_set_output_and_unmute(codec,
14382                                                   spec->autocfg.speaker_pins[0],
14383                                                   PIN_OUT,
14384                                                   spec->multiout.dac_nids[0]);
14385 }
14386
14387 static void alc861_auto_init_analog_input(struct hda_codec *codec)
14388 {
14389         struct alc_spec *spec = codec->spec;
14390         int i;
14391
14392         for (i = 0; i < AUTO_PIN_LAST; i++) {
14393                 hda_nid_t nid = spec->autocfg.input_pins[i];
14394                 if (nid >= 0x0c && nid <= 0x11)
14395                         alc_set_input_pin(codec, nid, i);
14396         }
14397 }
14398
14399 /* parse the BIOS configuration and set up the alc_spec */
14400 /* return 1 if successful, 0 if the proper config is not found,
14401  * or a negative error code
14402  */
14403 static int alc861_parse_auto_config(struct hda_codec *codec)
14404 {
14405         struct alc_spec *spec = codec->spec;
14406         int err;
14407         static hda_nid_t alc861_ignore[] = { 0x1d, 0 };
14408
14409         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
14410                                            alc861_ignore);
14411         if (err < 0)
14412                 return err;
14413         if (!spec->autocfg.line_outs)
14414                 return 0; /* can't find valid BIOS pin config */
14415
14416         err = alc861_auto_fill_dac_nids(codec, &spec->autocfg);
14417         if (err < 0)
14418                 return err;
14419         err = alc861_auto_create_multi_out_ctls(codec, &spec->autocfg);
14420         if (err < 0)
14421                 return err;
14422         err = alc861_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
14423         if (err < 0)
14424                 return err;
14425         err = alc861_auto_create_input_ctls(codec, &spec->autocfg);
14426         if (err < 0)
14427                 return err;
14428
14429         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
14430
14431         if (spec->autocfg.dig_outs)
14432                 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;
14433
14434         if (spec->kctls.list)
14435                 add_mixer(spec, spec->kctls.list);
14436
14437         add_verb(spec, alc861_auto_init_verbs);
14438
14439         spec->num_mux_defs = 1;
14440         spec->input_mux = &spec->private_imux[0];
14441
14442         spec->adc_nids = alc861_adc_nids;
14443         spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
14444         set_capture_mixer(codec);
14445
14446         alc_ssid_check(codec, 0x0e, 0x0f, 0x0b);
14447
14448         return 1;
14449 }
14450
14451 /* additional initialization for auto-configuration model */
14452 static void alc861_auto_init(struct hda_codec *codec)
14453 {
14454         struct alc_spec *spec = codec->spec;
14455         alc861_auto_init_multi_out(codec);
14456         alc861_auto_init_hp_out(codec);
14457         alc861_auto_init_analog_input(codec);
14458         if (spec->unsol_event)
14459                 alc_inithook(codec);
14460 }
14461
14462 #ifdef CONFIG_SND_HDA_POWER_SAVE
14463 static struct hda_amp_list alc861_loopbacks[] = {
14464         { 0x15, HDA_INPUT, 0 },
14465         { 0x15, HDA_INPUT, 1 },
14466         { 0x15, HDA_INPUT, 2 },
14467         { 0x15, HDA_INPUT, 3 },
14468         { } /* end */
14469 };
14470 #endif
14471
14472
14473 /*
14474  * configuration and preset
14475  */
14476 static const char *alc861_models[ALC861_MODEL_LAST] = {
14477         [ALC861_3ST]            = "3stack",
14478         [ALC660_3ST]            = "3stack-660",
14479         [ALC861_3ST_DIG]        = "3stack-dig",
14480         [ALC861_6ST_DIG]        = "6stack-dig",
14481         [ALC861_UNIWILL_M31]    = "uniwill-m31",
14482         [ALC861_TOSHIBA]        = "toshiba",
14483         [ALC861_ASUS]           = "asus",
14484         [ALC861_ASUS_LAPTOP]    = "asus-laptop",
14485         [ALC861_AUTO]           = "auto",
14486 };
14487
14488 static struct snd_pci_quirk alc861_cfg_tbl[] = {
14489         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC861_3ST),
14490         SND_PCI_QUIRK(0x1043, 0x1335, "ASUS F2/3", ALC861_ASUS_LAPTOP),
14491         SND_PCI_QUIRK(0x1043, 0x1338, "ASUS F2/3", ALC861_ASUS_LAPTOP),
14492         SND_PCI_QUIRK(0x1043, 0x1393, "ASUS", ALC861_ASUS),
14493         SND_PCI_QUIRK(0x1043, 0x13d7, "ASUS A9rp", ALC861_ASUS_LAPTOP),
14494         SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS P1-AH2", ALC861_3ST_DIG),
14495         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba", ALC861_TOSHIBA),
14496         /* FIXME: the entry below breaks Toshiba A100 (model=auto works!)
14497          *        Any other models that need this preset?
14498          */
14499         /* SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba", ALC861_TOSHIBA), */
14500         SND_PCI_QUIRK(0x1462, 0x7254, "HP dx2200 (MSI MS-7254)", ALC861_3ST),
14501         SND_PCI_QUIRK(0x1462, 0x7297, "HP dx2250 (MSI MS-7297)", ALC861_3ST),
14502         SND_PCI_QUIRK(0x1584, 0x2b01, "Uniwill X40AIx", ALC861_UNIWILL_M31),
14503         SND_PCI_QUIRK(0x1584, 0x9072, "Uniwill m31", ALC861_UNIWILL_M31),
14504         SND_PCI_QUIRK(0x1584, 0x9075, "Airis Praxis N1212", ALC861_ASUS_LAPTOP),
14505         /* FIXME: the below seems conflict */
14506         /* SND_PCI_QUIRK(0x1584, 0x9075, "Uniwill", ALC861_UNIWILL_M31), */
14507         SND_PCI_QUIRK(0x1849, 0x0660, "Asrock 939SLI32", ALC660_3ST),
14508         SND_PCI_QUIRK(0x8086, 0xd600, "Intel", ALC861_3ST),
14509         {}
14510 };
14511
14512 static struct alc_config_preset alc861_presets[] = {
14513         [ALC861_3ST] = {
14514                 .mixers = { alc861_3ST_mixer },
14515                 .init_verbs = { alc861_threestack_init_verbs },
14516                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14517                 .dac_nids = alc861_dac_nids,
14518                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
14519                 .channel_mode = alc861_threestack_modes,
14520                 .need_dac_fix = 1,
14521                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14522                 .adc_nids = alc861_adc_nids,
14523                 .input_mux = &alc861_capture_source,
14524         },
14525         [ALC861_3ST_DIG] = {
14526                 .mixers = { alc861_base_mixer },
14527                 .init_verbs = { alc861_threestack_init_verbs },
14528                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14529                 .dac_nids = alc861_dac_nids,
14530                 .dig_out_nid = ALC861_DIGOUT_NID,
14531                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
14532                 .channel_mode = alc861_threestack_modes,
14533                 .need_dac_fix = 1,
14534                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14535                 .adc_nids = alc861_adc_nids,
14536                 .input_mux = &alc861_capture_source,
14537         },
14538         [ALC861_6ST_DIG] = {
14539                 .mixers = { alc861_base_mixer },
14540                 .init_verbs = { alc861_base_init_verbs },
14541                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14542                 .dac_nids = alc861_dac_nids,
14543                 .dig_out_nid = ALC861_DIGOUT_NID,
14544                 .num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
14545                 .channel_mode = alc861_8ch_modes,
14546                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14547                 .adc_nids = alc861_adc_nids,
14548                 .input_mux = &alc861_capture_source,
14549         },
14550         [ALC660_3ST] = {
14551                 .mixers = { alc861_3ST_mixer },
14552                 .init_verbs = { alc861_threestack_init_verbs },
14553                 .num_dacs = ARRAY_SIZE(alc660_dac_nids),
14554                 .dac_nids = alc660_dac_nids,
14555                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
14556                 .channel_mode = alc861_threestack_modes,
14557                 .need_dac_fix = 1,
14558                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14559                 .adc_nids = alc861_adc_nids,
14560                 .input_mux = &alc861_capture_source,
14561         },
14562         [ALC861_UNIWILL_M31] = {
14563                 .mixers = { alc861_uniwill_m31_mixer },
14564                 .init_verbs = { alc861_uniwill_m31_init_verbs },
14565                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14566                 .dac_nids = alc861_dac_nids,
14567                 .dig_out_nid = ALC861_DIGOUT_NID,
14568                 .num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
14569                 .channel_mode = alc861_uniwill_m31_modes,
14570                 .need_dac_fix = 1,
14571                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14572                 .adc_nids = alc861_adc_nids,
14573                 .input_mux = &alc861_capture_source,
14574         },
14575         [ALC861_TOSHIBA] = {
14576                 .mixers = { alc861_toshiba_mixer },
14577                 .init_verbs = { alc861_base_init_verbs,
14578                                 alc861_toshiba_init_verbs },
14579                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14580                 .dac_nids = alc861_dac_nids,
14581                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
14582                 .channel_mode = alc883_3ST_2ch_modes,
14583                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14584                 .adc_nids = alc861_adc_nids,
14585                 .input_mux = &alc861_capture_source,
14586                 .unsol_event = alc861_toshiba_unsol_event,
14587                 .init_hook = alc861_toshiba_automute,
14588         },
14589         [ALC861_ASUS] = {
14590                 .mixers = { alc861_asus_mixer },
14591                 .init_verbs = { alc861_asus_init_verbs },
14592                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14593                 .dac_nids = alc861_dac_nids,
14594                 .dig_out_nid = ALC861_DIGOUT_NID,
14595                 .num_channel_mode = ARRAY_SIZE(alc861_asus_modes),
14596                 .channel_mode = alc861_asus_modes,
14597                 .need_dac_fix = 1,
14598                 .hp_nid = 0x06,
14599                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14600                 .adc_nids = alc861_adc_nids,
14601                 .input_mux = &alc861_capture_source,
14602         },
14603         [ALC861_ASUS_LAPTOP] = {
14604                 .mixers = { alc861_toshiba_mixer, alc861_asus_laptop_mixer },
14605                 .init_verbs = { alc861_asus_init_verbs,
14606                                 alc861_asus_laptop_init_verbs },
14607                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14608                 .dac_nids = alc861_dac_nids,
14609                 .dig_out_nid = ALC861_DIGOUT_NID,
14610                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
14611                 .channel_mode = alc883_3ST_2ch_modes,
14612                 .need_dac_fix = 1,
14613                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14614                 .adc_nids = alc861_adc_nids,
14615                 .input_mux = &alc861_capture_source,
14616         },
14617 };
14618
14619
14620 static int patch_alc861(struct hda_codec *codec)
14621 {
14622         struct alc_spec *spec;
14623         int board_config;
14624         int err;
14625
14626         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
14627         if (spec == NULL)
14628                 return -ENOMEM;
14629
14630         codec->spec = spec;
14631
14632         board_config = snd_hda_check_board_config(codec, ALC861_MODEL_LAST,
14633                                                   alc861_models,
14634                                                   alc861_cfg_tbl);
14635
14636         if (board_config < 0) {
14637                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
14638                        codec->chip_name);
14639                 board_config = ALC861_AUTO;
14640         }
14641
14642         if (board_config == ALC861_AUTO) {
14643                 /* automatic parse from the BIOS config */
14644                 err = alc861_parse_auto_config(codec);
14645                 if (err < 0) {
14646                         alc_free(codec);
14647                         return err;
14648                 } else if (!err) {
14649                         printk(KERN_INFO
14650                                "hda_codec: Cannot set up configuration "
14651                                "from BIOS.  Using base mode...\n");
14652                    board_config = ALC861_3ST_DIG;
14653                 }
14654         }
14655
14656         err = snd_hda_attach_beep_device(codec, 0x23);
14657         if (err < 0) {
14658                 alc_free(codec);
14659                 return err;
14660         }
14661
14662         if (board_config != ALC861_AUTO)
14663                 setup_preset(codec, &alc861_presets[board_config]);
14664
14665         spec->stream_analog_playback = &alc861_pcm_analog_playback;
14666         spec->stream_analog_capture = &alc861_pcm_analog_capture;
14667
14668         spec->stream_digital_playback = &alc861_pcm_digital_playback;
14669         spec->stream_digital_capture = &alc861_pcm_digital_capture;
14670
14671         set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
14672
14673         spec->vmaster_nid = 0x03;
14674
14675         codec->patch_ops = alc_patch_ops;
14676         if (board_config == ALC861_AUTO)
14677                 spec->init_hook = alc861_auto_init;
14678 #ifdef CONFIG_SND_HDA_POWER_SAVE
14679         if (!spec->loopback.amplist)
14680                 spec->loopback.amplist = alc861_loopbacks;
14681 #endif
14682         codec->proc_widget_hook = print_realtek_coef;
14683
14684         return 0;
14685 }
14686
14687 /*
14688  * ALC861-VD support
14689  *
14690  * Based on ALC882
14691  *
14692  * In addition, an independent DAC
14693  */
14694 #define ALC861VD_DIGOUT_NID     0x06
14695
14696 static hda_nid_t alc861vd_dac_nids[4] = {
14697         /* front, surr, clfe, side surr */
14698         0x02, 0x03, 0x04, 0x05
14699 };
14700
14701 /* dac_nids for ALC660vd are in a different order - according to
14702  * Realtek's driver.
14703  * This should probably result in a different mixer for 6stack models
14704  * of ALC660vd codecs, but for now there is only 3stack mixer
14705  * - and it is the same as in 861vd.
14706  * adc_nids in ALC660vd are (is) the same as in 861vd
14707  */
14708 static hda_nid_t alc660vd_dac_nids[3] = {
14709         /* front, rear, clfe, rear_surr */
14710         0x02, 0x04, 0x03
14711 };
14712
14713 static hda_nid_t alc861vd_adc_nids[1] = {
14714         /* ADC0 */
14715         0x09,
14716 };
14717
14718 static hda_nid_t alc861vd_capsrc_nids[1] = { 0x22 };
14719
14720 /* input MUX */
14721 /* FIXME: should be a matrix-type input source selection */
14722 static struct hda_input_mux alc861vd_capture_source = {
14723         .num_items = 4,
14724         .items = {
14725                 { "Mic", 0x0 },
14726                 { "Front Mic", 0x1 },
14727                 { "Line", 0x2 },
14728                 { "CD", 0x4 },
14729         },
14730 };
14731
14732 static struct hda_input_mux alc861vd_dallas_capture_source = {
14733         .num_items = 2,
14734         .items = {
14735                 { "Ext Mic", 0x0 },
14736                 { "Int Mic", 0x1 },
14737         },
14738 };
14739
14740 static struct hda_input_mux alc861vd_hp_capture_source = {
14741         .num_items = 2,
14742         .items = {
14743                 { "Front Mic", 0x0 },
14744                 { "ATAPI Mic", 0x1 },
14745         },
14746 };
14747
14748 /*
14749  * 2ch mode
14750  */
14751 static struct hda_channel_mode alc861vd_3stack_2ch_modes[1] = {
14752         { 2, NULL }
14753 };
14754
14755 /*
14756  * 6ch mode
14757  */
14758 static struct hda_verb alc861vd_6stack_ch6_init[] = {
14759         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
14760         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14761         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14762         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14763         { } /* end */
14764 };
14765
14766 /*
14767  * 8ch mode
14768  */
14769 static struct hda_verb alc861vd_6stack_ch8_init[] = {
14770         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14771         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14772         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14773         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14774         { } /* end */
14775 };
14776
14777 static struct hda_channel_mode alc861vd_6stack_modes[2] = {
14778         { 6, alc861vd_6stack_ch6_init },
14779         { 8, alc861vd_6stack_ch8_init },
14780 };
14781
14782 static struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
14783         {
14784                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
14785                 .name = "Channel Mode",
14786                 .info = alc_ch_mode_info,
14787                 .get = alc_ch_mode_get,
14788                 .put = alc_ch_mode_put,
14789         },
14790         { } /* end */
14791 };
14792
14793 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
14794  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
14795  */
14796 static struct snd_kcontrol_new alc861vd_6st_mixer[] = {
14797         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14798         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14799
14800         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14801         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
14802
14803         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0,
14804                                 HDA_OUTPUT),
14805         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0,
14806                                 HDA_OUTPUT),
14807         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
14808         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
14809
14810         HDA_CODEC_VOLUME("Side Playback Volume", 0x05, 0x0, HDA_OUTPUT),
14811         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
14812
14813         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14814
14815         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
14816         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14817         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14818
14819         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
14820         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14821         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14822
14823         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14824         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14825
14826         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14827         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14828
14829         { } /* end */
14830 };
14831
14832 static struct snd_kcontrol_new alc861vd_3st_mixer[] = {
14833         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14834         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14835
14836         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14837
14838         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
14839         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14840         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14841
14842         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
14843         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14844         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14845
14846         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14847         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14848
14849         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14850         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14851
14852         { } /* end */
14853 };
14854
14855 static struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
14856         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14857         /*HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),*/
14858         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14859
14860         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14861
14862         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
14863         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14864         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14865
14866         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
14867         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14868         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14869
14870         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14871         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14872
14873         { } /* end */
14874 };
14875
14876 /* Pin assignment: Speaker=0x14, HP = 0x15,
14877  *                 Ext Mic=0x18, Int Mic = 0x19, CD = 0x1c, PC Beep = 0x1d
14878  */
14879 static struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
14880         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14881         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
14882         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14883         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
14884         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
14885         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14886         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14887         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
14888         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14889         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14890         { } /* end */
14891 };
14892
14893 /* Pin assignment: Speaker=0x14, Line-out = 0x15,
14894  *                 Front Mic=0x18, ATAPI Mic = 0x19,
14895  */
14896 static struct snd_kcontrol_new alc861vd_hp_mixer[] = {
14897         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14898         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14899         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14900         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
14901         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14902         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14903         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14904         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14905
14906         { } /* end */
14907 };
14908
14909 /*
14910  * generic initialization of ADC, input mixers and output mixers
14911  */
14912 static struct hda_verb alc861vd_volume_init_verbs[] = {
14913         /*
14914          * Unmute ADC0 and set the default input to mic-in
14915          */
14916         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
14917         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14918
14919         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of
14920          * the analog-loopback mixer widget
14921          */
14922         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
14923         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14924         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14925         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14926         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14927         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14928
14929         /* Capture mixer: unmute Mic, F-Mic, Line, CD inputs */
14930         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14931         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14932         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14933         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
14934
14935         /*
14936          * Set up output mixers (0x02 - 0x05)
14937          */
14938         /* set vol=0 to output mixers */
14939         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14940         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14941         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14942         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14943
14944         /* set up input amps for analog loopback */
14945         /* Amp Indices: DAC = 0, mixer = 1 */
14946         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14947         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14948         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14949         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14950         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14951         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14952         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14953         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14954
14955         { }
14956 };
14957
14958 /*
14959  * 3-stack pin configuration:
14960  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
14961  */
14962 static struct hda_verb alc861vd_3stack_init_verbs[] = {
14963         /*
14964          * Set pin mode and muting
14965          */
14966         /* set front pin widgets 0x14 for output */
14967         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14968         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14969         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
14970
14971         /* Mic (rear) pin: input vref at 80% */
14972         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14973         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14974         /* Front Mic pin: input vref at 80% */
14975         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14976         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14977         /* Line In pin: input */
14978         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14979         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14980         /* Line-2 In: Headphone output (output 0 - 0x0c) */
14981         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14982         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14983         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
14984         /* CD pin widget for input */
14985         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14986
14987         { }
14988 };
14989
14990 /*
14991  * 6-stack pin configuration:
14992  */
14993 static struct hda_verb alc861vd_6stack_init_verbs[] = {
14994         /*
14995          * Set pin mode and muting
14996          */
14997         /* set front pin widgets 0x14 for output */
14998         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14999         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15000         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
15001
15002         /* Rear Pin: output 1 (0x0d) */
15003         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15004         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15005         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
15006         /* CLFE Pin: output 2 (0x0e) */
15007         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15008         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15009         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
15010         /* Side Pin: output 3 (0x0f) */
15011         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15012         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15013         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
15014
15015         /* Mic (rear) pin: input vref at 80% */
15016         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
15017         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15018         /* Front Mic pin: input vref at 80% */
15019         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
15020         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15021         /* Line In pin: input */
15022         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15023         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15024         /* Line-2 In: Headphone output (output 0 - 0x0c) */
15025         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15026         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15027         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
15028         /* CD pin widget for input */
15029         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15030
15031         { }
15032 };
15033
15034 static struct hda_verb alc861vd_eapd_verbs[] = {
15035         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
15036         { }
15037 };
15038
15039 static struct hda_verb alc660vd_eapd_verbs[] = {
15040         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
15041         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
15042         { }
15043 };
15044
15045 static struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
15046         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15047         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15048         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
15049         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15050         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15051         {}
15052 };
15053
15054 static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
15055 {
15056         unsigned int present;
15057         unsigned char bits;
15058
15059         present = snd_hda_codec_read(codec, 0x18, 0,
15060                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15061         bits = present ? HDA_AMP_MUTE : 0;
15062         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
15063                                  HDA_AMP_MUTE, bits);
15064 }
15065
15066 static void alc861vd_lenovo_setup(struct hda_codec *codec)
15067 {
15068         struct alc_spec *spec = codec->spec;
15069         spec->autocfg.hp_pins[0] = 0x1b;
15070         spec->autocfg.speaker_pins[0] = 0x14;
15071 }
15072
15073 static void alc861vd_lenovo_init_hook(struct hda_codec *codec)
15074 {
15075         alc_automute_amp(codec);
15076         alc861vd_lenovo_mic_automute(codec);
15077 }
15078
15079 static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
15080                                         unsigned int res)
15081 {
15082         switch (res >> 26) {
15083         case ALC880_MIC_EVENT:
15084                 alc861vd_lenovo_mic_automute(codec);
15085                 break;
15086         default:
15087                 alc_automute_amp_unsol_event(codec, res);
15088                 break;
15089         }
15090 }
15091
15092 static struct hda_verb alc861vd_dallas_verbs[] = {
15093         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15094         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15095         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15096         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15097
15098         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15099         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15100         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15101         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15102         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15103         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15104         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15105         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15106
15107         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15108         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15109         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15110         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15111         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15112         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15113         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15114         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15115
15116         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
15117         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15118         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
15119         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15120         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15121         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15122         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15123         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15124
15125         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15126         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
15127         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
15128         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
15129
15130         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15131         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
15132         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15133
15134         { } /* end */
15135 };
15136
15137 /* toggle speaker-output according to the hp-jack state */
15138 static void alc861vd_dallas_setup(struct hda_codec *codec)
15139 {
15140         struct alc_spec *spec = codec->spec;
15141
15142         spec->autocfg.hp_pins[0] = 0x15;
15143         spec->autocfg.speaker_pins[0] = 0x14;
15144 }
15145
15146 #ifdef CONFIG_SND_HDA_POWER_SAVE
15147 #define alc861vd_loopbacks      alc880_loopbacks
15148 #endif
15149
15150 /* pcm configuration: identical with ALC880 */
15151 #define alc861vd_pcm_analog_playback    alc880_pcm_analog_playback
15152 #define alc861vd_pcm_analog_capture     alc880_pcm_analog_capture
15153 #define alc861vd_pcm_digital_playback   alc880_pcm_digital_playback
15154 #define alc861vd_pcm_digital_capture    alc880_pcm_digital_capture
15155
15156 /*
15157  * configuration and preset
15158  */
15159 static const char *alc861vd_models[ALC861VD_MODEL_LAST] = {
15160         [ALC660VD_3ST]          = "3stack-660",
15161         [ALC660VD_3ST_DIG]      = "3stack-660-digout",
15162         [ALC660VD_ASUS_V1S]     = "asus-v1s",
15163         [ALC861VD_3ST]          = "3stack",
15164         [ALC861VD_3ST_DIG]      = "3stack-digout",
15165         [ALC861VD_6ST_DIG]      = "6stack-digout",
15166         [ALC861VD_LENOVO]       = "lenovo",
15167         [ALC861VD_DALLAS]       = "dallas",
15168         [ALC861VD_HP]           = "hp",
15169         [ALC861VD_AUTO]         = "auto",
15170 };
15171
15172 static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
15173         SND_PCI_QUIRK(0x1019, 0xa88d, "Realtek ALC660 demo", ALC660VD_3ST),
15174         SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_HP),
15175         SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST),
15176         /*SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),*/ /* auto */
15177         SND_PCI_QUIRK(0x1043, 0x1633, "Asus V1Sn", ALC660VD_ASUS_V1S),
15178         SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG),
15179         SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
15180         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
15181         /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
15182         SND_PCI_QUIRK(0x1179, 0xff01, "Toshiba A135", ALC861VD_LENOVO),
15183         SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
15184         SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_DALLAS),
15185         SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
15186         SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", ALC861VD_LENOVO),
15187         SND_PCI_QUIRK(0x1849, 0x0862, "ASRock K8NF6G-VSTA", ALC861VD_6ST_DIG),
15188         {}
15189 };
15190
15191 static struct alc_config_preset alc861vd_presets[] = {
15192         [ALC660VD_3ST] = {
15193                 .mixers = { alc861vd_3st_mixer },
15194                 .init_verbs = { alc861vd_volume_init_verbs,
15195                                  alc861vd_3stack_init_verbs },
15196                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
15197                 .dac_nids = alc660vd_dac_nids,
15198                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15199                 .channel_mode = alc861vd_3stack_2ch_modes,
15200                 .input_mux = &alc861vd_capture_source,
15201         },
15202         [ALC660VD_3ST_DIG] = {
15203                 .mixers = { alc861vd_3st_mixer },
15204                 .init_verbs = { alc861vd_volume_init_verbs,
15205                                  alc861vd_3stack_init_verbs },
15206                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
15207                 .dac_nids = alc660vd_dac_nids,
15208                 .dig_out_nid = ALC861VD_DIGOUT_NID,
15209                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15210                 .channel_mode = alc861vd_3stack_2ch_modes,
15211                 .input_mux = &alc861vd_capture_source,
15212         },
15213         [ALC861VD_3ST] = {
15214                 .mixers = { alc861vd_3st_mixer },
15215                 .init_verbs = { alc861vd_volume_init_verbs,
15216                                  alc861vd_3stack_init_verbs },
15217                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
15218                 .dac_nids = alc861vd_dac_nids,
15219                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15220                 .channel_mode = alc861vd_3stack_2ch_modes,
15221                 .input_mux = &alc861vd_capture_source,
15222         },
15223         [ALC861VD_3ST_DIG] = {
15224                 .mixers = { alc861vd_3st_mixer },
15225                 .init_verbs = { alc861vd_volume_init_verbs,
15226                                  alc861vd_3stack_init_verbs },
15227                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
15228                 .dac_nids = alc861vd_dac_nids,
15229                 .dig_out_nid = ALC861VD_DIGOUT_NID,
15230                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15231                 .channel_mode = alc861vd_3stack_2ch_modes,
15232                 .input_mux = &alc861vd_capture_source,
15233         },
15234         [ALC861VD_6ST_DIG] = {
15235                 .mixers = { alc861vd_6st_mixer, alc861vd_chmode_mixer },
15236                 .init_verbs = { alc861vd_volume_init_verbs,
15237                                 alc861vd_6stack_init_verbs },
15238                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
15239                 .dac_nids = alc861vd_dac_nids,
15240                 .dig_out_nid = ALC861VD_DIGOUT_NID,
15241                 .num_channel_mode = ARRAY_SIZE(alc861vd_6stack_modes),
15242                 .channel_mode = alc861vd_6stack_modes,
15243                 .input_mux = &alc861vd_capture_source,
15244         },
15245         [ALC861VD_LENOVO] = {
15246                 .mixers = { alc861vd_lenovo_mixer },
15247                 .init_verbs = { alc861vd_volume_init_verbs,
15248                                 alc861vd_3stack_init_verbs,
15249                                 alc861vd_eapd_verbs,
15250                                 alc861vd_lenovo_unsol_verbs },
15251                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
15252                 .dac_nids = alc660vd_dac_nids,
15253                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15254                 .channel_mode = alc861vd_3stack_2ch_modes,
15255                 .input_mux = &alc861vd_capture_source,
15256                 .unsol_event = alc861vd_lenovo_unsol_event,
15257                 .setup = alc861vd_lenovo_setup,
15258                 .init_hook = alc861vd_lenovo_init_hook,
15259         },
15260         [ALC861VD_DALLAS] = {
15261                 .mixers = { alc861vd_dallas_mixer },
15262                 .init_verbs = { alc861vd_dallas_verbs },
15263                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
15264                 .dac_nids = alc861vd_dac_nids,
15265                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15266                 .channel_mode = alc861vd_3stack_2ch_modes,
15267                 .input_mux = &alc861vd_dallas_capture_source,
15268                 .unsol_event = alc_automute_amp_unsol_event,
15269                 .setup = alc861vd_dallas_setup,
15270                 .init_hook = alc_automute_amp,
15271         },
15272         [ALC861VD_HP] = {
15273                 .mixers = { alc861vd_hp_mixer },
15274                 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs },
15275                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
15276                 .dac_nids = alc861vd_dac_nids,
15277                 .dig_out_nid = ALC861VD_DIGOUT_NID,
15278                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15279                 .channel_mode = alc861vd_3stack_2ch_modes,
15280                 .input_mux = &alc861vd_hp_capture_source,
15281                 .unsol_event = alc_automute_amp_unsol_event,
15282                 .setup = alc861vd_dallas_setup,
15283                 .init_hook = alc_automute_amp,
15284         },
15285         [ALC660VD_ASUS_V1S] = {
15286                 .mixers = { alc861vd_lenovo_mixer },
15287                 .init_verbs = { alc861vd_volume_init_verbs,
15288                                 alc861vd_3stack_init_verbs,
15289                                 alc861vd_eapd_verbs,
15290                                 alc861vd_lenovo_unsol_verbs },
15291                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
15292                 .dac_nids = alc660vd_dac_nids,
15293                 .dig_out_nid = ALC861VD_DIGOUT_NID,
15294                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15295                 .channel_mode = alc861vd_3stack_2ch_modes,
15296                 .input_mux = &alc861vd_capture_source,
15297                 .unsol_event = alc861vd_lenovo_unsol_event,
15298                 .setup = alc861vd_lenovo_setup,
15299                 .init_hook = alc861vd_lenovo_init_hook,
15300         },
15301 };
15302
15303 /*
15304  * BIOS auto configuration
15305  */
15306 static int alc861vd_auto_create_input_ctls(struct hda_codec *codec,
15307                                                 const struct auto_pin_cfg *cfg)
15308 {
15309         return alc_auto_create_input_ctls(codec, cfg, 0x15, 0x09, 0);
15310 }
15311
15312
15313 static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
15314                                 hda_nid_t nid, int pin_type, int dac_idx)
15315 {
15316         alc_set_pin_output(codec, nid, pin_type);
15317 }
15318
15319 static void alc861vd_auto_init_multi_out(struct hda_codec *codec)
15320 {
15321         struct alc_spec *spec = codec->spec;
15322         int i;
15323
15324         for (i = 0; i <= HDA_SIDE; i++) {
15325                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
15326                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
15327                 if (nid)
15328                         alc861vd_auto_set_output_and_unmute(codec, nid,
15329                                                             pin_type, i);
15330         }
15331 }
15332
15333
15334 static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
15335 {
15336         struct alc_spec *spec = codec->spec;
15337         hda_nid_t pin;
15338
15339         pin = spec->autocfg.hp_pins[0];
15340         if (pin) /* connect to front and use dac 0 */
15341                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
15342         pin = spec->autocfg.speaker_pins[0];
15343         if (pin)
15344                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
15345 }
15346
15347 #define ALC861VD_PIN_CD_NID             ALC880_PIN_CD_NID
15348
15349 static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
15350 {
15351         struct alc_spec *spec = codec->spec;
15352         int i;
15353
15354         for (i = 0; i < AUTO_PIN_LAST; i++) {
15355                 hda_nid_t nid = spec->autocfg.input_pins[i];
15356                 if (alc_is_input_pin(codec, nid)) {
15357                         alc_set_input_pin(codec, nid, i);
15358                         if (nid != ALC861VD_PIN_CD_NID &&
15359                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
15360                                 snd_hda_codec_write(codec, nid, 0,
15361                                                 AC_VERB_SET_AMP_GAIN_MUTE,
15362                                                 AMP_OUT_MUTE);
15363                 }
15364         }
15365 }
15366
15367 #define alc861vd_auto_init_input_src    alc882_auto_init_input_src
15368
15369 #define alc861vd_idx_to_mixer_vol(nid)          ((nid) + 0x02)
15370 #define alc861vd_idx_to_mixer_switch(nid)       ((nid) + 0x0c)
15371
15372 /* add playback controls from the parsed DAC table */
15373 /* Based on ALC880 version. But ALC861VD has separate,
15374  * different NIDs for mute/unmute switch and volume control */
15375 static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
15376                                              const struct auto_pin_cfg *cfg)
15377 {
15378         static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"};
15379         hda_nid_t nid_v, nid_s;
15380         int i, err;
15381
15382         for (i = 0; i < cfg->line_outs; i++) {
15383                 if (!spec->multiout.dac_nids[i])
15384                         continue;
15385                 nid_v = alc861vd_idx_to_mixer_vol(
15386                                 alc880_dac_to_idx(
15387                                         spec->multiout.dac_nids[i]));
15388                 nid_s = alc861vd_idx_to_mixer_switch(
15389                                 alc880_dac_to_idx(
15390                                         spec->multiout.dac_nids[i]));
15391
15392                 if (i == 2) {
15393                         /* Center/LFE */
15394                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
15395                                               "Center",
15396                                           HDA_COMPOSE_AMP_VAL(nid_v, 1, 0,
15397                                                               HDA_OUTPUT));
15398                         if (err < 0)
15399                                 return err;
15400                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
15401                                               "LFE",
15402                                           HDA_COMPOSE_AMP_VAL(nid_v, 2, 0,
15403                                                               HDA_OUTPUT));
15404                         if (err < 0)
15405                                 return err;
15406                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
15407                                              "Center",
15408                                           HDA_COMPOSE_AMP_VAL(nid_s, 1, 2,
15409                                                               HDA_INPUT));
15410                         if (err < 0)
15411                                 return err;
15412                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
15413                                              "LFE",
15414                                           HDA_COMPOSE_AMP_VAL(nid_s, 2, 2,
15415                                                               HDA_INPUT));
15416                         if (err < 0)
15417                                 return err;
15418                 } else {
15419                         const char *pfx;
15420                         if (cfg->line_outs == 1 &&
15421                             cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
15422                                 if (!cfg->hp_pins)
15423                                         pfx = "Speaker";
15424                                 else
15425                                         pfx = "PCM";
15426                         } else
15427                                 pfx = chname[i];
15428                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
15429                                           HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
15430                                                               HDA_OUTPUT));
15431                         if (err < 0)
15432                                 return err;
15433                         if (cfg->line_outs == 1 &&
15434                             cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
15435                                 pfx = "Speaker";
15436                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE, pfx,
15437                                           HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
15438                                                               HDA_INPUT));
15439                         if (err < 0)
15440                                 return err;
15441                 }
15442         }
15443         return 0;
15444 }
15445
15446 /* add playback controls for speaker and HP outputs */
15447 /* Based on ALC880 version. But ALC861VD has separate,
15448  * different NIDs for mute/unmute switch and volume control */
15449 static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
15450                                         hda_nid_t pin, const char *pfx)
15451 {
15452         hda_nid_t nid_v, nid_s;
15453         int err;
15454
15455         if (!pin)
15456                 return 0;
15457
15458         if (alc880_is_fixed_pin(pin)) {
15459                 nid_v = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
15460                 /* specify the DAC as the extra output */
15461                 if (!spec->multiout.hp_nid)
15462                         spec->multiout.hp_nid = nid_v;
15463                 else
15464                         spec->multiout.extra_out_nid[0] = nid_v;
15465                 /* control HP volume/switch on the output mixer amp */
15466                 nid_v = alc861vd_idx_to_mixer_vol(
15467                                 alc880_fixed_pin_idx(pin));
15468                 nid_s = alc861vd_idx_to_mixer_switch(
15469                                 alc880_fixed_pin_idx(pin));
15470
15471                 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
15472                                   HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT));
15473                 if (err < 0)
15474                         return err;
15475                 err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE, pfx,
15476                                   HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT));
15477                 if (err < 0)
15478                         return err;
15479         } else if (alc880_is_multi_pin(pin)) {
15480                 /* set manual connection */
15481                 /* we have only a switch on HP-out PIN */
15482                 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
15483                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
15484                 if (err < 0)
15485                         return err;
15486         }
15487         return 0;
15488 }
15489
15490 /* parse the BIOS configuration and set up the alc_spec
15491  * return 1 if successful, 0 if the proper config is not found,
15492  * or a negative error code
15493  * Based on ALC880 version - had to change it to override
15494  * alc880_auto_create_extra_out and alc880_auto_create_multi_out_ctls */
15495 static int alc861vd_parse_auto_config(struct hda_codec *codec)
15496 {
15497         struct alc_spec *spec = codec->spec;
15498         int err;
15499         static hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
15500
15501         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
15502                                            alc861vd_ignore);
15503         if (err < 0)
15504                 return err;
15505         if (!spec->autocfg.line_outs)
15506                 return 0; /* can't find valid BIOS pin config */
15507
15508         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
15509         if (err < 0)
15510                 return err;
15511         err = alc861vd_auto_create_multi_out_ctls(spec, &spec->autocfg);
15512         if (err < 0)
15513                 return err;
15514         err = alc861vd_auto_create_extra_out(spec,
15515                                              spec->autocfg.speaker_pins[0],
15516                                              "Speaker");
15517         if (err < 0)
15518                 return err;
15519         err = alc861vd_auto_create_extra_out(spec,
15520                                              spec->autocfg.hp_pins[0],
15521                                              "Headphone");
15522         if (err < 0)
15523                 return err;
15524         err = alc861vd_auto_create_input_ctls(codec, &spec->autocfg);
15525         if (err < 0)
15526                 return err;
15527
15528         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
15529
15530         if (spec->autocfg.dig_outs)
15531                 spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID;
15532
15533         if (spec->kctls.list)
15534                 add_mixer(spec, spec->kctls.list);
15535
15536         add_verb(spec, alc861vd_volume_init_verbs);
15537
15538         spec->num_mux_defs = 1;
15539         spec->input_mux = &spec->private_imux[0];
15540
15541         err = alc_auto_add_mic_boost(codec);
15542         if (err < 0)
15543                 return err;
15544
15545         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
15546
15547         return 1;
15548 }
15549
15550 /* additional initialization for auto-configuration model */
15551 static void alc861vd_auto_init(struct hda_codec *codec)
15552 {
15553         struct alc_spec *spec = codec->spec;
15554         alc861vd_auto_init_multi_out(codec);
15555         alc861vd_auto_init_hp_out(codec);
15556         alc861vd_auto_init_analog_input(codec);
15557         alc861vd_auto_init_input_src(codec);
15558         if (spec->unsol_event)
15559                 alc_inithook(codec);
15560 }
15561
15562 enum {
15563         ALC660VD_FIX_ASUS_GPIO1
15564 };
15565
15566 /* reset GPIO1 */
15567 static const struct hda_verb alc660vd_fix_asus_gpio1_verbs[] = {
15568         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
15569         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
15570         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
15571         { }
15572 };
15573
15574 static const struct alc_fixup alc861vd_fixups[] = {
15575         [ALC660VD_FIX_ASUS_GPIO1] = {
15576                 .verbs = alc660vd_fix_asus_gpio1_verbs,
15577         },
15578 };
15579
15580 static struct snd_pci_quirk alc861vd_fixup_tbl[] = {
15581         SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
15582         {}
15583 };
15584
15585 static int patch_alc861vd(struct hda_codec *codec)
15586 {
15587         struct alc_spec *spec;
15588         int err, board_config;
15589
15590         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
15591         if (spec == NULL)
15592                 return -ENOMEM;
15593
15594         codec->spec = spec;
15595
15596         board_config = snd_hda_check_board_config(codec, ALC861VD_MODEL_LAST,
15597                                                   alc861vd_models,
15598                                                   alc861vd_cfg_tbl);
15599
15600         if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) {
15601                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
15602                        codec->chip_name);
15603                 board_config = ALC861VD_AUTO;
15604         }
15605
15606         alc_pick_fixup(codec, alc861vd_fixup_tbl, alc861vd_fixups);
15607
15608         if (board_config == ALC861VD_AUTO) {
15609                 /* automatic parse from the BIOS config */
15610                 err = alc861vd_parse_auto_config(codec);
15611                 if (err < 0) {
15612                         alc_free(codec);
15613                         return err;
15614                 } else if (!err) {
15615                         printk(KERN_INFO
15616                                "hda_codec: Cannot set up configuration "
15617                                "from BIOS.  Using base mode...\n");
15618                         board_config = ALC861VD_3ST;
15619                 }
15620         }
15621
15622         err = snd_hda_attach_beep_device(codec, 0x23);
15623         if (err < 0) {
15624                 alc_free(codec);
15625                 return err;
15626         }
15627
15628         if (board_config != ALC861VD_AUTO)
15629                 setup_preset(codec, &alc861vd_presets[board_config]);
15630
15631         if (codec->vendor_id == 0x10ec0660) {
15632                 /* always turn on EAPD */
15633                 add_verb(spec, alc660vd_eapd_verbs);
15634         }
15635
15636         spec->stream_analog_playback = &alc861vd_pcm_analog_playback;
15637         spec->stream_analog_capture = &alc861vd_pcm_analog_capture;
15638
15639         spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
15640         spec->stream_digital_capture = &alc861vd_pcm_digital_capture;
15641
15642         if (!spec->adc_nids) {
15643                 spec->adc_nids = alc861vd_adc_nids;
15644                 spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
15645         }
15646         if (!spec->capsrc_nids)
15647                 spec->capsrc_nids = alc861vd_capsrc_nids;
15648
15649         set_capture_mixer(codec);
15650         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
15651
15652         spec->vmaster_nid = 0x02;
15653
15654         codec->patch_ops = alc_patch_ops;
15655
15656         if (board_config == ALC861VD_AUTO)
15657                 spec->init_hook = alc861vd_auto_init;
15658 #ifdef CONFIG_SND_HDA_POWER_SAVE
15659         if (!spec->loopback.amplist)
15660                 spec->loopback.amplist = alc861vd_loopbacks;
15661 #endif
15662         codec->proc_widget_hook = print_realtek_coef;
15663
15664         return 0;
15665 }
15666
15667 /*
15668  * ALC662 support
15669  *
15670  * ALC662 is almost identical with ALC880 but has cleaner and more flexible
15671  * configuration.  Each pin widget can choose any input DACs and a mixer.
15672  * Each ADC is connected from a mixer of all inputs.  This makes possible
15673  * 6-channel independent captures.
15674  *
15675  * In addition, an independent DAC for the multi-playback (not used in this
15676  * driver yet).
15677  */
15678 #define ALC662_DIGOUT_NID       0x06
15679 #define ALC662_DIGIN_NID        0x0a
15680
15681 static hda_nid_t alc662_dac_nids[4] = {
15682         /* front, rear, clfe, rear_surr */
15683         0x02, 0x03, 0x04
15684 };
15685
15686 static hda_nid_t alc272_dac_nids[2] = {
15687         0x02, 0x03
15688 };
15689
15690 static hda_nid_t alc662_adc_nids[2] = {
15691         /* ADC1-2 */
15692         0x09, 0x08
15693 };
15694
15695 static hda_nid_t alc272_adc_nids[1] = {
15696         /* ADC1-2 */
15697         0x08,
15698 };
15699
15700 static hda_nid_t alc662_capsrc_nids[2] = { 0x22, 0x23 };
15701 static hda_nid_t alc272_capsrc_nids[1] = { 0x23 };
15702
15703
15704 /* input MUX */
15705 /* FIXME: should be a matrix-type input source selection */
15706 static struct hda_input_mux alc662_capture_source = {
15707         .num_items = 4,
15708         .items = {
15709                 { "Mic", 0x0 },
15710                 { "Front Mic", 0x1 },
15711                 { "Line", 0x2 },
15712                 { "CD", 0x4 },
15713         },
15714 };
15715
15716 static struct hda_input_mux alc662_lenovo_101e_capture_source = {
15717         .num_items = 2,
15718         .items = {
15719                 { "Mic", 0x1 },
15720                 { "Line", 0x2 },
15721         },
15722 };
15723
15724 static struct hda_input_mux alc663_capture_source = {
15725         .num_items = 3,
15726         .items = {
15727                 { "Mic", 0x0 },
15728                 { "Front Mic", 0x1 },
15729                 { "Line", 0x2 },
15730         },
15731 };
15732
15733 #if 0 /* set to 1 for testing other input sources below */
15734 static struct hda_input_mux alc272_nc10_capture_source = {
15735         .num_items = 16,
15736         .items = {
15737                 { "Autoselect Mic", 0x0 },
15738                 { "Internal Mic", 0x1 },
15739                 { "In-0x02", 0x2 },
15740                 { "In-0x03", 0x3 },
15741                 { "In-0x04", 0x4 },
15742                 { "In-0x05", 0x5 },
15743                 { "In-0x06", 0x6 },
15744                 { "In-0x07", 0x7 },
15745                 { "In-0x08", 0x8 },
15746                 { "In-0x09", 0x9 },
15747                 { "In-0x0a", 0x0a },
15748                 { "In-0x0b", 0x0b },
15749                 { "In-0x0c", 0x0c },
15750                 { "In-0x0d", 0x0d },
15751                 { "In-0x0e", 0x0e },
15752                 { "In-0x0f", 0x0f },
15753         },
15754 };
15755 #endif
15756
15757 /*
15758  * 2ch mode
15759  */
15760 static struct hda_channel_mode alc662_3ST_2ch_modes[1] = {
15761         { 2, NULL }
15762 };
15763
15764 /*
15765  * 2ch mode
15766  */
15767 static struct hda_verb alc662_3ST_ch2_init[] = {
15768         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
15769         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
15770         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
15771         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
15772         { } /* end */
15773 };
15774
15775 /*
15776  * 6ch mode
15777  */
15778 static struct hda_verb alc662_3ST_ch6_init[] = {
15779         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15780         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
15781         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
15782         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15783         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
15784         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
15785         { } /* end */
15786 };
15787
15788 static struct hda_channel_mode alc662_3ST_6ch_modes[2] = {
15789         { 2, alc662_3ST_ch2_init },
15790         { 6, alc662_3ST_ch6_init },
15791 };
15792
15793 /*
15794  * 2ch mode
15795  */
15796 static struct hda_verb alc662_sixstack_ch6_init[] = {
15797         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
15798         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
15799         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15800         { } /* end */
15801 };
15802
15803 /*
15804  * 6ch mode
15805  */
15806 static struct hda_verb alc662_sixstack_ch8_init[] = {
15807         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15808         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15809         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15810         { } /* end */
15811 };
15812
15813 static struct hda_channel_mode alc662_5stack_modes[2] = {
15814         { 2, alc662_sixstack_ch6_init },
15815         { 6, alc662_sixstack_ch8_init },
15816 };
15817
15818 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
15819  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
15820  */
15821
15822 static struct snd_kcontrol_new alc662_base_mixer[] = {
15823         /* output mixer control */
15824         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
15825         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
15826         HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
15827         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
15828         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15829         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15830         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
15831         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
15832         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15833
15834         /*Input mixer control */
15835         HDA_CODEC_VOLUME("CD Playback Volume", 0xb, 0x4, HDA_INPUT),
15836         HDA_CODEC_MUTE("CD Playback Switch", 0xb, 0x4, HDA_INPUT),
15837         HDA_CODEC_VOLUME("Line Playback Volume", 0xb, 0x02, HDA_INPUT),
15838         HDA_CODEC_MUTE("Line Playback Switch", 0xb, 0x02, HDA_INPUT),
15839         HDA_CODEC_VOLUME("Mic Playback Volume", 0xb, 0x0, HDA_INPUT),
15840         HDA_CODEC_MUTE("Mic Playback Switch", 0xb, 0x0, HDA_INPUT),
15841         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0xb, 0x01, HDA_INPUT),
15842         HDA_CODEC_MUTE("Front Mic Playback Switch", 0xb, 0x01, HDA_INPUT),
15843         { } /* end */
15844 };
15845
15846 static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
15847         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15848         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
15849         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15850         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
15851         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
15852         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15853         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15854         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15855         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15856         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15857         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15858         { } /* end */
15859 };
15860
15861 static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
15862         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15863         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
15864         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15865         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
15866         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15867         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15868         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
15869         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
15870         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15871         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
15872         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
15873         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15874         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15875         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15876         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15877         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15878         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15879         { } /* end */
15880 };
15881
15882 static struct snd_kcontrol_new alc662_lenovo_101e_mixer[] = {
15883         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15884         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
15885         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15886         HDA_BIND_MUTE("Speaker Playback Switch", 0x03, 2, HDA_INPUT),
15887         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15888         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15889         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15890         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15891         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15892         { } /* end */
15893 };
15894
15895 static struct snd_kcontrol_new alc662_eeepc_p701_mixer[] = {
15896         HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15897         ALC262_HIPPO_MASTER_SWITCH,
15898
15899         HDA_CODEC_VOLUME("e-Mic Boost", 0x18, 0, HDA_INPUT),
15900         HDA_CODEC_VOLUME("e-Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15901         HDA_CODEC_MUTE("e-Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15902
15903         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
15904         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15905         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15906         { } /* end */
15907 };
15908
15909 static struct snd_kcontrol_new alc662_eeepc_ep20_mixer[] = {
15910         ALC262_HIPPO_MASTER_SWITCH,
15911         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15912         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15913         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15914         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15915         HDA_BIND_MUTE("MuteCtrl Playback Switch", 0x0c, 2, HDA_INPUT),
15916         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15917         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15918         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15919         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15920         { } /* end */
15921 };
15922
15923 static struct hda_bind_ctls alc663_asus_bind_master_vol = {
15924         .ops = &snd_hda_bind_vol,
15925         .values = {
15926                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
15927                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
15928                 0
15929         },
15930 };
15931
15932 static struct hda_bind_ctls alc663_asus_one_bind_switch = {
15933         .ops = &snd_hda_bind_sw,
15934         .values = {
15935                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15936                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
15937                 0
15938         },
15939 };
15940
15941 static struct snd_kcontrol_new alc663_m51va_mixer[] = {
15942         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15943         HDA_BIND_SW("Master Playback Switch", &alc663_asus_one_bind_switch),
15944         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15945         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15946         { } /* end */
15947 };
15948
15949 static struct hda_bind_ctls alc663_asus_tree_bind_switch = {
15950         .ops = &snd_hda_bind_sw,
15951         .values = {
15952                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15953                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
15954                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
15955                 0
15956         },
15957 };
15958
15959 static struct snd_kcontrol_new alc663_two_hp_m1_mixer[] = {
15960         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15961         HDA_BIND_SW("Master Playback Switch", &alc663_asus_tree_bind_switch),
15962         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15963         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15964         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15965         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15966
15967         { } /* end */
15968 };
15969
15970 static struct hda_bind_ctls alc663_asus_four_bind_switch = {
15971         .ops = &snd_hda_bind_sw,
15972         .values = {
15973                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15974                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
15975                 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
15976                 0
15977         },
15978 };
15979
15980 static struct snd_kcontrol_new alc663_two_hp_m2_mixer[] = {
15981         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15982         HDA_BIND_SW("Master Playback Switch", &alc663_asus_four_bind_switch),
15983         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15984         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15985         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15986         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15987         { } /* end */
15988 };
15989
15990 static struct snd_kcontrol_new alc662_1bjd_mixer[] = {
15991         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15992         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15993         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15994         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15995         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15996         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15997         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15998         { } /* end */
15999 };
16000
16001 static struct hda_bind_ctls alc663_asus_two_bind_master_vol = {
16002         .ops = &snd_hda_bind_vol,
16003         .values = {
16004                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
16005                 HDA_COMPOSE_AMP_VAL(0x04, 3, 0, HDA_OUTPUT),
16006                 0
16007         },
16008 };
16009
16010 static struct hda_bind_ctls alc663_asus_two_bind_switch = {
16011         .ops = &snd_hda_bind_sw,
16012         .values = {
16013                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
16014                 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT),
16015                 0
16016         },
16017 };
16018
16019 static struct snd_kcontrol_new alc663_asus_21jd_clfe_mixer[] = {
16020         HDA_BIND_VOL("Master Playback Volume",
16021                                 &alc663_asus_two_bind_master_vol),
16022         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
16023         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
16024         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
16025         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16026         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16027         { } /* end */
16028 };
16029
16030 static struct snd_kcontrol_new alc663_asus_15jd_clfe_mixer[] = {
16031         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
16032         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
16033         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
16034         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
16035         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16036         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16037         { } /* end */
16038 };
16039
16040 static struct snd_kcontrol_new alc663_g71v_mixer[] = {
16041         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16042         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
16043         HDA_CODEC_VOLUME("Front Playback Volume", 0x03, 0x0, HDA_OUTPUT),
16044         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
16045         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
16046
16047         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16048         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16049         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16050         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16051         { } /* end */
16052 };
16053
16054 static struct snd_kcontrol_new alc663_g50v_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_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
16058
16059         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16060         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16061         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16062         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16063         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
16064         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
16065         { } /* end */
16066 };
16067
16068 static struct snd_kcontrol_new alc662_chmode_mixer[] = {
16069         {
16070                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
16071                 .name = "Channel Mode",
16072                 .info = alc_ch_mode_info,
16073                 .get = alc_ch_mode_get,
16074                 .put = alc_ch_mode_put,
16075         },
16076         { } /* end */
16077 };
16078
16079 static struct hda_verb alc662_init_verbs[] = {
16080         /* ADC: mute amp left and right */
16081         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16082         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
16083         /* Front mixer: unmute input/output amp left and right (volume = 0) */
16084
16085         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16086         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
16087         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
16088         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
16089         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
16090
16091         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16092         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16093         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16094         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16095         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16096         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16097
16098         /* Front Pin: output 0 (0x0c) */
16099         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16100         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16101
16102         /* Rear Pin: output 1 (0x0d) */
16103         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16104         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16105
16106         /* CLFE Pin: output 2 (0x0e) */
16107         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16108         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16109
16110         /* Mic (rear) pin: input vref at 80% */
16111         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
16112         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16113         /* Front Mic pin: input vref at 80% */
16114         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
16115         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16116         /* Line In pin: input */
16117         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16118         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16119         /* Line-2 In: Headphone output (output 0 - 0x0c) */
16120         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16121         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16122         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
16123         /* CD pin widget for input */
16124         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16125
16126         /* FIXME: use matrix-type input source selection */
16127         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
16128         /* Input mixer */
16129         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16130         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16131
16132         /* always trun on EAPD */
16133         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
16134         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
16135
16136         { }
16137 };
16138
16139 static struct hda_verb alc662_sue_init_verbs[] = {
16140         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
16141         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
16142         {}
16143 };
16144
16145 static struct hda_verb alc662_eeepc_sue_init_verbs[] = {
16146         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16147         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16148         {}
16149 };
16150
16151 /* Set Unsolicited Event*/
16152 static struct hda_verb alc662_eeepc_ep20_sue_init_verbs[] = {
16153         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16154         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16155         {}
16156 };
16157
16158 /*
16159  * generic initialization of ADC, input mixers and output mixers
16160  */
16161 static struct hda_verb alc662_auto_init_verbs[] = {
16162         /*
16163          * Unmute ADC and set the default input to mic-in
16164          */
16165         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
16166         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16167
16168         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
16169          * mixer widget
16170          * Note: PASD motherboards uses the Line In 2 as the input for front
16171          * panel mic (mic 2)
16172          */
16173         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
16174         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16175         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
16176         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
16177         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
16178         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
16179
16180         /*
16181          * Set up output mixers (0x0c - 0x0f)
16182          */
16183         /* set vol=0 to output mixers */
16184         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
16185         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
16186         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
16187
16188         /* set up input amps for analog loopback */
16189         /* Amp Indices: DAC = 0, mixer = 1 */
16190         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16191         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16192         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16193         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16194         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16195         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16196
16197
16198         /* FIXME: use matrix-type input source selection */
16199         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
16200         /* Input mixer */
16201         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16202         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16203         { }
16204 };
16205
16206 /* additional verbs for ALC663 */
16207 static struct hda_verb alc663_auto_init_verbs[] = {
16208         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16209         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16210         { }
16211 };
16212
16213 static struct hda_verb alc663_m51va_init_verbs[] = {
16214         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16215         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16216         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16217         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16218         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16219         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16220         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
16221         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16222         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16223         {}
16224 };
16225
16226 static struct hda_verb alc663_21jd_amic_init_verbs[] = {
16227         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16228         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16229         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16230         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16231         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16232         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16233         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16234         {}
16235 };
16236
16237 static struct hda_verb alc662_1bjd_amic_init_verbs[] = {
16238         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16239         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16240         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16241         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
16242         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16243         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16244         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16245         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16246         {}
16247 };
16248
16249 static struct hda_verb alc663_15jd_amic_init_verbs[] = {
16250         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16251         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16252         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16253         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16254         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16255         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16256         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16257         {}
16258 };
16259
16260 static struct hda_verb alc663_two_hp_amic_m1_init_verbs[] = {
16261         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16262         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16263         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16264         {0x21, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
16265         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16266         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16267         {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
16268         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16269         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16270         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16271         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16272         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16273         {}
16274 };
16275
16276 static struct hda_verb alc663_two_hp_amic_m2_init_verbs[] = {
16277         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16278         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16279         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16280         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16281         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16282         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16283         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16284         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16285         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16286         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16287         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16288         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16289         {}
16290 };
16291
16292 static struct hda_verb alc663_g71v_init_verbs[] = {
16293         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16294         /* {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
16295         /* {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, */ /* Headphone */
16296
16297         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16298         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16299         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
16300
16301         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
16302         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_MIC_EVENT},
16303         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
16304         {}
16305 };
16306
16307 static struct hda_verb alc663_g50v_init_verbs[] = {
16308         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16309         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16310         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
16311
16312         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16313         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16314         {}
16315 };
16316
16317 static struct hda_verb alc662_ecs_init_verbs[] = {
16318         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0x701f},
16319         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16320         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16321         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16322         {}
16323 };
16324
16325 static struct hda_verb alc272_dell_zm1_init_verbs[] = {
16326         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16327         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16328         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16329         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16330         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16331         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16332         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16333         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16334         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
16335         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16336         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16337         {}
16338 };
16339
16340 static struct hda_verb alc272_dell_init_verbs[] = {
16341         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16342         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16343         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16344         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16345         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16346         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16347         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16348         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16349         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
16350         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16351         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16352         {}
16353 };
16354
16355 static struct snd_kcontrol_new alc662_auto_capture_mixer[] = {
16356         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
16357         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
16358         { } /* end */
16359 };
16360
16361 static struct snd_kcontrol_new alc272_auto_capture_mixer[] = {
16362         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
16363         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
16364         { } /* end */
16365 };
16366
16367 static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
16368 {
16369         unsigned int present;
16370         unsigned char bits;
16371
16372         present = snd_hda_codec_read(codec, 0x14, 0,
16373                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
16374         bits = present ? HDA_AMP_MUTE : 0;
16375         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
16376                                  HDA_AMP_MUTE, bits);
16377 }
16378
16379 static void alc662_lenovo_101e_all_automute(struct hda_codec *codec)
16380 {
16381         unsigned int present;
16382         unsigned char bits;
16383
16384         present = snd_hda_codec_read(codec, 0x1b, 0,
16385                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
16386         bits = present ? HDA_AMP_MUTE : 0;
16387         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
16388                                  HDA_AMP_MUTE, bits);
16389         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
16390                                  HDA_AMP_MUTE, bits);
16391 }
16392
16393 static void alc662_lenovo_101e_unsol_event(struct hda_codec *codec,
16394                                            unsigned int res)
16395 {
16396         if ((res >> 26) == ALC880_HP_EVENT)
16397                 alc662_lenovo_101e_all_automute(codec);
16398         if ((res >> 26) == ALC880_FRONT_EVENT)
16399                 alc662_lenovo_101e_ispeaker_automute(codec);
16400 }
16401
16402 /* unsolicited event for HP jack sensing */
16403 static void alc662_eeepc_unsol_event(struct hda_codec *codec,
16404                                      unsigned int res)
16405 {
16406         if ((res >> 26) == ALC880_MIC_EVENT)
16407                 alc_mic_automute(codec);
16408         else
16409                 alc262_hippo_unsol_event(codec, res);
16410 }
16411
16412 static void alc662_eeepc_setup(struct hda_codec *codec)
16413 {
16414         struct alc_spec *spec = codec->spec;
16415
16416         alc262_hippo1_setup(codec);
16417         spec->ext_mic.pin = 0x18;
16418         spec->ext_mic.mux_idx = 0;
16419         spec->int_mic.pin = 0x19;
16420         spec->int_mic.mux_idx = 1;
16421         spec->auto_mic = 1;
16422 }
16423
16424 static void alc662_eeepc_inithook(struct hda_codec *codec)
16425 {
16426         alc262_hippo_automute(codec);
16427         alc_mic_automute(codec);
16428 }
16429
16430 static void alc662_eeepc_ep20_setup(struct hda_codec *codec)
16431 {
16432         struct alc_spec *spec = codec->spec;
16433
16434         spec->autocfg.hp_pins[0] = 0x14;
16435         spec->autocfg.speaker_pins[0] = 0x1b;
16436 }
16437
16438 #define alc662_eeepc_ep20_inithook      alc262_hippo_master_update
16439
16440 static void alc663_m51va_speaker_automute(struct hda_codec *codec)
16441 {
16442         unsigned int present;
16443         unsigned char bits;
16444
16445         present = snd_hda_codec_read(codec, 0x21, 0,
16446                         AC_VERB_GET_PIN_SENSE, 0)
16447                         & AC_PINSENSE_PRESENCE;
16448         bits = present ? HDA_AMP_MUTE : 0;
16449         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16450                                 AMP_IN_MUTE(0), bits);
16451         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16452                                 AMP_IN_MUTE(0), bits);
16453 }
16454
16455 static void alc663_21jd_two_speaker_automute(struct hda_codec *codec)
16456 {
16457         unsigned int present;
16458         unsigned char bits;
16459
16460         present = snd_hda_codec_read(codec, 0x21, 0,
16461                         AC_VERB_GET_PIN_SENSE, 0)
16462                         & AC_PINSENSE_PRESENCE;
16463         bits = present ? HDA_AMP_MUTE : 0;
16464         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16465                                 AMP_IN_MUTE(0), bits);
16466         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16467                                 AMP_IN_MUTE(0), bits);
16468         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
16469                                 AMP_IN_MUTE(0), bits);
16470         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
16471                                 AMP_IN_MUTE(0), bits);
16472 }
16473
16474 static void alc663_15jd_two_speaker_automute(struct hda_codec *codec)
16475 {
16476         unsigned int present;
16477         unsigned char bits;
16478
16479         present = snd_hda_codec_read(codec, 0x15, 0,
16480                         AC_VERB_GET_PIN_SENSE, 0)
16481                         & AC_PINSENSE_PRESENCE;
16482         bits = present ? HDA_AMP_MUTE : 0;
16483         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16484                                 AMP_IN_MUTE(0), bits);
16485         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16486                                 AMP_IN_MUTE(0), bits);
16487         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
16488                                 AMP_IN_MUTE(0), bits);
16489         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
16490                                 AMP_IN_MUTE(0), bits);
16491 }
16492
16493 static void alc662_f5z_speaker_automute(struct hda_codec *codec)
16494 {
16495         unsigned int present;
16496         unsigned char bits;
16497
16498         present = snd_hda_codec_read(codec, 0x1b, 0,
16499                         AC_VERB_GET_PIN_SENSE, 0)
16500                         & AC_PINSENSE_PRESENCE;
16501         bits = present ? 0 : PIN_OUT;
16502         snd_hda_codec_write(codec, 0x14, 0,
16503                          AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
16504 }
16505
16506 static void alc663_two_hp_m1_speaker_automute(struct hda_codec *codec)
16507 {
16508         unsigned int present1, present2;
16509
16510         present1 = snd_hda_codec_read(codec, 0x21, 0,
16511                         AC_VERB_GET_PIN_SENSE, 0)
16512                         & AC_PINSENSE_PRESENCE;
16513         present2 = snd_hda_codec_read(codec, 0x15, 0,
16514                         AC_VERB_GET_PIN_SENSE, 0)
16515                         & AC_PINSENSE_PRESENCE;
16516
16517         if (present1 || present2) {
16518                 snd_hda_codec_write_cache(codec, 0x14, 0,
16519                         AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
16520         } else {
16521                 snd_hda_codec_write_cache(codec, 0x14, 0,
16522                         AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
16523         }
16524 }
16525
16526 static void alc663_two_hp_m2_speaker_automute(struct hda_codec *codec)
16527 {
16528         unsigned int present1, present2;
16529
16530         present1 = snd_hda_codec_read(codec, 0x1b, 0,
16531                                 AC_VERB_GET_PIN_SENSE, 0)
16532                                 & AC_PINSENSE_PRESENCE;
16533         present2 = snd_hda_codec_read(codec, 0x15, 0,
16534                                 AC_VERB_GET_PIN_SENSE, 0)
16535                                 & AC_PINSENSE_PRESENCE;
16536
16537         if (present1 || present2) {
16538                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16539                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
16540                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16541                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
16542         } else {
16543                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16544                                 AMP_IN_MUTE(0), 0);
16545                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16546                                 AMP_IN_MUTE(0), 0);
16547         }
16548 }
16549
16550 static void alc663_m51va_unsol_event(struct hda_codec *codec,
16551                                            unsigned int res)
16552 {
16553         switch (res >> 26) {
16554         case ALC880_HP_EVENT:
16555                 alc663_m51va_speaker_automute(codec);
16556                 break;
16557         case ALC880_MIC_EVENT:
16558                 alc_mic_automute(codec);
16559                 break;
16560         }
16561 }
16562
16563 static void alc663_m51va_setup(struct hda_codec *codec)
16564 {
16565         struct alc_spec *spec = codec->spec;
16566         spec->ext_mic.pin = 0x18;
16567         spec->ext_mic.mux_idx = 0;
16568         spec->int_mic.pin = 0x12;
16569         spec->int_mic.mux_idx = 1;
16570         spec->auto_mic = 1;
16571 }
16572
16573 static void alc663_m51va_inithook(struct hda_codec *codec)
16574 {
16575         alc663_m51va_speaker_automute(codec);
16576         alc_mic_automute(codec);
16577 }
16578
16579 /* ***************** Mode1 ******************************/
16580 #define alc663_mode1_unsol_event        alc663_m51va_unsol_event
16581 #define alc663_mode1_setup              alc663_m51va_setup
16582 #define alc663_mode1_inithook           alc663_m51va_inithook
16583
16584 /* ***************** Mode2 ******************************/
16585 static void alc662_mode2_unsol_event(struct hda_codec *codec,
16586                                            unsigned int res)
16587 {
16588         switch (res >> 26) {
16589         case ALC880_HP_EVENT:
16590                 alc662_f5z_speaker_automute(codec);
16591                 break;
16592         case ALC880_MIC_EVENT:
16593                 alc_mic_automute(codec);
16594                 break;
16595         }
16596 }
16597
16598 #define alc662_mode2_setup      alc663_m51va_setup
16599
16600 static void alc662_mode2_inithook(struct hda_codec *codec)
16601 {
16602         alc662_f5z_speaker_automute(codec);
16603         alc_mic_automute(codec);
16604 }
16605 /* ***************** Mode3 ******************************/
16606 static void alc663_mode3_unsol_event(struct hda_codec *codec,
16607                                            unsigned int res)
16608 {
16609         switch (res >> 26) {
16610         case ALC880_HP_EVENT:
16611                 alc663_two_hp_m1_speaker_automute(codec);
16612                 break;
16613         case ALC880_MIC_EVENT:
16614                 alc_mic_automute(codec);
16615                 break;
16616         }
16617 }
16618
16619 #define alc663_mode3_setup      alc663_m51va_setup
16620
16621 static void alc663_mode3_inithook(struct hda_codec *codec)
16622 {
16623         alc663_two_hp_m1_speaker_automute(codec);
16624         alc_mic_automute(codec);
16625 }
16626 /* ***************** Mode4 ******************************/
16627 static void alc663_mode4_unsol_event(struct hda_codec *codec,
16628                                            unsigned int res)
16629 {
16630         switch (res >> 26) {
16631         case ALC880_HP_EVENT:
16632                 alc663_21jd_two_speaker_automute(codec);
16633                 break;
16634         case ALC880_MIC_EVENT:
16635                 alc_mic_automute(codec);
16636                 break;
16637         }
16638 }
16639
16640 #define alc663_mode4_setup      alc663_m51va_setup
16641
16642 static void alc663_mode4_inithook(struct hda_codec *codec)
16643 {
16644         alc663_21jd_two_speaker_automute(codec);
16645         alc_mic_automute(codec);
16646 }
16647 /* ***************** Mode5 ******************************/
16648 static void alc663_mode5_unsol_event(struct hda_codec *codec,
16649                                            unsigned int res)
16650 {
16651         switch (res >> 26) {
16652         case ALC880_HP_EVENT:
16653                 alc663_15jd_two_speaker_automute(codec);
16654                 break;
16655         case ALC880_MIC_EVENT:
16656                 alc_mic_automute(codec);
16657                 break;
16658         }
16659 }
16660
16661 #define alc663_mode5_setup      alc663_m51va_setup
16662
16663 static void alc663_mode5_inithook(struct hda_codec *codec)
16664 {
16665         alc663_15jd_two_speaker_automute(codec);
16666         alc_mic_automute(codec);
16667 }
16668 /* ***************** Mode6 ******************************/
16669 static void alc663_mode6_unsol_event(struct hda_codec *codec,
16670                                            unsigned int res)
16671 {
16672         switch (res >> 26) {
16673         case ALC880_HP_EVENT:
16674                 alc663_two_hp_m2_speaker_automute(codec);
16675                 break;
16676         case ALC880_MIC_EVENT:
16677                 alc_mic_automute(codec);
16678                 break;
16679         }
16680 }
16681
16682 #define alc663_mode6_setup      alc663_m51va_setup
16683
16684 static void alc663_mode6_inithook(struct hda_codec *codec)
16685 {
16686         alc663_two_hp_m2_speaker_automute(codec);
16687         alc_mic_automute(codec);
16688 }
16689
16690 static void alc663_g71v_hp_automute(struct hda_codec *codec)
16691 {
16692         unsigned int present;
16693         unsigned char bits;
16694
16695         present = snd_hda_codec_read(codec, 0x21, 0,
16696                                      AC_VERB_GET_PIN_SENSE, 0)
16697                 & AC_PINSENSE_PRESENCE;
16698         bits = present ? HDA_AMP_MUTE : 0;
16699         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
16700                                  HDA_AMP_MUTE, bits);
16701         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
16702                                  HDA_AMP_MUTE, bits);
16703 }
16704
16705 static void alc663_g71v_front_automute(struct hda_codec *codec)
16706 {
16707         unsigned int present;
16708         unsigned char bits;
16709
16710         present = snd_hda_codec_read(codec, 0x15, 0,
16711                                      AC_VERB_GET_PIN_SENSE, 0)
16712                 & AC_PINSENSE_PRESENCE;
16713         bits = present ? HDA_AMP_MUTE : 0;
16714         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
16715                                  HDA_AMP_MUTE, bits);
16716 }
16717
16718 static void alc663_g71v_unsol_event(struct hda_codec *codec,
16719                                            unsigned int res)
16720 {
16721         switch (res >> 26) {
16722         case ALC880_HP_EVENT:
16723                 alc663_g71v_hp_automute(codec);
16724                 break;
16725         case ALC880_FRONT_EVENT:
16726                 alc663_g71v_front_automute(codec);
16727                 break;
16728         case ALC880_MIC_EVENT:
16729                 alc_mic_automute(codec);
16730                 break;
16731         }
16732 }
16733
16734 #define alc663_g71v_setup       alc663_m51va_setup
16735
16736 static void alc663_g71v_inithook(struct hda_codec *codec)
16737 {
16738         alc663_g71v_front_automute(codec);
16739         alc663_g71v_hp_automute(codec);
16740         alc_mic_automute(codec);
16741 }
16742
16743 static void alc663_g50v_unsol_event(struct hda_codec *codec,
16744                                            unsigned int res)
16745 {
16746         switch (res >> 26) {
16747         case ALC880_HP_EVENT:
16748                 alc663_m51va_speaker_automute(codec);
16749                 break;
16750         case ALC880_MIC_EVENT:
16751                 alc_mic_automute(codec);
16752                 break;
16753         }
16754 }
16755
16756 #define alc663_g50v_setup       alc663_m51va_setup
16757
16758 static void alc663_g50v_inithook(struct hda_codec *codec)
16759 {
16760         alc663_m51va_speaker_automute(codec);
16761         alc_mic_automute(codec);
16762 }
16763
16764 static struct snd_kcontrol_new alc662_ecs_mixer[] = {
16765         HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16766         ALC262_HIPPO_MASTER_SWITCH,
16767
16768         HDA_CODEC_VOLUME("e-Mic/LineIn Boost", 0x18, 0, HDA_INPUT),
16769         HDA_CODEC_VOLUME("e-Mic/LineIn Playback Volume", 0x0b, 0x0, HDA_INPUT),
16770         HDA_CODEC_MUTE("e-Mic/LineIn Playback Switch", 0x0b, 0x0, HDA_INPUT),
16771
16772         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
16773         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16774         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16775         { } /* end */
16776 };
16777
16778 static struct snd_kcontrol_new alc272_nc10_mixer[] = {
16779         /* Master Playback automatically created from Speaker and Headphone */
16780         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16781         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
16782         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
16783         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
16784
16785         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16786         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16787         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
16788
16789         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16790         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16791         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
16792         { } /* end */
16793 };
16794
16795 #ifdef CONFIG_SND_HDA_POWER_SAVE
16796 #define alc662_loopbacks        alc880_loopbacks
16797 #endif
16798
16799
16800 /* pcm configuration: identical with ALC880 */
16801 #define alc662_pcm_analog_playback      alc880_pcm_analog_playback
16802 #define alc662_pcm_analog_capture       alc880_pcm_analog_capture
16803 #define alc662_pcm_digital_playback     alc880_pcm_digital_playback
16804 #define alc662_pcm_digital_capture      alc880_pcm_digital_capture
16805
16806 /*
16807  * configuration and preset
16808  */
16809 static const char *alc662_models[ALC662_MODEL_LAST] = {
16810         [ALC662_3ST_2ch_DIG]    = "3stack-dig",
16811         [ALC662_3ST_6ch_DIG]    = "3stack-6ch-dig",
16812         [ALC662_3ST_6ch]        = "3stack-6ch",
16813         [ALC662_5ST_DIG]        = "6stack-dig",
16814         [ALC662_LENOVO_101E]    = "lenovo-101e",
16815         [ALC662_ASUS_EEEPC_P701] = "eeepc-p701",
16816         [ALC662_ASUS_EEEPC_EP20] = "eeepc-ep20",
16817         [ALC662_ECS] = "ecs",
16818         [ALC663_ASUS_M51VA] = "m51va",
16819         [ALC663_ASUS_G71V] = "g71v",
16820         [ALC663_ASUS_H13] = "h13",
16821         [ALC663_ASUS_G50V] = "g50v",
16822         [ALC663_ASUS_MODE1] = "asus-mode1",
16823         [ALC662_ASUS_MODE2] = "asus-mode2",
16824         [ALC663_ASUS_MODE3] = "asus-mode3",
16825         [ALC663_ASUS_MODE4] = "asus-mode4",
16826         [ALC663_ASUS_MODE5] = "asus-mode5",
16827         [ALC663_ASUS_MODE6] = "asus-mode6",
16828         [ALC272_DELL]           = "dell",
16829         [ALC272_DELL_ZM1]       = "dell-zm1",
16830         [ALC272_SAMSUNG_NC10]   = "samsung-nc10",
16831         [ALC662_AUTO]           = "auto",
16832 };
16833
16834 static struct snd_pci_quirk alc662_cfg_tbl[] = {
16835         SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_ECS),
16836         SND_PCI_QUIRK(0x1028, 0x02d6, "DELL", ALC272_DELL),
16837         SND_PCI_QUIRK(0x1028, 0x02f4, "DELL ZM1", ALC272_DELL_ZM1),
16838         SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC663_ASUS_MODE1),
16839         SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC663_ASUS_MODE3),
16840         SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC663_ASUS_MODE3),
16841         SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC663_ASUS_MODE1),
16842         SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_ASUS_MODE2),
16843         SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC663_ASUS_MODE1),
16844         SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_ASUS_MODE2),
16845         SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_ASUS_MODE2),
16846         SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_ASUS_MODE2),
16847         SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC663_ASUS_MODE6),
16848         SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC663_ASUS_MODE6),
16849         SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_ASUS_MODE2),
16850         SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC663_ASUS_MODE3),
16851         SND_PCI_QUIRK(0x1043, 0x17c3, "ASUS UX20", ALC663_ASUS_M51VA),
16852         SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_ASUS_MODE2),
16853         SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_ASUS_MODE2),
16854         SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC663_ASUS_MODE5),
16855         SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC663_ASUS_MODE6),
16856         SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_ASUS_MODE2),
16857         SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC663_ASUS_MODE1),
16858         SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_ASUS_MODE2),
16859         SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_ASUS_MODE2),
16860         SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M51VA", ALC663_ASUS_M51VA),
16861         /*SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M50Vr", ALC663_ASUS_MODE1),*/
16862         SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC663_ASUS_MODE3),
16863         SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC663_ASUS_MODE3),
16864         SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC663_ASUS_MODE1),
16865         SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC663_ASUS_MODE1),
16866         SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC663_ASUS_MODE1),
16867         SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC663_ASUS_MODE1),
16868         SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_ASUS_MODE2),
16869         SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_ASUS_MODE2),
16870         SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC663_ASUS_MODE1),
16871         SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC663_ASUS_MODE1),
16872         SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC663_ASUS_MODE3),
16873         SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC663_ASUS_MODE1),
16874         SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC663_ASUS_MODE1),
16875         SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS G50V", ALC663_ASUS_G50V),
16876         /*SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS NB", ALC663_ASUS_MODE1),*/
16877         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC663_ASUS_MODE1),
16878         SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_ASUS_MODE2),
16879         SND_PCI_QUIRK(0x1043, 0x19d3, "ASUS NB", ALC663_ASUS_M51VA),
16880         SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC663_ASUS_MODE1),
16881         SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC663_ASUS_MODE4),
16882         SND_PCI_QUIRK(0x1043, 0x8290, "ASUS P5GC-MX", ALC662_3ST_6ch_DIG),
16883         SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
16884         SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20),
16885         SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_ECS),
16886         SND_PCI_QUIRK(0x105b, 0x0d47, "Foxconn 45CMX/45GMX/45CMX-K",
16887                       ALC662_3ST_6ch_DIG),
16888         SND_PCI_QUIRK(0x1179, 0xff6e, "Toshiba NB200", ALC663_ASUS_MODE4),
16889         SND_PCI_QUIRK(0x144d, 0xca00, "Samsung NC10", ALC272_SAMSUNG_NC10),
16890         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte 945GCM-S2L",
16891                       ALC662_3ST_6ch_DIG),
16892         SND_PCI_QUIRK(0x1565, 0x820f, "Biostar TA780G M2+", ALC662_3ST_6ch_DIG),
16893         SND_PCI_QUIRK(0x1631, 0xc10c, "PB RS65", ALC663_ASUS_M51VA),
16894         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
16895         SND_PCI_QUIRK(0x1849, 0x3662, "ASROCK K10N78FullHD-hSLI R3.0",
16896                                         ALC662_3ST_6ch_DIG),
16897         SND_PCI_QUIRK_MASK(0x1854, 0xf000, 0x2000, "ASUS H13-200x",
16898                            ALC663_ASUS_H13),
16899         {}
16900 };
16901
16902 static struct alc_config_preset alc662_presets[] = {
16903         [ALC662_3ST_2ch_DIG] = {
16904                 .mixers = { alc662_3ST_2ch_mixer },
16905                 .init_verbs = { alc662_init_verbs },
16906                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16907                 .dac_nids = alc662_dac_nids,
16908                 .dig_out_nid = ALC662_DIGOUT_NID,
16909                 .dig_in_nid = ALC662_DIGIN_NID,
16910                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16911                 .channel_mode = alc662_3ST_2ch_modes,
16912                 .input_mux = &alc662_capture_source,
16913         },
16914         [ALC662_3ST_6ch_DIG] = {
16915                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
16916                 .init_verbs = { alc662_init_verbs },
16917                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16918                 .dac_nids = alc662_dac_nids,
16919                 .dig_out_nid = ALC662_DIGOUT_NID,
16920                 .dig_in_nid = ALC662_DIGIN_NID,
16921                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16922                 .channel_mode = alc662_3ST_6ch_modes,
16923                 .need_dac_fix = 1,
16924                 .input_mux = &alc662_capture_source,
16925         },
16926         [ALC662_3ST_6ch] = {
16927                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
16928                 .init_verbs = { alc662_init_verbs },
16929                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16930                 .dac_nids = alc662_dac_nids,
16931                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16932                 .channel_mode = alc662_3ST_6ch_modes,
16933                 .need_dac_fix = 1,
16934                 .input_mux = &alc662_capture_source,
16935         },
16936         [ALC662_5ST_DIG] = {
16937                 .mixers = { alc662_base_mixer, alc662_chmode_mixer },
16938                 .init_verbs = { alc662_init_verbs },
16939                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16940                 .dac_nids = alc662_dac_nids,
16941                 .dig_out_nid = ALC662_DIGOUT_NID,
16942                 .dig_in_nid = ALC662_DIGIN_NID,
16943                 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
16944                 .channel_mode = alc662_5stack_modes,
16945                 .input_mux = &alc662_capture_source,
16946         },
16947         [ALC662_LENOVO_101E] = {
16948                 .mixers = { alc662_lenovo_101e_mixer },
16949                 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs },
16950                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16951                 .dac_nids = alc662_dac_nids,
16952                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16953                 .channel_mode = alc662_3ST_2ch_modes,
16954                 .input_mux = &alc662_lenovo_101e_capture_source,
16955                 .unsol_event = alc662_lenovo_101e_unsol_event,
16956                 .init_hook = alc662_lenovo_101e_all_automute,
16957         },
16958         [ALC662_ASUS_EEEPC_P701] = {
16959                 .mixers = { alc662_eeepc_p701_mixer },
16960                 .init_verbs = { alc662_init_verbs,
16961                                 alc662_eeepc_sue_init_verbs },
16962                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16963                 .dac_nids = alc662_dac_nids,
16964                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16965                 .channel_mode = alc662_3ST_2ch_modes,
16966                 .unsol_event = alc662_eeepc_unsol_event,
16967                 .setup = alc662_eeepc_setup,
16968                 .init_hook = alc662_eeepc_inithook,
16969         },
16970         [ALC662_ASUS_EEEPC_EP20] = {
16971                 .mixers = { alc662_eeepc_ep20_mixer,
16972                             alc662_chmode_mixer },
16973                 .init_verbs = { alc662_init_verbs,
16974                                 alc662_eeepc_ep20_sue_init_verbs },
16975                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16976                 .dac_nids = alc662_dac_nids,
16977                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16978                 .channel_mode = alc662_3ST_6ch_modes,
16979                 .input_mux = &alc662_lenovo_101e_capture_source,
16980                 .unsol_event = alc662_eeepc_unsol_event,
16981                 .setup = alc662_eeepc_ep20_setup,
16982                 .init_hook = alc662_eeepc_ep20_inithook,
16983         },
16984         [ALC662_ECS] = {
16985                 .mixers = { alc662_ecs_mixer },
16986                 .init_verbs = { alc662_init_verbs,
16987                                 alc662_ecs_init_verbs },
16988                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16989                 .dac_nids = alc662_dac_nids,
16990                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16991                 .channel_mode = alc662_3ST_2ch_modes,
16992                 .unsol_event = alc662_eeepc_unsol_event,
16993                 .setup = alc662_eeepc_setup,
16994                 .init_hook = alc662_eeepc_inithook,
16995         },
16996         [ALC663_ASUS_M51VA] = {
16997                 .mixers = { alc663_m51va_mixer },
16998                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
16999                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17000                 .dac_nids = alc662_dac_nids,
17001                 .dig_out_nid = ALC662_DIGOUT_NID,
17002                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17003                 .channel_mode = alc662_3ST_2ch_modes,
17004                 .unsol_event = alc663_m51va_unsol_event,
17005                 .setup = alc663_m51va_setup,
17006                 .init_hook = alc663_m51va_inithook,
17007         },
17008         [ALC663_ASUS_G71V] = {
17009                 .mixers = { alc663_g71v_mixer },
17010                 .init_verbs = { alc662_init_verbs, alc663_g71v_init_verbs },
17011                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17012                 .dac_nids = alc662_dac_nids,
17013                 .dig_out_nid = ALC662_DIGOUT_NID,
17014                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17015                 .channel_mode = alc662_3ST_2ch_modes,
17016                 .unsol_event = alc663_g71v_unsol_event,
17017                 .setup = alc663_g71v_setup,
17018                 .init_hook = alc663_g71v_inithook,
17019         },
17020         [ALC663_ASUS_H13] = {
17021                 .mixers = { alc663_m51va_mixer },
17022                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
17023                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17024                 .dac_nids = alc662_dac_nids,
17025                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17026                 .channel_mode = alc662_3ST_2ch_modes,
17027                 .unsol_event = alc663_m51va_unsol_event,
17028                 .init_hook = alc663_m51va_inithook,
17029         },
17030         [ALC663_ASUS_G50V] = {
17031                 .mixers = { alc663_g50v_mixer },
17032                 .init_verbs = { alc662_init_verbs, alc663_g50v_init_verbs },
17033                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17034                 .dac_nids = alc662_dac_nids,
17035                 .dig_out_nid = ALC662_DIGOUT_NID,
17036                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
17037                 .channel_mode = alc662_3ST_6ch_modes,
17038                 .input_mux = &alc663_capture_source,
17039                 .unsol_event = alc663_g50v_unsol_event,
17040                 .setup = alc663_g50v_setup,
17041                 .init_hook = alc663_g50v_inithook,
17042         },
17043         [ALC663_ASUS_MODE1] = {
17044                 .mixers = { alc663_m51va_mixer },
17045                 .cap_mixer = alc662_auto_capture_mixer,
17046                 .init_verbs = { alc662_init_verbs,
17047                                 alc663_21jd_amic_init_verbs },
17048                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17049                 .hp_nid = 0x03,
17050                 .dac_nids = alc662_dac_nids,
17051                 .dig_out_nid = ALC662_DIGOUT_NID,
17052                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17053                 .channel_mode = alc662_3ST_2ch_modes,
17054                 .unsol_event = alc663_mode1_unsol_event,
17055                 .setup = alc663_mode1_setup,
17056                 .init_hook = alc663_mode1_inithook,
17057         },
17058         [ALC662_ASUS_MODE2] = {
17059                 .mixers = { alc662_1bjd_mixer },
17060                 .cap_mixer = alc662_auto_capture_mixer,
17061                 .init_verbs = { alc662_init_verbs,
17062                                 alc662_1bjd_amic_init_verbs },
17063                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
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 = alc662_mode2_unsol_event,
17069                 .setup = alc662_mode2_setup,
17070                 .init_hook = alc662_mode2_inithook,
17071         },
17072         [ALC663_ASUS_MODE3] = {
17073                 .mixers = { alc663_two_hp_m1_mixer },
17074                 .cap_mixer = alc662_auto_capture_mixer,
17075                 .init_verbs = { alc662_init_verbs,
17076                                 alc663_two_hp_amic_m1_init_verbs },
17077                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17078                 .hp_nid = 0x03,
17079                 .dac_nids = alc662_dac_nids,
17080                 .dig_out_nid = ALC662_DIGOUT_NID,
17081                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17082                 .channel_mode = alc662_3ST_2ch_modes,
17083                 .unsol_event = alc663_mode3_unsol_event,
17084                 .setup = alc663_mode3_setup,
17085                 .init_hook = alc663_mode3_inithook,
17086         },
17087         [ALC663_ASUS_MODE4] = {
17088                 .mixers = { alc663_asus_21jd_clfe_mixer },
17089                 .cap_mixer = alc662_auto_capture_mixer,
17090                 .init_verbs = { alc662_init_verbs,
17091                                 alc663_21jd_amic_init_verbs},
17092                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17093                 .hp_nid = 0x03,
17094                 .dac_nids = alc662_dac_nids,
17095                 .dig_out_nid = ALC662_DIGOUT_NID,
17096                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17097                 .channel_mode = alc662_3ST_2ch_modes,
17098                 .unsol_event = alc663_mode4_unsol_event,
17099                 .setup = alc663_mode4_setup,
17100                 .init_hook = alc663_mode4_inithook,
17101         },
17102         [ALC663_ASUS_MODE5] = {
17103                 .mixers = { alc663_asus_15jd_clfe_mixer },
17104                 .cap_mixer = alc662_auto_capture_mixer,
17105                 .init_verbs = { alc662_init_verbs,
17106                                 alc663_15jd_amic_init_verbs },
17107                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17108                 .hp_nid = 0x03,
17109                 .dac_nids = alc662_dac_nids,
17110                 .dig_out_nid = ALC662_DIGOUT_NID,
17111                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17112                 .channel_mode = alc662_3ST_2ch_modes,
17113                 .unsol_event = alc663_mode5_unsol_event,
17114                 .setup = alc663_mode5_setup,
17115                 .init_hook = alc663_mode5_inithook,
17116         },
17117         [ALC663_ASUS_MODE6] = {
17118                 .mixers = { alc663_two_hp_m2_mixer },
17119                 .cap_mixer = alc662_auto_capture_mixer,
17120                 .init_verbs = { alc662_init_verbs,
17121                                 alc663_two_hp_amic_m2_init_verbs },
17122                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17123                 .hp_nid = 0x03,
17124                 .dac_nids = alc662_dac_nids,
17125                 .dig_out_nid = ALC662_DIGOUT_NID,
17126                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17127                 .channel_mode = alc662_3ST_2ch_modes,
17128                 .unsol_event = alc663_mode6_unsol_event,
17129                 .setup = alc663_mode6_setup,
17130                 .init_hook = alc663_mode6_inithook,
17131         },
17132         [ALC272_DELL] = {
17133                 .mixers = { alc663_m51va_mixer },
17134                 .cap_mixer = alc272_auto_capture_mixer,
17135                 .init_verbs = { alc662_init_verbs, alc272_dell_init_verbs },
17136                 .num_dacs = ARRAY_SIZE(alc272_dac_nids),
17137                 .dac_nids = alc662_dac_nids,
17138                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17139                 .adc_nids = alc272_adc_nids,
17140                 .num_adc_nids = ARRAY_SIZE(alc272_adc_nids),
17141                 .capsrc_nids = alc272_capsrc_nids,
17142                 .channel_mode = alc662_3ST_2ch_modes,
17143                 .unsol_event = alc663_m51va_unsol_event,
17144                 .setup = alc663_m51va_setup,
17145                 .init_hook = alc663_m51va_inithook,
17146         },
17147         [ALC272_DELL_ZM1] = {
17148                 .mixers = { alc663_m51va_mixer },
17149                 .cap_mixer = alc662_auto_capture_mixer,
17150                 .init_verbs = { alc662_init_verbs, alc272_dell_zm1_init_verbs },
17151                 .num_dacs = ARRAY_SIZE(alc272_dac_nids),
17152                 .dac_nids = alc662_dac_nids,
17153                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17154                 .adc_nids = alc662_adc_nids,
17155                 .num_adc_nids = 1,
17156                 .capsrc_nids = alc662_capsrc_nids,
17157                 .channel_mode = alc662_3ST_2ch_modes,
17158                 .unsol_event = alc663_m51va_unsol_event,
17159                 .setup = alc663_m51va_setup,
17160                 .init_hook = alc663_m51va_inithook,
17161         },
17162         [ALC272_SAMSUNG_NC10] = {
17163                 .mixers = { alc272_nc10_mixer },
17164                 .init_verbs = { alc662_init_verbs,
17165                                 alc663_21jd_amic_init_verbs },
17166                 .num_dacs = ARRAY_SIZE(alc272_dac_nids),
17167                 .dac_nids = alc272_dac_nids,
17168                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17169                 .channel_mode = alc662_3ST_2ch_modes,
17170                 /*.input_mux = &alc272_nc10_capture_source,*/
17171                 .unsol_event = alc663_mode4_unsol_event,
17172                 .setup = alc663_mode4_setup,
17173                 .init_hook = alc663_mode4_inithook,
17174         },
17175 };
17176
17177
17178 /*
17179  * BIOS auto configuration
17180  */
17181
17182 /* convert from MIX nid to DAC */
17183 static inline hda_nid_t alc662_mix_to_dac(hda_nid_t nid)
17184 {
17185         if (nid == 0x0f)
17186                 return 0x02;
17187         else if (nid >= 0x0c && nid <= 0x0e)
17188                 return nid - 0x0c + 0x02;
17189         else
17190                 return 0;
17191 }
17192
17193 /* get MIX nid connected to the given pin targeted to DAC */
17194 static hda_nid_t alc662_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
17195                                    hda_nid_t dac)
17196 {
17197         hda_nid_t mix[4];
17198         int i, num;
17199
17200         num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
17201         for (i = 0; i < num; i++) {
17202                 if (alc662_mix_to_dac(mix[i]) == dac)
17203                         return mix[i];
17204         }
17205         return 0;
17206 }
17207
17208 /* look for an empty DAC slot */
17209 static hda_nid_t alc662_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
17210 {
17211         struct alc_spec *spec = codec->spec;
17212         hda_nid_t srcs[5];
17213         int i, j, num;
17214
17215         num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
17216         if (num < 0)
17217                 return 0;
17218         for (i = 0; i < num; i++) {
17219                 hda_nid_t nid = alc662_mix_to_dac(srcs[i]);
17220                 if (!nid)
17221                         continue;
17222                 for (j = 0; j < spec->multiout.num_dacs; j++)
17223                         if (spec->multiout.dac_nids[j] == nid)
17224                                 break;
17225                 if (j >= spec->multiout.num_dacs)
17226                         return nid;
17227         }
17228         return 0;
17229 }
17230
17231 /* fill in the dac_nids table from the parsed pin configuration */
17232 static int alc662_auto_fill_dac_nids(struct hda_codec *codec,
17233                                      const struct auto_pin_cfg *cfg)
17234 {
17235         struct alc_spec *spec = codec->spec;
17236         int i;
17237         hda_nid_t dac;
17238
17239         spec->multiout.dac_nids = spec->private_dac_nids;
17240         for (i = 0; i < cfg->line_outs; i++) {
17241                 dac = alc662_look_for_dac(codec, cfg->line_out_pins[i]);
17242                 if (!dac)
17243                         continue;
17244                 spec->multiout.dac_nids[spec->multiout.num_dacs++] = dac;
17245         }
17246         return 0;
17247 }
17248
17249 static inline int alc662_add_vol_ctl(struct alc_spec *spec, const char *pfx,
17250                               hda_nid_t nid, unsigned int chs)
17251 {
17252         return add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
17253                            HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
17254 }
17255
17256 static inline int alc662_add_sw_ctl(struct alc_spec *spec, const char *pfx,
17257                              hda_nid_t nid, unsigned int chs)
17258 {
17259         return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
17260                            HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT));
17261 }
17262
17263 #define alc662_add_stereo_vol(spec, pfx, nid) \
17264         alc662_add_vol_ctl(spec, pfx, nid, 3)
17265 #define alc662_add_stereo_sw(spec, pfx, nid) \
17266         alc662_add_sw_ctl(spec, pfx, nid, 3)
17267
17268 /* add playback controls from the parsed DAC table */
17269 static int alc662_auto_create_multi_out_ctls(struct hda_codec *codec,
17270                                              const struct auto_pin_cfg *cfg)
17271 {
17272         struct alc_spec *spec = codec->spec;
17273         static const char *chname[4] = {
17274                 "Front", "Surround", NULL /*CLFE*/, "Side"
17275         };
17276         hda_nid_t nid, mix;
17277         int i, err;
17278
17279         for (i = 0; i < cfg->line_outs; i++) {
17280                 nid = spec->multiout.dac_nids[i];
17281                 if (!nid)
17282                         continue;
17283                 mix = alc662_dac_to_mix(codec, cfg->line_out_pins[i], nid);
17284                 if (!mix)
17285                         continue;
17286                 if (i == 2) {
17287                         /* Center/LFE */
17288                         err = alc662_add_vol_ctl(spec, "Center", nid, 1);
17289                         if (err < 0)
17290                                 return err;
17291                         err = alc662_add_vol_ctl(spec, "LFE", nid, 2);
17292                         if (err < 0)
17293                                 return err;
17294                         err = alc662_add_sw_ctl(spec, "Center", mix, 1);
17295                         if (err < 0)
17296                                 return err;
17297                         err = alc662_add_sw_ctl(spec, "LFE", mix, 2);
17298                         if (err < 0)
17299                                 return err;
17300                 } else {
17301                         const char *pfx;
17302                         if (cfg->line_outs == 1 &&
17303                             cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
17304                                 if (cfg->hp_outs)
17305                                         pfx = "Speaker";
17306                                 else
17307                                         pfx = "PCM";
17308                         } else
17309                                 pfx = chname[i];
17310                         err = alc662_add_vol_ctl(spec, pfx, nid, 3);
17311                         if (err < 0)
17312                                 return err;
17313                         if (cfg->line_outs == 1 &&
17314                             cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
17315                                 pfx = "Speaker";
17316                         err = alc662_add_sw_ctl(spec, pfx, mix, 3);
17317                         if (err < 0)
17318                                 return err;
17319                 }
17320         }
17321         return 0;
17322 }
17323
17324 /* add playback controls for speaker and HP outputs */
17325 /* return DAC nid if any new DAC is assigned */
17326 static int alc662_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
17327                                         const char *pfx)
17328 {
17329         struct alc_spec *spec = codec->spec;
17330         hda_nid_t nid, mix;
17331         int err;
17332
17333         if (!pin)
17334                 return 0;
17335         nid = alc662_look_for_dac(codec, pin);
17336         if (!nid) {
17337                 /* the corresponding DAC is already occupied */
17338                 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
17339                         return 0; /* no way */
17340                 /* create a switch only */
17341                 return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
17342                                    HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
17343         }
17344
17345         mix = alc662_dac_to_mix(codec, pin, nid);
17346         if (!mix)
17347                 return 0;
17348         err = alc662_add_vol_ctl(spec, pfx, nid, 3);
17349         if (err < 0)
17350                 return err;
17351         err = alc662_add_sw_ctl(spec, pfx, mix, 3);
17352         if (err < 0)
17353                 return err;
17354         return nid;
17355 }
17356
17357 /* create playback/capture controls for input pins */
17358 #define alc662_auto_create_input_ctls \
17359         alc882_auto_create_input_ctls
17360
17361 static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
17362                                               hda_nid_t nid, int pin_type,
17363                                               hda_nid_t dac)
17364 {
17365         int i, num;
17366         hda_nid_t srcs[4];
17367
17368         alc_set_pin_output(codec, nid, pin_type);
17369         /* need the manual connection? */
17370         num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
17371         if (num <= 1)
17372                 return;
17373         for (i = 0; i < num; i++) {
17374                 if (alc662_mix_to_dac(srcs[i]) != dac)
17375                         continue;
17376                 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
17377                 return;
17378         }
17379 }
17380
17381 static void alc662_auto_init_multi_out(struct hda_codec *codec)
17382 {
17383         struct alc_spec *spec = codec->spec;
17384         int pin_type = get_pin_type(spec->autocfg.line_out_type);
17385         int i;
17386
17387         for (i = 0; i <= HDA_SIDE; i++) {
17388                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
17389                 if (nid)
17390                         alc662_auto_set_output_and_unmute(codec, nid, pin_type,
17391                                         spec->multiout.dac_nids[i]);
17392         }
17393 }
17394
17395 static void alc662_auto_init_hp_out(struct hda_codec *codec)
17396 {
17397         struct alc_spec *spec = codec->spec;
17398         hda_nid_t pin;
17399
17400         pin = spec->autocfg.hp_pins[0];
17401         if (pin)
17402                 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP,
17403                                                   spec->multiout.hp_nid);
17404         pin = spec->autocfg.speaker_pins[0];
17405         if (pin)
17406                 alc662_auto_set_output_and_unmute(codec, pin, PIN_OUT,
17407                                         spec->multiout.extra_out_nid[0]);
17408 }
17409
17410 #define ALC662_PIN_CD_NID               ALC880_PIN_CD_NID
17411
17412 static void alc662_auto_init_analog_input(struct hda_codec *codec)
17413 {
17414         struct alc_spec *spec = codec->spec;
17415         int i;
17416
17417         for (i = 0; i < AUTO_PIN_LAST; i++) {
17418                 hda_nid_t nid = spec->autocfg.input_pins[i];
17419                 if (alc_is_input_pin(codec, nid)) {
17420                         alc_set_input_pin(codec, nid, i);
17421                         if (nid != ALC662_PIN_CD_NID &&
17422                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
17423                                 snd_hda_codec_write(codec, nid, 0,
17424                                                     AC_VERB_SET_AMP_GAIN_MUTE,
17425                                                     AMP_OUT_MUTE);
17426                 }
17427         }
17428 }
17429
17430 #define alc662_auto_init_input_src      alc882_auto_init_input_src
17431
17432 static int alc662_parse_auto_config(struct hda_codec *codec)
17433 {
17434         struct alc_spec *spec = codec->spec;
17435         int err;
17436         static hda_nid_t alc662_ignore[] = { 0x1d, 0 };
17437
17438         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
17439                                            alc662_ignore);
17440         if (err < 0)
17441                 return err;
17442         if (!spec->autocfg.line_outs)
17443                 return 0; /* can't find valid BIOS pin config */
17444
17445         err = alc662_auto_fill_dac_nids(codec, &spec->autocfg);
17446         if (err < 0)
17447                 return err;
17448         err = alc662_auto_create_multi_out_ctls(codec, &spec->autocfg);
17449         if (err < 0)
17450                 return err;
17451         err = alc662_auto_create_extra_out(codec,
17452                                            spec->autocfg.speaker_pins[0],
17453                                            "Speaker");
17454         if (err < 0)
17455                 return err;
17456         if (err)
17457                 spec->multiout.extra_out_nid[0] = err;
17458         err = alc662_auto_create_extra_out(codec, spec->autocfg.hp_pins[0],
17459                                            "Headphone");
17460         if (err < 0)
17461                 return err;
17462         if (err)
17463                 spec->multiout.hp_nid = err;
17464         err = alc662_auto_create_input_ctls(codec, &spec->autocfg);
17465         if (err < 0)
17466                 return err;
17467
17468         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
17469
17470         if (spec->autocfg.dig_outs)
17471                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
17472
17473         if (spec->kctls.list)
17474                 add_mixer(spec, spec->kctls.list);
17475
17476         spec->num_mux_defs = 1;
17477         spec->input_mux = &spec->private_imux[0];
17478
17479         add_verb(spec, alc662_auto_init_verbs);
17480         if (codec->vendor_id == 0x10ec0663)
17481                 add_verb(spec, alc663_auto_init_verbs);
17482
17483         err = alc_auto_add_mic_boost(codec);
17484         if (err < 0)
17485                 return err;
17486
17487         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
17488
17489         return 1;
17490 }
17491
17492 /* additional initialization for auto-configuration model */
17493 static void alc662_auto_init(struct hda_codec *codec)
17494 {
17495         struct alc_spec *spec = codec->spec;
17496         alc662_auto_init_multi_out(codec);
17497         alc662_auto_init_hp_out(codec);
17498         alc662_auto_init_analog_input(codec);
17499         alc662_auto_init_input_src(codec);
17500         if (spec->unsol_event)
17501                 alc_inithook(codec);
17502 }
17503
17504 static int patch_alc662(struct hda_codec *codec)
17505 {
17506         struct alc_spec *spec;
17507         int err, board_config;
17508
17509         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
17510         if (!spec)
17511                 return -ENOMEM;
17512
17513         codec->spec = spec;
17514
17515         alc_fix_pll_init(codec, 0x20, 0x04, 15);
17516
17517         board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
17518                                                   alc662_models,
17519                                                   alc662_cfg_tbl);
17520         if (board_config < 0) {
17521                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
17522                        codec->chip_name);
17523                 board_config = ALC662_AUTO;
17524         }
17525
17526         if (board_config == ALC662_AUTO) {
17527                 /* automatic parse from the BIOS config */
17528                 err = alc662_parse_auto_config(codec);
17529                 if (err < 0) {
17530                         alc_free(codec);
17531                         return err;
17532                 } else if (!err) {
17533                         printk(KERN_INFO
17534                                "hda_codec: Cannot set up configuration "
17535                                "from BIOS.  Using base mode...\n");
17536                         board_config = ALC662_3ST_2ch_DIG;
17537                 }
17538         }
17539
17540         err = snd_hda_attach_beep_device(codec, 0x1);
17541         if (err < 0) {
17542                 alc_free(codec);
17543                 return err;
17544         }
17545
17546         if (board_config != ALC662_AUTO)
17547                 setup_preset(codec, &alc662_presets[board_config]);
17548
17549         spec->stream_analog_playback = &alc662_pcm_analog_playback;
17550         spec->stream_analog_capture = &alc662_pcm_analog_capture;
17551
17552         spec->stream_digital_playback = &alc662_pcm_digital_playback;
17553         spec->stream_digital_capture = &alc662_pcm_digital_capture;
17554
17555         if (!spec->adc_nids) {
17556                 spec->adc_nids = alc662_adc_nids;
17557                 spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
17558         }
17559         if (!spec->capsrc_nids)
17560                 spec->capsrc_nids = alc662_capsrc_nids;
17561
17562         if (!spec->cap_mixer)
17563                 set_capture_mixer(codec);
17564         if (codec->vendor_id == 0x10ec0662)
17565                 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
17566         else
17567                 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
17568
17569         spec->vmaster_nid = 0x02;
17570
17571         codec->patch_ops = alc_patch_ops;
17572         if (board_config == ALC662_AUTO)
17573                 spec->init_hook = alc662_auto_init;
17574 #ifdef CONFIG_SND_HDA_POWER_SAVE
17575         if (!spec->loopback.amplist)
17576                 spec->loopback.amplist = alc662_loopbacks;
17577 #endif
17578         codec->proc_widget_hook = print_realtek_coef;
17579
17580         return 0;
17581 }
17582
17583 /*
17584  * patch entries
17585  */
17586 static struct hda_codec_preset snd_hda_preset_realtek[] = {
17587         { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
17588         { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
17589         { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
17590         { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
17591         { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
17592         { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
17593         { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
17594           .patch = patch_alc861 },
17595         { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
17596         { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
17597         { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
17598         { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
17599           .patch = patch_alc882 },
17600         { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
17601           .patch = patch_alc662 },
17602         { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
17603         { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
17604         { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
17605         { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
17606         { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
17607           .patch = patch_alc882 },
17608         { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
17609           .patch = patch_alc882 },
17610         { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
17611         { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
17612         { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
17613           .patch = patch_alc882 },
17614         { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
17615         { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
17616         {} /* terminator */
17617 };
17618
17619 MODULE_ALIAS("snd-hda-codec-id:10ec*");
17620
17621 MODULE_LICENSE("GPL");
17622 MODULE_DESCRIPTION("Realtek HD-audio codec");
17623
17624 static struct hda_codec_preset_list realtek_list = {
17625         .preset = snd_hda_preset_realtek,
17626         .owner = THIS_MODULE,
17627 };
17628
17629 static int __init patch_realtek_init(void)
17630 {
17631         return snd_hda_add_codec_preset(&realtek_list);
17632 }
17633
17634 static void __exit patch_realtek_exit(void)
17635 {
17636         snd_hda_delete_codec_preset(&realtek_list);
17637 }
17638
17639 module_init(patch_realtek_init)
17640 module_exit(patch_realtek_exit)