ALSA: hda - proc - introduce Control: lines to show mixer<->NID assignment
[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("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,
2465                                         get_amp_nid_(spec->beep_amp), kctl);
2466                         if (err < 0)
2467                                 return err;
2468                 }
2469         }
2470
2471         /* if we have no master control, let's create it */
2472         if (!spec->no_analog &&
2473             !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
2474                 unsigned int vmaster_tlv[4];
2475                 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
2476                                         HDA_OUTPUT, vmaster_tlv);
2477                 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
2478                                           vmaster_tlv, alc_slave_vols);
2479                 if (err < 0)
2480                         return err;
2481         }
2482         if (!spec->no_analog &&
2483             !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
2484                 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
2485                                           NULL, alc_slave_sws);
2486                 if (err < 0)
2487                         return err;
2488         }
2489
2490         alc_free_kctls(codec); /* no longer needed */
2491         return 0;
2492 }
2493
2494
2495 /*
2496  * initialize the codec volumes, etc
2497  */
2498
2499 /*
2500  * generic initialization of ADC, input mixers and output mixers
2501  */
2502 static struct hda_verb alc880_volume_init_verbs[] = {
2503         /*
2504          * Unmute ADC0-2 and set the default input to mic-in
2505          */
2506         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
2507         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2508         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
2509         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2510         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
2511         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2512
2513         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2514          * mixer widget
2515          * Note: PASD motherboards uses the Line In 2 as the input for front
2516          * panel mic (mic 2)
2517          */
2518         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
2519         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2520         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2521         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2522         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2523         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2524         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2525         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2526
2527         /*
2528          * Set up output mixers (0x0c - 0x0f)
2529          */
2530         /* set vol=0 to output mixers */
2531         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2532         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2533         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2534         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2535         /* set up input amps for analog loopback */
2536         /* Amp Indices: DAC = 0, mixer = 1 */
2537         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2538         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2539         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2540         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2541         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2542         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2543         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2544         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2545
2546         { }
2547 };
2548
2549 /*
2550  * 3-stack pin configuration:
2551  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
2552  */
2553 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
2554         /*
2555          * preset connection lists of input pins
2556          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2557          */
2558         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2559         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2560         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2561
2562         /*
2563          * Set pin mode and muting
2564          */
2565         /* set front pin widgets 0x14 for output */
2566         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2567         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2568         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2569         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2570         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2571         /* Mic2 (as headphone out) for HP output */
2572         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2573         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2574         /* Line In pin widget for input */
2575         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2576         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2577         /* Line2 (as front mic) pin widget for input and vref at 80% */
2578         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2579         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2580         /* CD pin widget for input */
2581         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2582
2583         { }
2584 };
2585
2586 /*
2587  * 5-stack pin configuration:
2588  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
2589  * line-in/side = 0x1a, f-mic = 0x1b
2590  */
2591 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
2592         /*
2593          * preset connection lists of input pins
2594          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2595          */
2596         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2597         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
2598
2599         /*
2600          * Set pin mode and muting
2601          */
2602         /* set pin widgets 0x14-0x17 for output */
2603         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2604         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2605         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2606         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2607         /* unmute pins for output (no gain on this amp) */
2608         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2609         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2610         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2611         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2612
2613         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2614         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2615         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2616         /* Mic2 (as headphone out) for HP output */
2617         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2618         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2619         /* Line In pin widget for input */
2620         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2621         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2622         /* Line2 (as front mic) pin widget for input and vref at 80% */
2623         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2624         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2625         /* CD pin widget for input */
2626         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2627
2628         { }
2629 };
2630
2631 /*
2632  * W810 pin configuration:
2633  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
2634  */
2635 static struct hda_verb alc880_pin_w810_init_verbs[] = {
2636         /* hphone/speaker input selector: front DAC */
2637         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
2638
2639         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2640         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2641         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2642         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2643         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2644         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2645
2646         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2647         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2648
2649         { }
2650 };
2651
2652 /*
2653  * Z71V pin configuration:
2654  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
2655  */
2656 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
2657         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2658         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2659         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2660         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2661
2662         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2663         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2664         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2665         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2666
2667         { }
2668 };
2669
2670 /*
2671  * 6-stack pin configuration:
2672  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
2673  * f-mic = 0x19, line = 0x1a, HP = 0x1b
2674  */
2675 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
2676         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2677
2678         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2679         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2680         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2681         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2682         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2683         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2684         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2685         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2686
2687         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2688         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2689         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2690         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2691         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2692         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2693         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2694         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2695         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2696
2697         { }
2698 };
2699
2700 /*
2701  * Uniwill pin configuration:
2702  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
2703  * line = 0x1a
2704  */
2705 static struct hda_verb alc880_uniwill_init_verbs[] = {
2706         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2707
2708         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2709         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2710         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2711         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2712         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2713         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2714         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2715         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2716         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2717         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2718         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2719         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2720         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2721         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2722
2723         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2724         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2725         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2726         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2727         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2728         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2729         /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
2730         /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
2731         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2732
2733         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2734         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
2735
2736         { }
2737 };
2738
2739 /*
2740 * Uniwill P53
2741 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19,
2742  */
2743 static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
2744         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2745
2746         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2747         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2748         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2749         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2750         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2751         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2752         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2753         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2754         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2755         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2756         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2757         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2758
2759         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2760         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2761         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2762         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2763         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2764         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2765
2766         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2767         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
2768
2769         { }
2770 };
2771
2772 static struct hda_verb alc880_beep_init_verbs[] = {
2773         { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
2774         { }
2775 };
2776
2777 /* auto-toggle front mic */
2778 static void alc880_uniwill_mic_automute(struct hda_codec *codec)
2779 {
2780         unsigned int present;
2781         unsigned char bits;
2782
2783         present = snd_hda_codec_read(codec, 0x18, 0,
2784                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2785         bits = present ? HDA_AMP_MUTE : 0;
2786         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
2787 }
2788
2789 static void alc880_uniwill_setup(struct hda_codec *codec)
2790 {
2791         struct alc_spec *spec = codec->spec;
2792
2793         spec->autocfg.hp_pins[0] = 0x14;
2794         spec->autocfg.speaker_pins[0] = 0x15;
2795         spec->autocfg.speaker_pins[0] = 0x16;
2796 }
2797
2798 static void alc880_uniwill_init_hook(struct hda_codec *codec)
2799 {
2800         alc_automute_amp(codec);
2801         alc880_uniwill_mic_automute(codec);
2802 }
2803
2804 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
2805                                        unsigned int res)
2806 {
2807         /* Looks like the unsol event is incompatible with the standard
2808          * definition.  4bit tag is placed at 28 bit!
2809          */
2810         switch (res >> 28) {
2811         case ALC880_MIC_EVENT:
2812                 alc880_uniwill_mic_automute(codec);
2813                 break;
2814         default:
2815                 alc_automute_amp_unsol_event(codec, res);
2816                 break;
2817         }
2818 }
2819
2820 static void alc880_uniwill_p53_setup(struct hda_codec *codec)
2821 {
2822         struct alc_spec *spec = codec->spec;
2823
2824         spec->autocfg.hp_pins[0] = 0x14;
2825         spec->autocfg.speaker_pins[0] = 0x15;
2826 }
2827
2828 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
2829 {
2830         unsigned int present;
2831
2832         present = snd_hda_codec_read(codec, 0x21, 0,
2833                                      AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
2834         present &= HDA_AMP_VOLMASK;
2835         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
2836                                  HDA_AMP_VOLMASK, present);
2837         snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
2838                                  HDA_AMP_VOLMASK, present);
2839 }
2840
2841 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
2842                                            unsigned int res)
2843 {
2844         /* Looks like the unsol event is incompatible with the standard
2845          * definition.  4bit tag is placed at 28 bit!
2846          */
2847         if ((res >> 28) == ALC880_DCVOL_EVENT)
2848                 alc880_uniwill_p53_dcvol_automute(codec);
2849         else
2850                 alc_automute_amp_unsol_event(codec, res);
2851 }
2852
2853 /*
2854  * F1734 pin configuration:
2855  * HP = 0x14, speaker-out = 0x15, mic = 0x18
2856  */
2857 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
2858         {0x07, AC_VERB_SET_CONNECT_SEL, 0x01},
2859         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2860         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2861         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2862         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2863
2864         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2865         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2866         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2867         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2868
2869         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2870         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2871         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
2872         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2873         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2874         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2875         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2876         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2877         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2878
2879         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
2880         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_DCVOL_EVENT},
2881
2882         { }
2883 };
2884
2885 /*
2886  * ASUS pin configuration:
2887  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
2888  */
2889 static struct hda_verb alc880_pin_asus_init_verbs[] = {
2890         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2891         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2892         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2893         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2894
2895         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2896         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2897         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2898         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2899         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2900         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2901         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2902         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2903
2904         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2905         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2906         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2907         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2908         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2909         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2910         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2911         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2912         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2913
2914         { }
2915 };
2916
2917 /* Enable GPIO mask and set output */
2918 #define alc880_gpio1_init_verbs alc_gpio1_init_verbs
2919 #define alc880_gpio2_init_verbs alc_gpio2_init_verbs
2920 #define alc880_gpio3_init_verbs alc_gpio3_init_verbs
2921
2922 /* Clevo m520g init */
2923 static struct hda_verb alc880_pin_clevo_init_verbs[] = {
2924         /* headphone output */
2925         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2926         /* line-out */
2927         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2928         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2929         /* Line-in */
2930         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2931         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2932         /* CD */
2933         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2934         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2935         /* Mic1 (rear panel) */
2936         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2937         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2938         /* Mic2 (front panel) */
2939         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2940         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2941         /* headphone */
2942         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2943         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2944         /* change to EAPD mode */
2945         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2946         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2947
2948         { }
2949 };
2950
2951 static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
2952         /* change to EAPD mode */
2953         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2954         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2955
2956         /* Headphone output */
2957         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2958         /* Front output*/
2959         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2960         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
2961
2962         /* Line In pin widget for input */
2963         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2964         /* CD pin widget for input */
2965         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2966         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2967         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2968
2969         /* change to EAPD mode */
2970         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2971         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
2972
2973         { }
2974 };
2975
2976 /*
2977  * LG m1 express dual
2978  *
2979  * Pin assignment:
2980  *   Rear Line-In/Out (blue): 0x14
2981  *   Build-in Mic-In: 0x15
2982  *   Speaker-out: 0x17
2983  *   HP-Out (green): 0x1b
2984  *   Mic-In/Out (red): 0x19
2985  *   SPDIF-Out: 0x1e
2986  */
2987
2988 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
2989 static hda_nid_t alc880_lg_dac_nids[3] = {
2990         0x05, 0x02, 0x03
2991 };
2992
2993 /* seems analog CD is not working */
2994 static struct hda_input_mux alc880_lg_capture_source = {
2995         .num_items = 3,
2996         .items = {
2997                 { "Mic", 0x1 },
2998                 { "Line", 0x5 },
2999                 { "Internal Mic", 0x6 },
3000         },
3001 };
3002
3003 /* 2,4,6 channel modes */
3004 static struct hda_verb alc880_lg_ch2_init[] = {
3005         /* set line-in and mic-in to input */
3006         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
3007         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
3008         { }
3009 };
3010
3011 static struct hda_verb alc880_lg_ch4_init[] = {
3012         /* set line-in to out and mic-in to input */
3013         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
3014         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
3015         { }
3016 };
3017
3018 static struct hda_verb alc880_lg_ch6_init[] = {
3019         /* set line-in and mic-in to output */
3020         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
3021         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
3022         { }
3023 };
3024
3025 static struct hda_channel_mode alc880_lg_ch_modes[3] = {
3026         { 2, alc880_lg_ch2_init },
3027         { 4, alc880_lg_ch4_init },
3028         { 6, alc880_lg_ch6_init },
3029 };
3030
3031 static struct snd_kcontrol_new alc880_lg_mixer[] = {
3032         HDA_CODEC_VOLUME("Front Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3033         HDA_BIND_MUTE("Front Playback Switch", 0x0f, 2, HDA_INPUT),
3034         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3035         HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
3036         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
3037         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
3038         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
3039         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
3040         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
3041         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
3042         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
3043         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
3044         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
3045         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
3046         {
3047                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3048                 .name = "Channel Mode",
3049                 .info = alc_ch_mode_info,
3050                 .get = alc_ch_mode_get,
3051                 .put = alc_ch_mode_put,
3052         },
3053         { } /* end */
3054 };
3055
3056 static struct hda_verb alc880_lg_init_verbs[] = {
3057         /* set capture source to mic-in */
3058         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3059         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3060         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3061         /* mute all amp mixer inputs */
3062         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
3063         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
3064         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
3065         /* line-in to input */
3066         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3067         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3068         /* built-in mic */
3069         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3070         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3071         /* speaker-out */
3072         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3073         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3074         /* mic-in to input */
3075         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
3076         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3077         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3078         /* HP-out */
3079         {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
3080         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3081         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3082         /* jack sense */
3083         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3084         { }
3085 };
3086
3087 /* toggle speaker-output according to the hp-jack state */
3088 static void alc880_lg_setup(struct hda_codec *codec)
3089 {
3090         struct alc_spec *spec = codec->spec;
3091
3092         spec->autocfg.hp_pins[0] = 0x1b;
3093         spec->autocfg.speaker_pins[0] = 0x17;
3094 }
3095
3096 /*
3097  * LG LW20
3098  *
3099  * Pin assignment:
3100  *   Speaker-out: 0x14
3101  *   Mic-In: 0x18
3102  *   Built-in Mic-In: 0x19
3103  *   Line-In: 0x1b
3104  *   HP-Out: 0x1a
3105  *   SPDIF-Out: 0x1e
3106  */
3107
3108 static struct hda_input_mux alc880_lg_lw_capture_source = {
3109         .num_items = 3,
3110         .items = {
3111                 { "Mic", 0x0 },
3112                 { "Internal Mic", 0x1 },
3113                 { "Line In", 0x2 },
3114         },
3115 };
3116
3117 #define alc880_lg_lw_modes alc880_threestack_modes
3118
3119 static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
3120         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3121         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
3122         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3123         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
3124         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
3125         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
3126         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
3127         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
3128         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
3129         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
3130         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
3131         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
3132         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
3133         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
3134         {
3135                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3136                 .name = "Channel Mode",
3137                 .info = alc_ch_mode_info,
3138                 .get = alc_ch_mode_get,
3139                 .put = alc_ch_mode_put,
3140         },
3141         { } /* end */
3142 };
3143
3144 static struct hda_verb alc880_lg_lw_init_verbs[] = {
3145         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3146         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
3147         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
3148
3149         /* set capture source to mic-in */
3150         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3151         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3152         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3153         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
3154         /* speaker-out */
3155         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3156         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3157         /* HP-out */
3158         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3159         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3160         /* mic-in to input */
3161         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3162         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3163         /* built-in mic */
3164         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3165         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3166         /* jack sense */
3167         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3168         { }
3169 };
3170
3171 /* toggle speaker-output according to the hp-jack state */
3172 static void alc880_lg_lw_setup(struct hda_codec *codec)
3173 {
3174         struct alc_spec *spec = codec->spec;
3175
3176         spec->autocfg.hp_pins[0] = 0x1b;
3177         spec->autocfg.speaker_pins[0] = 0x14;
3178 }
3179
3180 static struct snd_kcontrol_new alc880_medion_rim_mixer[] = {
3181         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3182         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
3183         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
3184         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
3185         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
3186         HDA_CODEC_MUTE("Internal Playback Switch", 0x0b, 0x1, HDA_INPUT),
3187         { } /* end */
3188 };
3189
3190 static struct hda_input_mux alc880_medion_rim_capture_source = {
3191         .num_items = 2,
3192         .items = {
3193                 { "Mic", 0x0 },
3194                 { "Internal Mic", 0x1 },
3195         },
3196 };
3197
3198 static struct hda_verb alc880_medion_rim_init_verbs[] = {
3199         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3200
3201         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3202         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3203
3204         /* Mic1 (rear panel) pin widget for input and vref at 80% */
3205         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3206         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3207         /* Mic2 (as headphone out) for HP output */
3208         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3209         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3210         /* Internal Speaker */
3211         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3212         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3213
3214         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
3215         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
3216
3217         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3218         { }
3219 };
3220
3221 /* toggle speaker-output according to the hp-jack state */
3222 static void alc880_medion_rim_automute(struct hda_codec *codec)
3223 {
3224         struct alc_spec *spec = codec->spec;
3225         alc_automute_amp(codec);
3226         /* toggle EAPD */
3227         if (spec->jack_present)
3228                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0);
3229         else
3230                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 2);
3231 }
3232
3233 static void alc880_medion_rim_unsol_event(struct hda_codec *codec,
3234                                           unsigned int res)
3235 {
3236         /* Looks like the unsol event is incompatible with the standard
3237          * definition.  4bit tag is placed at 28 bit!
3238          */
3239         if ((res >> 28) == ALC880_HP_EVENT)
3240                 alc880_medion_rim_automute(codec);
3241 }
3242
3243 static void alc880_medion_rim_setup(struct hda_codec *codec)
3244 {
3245         struct alc_spec *spec = codec->spec;
3246
3247         spec->autocfg.hp_pins[0] = 0x14;
3248         spec->autocfg.speaker_pins[0] = 0x1b;
3249 }
3250
3251 #ifdef CONFIG_SND_HDA_POWER_SAVE
3252 static struct hda_amp_list alc880_loopbacks[] = {
3253         { 0x0b, HDA_INPUT, 0 },
3254         { 0x0b, HDA_INPUT, 1 },
3255         { 0x0b, HDA_INPUT, 2 },
3256         { 0x0b, HDA_INPUT, 3 },
3257         { 0x0b, HDA_INPUT, 4 },
3258         { } /* end */
3259 };
3260
3261 static struct hda_amp_list alc880_lg_loopbacks[] = {
3262         { 0x0b, HDA_INPUT, 1 },
3263         { 0x0b, HDA_INPUT, 6 },
3264         { 0x0b, HDA_INPUT, 7 },
3265         { } /* end */
3266 };
3267 #endif
3268
3269 /*
3270  * Common callbacks
3271  */
3272
3273 static int alc_init(struct hda_codec *codec)
3274 {
3275         struct alc_spec *spec = codec->spec;
3276         unsigned int i;
3277
3278         alc_fix_pll(codec);
3279         alc_auto_init_amp(codec, spec->init_amp);
3280
3281         for (i = 0; i < spec->num_init_verbs; i++)
3282                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
3283
3284         if (spec->init_hook)
3285                 spec->init_hook(codec);
3286
3287         return 0;
3288 }
3289
3290 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
3291 {
3292         struct alc_spec *spec = codec->spec;
3293
3294         if (spec->unsol_event)
3295                 spec->unsol_event(codec, res);
3296 }
3297
3298 #ifdef CONFIG_SND_HDA_POWER_SAVE
3299 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
3300 {
3301         struct alc_spec *spec = codec->spec;
3302         return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
3303 }
3304 #endif
3305
3306 /*
3307  * Analog playback callbacks
3308  */
3309 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
3310                                     struct hda_codec *codec,
3311                                     struct snd_pcm_substream *substream)
3312 {
3313         struct alc_spec *spec = codec->spec;
3314         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
3315                                              hinfo);
3316 }
3317
3318 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3319                                        struct hda_codec *codec,
3320                                        unsigned int stream_tag,
3321                                        unsigned int format,
3322                                        struct snd_pcm_substream *substream)
3323 {
3324         struct alc_spec *spec = codec->spec;
3325         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
3326                                                 stream_tag, format, substream);
3327 }
3328
3329 static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
3330                                        struct hda_codec *codec,
3331                                        struct snd_pcm_substream *substream)
3332 {
3333         struct alc_spec *spec = codec->spec;
3334         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
3335 }
3336
3337 /*
3338  * Digital out
3339  */
3340 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
3341                                         struct hda_codec *codec,
3342                                         struct snd_pcm_substream *substream)
3343 {
3344         struct alc_spec *spec = codec->spec;
3345         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
3346 }
3347
3348 static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3349                                            struct hda_codec *codec,
3350                                            unsigned int stream_tag,
3351                                            unsigned int format,
3352                                            struct snd_pcm_substream *substream)
3353 {
3354         struct alc_spec *spec = codec->spec;
3355         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
3356                                              stream_tag, format, substream);
3357 }
3358
3359 static int alc880_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
3360                                            struct hda_codec *codec,
3361                                            struct snd_pcm_substream *substream)
3362 {
3363         struct alc_spec *spec = codec->spec;
3364         return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
3365 }
3366
3367 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
3368                                          struct hda_codec *codec,
3369                                          struct snd_pcm_substream *substream)
3370 {
3371         struct alc_spec *spec = codec->spec;
3372         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
3373 }
3374
3375 /*
3376  * Analog capture
3377  */
3378 static int alc880_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3379                                       struct hda_codec *codec,
3380                                       unsigned int stream_tag,
3381                                       unsigned int format,
3382                                       struct snd_pcm_substream *substream)
3383 {
3384         struct alc_spec *spec = codec->spec;
3385
3386         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
3387                                    stream_tag, 0, format);
3388         return 0;
3389 }
3390
3391 static int alc880_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3392                                       struct hda_codec *codec,
3393                                       struct snd_pcm_substream *substream)
3394 {
3395         struct alc_spec *spec = codec->spec;
3396
3397         snd_hda_codec_cleanup_stream(codec,
3398                                      spec->adc_nids[substream->number + 1]);
3399         return 0;
3400 }
3401
3402
3403 /*
3404  */
3405 static struct hda_pcm_stream alc880_pcm_analog_playback = {
3406         .substreams = 1,
3407         .channels_min = 2,
3408         .channels_max = 8,
3409         /* NID is set in alc_build_pcms */
3410         .ops = {
3411                 .open = alc880_playback_pcm_open,
3412                 .prepare = alc880_playback_pcm_prepare,
3413                 .cleanup = alc880_playback_pcm_cleanup
3414         },
3415 };
3416
3417 static struct hda_pcm_stream alc880_pcm_analog_capture = {
3418         .substreams = 1,
3419         .channels_min = 2,
3420         .channels_max = 2,
3421         /* NID is set in alc_build_pcms */
3422 };
3423
3424 static struct hda_pcm_stream alc880_pcm_analog_alt_playback = {
3425         .substreams = 1,
3426         .channels_min = 2,
3427         .channels_max = 2,
3428         /* NID is set in alc_build_pcms */
3429 };
3430
3431 static struct hda_pcm_stream alc880_pcm_analog_alt_capture = {
3432         .substreams = 2, /* can be overridden */
3433         .channels_min = 2,
3434         .channels_max = 2,
3435         /* NID is set in alc_build_pcms */
3436         .ops = {
3437                 .prepare = alc880_alt_capture_pcm_prepare,
3438                 .cleanup = alc880_alt_capture_pcm_cleanup
3439         },
3440 };
3441
3442 static struct hda_pcm_stream alc880_pcm_digital_playback = {
3443         .substreams = 1,
3444         .channels_min = 2,
3445         .channels_max = 2,
3446         /* NID is set in alc_build_pcms */
3447         .ops = {
3448                 .open = alc880_dig_playback_pcm_open,
3449                 .close = alc880_dig_playback_pcm_close,
3450                 .prepare = alc880_dig_playback_pcm_prepare,
3451                 .cleanup = alc880_dig_playback_pcm_cleanup
3452         },
3453 };
3454
3455 static struct hda_pcm_stream alc880_pcm_digital_capture = {
3456         .substreams = 1,
3457         .channels_min = 2,
3458         .channels_max = 2,
3459         /* NID is set in alc_build_pcms */
3460 };
3461
3462 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
3463 static struct hda_pcm_stream alc_pcm_null_stream = {
3464         .substreams = 0,
3465         .channels_min = 0,
3466         .channels_max = 0,
3467 };
3468
3469 static int alc_build_pcms(struct hda_codec *codec)
3470 {
3471         struct alc_spec *spec = codec->spec;
3472         struct hda_pcm *info = spec->pcm_rec;
3473         int i;
3474
3475         codec->num_pcms = 1;
3476         codec->pcm_info = info;
3477
3478         if (spec->no_analog)
3479                 goto skip_analog;
3480
3481         snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
3482                  "%s Analog", codec->chip_name);
3483         info->name = spec->stream_name_analog;
3484         
3485         if (spec->stream_analog_playback) {
3486                 if (snd_BUG_ON(!spec->multiout.dac_nids))
3487                         return -EINVAL;
3488                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
3489                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
3490         }
3491         if (spec->stream_analog_capture) {
3492                 if (snd_BUG_ON(!spec->adc_nids))
3493                         return -EINVAL;
3494                 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
3495                 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
3496         }
3497
3498         if (spec->channel_mode) {
3499                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
3500                 for (i = 0; i < spec->num_channel_mode; i++) {
3501                         if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
3502                                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
3503                         }
3504                 }
3505         }
3506
3507  skip_analog:
3508         /* SPDIF for stream index #1 */
3509         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
3510                 snprintf(spec->stream_name_digital,
3511                          sizeof(spec->stream_name_digital),
3512                          "%s Digital", codec->chip_name);
3513                 codec->num_pcms = 2;
3514                 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
3515                 info = spec->pcm_rec + 1;
3516                 info->name = spec->stream_name_digital;
3517                 if (spec->dig_out_type)
3518                         info->pcm_type = spec->dig_out_type;
3519                 else
3520                         info->pcm_type = HDA_PCM_TYPE_SPDIF;
3521                 if (spec->multiout.dig_out_nid &&
3522                     spec->stream_digital_playback) {
3523                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
3524                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
3525                 }
3526                 if (spec->dig_in_nid &&
3527                     spec->stream_digital_capture) {
3528                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
3529                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
3530                 }
3531                 /* FIXME: do we need this for all Realtek codec models? */
3532                 codec->spdif_status_reset = 1;
3533         }
3534
3535         if (spec->no_analog)
3536                 return 0;
3537
3538         /* If the use of more than one ADC is requested for the current
3539          * model, configure a second analog capture-only PCM.
3540          */
3541         /* Additional Analaog capture for index #2 */
3542         if ((spec->alt_dac_nid && spec->stream_analog_alt_playback) ||
3543             (spec->num_adc_nids > 1 && spec->stream_analog_alt_capture)) {
3544                 codec->num_pcms = 3;
3545                 info = spec->pcm_rec + 2;
3546                 info->name = spec->stream_name_analog;
3547                 if (spec->alt_dac_nid) {
3548                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
3549                                 *spec->stream_analog_alt_playback;
3550                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
3551                                 spec->alt_dac_nid;
3552                 } else {
3553                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
3554                                 alc_pcm_null_stream;
3555                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
3556                 }
3557                 if (spec->num_adc_nids > 1) {
3558                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
3559                                 *spec->stream_analog_alt_capture;
3560                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
3561                                 spec->adc_nids[1];
3562                         info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
3563                                 spec->num_adc_nids - 1;
3564                 } else {
3565                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
3566                                 alc_pcm_null_stream;
3567                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
3568                 }
3569         }
3570
3571         return 0;
3572 }
3573
3574 static void alc_free_kctls(struct hda_codec *codec)
3575 {
3576         struct alc_spec *spec = codec->spec;
3577
3578         if (spec->kctls.list) {
3579                 struct snd_kcontrol_new *kctl = spec->kctls.list;
3580                 int i;
3581                 for (i = 0; i < spec->kctls.used; i++)
3582                         kfree(kctl[i].name);
3583         }
3584         snd_array_free(&spec->kctls);
3585 }
3586
3587 static void alc_free(struct hda_codec *codec)
3588 {
3589         struct alc_spec *spec = codec->spec;
3590
3591         if (!spec)
3592                 return;
3593
3594         alc_free_kctls(codec);
3595         kfree(spec);
3596         snd_hda_detach_beep_device(codec);
3597 }
3598
3599 #ifdef SND_HDA_NEEDS_RESUME
3600 static int alc_resume(struct hda_codec *codec)
3601 {
3602         codec->patch_ops.init(codec);
3603         snd_hda_codec_resume_amp(codec);
3604         snd_hda_codec_resume_cache(codec);
3605         return 0;
3606 }
3607 #endif
3608
3609 /*
3610  */
3611 static struct hda_codec_ops alc_patch_ops = {
3612         .build_controls = alc_build_controls,
3613         .build_pcms = alc_build_pcms,
3614         .init = alc_init,
3615         .free = alc_free,
3616         .unsol_event = alc_unsol_event,
3617 #ifdef SND_HDA_NEEDS_RESUME
3618         .resume = alc_resume,
3619 #endif
3620 #ifdef CONFIG_SND_HDA_POWER_SAVE
3621         .check_power_status = alc_check_power_status,
3622 #endif
3623 };
3624
3625
3626 /*
3627  * Test configuration for debugging
3628  *
3629  * Almost all inputs/outputs are enabled.  I/O pins can be configured via
3630  * enum controls.
3631  */
3632 #ifdef CONFIG_SND_DEBUG
3633 static hda_nid_t alc880_test_dac_nids[4] = {
3634         0x02, 0x03, 0x04, 0x05
3635 };
3636
3637 static struct hda_input_mux alc880_test_capture_source = {
3638         .num_items = 7,
3639         .items = {
3640                 { "In-1", 0x0 },
3641                 { "In-2", 0x1 },
3642                 { "In-3", 0x2 },
3643                 { "In-4", 0x3 },
3644                 { "CD", 0x4 },
3645                 { "Front", 0x5 },
3646                 { "Surround", 0x6 },
3647         },
3648 };
3649
3650 static struct hda_channel_mode alc880_test_modes[4] = {
3651         { 2, NULL },
3652         { 4, NULL },
3653         { 6, NULL },
3654         { 8, NULL },
3655 };
3656
3657 static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
3658                                  struct snd_ctl_elem_info *uinfo)
3659 {
3660         static char *texts[] = {
3661                 "N/A", "Line Out", "HP Out",
3662                 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
3663         };
3664         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3665         uinfo->count = 1;
3666         uinfo->value.enumerated.items = 8;
3667         if (uinfo->value.enumerated.item >= 8)
3668                 uinfo->value.enumerated.item = 7;
3669         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3670         return 0;
3671 }
3672
3673 static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
3674                                 struct snd_ctl_elem_value *ucontrol)
3675 {
3676         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3677         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3678         unsigned int pin_ctl, item = 0;
3679
3680         pin_ctl = snd_hda_codec_read(codec, nid, 0,
3681                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3682         if (pin_ctl & AC_PINCTL_OUT_EN) {
3683                 if (pin_ctl & AC_PINCTL_HP_EN)
3684                         item = 2;
3685                 else
3686                         item = 1;
3687         } else if (pin_ctl & AC_PINCTL_IN_EN) {
3688                 switch (pin_ctl & AC_PINCTL_VREFEN) {
3689                 case AC_PINCTL_VREF_HIZ: item = 3; break;
3690                 case AC_PINCTL_VREF_50:  item = 4; break;
3691                 case AC_PINCTL_VREF_GRD: item = 5; break;
3692                 case AC_PINCTL_VREF_80:  item = 6; break;
3693                 case AC_PINCTL_VREF_100: item = 7; break;
3694                 }
3695         }
3696         ucontrol->value.enumerated.item[0] = item;
3697         return 0;
3698 }
3699
3700 static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
3701                                 struct snd_ctl_elem_value *ucontrol)
3702 {
3703         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3704         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3705         static unsigned int ctls[] = {
3706                 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
3707                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
3708                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
3709                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
3710                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
3711                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
3712         };
3713         unsigned int old_ctl, new_ctl;
3714
3715         old_ctl = snd_hda_codec_read(codec, nid, 0,
3716                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3717         new_ctl = ctls[ucontrol->value.enumerated.item[0]];
3718         if (old_ctl != new_ctl) {
3719                 int val;
3720                 snd_hda_codec_write_cache(codec, nid, 0,
3721                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
3722                                           new_ctl);
3723                 val = ucontrol->value.enumerated.item[0] >= 3 ?
3724                         HDA_AMP_MUTE : 0;
3725                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3726                                          HDA_AMP_MUTE, val);
3727                 return 1;
3728         }
3729         return 0;
3730 }
3731
3732 static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
3733                                  struct snd_ctl_elem_info *uinfo)
3734 {
3735         static char *texts[] = {
3736                 "Front", "Surround", "CLFE", "Side"
3737         };
3738         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3739         uinfo->count = 1;
3740         uinfo->value.enumerated.items = 4;
3741         if (uinfo->value.enumerated.item >= 4)
3742                 uinfo->value.enumerated.item = 3;
3743         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3744         return 0;
3745 }
3746
3747 static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
3748                                 struct snd_ctl_elem_value *ucontrol)
3749 {
3750         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3751         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3752         unsigned int sel;
3753
3754         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
3755         ucontrol->value.enumerated.item[0] = sel & 3;
3756         return 0;
3757 }
3758
3759 static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
3760                                 struct snd_ctl_elem_value *ucontrol)
3761 {
3762         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3763         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3764         unsigned int sel;
3765
3766         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
3767         if (ucontrol->value.enumerated.item[0] != sel) {
3768                 sel = ucontrol->value.enumerated.item[0] & 3;
3769                 snd_hda_codec_write_cache(codec, nid, 0,
3770                                           AC_VERB_SET_CONNECT_SEL, sel);
3771                 return 1;
3772         }
3773         return 0;
3774 }
3775
3776 #define PIN_CTL_TEST(xname,nid) {                       \
3777                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3778                         .name = xname,                 \
3779                         .info = alc_test_pin_ctl_info, \
3780                         .get = alc_test_pin_ctl_get,   \
3781                         .put = alc_test_pin_ctl_put,   \
3782                         .private_value = nid           \
3783                         }
3784
3785 #define PIN_SRC_TEST(xname,nid) {                       \
3786                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3787                         .name = xname,                 \
3788                         .info = alc_test_pin_src_info, \
3789                         .get = alc_test_pin_src_get,   \
3790                         .put = alc_test_pin_src_put,   \
3791                         .private_value = nid           \
3792                         }
3793
3794 static struct snd_kcontrol_new alc880_test_mixer[] = {
3795         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3796         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
3797         HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
3798         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3799         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
3800         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
3801         HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
3802         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
3803         PIN_CTL_TEST("Front Pin Mode", 0x14),
3804         PIN_CTL_TEST("Surround Pin Mode", 0x15),
3805         PIN_CTL_TEST("CLFE Pin Mode", 0x16),
3806         PIN_CTL_TEST("Side Pin Mode", 0x17),
3807         PIN_CTL_TEST("In-1 Pin Mode", 0x18),
3808         PIN_CTL_TEST("In-2 Pin Mode", 0x19),
3809         PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
3810         PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
3811         PIN_SRC_TEST("In-1 Pin Source", 0x18),
3812         PIN_SRC_TEST("In-2 Pin Source", 0x19),
3813         PIN_SRC_TEST("In-3 Pin Source", 0x1a),
3814         PIN_SRC_TEST("In-4 Pin Source", 0x1b),
3815         HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
3816         HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
3817         HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
3818         HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
3819         HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
3820         HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
3821         HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
3822         HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
3823         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
3824         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
3825         {
3826                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3827                 .name = "Channel Mode",
3828                 .info = alc_ch_mode_info,
3829                 .get = alc_ch_mode_get,
3830                 .put = alc_ch_mode_put,
3831         },
3832         { } /* end */
3833 };
3834
3835 static struct hda_verb alc880_test_init_verbs[] = {
3836         /* Unmute inputs of 0x0c - 0x0f */
3837         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3838         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3839         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3840         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3841         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3842         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3843         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3844         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3845         /* Vol output for 0x0c-0x0f */
3846         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3847         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3848         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3849         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3850         /* Set output pins 0x14-0x17 */
3851         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3852         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3853         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3854         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3855         /* Unmute output pins 0x14-0x17 */
3856         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3857         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3858         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3859         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3860         /* Set input pins 0x18-0x1c */
3861         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3862         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3863         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3864         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3865         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3866         /* Mute input pins 0x18-0x1b */
3867         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3868         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3869         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3870         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3871         /* ADC set up */
3872         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3873         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
3874         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3875         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
3876         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3877         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
3878         /* Analog input/passthru */
3879         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3880         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3881         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3882         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3883         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3884         { }
3885 };
3886 #endif
3887
3888 /*
3889  */
3890
3891 static const char *alc880_models[ALC880_MODEL_LAST] = {
3892         [ALC880_3ST]            = "3stack",
3893         [ALC880_TCL_S700]       = "tcl",
3894         [ALC880_3ST_DIG]        = "3stack-digout",
3895         [ALC880_CLEVO]          = "clevo",
3896         [ALC880_5ST]            = "5stack",
3897         [ALC880_5ST_DIG]        = "5stack-digout",
3898         [ALC880_W810]           = "w810",
3899         [ALC880_Z71V]           = "z71v",
3900         [ALC880_6ST]            = "6stack",
3901         [ALC880_6ST_DIG]        = "6stack-digout",
3902         [ALC880_ASUS]           = "asus",
3903         [ALC880_ASUS_W1V]       = "asus-w1v",
3904         [ALC880_ASUS_DIG]       = "asus-dig",
3905         [ALC880_ASUS_DIG2]      = "asus-dig2",
3906         [ALC880_UNIWILL_DIG]    = "uniwill",
3907         [ALC880_UNIWILL_P53]    = "uniwill-p53",
3908         [ALC880_FUJITSU]        = "fujitsu",
3909         [ALC880_F1734]          = "F1734",
3910         [ALC880_LG]             = "lg",
3911         [ALC880_LG_LW]          = "lg-lw",
3912         [ALC880_MEDION_RIM]     = "medion",
3913 #ifdef CONFIG_SND_DEBUG
3914         [ALC880_TEST]           = "test",
3915 #endif
3916         [ALC880_AUTO]           = "auto",
3917 };
3918
3919 static struct snd_pci_quirk alc880_cfg_tbl[] = {
3920         SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
3921         SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
3922         SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
3923         SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
3924         SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
3925         SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
3926         SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
3927         SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
3928         SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
3929         SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
3930         SND_PCI_QUIRK(0x103c, 0x2a09, "HP", ALC880_5ST),
3931         SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
3932         SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
3933         SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
3934         SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
3935         SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
3936         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
3937         SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
3938         /* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
3939         SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
3940         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
3941         SND_PCI_QUIRK(0x1043, 0x814e, "ASUS P5GD1 w/SPDIF", ALC880_6ST_DIG),
3942         SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
3943         SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
3944         SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
3945         SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_ASUS), /* default ASUS */
3946         SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
3947         SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
3948         SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
3949         SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
3950         SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
3951         SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
3952         SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
3953         SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
3954         SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
3955         SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
3956         SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
3957         SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
3958         SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
3959         SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
3960         SND_PCI_QUIRK(0x1584, 0x9054, "Uniwlll", ALC880_F1734),
3961         SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
3962         SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
3963         SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
3964         SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_MEDION_RIM),
3965         SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
3966         SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
3967         SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
3968         SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FUJITSU),
3969         SND_PCI_QUIRK(0x1734, 0x10ac, "FSC", ALC880_UNIWILL),
3970         SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
3971         SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
3972         SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
3973         SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
3974         SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
3975         SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
3976         SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG), /* broken BIOS */
3977         SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
3978         SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
3979         SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
3980         SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
3981         SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
3982         SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
3983         SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
3984         SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
3985         SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
3986         SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
3987         SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
3988         /* default Intel */
3989         SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_3ST),
3990         SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
3991         SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
3992         {}
3993 };
3994
3995 /*
3996  * ALC880 codec presets
3997  */
3998 static struct alc_config_preset alc880_presets[] = {
3999         [ALC880_3ST] = {
4000                 .mixers = { alc880_three_stack_mixer },
4001                 .init_verbs = { alc880_volume_init_verbs,
4002                                 alc880_pin_3stack_init_verbs },
4003                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4004                 .dac_nids = alc880_dac_nids,
4005                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
4006                 .channel_mode = alc880_threestack_modes,
4007                 .need_dac_fix = 1,
4008                 .input_mux = &alc880_capture_source,
4009         },
4010         [ALC880_3ST_DIG] = {
4011                 .mixers = { alc880_three_stack_mixer },
4012                 .init_verbs = { alc880_volume_init_verbs,
4013                                 alc880_pin_3stack_init_verbs },
4014                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4015                 .dac_nids = alc880_dac_nids,
4016                 .dig_out_nid = ALC880_DIGOUT_NID,
4017                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
4018                 .channel_mode = alc880_threestack_modes,
4019                 .need_dac_fix = 1,
4020                 .input_mux = &alc880_capture_source,
4021         },
4022         [ALC880_TCL_S700] = {
4023                 .mixers = { alc880_tcl_s700_mixer },
4024                 .init_verbs = { alc880_volume_init_verbs,
4025                                 alc880_pin_tcl_S700_init_verbs,
4026                                 alc880_gpio2_init_verbs },
4027                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4028                 .dac_nids = alc880_dac_nids,
4029                 .adc_nids = alc880_adc_nids_alt, /* FIXME: correct? */
4030                 .num_adc_nids = 1, /* single ADC */
4031                 .hp_nid = 0x03,
4032                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4033                 .channel_mode = alc880_2_jack_modes,
4034                 .input_mux = &alc880_capture_source,
4035         },
4036         [ALC880_5ST] = {
4037                 .mixers = { alc880_three_stack_mixer,
4038                             alc880_five_stack_mixer},
4039                 .init_verbs = { alc880_volume_init_verbs,
4040                                 alc880_pin_5stack_init_verbs },
4041                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4042                 .dac_nids = alc880_dac_nids,
4043                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
4044                 .channel_mode = alc880_fivestack_modes,
4045                 .input_mux = &alc880_capture_source,
4046         },
4047         [ALC880_5ST_DIG] = {
4048                 .mixers = { alc880_three_stack_mixer,
4049                             alc880_five_stack_mixer },
4050                 .init_verbs = { alc880_volume_init_verbs,
4051                                 alc880_pin_5stack_init_verbs },
4052                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4053                 .dac_nids = alc880_dac_nids,
4054                 .dig_out_nid = ALC880_DIGOUT_NID,
4055                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
4056                 .channel_mode = alc880_fivestack_modes,
4057                 .input_mux = &alc880_capture_source,
4058         },
4059         [ALC880_6ST] = {
4060                 .mixers = { alc880_six_stack_mixer },
4061                 .init_verbs = { alc880_volume_init_verbs,
4062                                 alc880_pin_6stack_init_verbs },
4063                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
4064                 .dac_nids = alc880_6st_dac_nids,
4065                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
4066                 .channel_mode = alc880_sixstack_modes,
4067                 .input_mux = &alc880_6stack_capture_source,
4068         },
4069         [ALC880_6ST_DIG] = {
4070                 .mixers = { alc880_six_stack_mixer },
4071                 .init_verbs = { alc880_volume_init_verbs,
4072                                 alc880_pin_6stack_init_verbs },
4073                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
4074                 .dac_nids = alc880_6st_dac_nids,
4075                 .dig_out_nid = ALC880_DIGOUT_NID,
4076                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
4077                 .channel_mode = alc880_sixstack_modes,
4078                 .input_mux = &alc880_6stack_capture_source,
4079         },
4080         [ALC880_W810] = {
4081                 .mixers = { alc880_w810_base_mixer },
4082                 .init_verbs = { alc880_volume_init_verbs,
4083                                 alc880_pin_w810_init_verbs,
4084                                 alc880_gpio2_init_verbs },
4085                 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
4086                 .dac_nids = alc880_w810_dac_nids,
4087                 .dig_out_nid = ALC880_DIGOUT_NID,
4088                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
4089                 .channel_mode = alc880_w810_modes,
4090                 .input_mux = &alc880_capture_source,
4091         },
4092         [ALC880_Z71V] = {
4093                 .mixers = { alc880_z71v_mixer },
4094                 .init_verbs = { alc880_volume_init_verbs,
4095                                 alc880_pin_z71v_init_verbs },
4096                 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
4097                 .dac_nids = alc880_z71v_dac_nids,
4098                 .dig_out_nid = ALC880_DIGOUT_NID,
4099                 .hp_nid = 0x03,
4100                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4101                 .channel_mode = alc880_2_jack_modes,
4102                 .input_mux = &alc880_capture_source,
4103         },
4104         [ALC880_F1734] = {
4105                 .mixers = { alc880_f1734_mixer },
4106                 .init_verbs = { alc880_volume_init_verbs,
4107                                 alc880_pin_f1734_init_verbs },
4108                 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
4109                 .dac_nids = alc880_f1734_dac_nids,
4110                 .hp_nid = 0x02,
4111                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4112                 .channel_mode = alc880_2_jack_modes,
4113                 .input_mux = &alc880_f1734_capture_source,
4114                 .unsol_event = alc880_uniwill_p53_unsol_event,
4115                 .setup = alc880_uniwill_p53_setup,
4116                 .init_hook = alc_automute_amp,
4117         },
4118         [ALC880_ASUS] = {
4119                 .mixers = { alc880_asus_mixer },
4120                 .init_verbs = { alc880_volume_init_verbs,
4121                                 alc880_pin_asus_init_verbs,
4122                                 alc880_gpio1_init_verbs },
4123                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4124                 .dac_nids = alc880_asus_dac_nids,
4125                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4126                 .channel_mode = alc880_asus_modes,
4127                 .need_dac_fix = 1,
4128                 .input_mux = &alc880_capture_source,
4129         },
4130         [ALC880_ASUS_DIG] = {
4131                 .mixers = { alc880_asus_mixer },
4132                 .init_verbs = { alc880_volume_init_verbs,
4133                                 alc880_pin_asus_init_verbs,
4134                                 alc880_gpio1_init_verbs },
4135                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4136                 .dac_nids = alc880_asus_dac_nids,
4137                 .dig_out_nid = ALC880_DIGOUT_NID,
4138                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4139                 .channel_mode = alc880_asus_modes,
4140                 .need_dac_fix = 1,
4141                 .input_mux = &alc880_capture_source,
4142         },
4143         [ALC880_ASUS_DIG2] = {
4144                 .mixers = { alc880_asus_mixer },
4145                 .init_verbs = { alc880_volume_init_verbs,
4146                                 alc880_pin_asus_init_verbs,
4147                                 alc880_gpio2_init_verbs }, /* use GPIO2 */
4148                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4149                 .dac_nids = alc880_asus_dac_nids,
4150                 .dig_out_nid = ALC880_DIGOUT_NID,
4151                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4152                 .channel_mode = alc880_asus_modes,
4153                 .need_dac_fix = 1,
4154                 .input_mux = &alc880_capture_source,
4155         },
4156         [ALC880_ASUS_W1V] = {
4157                 .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
4158                 .init_verbs = { alc880_volume_init_verbs,
4159                                 alc880_pin_asus_init_verbs,
4160                                 alc880_gpio1_init_verbs },
4161                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4162                 .dac_nids = alc880_asus_dac_nids,
4163                 .dig_out_nid = ALC880_DIGOUT_NID,
4164                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4165                 .channel_mode = alc880_asus_modes,
4166                 .need_dac_fix = 1,
4167                 .input_mux = &alc880_capture_source,
4168         },
4169         [ALC880_UNIWILL_DIG] = {
4170                 .mixers = { alc880_asus_mixer },
4171                 .init_verbs = { alc880_volume_init_verbs,
4172                                 alc880_pin_asus_init_verbs },
4173                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4174                 .dac_nids = alc880_asus_dac_nids,
4175                 .dig_out_nid = ALC880_DIGOUT_NID,
4176                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4177                 .channel_mode = alc880_asus_modes,
4178                 .need_dac_fix = 1,
4179                 .input_mux = &alc880_capture_source,
4180         },
4181         [ALC880_UNIWILL] = {
4182                 .mixers = { alc880_uniwill_mixer },
4183                 .init_verbs = { alc880_volume_init_verbs,
4184                                 alc880_uniwill_init_verbs },
4185                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4186                 .dac_nids = alc880_asus_dac_nids,
4187                 .dig_out_nid = ALC880_DIGOUT_NID,
4188                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
4189                 .channel_mode = alc880_threestack_modes,
4190                 .need_dac_fix = 1,
4191                 .input_mux = &alc880_capture_source,
4192                 .unsol_event = alc880_uniwill_unsol_event,
4193                 .setup = alc880_uniwill_setup,
4194                 .init_hook = alc880_uniwill_init_hook,
4195         },
4196         [ALC880_UNIWILL_P53] = {
4197                 .mixers = { alc880_uniwill_p53_mixer },
4198                 .init_verbs = { alc880_volume_init_verbs,
4199                                 alc880_uniwill_p53_init_verbs },
4200                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4201                 .dac_nids = alc880_asus_dac_nids,
4202                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
4203                 .channel_mode = alc880_threestack_modes,
4204                 .input_mux = &alc880_capture_source,
4205                 .unsol_event = alc880_uniwill_p53_unsol_event,
4206                 .setup = alc880_uniwill_p53_setup,
4207                 .init_hook = alc_automute_amp,
4208         },
4209         [ALC880_FUJITSU] = {
4210                 .mixers = { alc880_fujitsu_mixer },
4211                 .init_verbs = { alc880_volume_init_verbs,
4212                                 alc880_uniwill_p53_init_verbs,
4213                                 alc880_beep_init_verbs },
4214                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4215                 .dac_nids = alc880_dac_nids,
4216                 .dig_out_nid = ALC880_DIGOUT_NID,
4217                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4218                 .channel_mode = alc880_2_jack_modes,
4219                 .input_mux = &alc880_capture_source,
4220                 .unsol_event = alc880_uniwill_p53_unsol_event,
4221                 .setup = alc880_uniwill_p53_setup,
4222                 .init_hook = alc_automute_amp,
4223         },
4224         [ALC880_CLEVO] = {
4225                 .mixers = { alc880_three_stack_mixer },
4226                 .init_verbs = { alc880_volume_init_verbs,
4227                                 alc880_pin_clevo_init_verbs },
4228                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4229                 .dac_nids = alc880_dac_nids,
4230                 .hp_nid = 0x03,
4231                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
4232                 .channel_mode = alc880_threestack_modes,
4233                 .need_dac_fix = 1,
4234                 .input_mux = &alc880_capture_source,
4235         },
4236         [ALC880_LG] = {
4237                 .mixers = { alc880_lg_mixer },
4238                 .init_verbs = { alc880_volume_init_verbs,
4239                                 alc880_lg_init_verbs },
4240                 .num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
4241                 .dac_nids = alc880_lg_dac_nids,
4242                 .dig_out_nid = ALC880_DIGOUT_NID,
4243                 .num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
4244                 .channel_mode = alc880_lg_ch_modes,
4245                 .need_dac_fix = 1,
4246                 .input_mux = &alc880_lg_capture_source,
4247                 .unsol_event = alc_automute_amp_unsol_event,
4248                 .setup = alc880_lg_setup,
4249                 .init_hook = alc_automute_amp,
4250 #ifdef CONFIG_SND_HDA_POWER_SAVE
4251                 .loopbacks = alc880_lg_loopbacks,
4252 #endif
4253         },
4254         [ALC880_LG_LW] = {
4255                 .mixers = { alc880_lg_lw_mixer },
4256                 .init_verbs = { alc880_volume_init_verbs,
4257                                 alc880_lg_lw_init_verbs },
4258                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4259                 .dac_nids = alc880_dac_nids,
4260                 .dig_out_nid = ALC880_DIGOUT_NID,
4261                 .num_channel_mode = ARRAY_SIZE(alc880_lg_lw_modes),
4262                 .channel_mode = alc880_lg_lw_modes,
4263                 .input_mux = &alc880_lg_lw_capture_source,
4264                 .unsol_event = alc_automute_amp_unsol_event,
4265                 .setup = alc880_lg_lw_setup,
4266                 .init_hook = alc_automute_amp,
4267         },
4268         [ALC880_MEDION_RIM] = {
4269                 .mixers = { alc880_medion_rim_mixer },
4270                 .init_verbs = { alc880_volume_init_verbs,
4271                                 alc880_medion_rim_init_verbs,
4272                                 alc_gpio2_init_verbs },
4273                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4274                 .dac_nids = alc880_dac_nids,
4275                 .dig_out_nid = ALC880_DIGOUT_NID,
4276                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4277                 .channel_mode = alc880_2_jack_modes,
4278                 .input_mux = &alc880_medion_rim_capture_source,
4279                 .unsol_event = alc880_medion_rim_unsol_event,
4280                 .setup = alc880_medion_rim_setup,
4281                 .init_hook = alc880_medion_rim_automute,
4282         },
4283 #ifdef CONFIG_SND_DEBUG
4284         [ALC880_TEST] = {
4285                 .mixers = { alc880_test_mixer },
4286                 .init_verbs = { alc880_test_init_verbs },
4287                 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
4288                 .dac_nids = alc880_test_dac_nids,
4289                 .dig_out_nid = ALC880_DIGOUT_NID,
4290                 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
4291                 .channel_mode = alc880_test_modes,
4292                 .input_mux = &alc880_test_capture_source,
4293         },
4294 #endif
4295 };
4296
4297 /*
4298  * Automatic parse of I/O pins from the BIOS configuration
4299  */
4300
4301 enum {
4302         ALC_CTL_WIDGET_VOL,
4303         ALC_CTL_WIDGET_MUTE,
4304         ALC_CTL_BIND_MUTE,
4305 };
4306 static struct snd_kcontrol_new alc880_control_templates[] = {
4307         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
4308         HDA_CODEC_MUTE(NULL, 0, 0, 0),
4309         HDA_BIND_MUTE(NULL, 0, 0, 0),
4310 };
4311
4312 /* add dynamic controls */
4313 static int add_control(struct alc_spec *spec, int type, const char *name,
4314                        unsigned long val)
4315 {
4316         struct snd_kcontrol_new *knew;
4317
4318         snd_array_init(&spec->kctls, sizeof(*knew), 32);
4319         knew = snd_array_new(&spec->kctls);
4320         if (!knew)
4321                 return -ENOMEM;
4322         *knew = alc880_control_templates[type];
4323         knew->name = kstrdup(name, GFP_KERNEL);
4324         if (!knew->name)
4325                 return -ENOMEM;
4326         knew->private_value = val;
4327         return 0;
4328 }
4329
4330 static int add_control_with_pfx(struct alc_spec *spec, int type,
4331                                 const char *pfx, const char *dir,
4332                                 const char *sfx, unsigned long val)
4333 {
4334         char name[32];
4335         snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
4336         return add_control(spec, type, name, val);
4337 }
4338
4339 #define add_pb_vol_ctrl(spec, type, pfx, val) \
4340         add_control_with_pfx(spec, type, pfx, "Playback", "Volume", val)
4341 #define add_pb_sw_ctrl(spec, type, pfx, val) \
4342         add_control_with_pfx(spec, type, pfx, "Playback", "Switch", val)
4343
4344 #define alc880_is_fixed_pin(nid)        ((nid) >= 0x14 && (nid) <= 0x17)
4345 #define alc880_fixed_pin_idx(nid)       ((nid) - 0x14)
4346 #define alc880_is_multi_pin(nid)        ((nid) >= 0x18)
4347 #define alc880_multi_pin_idx(nid)       ((nid) - 0x18)
4348 #define alc880_idx_to_dac(nid)          ((nid) + 0x02)
4349 #define alc880_dac_to_idx(nid)          ((nid) - 0x02)
4350 #define alc880_idx_to_mixer(nid)        ((nid) + 0x0c)
4351 #define alc880_idx_to_selector(nid)     ((nid) + 0x10)
4352 #define ALC880_PIN_CD_NID               0x1c
4353
4354 /* fill in the dac_nids table from the parsed pin configuration */
4355 static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
4356                                      const struct auto_pin_cfg *cfg)
4357 {
4358         hda_nid_t nid;
4359         int assigned[4];
4360         int i, j;
4361
4362         memset(assigned, 0, sizeof(assigned));
4363         spec->multiout.dac_nids = spec->private_dac_nids;
4364
4365         /* check the pins hardwired to audio widget */
4366         for (i = 0; i < cfg->line_outs; i++) {
4367                 nid = cfg->line_out_pins[i];
4368                 if (alc880_is_fixed_pin(nid)) {
4369                         int idx = alc880_fixed_pin_idx(nid);
4370                         spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
4371                         assigned[idx] = 1;
4372                 }
4373         }
4374         /* left pins can be connect to any audio widget */
4375         for (i = 0; i < cfg->line_outs; i++) {
4376                 nid = cfg->line_out_pins[i];
4377                 if (alc880_is_fixed_pin(nid))
4378                         continue;
4379                 /* search for an empty channel */
4380                 for (j = 0; j < cfg->line_outs; j++) {
4381                         if (!assigned[j]) {
4382                                 spec->multiout.dac_nids[i] =
4383                                         alc880_idx_to_dac(j);
4384                                 assigned[j] = 1;
4385                                 break;
4386                         }
4387                 }
4388         }
4389         spec->multiout.num_dacs = cfg->line_outs;
4390         return 0;
4391 }
4392
4393 /* add playback controls from the parsed DAC table */
4394 static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
4395                                              const struct auto_pin_cfg *cfg)
4396 {
4397         static const char *chname[4] = {
4398                 "Front", "Surround", NULL /*CLFE*/, "Side"
4399         };
4400         hda_nid_t nid;
4401         int i, err;
4402
4403         for (i = 0; i < cfg->line_outs; i++) {
4404                 if (!spec->multiout.dac_nids[i])
4405                         continue;
4406                 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
4407                 if (i == 2) {
4408                         /* Center/LFE */
4409                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
4410                                               "Center",
4411                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
4412                                                               HDA_OUTPUT));
4413                         if (err < 0)
4414                                 return err;
4415                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
4416                                               "LFE",
4417                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
4418                                                               HDA_OUTPUT));
4419                         if (err < 0)
4420                                 return err;
4421                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
4422                                              "Center",
4423                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
4424                                                               HDA_INPUT));
4425                         if (err < 0)
4426                                 return err;
4427                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
4428                                              "LFE",
4429                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
4430                                                               HDA_INPUT));
4431                         if (err < 0)
4432                                 return err;
4433                 } else {
4434                         const char *pfx;
4435                         if (cfg->line_outs == 1 &&
4436                             cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
4437                                 pfx = "Speaker";
4438                         else
4439                                 pfx = chname[i];
4440                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
4441                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
4442                                                               HDA_OUTPUT));
4443                         if (err < 0)
4444                                 return err;
4445                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE, pfx,
4446                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
4447                                                               HDA_INPUT));
4448                         if (err < 0)
4449                                 return err;
4450                 }
4451         }
4452         return 0;
4453 }
4454
4455 /* add playback controls for speaker and HP outputs */
4456 static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
4457                                         const char *pfx)
4458 {
4459         hda_nid_t nid;
4460         int err;
4461
4462         if (!pin)
4463                 return 0;
4464
4465         if (alc880_is_fixed_pin(pin)) {
4466                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
4467                 /* specify the DAC as the extra output */
4468                 if (!spec->multiout.hp_nid)
4469                         spec->multiout.hp_nid = nid;
4470                 else
4471                         spec->multiout.extra_out_nid[0] = nid;
4472                 /* control HP volume/switch on the output mixer amp */
4473                 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
4474                 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
4475                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
4476                 if (err < 0)
4477                         return err;
4478                 err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE, pfx,
4479                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
4480                 if (err < 0)
4481                         return err;
4482         } else if (alc880_is_multi_pin(pin)) {
4483                 /* set manual connection */
4484                 /* we have only a switch on HP-out PIN */
4485                 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
4486                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4487                 if (err < 0)
4488                         return err;
4489         }
4490         return 0;
4491 }
4492
4493 /* create input playback/capture controls for the given pin */
4494 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
4495                             const char *ctlname,
4496                             int idx, hda_nid_t mix_nid)
4497 {
4498         int err;
4499
4500         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname,
4501                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
4502         if (err < 0)
4503                 return err;
4504         err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname,
4505                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
4506         if (err < 0)
4507                 return err;
4508         return 0;
4509 }
4510
4511 static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
4512 {
4513         unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
4514         return (pincap & AC_PINCAP_IN) != 0;
4515 }
4516
4517 /* create playback/capture controls for input pins */
4518 static int alc_auto_create_input_ctls(struct hda_codec *codec,
4519                                       const struct auto_pin_cfg *cfg,
4520                                       hda_nid_t mixer,
4521                                       hda_nid_t cap1, hda_nid_t cap2)
4522 {
4523         struct alc_spec *spec = codec->spec;
4524         struct hda_input_mux *imux = &spec->private_imux[0];
4525         int i, err, idx;
4526
4527         for (i = 0; i < AUTO_PIN_LAST; i++) {
4528                 hda_nid_t pin;
4529
4530                 pin = cfg->input_pins[i];
4531                 if (!alc_is_input_pin(codec, pin))
4532                         continue;
4533
4534                 if (mixer) {
4535                         idx = get_connection_index(codec, mixer, pin);
4536                         if (idx >= 0) {
4537                                 err = new_analog_input(spec, pin,
4538                                                        auto_pin_cfg_labels[i],
4539                                                        idx, mixer);
4540                                 if (err < 0)
4541                                         return err;
4542                         }
4543                 }
4544
4545                 if (!cap1)
4546                         continue;
4547                 idx = get_connection_index(codec, cap1, pin);
4548                 if (idx < 0 && cap2)
4549                         idx = get_connection_index(codec, cap2, pin);
4550                 if (idx >= 0) {
4551                         imux->items[imux->num_items].label =
4552                                 auto_pin_cfg_labels[i];
4553                         imux->items[imux->num_items].index = idx;
4554                         imux->num_items++;
4555                 }
4556         }
4557         return 0;
4558 }
4559
4560 static int alc880_auto_create_input_ctls(struct hda_codec *codec,
4561                                                 const struct auto_pin_cfg *cfg)
4562 {
4563         return alc_auto_create_input_ctls(codec, cfg, 0x0b, 0x08, 0x09);
4564 }
4565
4566 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
4567                                unsigned int pin_type)
4568 {
4569         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4570                             pin_type);
4571         /* unmute pin */
4572         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4573                             AMP_OUT_UNMUTE);
4574 }
4575
4576 static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
4577                                               hda_nid_t nid, int pin_type,
4578                                               int dac_idx)
4579 {
4580         alc_set_pin_output(codec, nid, pin_type);
4581         /* need the manual connection? */
4582         if (alc880_is_multi_pin(nid)) {
4583                 struct alc_spec *spec = codec->spec;
4584                 int idx = alc880_multi_pin_idx(nid);
4585                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
4586                                     AC_VERB_SET_CONNECT_SEL,
4587                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
4588         }
4589 }
4590
4591 static int get_pin_type(int line_out_type)
4592 {
4593         if (line_out_type == AUTO_PIN_HP_OUT)
4594                 return PIN_HP;
4595         else
4596                 return PIN_OUT;
4597 }
4598
4599 static void alc880_auto_init_multi_out(struct hda_codec *codec)
4600 {
4601         struct alc_spec *spec = codec->spec;
4602         int i;
4603
4604         for (i = 0; i < spec->autocfg.line_outs; i++) {
4605                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
4606                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
4607                 alc880_auto_set_output_and_unmute(codec, nid, pin_type, i);
4608         }
4609 }
4610
4611 static void alc880_auto_init_extra_out(struct hda_codec *codec)
4612 {
4613         struct alc_spec *spec = codec->spec;
4614         hda_nid_t pin;
4615
4616         pin = spec->autocfg.speaker_pins[0];
4617         if (pin) /* connect to front */
4618                 alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
4619         pin = spec->autocfg.hp_pins[0];
4620         if (pin) /* connect to front */
4621                 alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
4622 }
4623
4624 static void alc880_auto_init_analog_input(struct hda_codec *codec)
4625 {
4626         struct alc_spec *spec = codec->spec;
4627         int i;
4628
4629         for (i = 0; i < AUTO_PIN_LAST; i++) {
4630                 hda_nid_t nid = spec->autocfg.input_pins[i];
4631                 if (alc_is_input_pin(codec, nid)) {
4632                         alc_set_input_pin(codec, nid, i);
4633                         if (nid != ALC880_PIN_CD_NID &&
4634                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
4635                                 snd_hda_codec_write(codec, nid, 0,
4636                                                     AC_VERB_SET_AMP_GAIN_MUTE,
4637                                                     AMP_OUT_MUTE);
4638                 }
4639         }
4640 }
4641
4642 /* parse the BIOS configuration and set up the alc_spec */
4643 /* return 1 if successful, 0 if the proper config is not found,
4644  * or a negative error code
4645  */
4646 static int alc880_parse_auto_config(struct hda_codec *codec)
4647 {
4648         struct alc_spec *spec = codec->spec;
4649         int i, err;
4650         static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4651
4652         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
4653                                            alc880_ignore);
4654         if (err < 0)
4655                 return err;
4656         if (!spec->autocfg.line_outs)
4657                 return 0; /* can't find valid BIOS pin config */
4658
4659         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
4660         if (err < 0)
4661                 return err;
4662         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
4663         if (err < 0)
4664                 return err;
4665         err = alc880_auto_create_extra_out(spec,
4666                                            spec->autocfg.speaker_pins[0],
4667                                            "Speaker");
4668         if (err < 0)
4669                 return err;
4670         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
4671                                            "Headphone");
4672         if (err < 0)
4673                 return err;
4674         err = alc880_auto_create_input_ctls(codec, &spec->autocfg);
4675         if (err < 0)
4676                 return err;
4677
4678         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4679
4680         /* check multiple SPDIF-out (for recent codecs) */
4681         for (i = 0; i < spec->autocfg.dig_outs; i++) {
4682                 hda_nid_t dig_nid;
4683                 err = snd_hda_get_connections(codec,
4684                                               spec->autocfg.dig_out_pins[i],
4685                                               &dig_nid, 1);
4686                 if (err < 0)
4687                         continue;
4688                 if (!i)
4689                         spec->multiout.dig_out_nid = dig_nid;
4690                 else {
4691                         spec->multiout.slave_dig_outs = spec->slave_dig_outs;
4692                         if (i >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
4693                                 break;
4694                         spec->slave_dig_outs[i - 1] = dig_nid;
4695                 }
4696         }
4697         if (spec->autocfg.dig_in_pin)
4698                 spec->dig_in_nid = ALC880_DIGIN_NID;
4699
4700         if (spec->kctls.list)
4701                 add_mixer(spec, spec->kctls.list);
4702
4703         add_verb(spec, alc880_volume_init_verbs);
4704
4705         spec->num_mux_defs = 1;
4706         spec->input_mux = &spec->private_imux[0];
4707
4708         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
4709
4710         return 1;
4711 }
4712
4713 /* additional initialization for auto-configuration model */
4714 static void alc880_auto_init(struct hda_codec *codec)
4715 {
4716         struct alc_spec *spec = codec->spec;
4717         alc880_auto_init_multi_out(codec);
4718         alc880_auto_init_extra_out(codec);
4719         alc880_auto_init_analog_input(codec);
4720         if (spec->unsol_event)
4721                 alc_inithook(codec);
4722 }
4723
4724 /* check the ADC/MUX contains all input pins; some ADC/MUX contains only
4725  * one of two digital mic pins, e.g. on ALC272
4726  */
4727 static void fixup_automic_adc(struct hda_codec *codec)
4728 {
4729         struct alc_spec *spec = codec->spec;
4730         int i;
4731
4732         for (i = 0; i < spec->num_adc_nids; i++) {
4733                 hda_nid_t cap = spec->capsrc_nids ?
4734                         spec->capsrc_nids[i] : spec->adc_nids[i];
4735                 int iidx, eidx;
4736
4737                 iidx = get_connection_index(codec, cap, spec->int_mic.pin);
4738                 if (iidx < 0)
4739                         continue;
4740                 eidx = get_connection_index(codec, cap, spec->ext_mic.pin);
4741                 if (eidx < 0)
4742                         continue;
4743                 spec->int_mic.mux_idx = iidx;
4744                 spec->ext_mic.mux_idx = eidx;
4745                 if (spec->capsrc_nids)
4746                         spec->capsrc_nids += i;
4747                 spec->adc_nids += i;
4748                 spec->num_adc_nids = 1;
4749                 return;
4750         }
4751         snd_printd(KERN_INFO "hda_codec: %s: "
4752                    "No ADC/MUX containing both 0x%x and 0x%x pins\n",
4753                    codec->chip_name, spec->int_mic.pin, spec->ext_mic.pin);
4754         spec->auto_mic = 0; /* disable auto-mic to be sure */
4755 }
4756
4757 static void set_capture_mixer(struct hda_codec *codec)
4758 {
4759         struct alc_spec *spec = codec->spec;
4760         static struct snd_kcontrol_new *caps[2][3] = {
4761                 { alc_capture_mixer_nosrc1,
4762                   alc_capture_mixer_nosrc2,
4763                   alc_capture_mixer_nosrc3 },
4764                 { alc_capture_mixer1,
4765                   alc_capture_mixer2,
4766                   alc_capture_mixer3 },
4767         };
4768         if (spec->num_adc_nids > 0 && spec->num_adc_nids <= 3) {
4769                 int mux;
4770                 if (spec->auto_mic) {
4771                         mux = 0;
4772                         fixup_automic_adc(codec);
4773                 } else if (spec->input_mux && spec->input_mux->num_items > 1)
4774                         mux = 1;
4775                 else
4776                         mux = 0;
4777                 spec->cap_mixer = caps[mux][spec->num_adc_nids - 1];
4778         }
4779 }
4780
4781 #define set_beep_amp(spec, nid, idx, dir) \
4782         ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4783
4784 /*
4785  * OK, here we have finally the patch for ALC880
4786  */
4787
4788 static int patch_alc880(struct hda_codec *codec)
4789 {
4790         struct alc_spec *spec;
4791         int board_config;
4792         int err;
4793
4794         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4795         if (spec == NULL)
4796                 return -ENOMEM;
4797
4798         codec->spec = spec;
4799
4800         board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
4801                                                   alc880_models,
4802                                                   alc880_cfg_tbl);
4803         if (board_config < 0) {
4804                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4805                        codec->chip_name);
4806                 board_config = ALC880_AUTO;
4807         }
4808
4809         if (board_config == ALC880_AUTO) {
4810                 /* automatic parse from the BIOS config */
4811                 err = alc880_parse_auto_config(codec);
4812                 if (err < 0) {
4813                         alc_free(codec);
4814                         return err;
4815                 } else if (!err) {
4816                         printk(KERN_INFO
4817                                "hda_codec: Cannot set up configuration "
4818                                "from BIOS.  Using 3-stack mode...\n");
4819                         board_config = ALC880_3ST;
4820                 }
4821         }
4822
4823         err = snd_hda_attach_beep_device(codec, 0x1);
4824         if (err < 0) {
4825                 alc_free(codec);
4826                 return err;
4827         }
4828
4829         if (board_config != ALC880_AUTO)
4830                 setup_preset(codec, &alc880_presets[board_config]);
4831
4832         spec->stream_analog_playback = &alc880_pcm_analog_playback;
4833         spec->stream_analog_capture = &alc880_pcm_analog_capture;
4834         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
4835
4836         spec->stream_digital_playback = &alc880_pcm_digital_playback;
4837         spec->stream_digital_capture = &alc880_pcm_digital_capture;
4838
4839         if (!spec->adc_nids && spec->input_mux) {
4840                 /* check whether NID 0x07 is valid */
4841                 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
4842                 /* get type */
4843                 wcap = get_wcaps_type(wcap);
4844                 if (wcap != AC_WID_AUD_IN) {
4845                         spec->adc_nids = alc880_adc_nids_alt;
4846                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
4847                 } else {
4848                         spec->adc_nids = alc880_adc_nids;
4849                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
4850                 }
4851         }
4852         set_capture_mixer(codec);
4853         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4854
4855         spec->vmaster_nid = 0x0c;
4856
4857         codec->patch_ops = alc_patch_ops;
4858         if (board_config == ALC880_AUTO)
4859                 spec->init_hook = alc880_auto_init;
4860 #ifdef CONFIG_SND_HDA_POWER_SAVE
4861         if (!spec->loopback.amplist)
4862                 spec->loopback.amplist = alc880_loopbacks;
4863 #endif
4864         codec->proc_widget_hook = print_realtek_coef;
4865
4866         return 0;
4867 }
4868
4869
4870 /*
4871  * ALC260 support
4872  */
4873
4874 static hda_nid_t alc260_dac_nids[1] = {
4875         /* front */
4876         0x02,
4877 };
4878
4879 static hda_nid_t alc260_adc_nids[1] = {
4880         /* ADC0 */
4881         0x04,
4882 };
4883
4884 static hda_nid_t alc260_adc_nids_alt[1] = {
4885         /* ADC1 */
4886         0x05,
4887 };
4888
4889 /* NIDs used when simultaneous access to both ADCs makes sense.  Note that
4890  * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
4891  */
4892 static hda_nid_t alc260_dual_adc_nids[2] = {
4893         /* ADC0, ADC1 */
4894         0x04, 0x05
4895 };
4896
4897 #define ALC260_DIGOUT_NID       0x03
4898 #define ALC260_DIGIN_NID        0x06
4899
4900 static struct hda_input_mux alc260_capture_source = {
4901         .num_items = 4,
4902         .items = {
4903                 { "Mic", 0x0 },
4904                 { "Front Mic", 0x1 },
4905                 { "Line", 0x2 },
4906                 { "CD", 0x4 },
4907         },
4908 };
4909
4910 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
4911  * headphone jack and the internal CD lines since these are the only pins at
4912  * which audio can appear.  For flexibility, also allow the option of
4913  * recording the mixer output on the second ADC (ADC0 doesn't have a
4914  * connection to the mixer output).
4915  */
4916 static struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
4917         {
4918                 .num_items = 3,
4919                 .items = {
4920                         { "Mic/Line", 0x0 },
4921                         { "CD", 0x4 },
4922                         { "Headphone", 0x2 },
4923                 },
4924         },
4925         {
4926                 .num_items = 4,
4927                 .items = {
4928                         { "Mic/Line", 0x0 },
4929                         { "CD", 0x4 },
4930                         { "Headphone", 0x2 },
4931                         { "Mixer", 0x5 },
4932                 },
4933         },
4934
4935 };
4936
4937 /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
4938  * the Fujitsu S702x, but jacks are marked differently.
4939  */
4940 static struct hda_input_mux alc260_acer_capture_sources[2] = {
4941         {
4942                 .num_items = 4,
4943                 .items = {
4944                         { "Mic", 0x0 },
4945                         { "Line", 0x2 },
4946                         { "CD", 0x4 },
4947                         { "Headphone", 0x5 },
4948                 },
4949         },
4950         {
4951                 .num_items = 5,
4952                 .items = {
4953                         { "Mic", 0x0 },
4954                         { "Line", 0x2 },
4955                         { "CD", 0x4 },
4956                         { "Headphone", 0x6 },
4957                         { "Mixer", 0x5 },
4958                 },
4959         },
4960 };
4961
4962 /* Maxdata Favorit 100XS */
4963 static struct hda_input_mux alc260_favorit100_capture_sources[2] = {
4964         {
4965                 .num_items = 2,
4966                 .items = {
4967                         { "Line/Mic", 0x0 },
4968                         { "CD", 0x4 },
4969                 },
4970         },
4971         {
4972                 .num_items = 3,
4973                 .items = {
4974                         { "Line/Mic", 0x0 },
4975                         { "CD", 0x4 },
4976                         { "Mixer", 0x5 },
4977                 },
4978         },
4979 };
4980
4981 /*
4982  * This is just place-holder, so there's something for alc_build_pcms to look
4983  * at when it calculates the maximum number of channels. ALC260 has no mixer
4984  * element which allows changing the channel mode, so the verb list is
4985  * never used.
4986  */
4987 static struct hda_channel_mode alc260_modes[1] = {
4988         { 2, NULL },
4989 };
4990
4991
4992 /* Mixer combinations
4993  *
4994  * basic: base_output + input + pc_beep + capture
4995  * HP: base_output + input + capture_alt
4996  * HP_3013: hp_3013 + input + capture
4997  * fujitsu: fujitsu + capture
4998  * acer: acer + capture
4999  */
5000
5001 static struct snd_kcontrol_new alc260_base_output_mixer[] = {
5002         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5003         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
5004         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5005         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
5006         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
5007         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
5008         { } /* end */
5009 };
5010
5011 static struct snd_kcontrol_new alc260_input_mixer[] = {
5012         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5013         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5014         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
5015         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
5016         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
5017         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
5018         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
5019         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
5020         { } /* end */
5021 };
5022
5023 /* update HP, line and mono out pins according to the master switch */
5024 static void alc260_hp_master_update(struct hda_codec *codec,
5025                                     hda_nid_t hp, hda_nid_t line,
5026                                     hda_nid_t mono)
5027 {
5028         struct alc_spec *spec = codec->spec;
5029         unsigned int val = spec->master_sw ? PIN_HP : 0;
5030         /* change HP and line-out pins */
5031         snd_hda_codec_write(codec, hp, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5032                             val);
5033         snd_hda_codec_write(codec, line, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5034                             val);
5035         /* mono (speaker) depending on the HP jack sense */
5036         val = (val && !spec->jack_present) ? PIN_OUT : 0;
5037         snd_hda_codec_write(codec, mono, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5038                             val);
5039 }
5040
5041 static int alc260_hp_master_sw_get(struct snd_kcontrol *kcontrol,
5042                                    struct snd_ctl_elem_value *ucontrol)
5043 {
5044         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5045         struct alc_spec *spec = codec->spec;
5046         *ucontrol->value.integer.value = spec->master_sw;
5047         return 0;
5048 }
5049
5050 static int alc260_hp_master_sw_put(struct snd_kcontrol *kcontrol,
5051                                    struct snd_ctl_elem_value *ucontrol)
5052 {
5053         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5054         struct alc_spec *spec = codec->spec;
5055         int val = !!*ucontrol->value.integer.value;
5056         hda_nid_t hp, line, mono;
5057
5058         if (val == spec->master_sw)
5059                 return 0;
5060         spec->master_sw = val;
5061         hp = (kcontrol->private_value >> 16) & 0xff;
5062         line = (kcontrol->private_value >> 8) & 0xff;
5063         mono = kcontrol->private_value & 0xff;
5064         alc260_hp_master_update(codec, hp, line, mono);
5065         return 1;
5066 }
5067
5068 static struct snd_kcontrol_new alc260_hp_output_mixer[] = {
5069         {
5070                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5071                 .name = "Master Playback Switch",
5072                 .info = snd_ctl_boolean_mono_info,
5073                 .get = alc260_hp_master_sw_get,
5074                 .put = alc260_hp_master_sw_put,
5075                 .private_value = (0x0f << 16) | (0x10 << 8) | 0x11
5076         },
5077         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5078         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
5079         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5080         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
5081         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
5082                               HDA_OUTPUT),
5083         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2, HDA_INPUT),
5084         { } /* end */
5085 };
5086
5087 static struct hda_verb alc260_hp_unsol_verbs[] = {
5088         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5089         {},
5090 };
5091
5092 static void alc260_hp_automute(struct hda_codec *codec)
5093 {
5094         struct alc_spec *spec = codec->spec;
5095         unsigned int present;
5096
5097         present = snd_hda_codec_read(codec, 0x10, 0,
5098                                      AC_VERB_GET_PIN_SENSE, 0);
5099         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
5100         alc260_hp_master_update(codec, 0x0f, 0x10, 0x11);
5101 }
5102
5103 static void alc260_hp_unsol_event(struct hda_codec *codec, unsigned int res)
5104 {
5105         if ((res >> 26) == ALC880_HP_EVENT)
5106                 alc260_hp_automute(codec);
5107 }
5108
5109 static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
5110         {
5111                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5112                 .name = "Master Playback Switch",
5113                 .info = snd_ctl_boolean_mono_info,
5114                 .get = alc260_hp_master_sw_get,
5115                 .put = alc260_hp_master_sw_put,
5116                 .private_value = (0x15 << 16) | (0x10 << 8) | 0x11
5117         },
5118         HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5119         HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
5120         HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
5121         HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
5122         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5123         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
5124         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
5125         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
5126         { } /* end */
5127 };
5128
5129 static struct hda_bind_ctls alc260_dc7600_bind_master_vol = {
5130         .ops = &snd_hda_bind_vol,
5131         .values = {
5132                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_OUTPUT),
5133                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
5134                 HDA_COMPOSE_AMP_VAL(0x0a, 3, 0, HDA_OUTPUT),
5135                 0
5136         },
5137 };
5138
5139 static struct hda_bind_ctls alc260_dc7600_bind_switch = {
5140         .ops = &snd_hda_bind_sw,
5141         .values = {
5142                 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
5143                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
5144                 0
5145         },
5146 };
5147
5148 static struct snd_kcontrol_new alc260_hp_dc7600_mixer[] = {
5149         HDA_BIND_VOL("Master Playback Volume", &alc260_dc7600_bind_master_vol),
5150         HDA_BIND_SW("LineOut Playback Switch", &alc260_dc7600_bind_switch),
5151         HDA_CODEC_MUTE("Speaker Playback Switch", 0x0f, 0x0, HDA_OUTPUT),
5152         HDA_CODEC_MUTE("Headphone Playback Switch", 0x10, 0x0, HDA_OUTPUT),
5153         { } /* end */
5154 };
5155
5156 static struct hda_verb alc260_hp_3013_unsol_verbs[] = {
5157         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5158         {},
5159 };
5160
5161 static void alc260_hp_3013_automute(struct hda_codec *codec)
5162 {
5163         struct alc_spec *spec = codec->spec;
5164         unsigned int present;
5165
5166         present = snd_hda_codec_read(codec, 0x15, 0,
5167                                      AC_VERB_GET_PIN_SENSE, 0);
5168         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
5169         alc260_hp_master_update(codec, 0x15, 0x10, 0x11);
5170 }
5171
5172 static void alc260_hp_3013_unsol_event(struct hda_codec *codec,
5173                                        unsigned int res)
5174 {
5175         if ((res >> 26) == ALC880_HP_EVENT)
5176                 alc260_hp_3013_automute(codec);
5177 }
5178
5179 static void alc260_hp_3012_automute(struct hda_codec *codec)
5180 {
5181         unsigned int present, bits;
5182
5183         present = snd_hda_codec_read(codec, 0x10, 0,
5184                         AC_VERB_GET_PIN_SENSE, 0) & AC_PINSENSE_PRESENCE;
5185
5186         bits = present ? 0 : PIN_OUT;
5187         snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5188                             bits);
5189         snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5190                             bits);
5191         snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5192                             bits);
5193 }
5194
5195 static void alc260_hp_3012_unsol_event(struct hda_codec *codec,
5196                                        unsigned int res)
5197 {
5198         if ((res >> 26) == ALC880_HP_EVENT)
5199                 alc260_hp_3012_automute(codec);
5200 }
5201
5202 /* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12,
5203  * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
5204  */
5205 static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
5206         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5207         HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
5208         ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
5209         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5210         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5211         HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
5212         HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
5213         ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
5214         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5215         HDA_BIND_MUTE("Speaker Playback Switch", 0x09, 2, HDA_INPUT),
5216         { } /* end */
5217 };
5218
5219 /* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks.  Note that current
5220  * versions of the ALC260 don't act on requests to enable mic bias from NID
5221  * 0x0f (used to drive the headphone jack in these laptops).  The ALC260
5222  * datasheet doesn't mention this restriction.  At this stage it's not clear
5223  * whether this behaviour is intentional or is a hardware bug in chip
5224  * revisions available in early 2006.  Therefore for now allow the
5225  * "Headphone Jack Mode" control to span all choices, but if it turns out
5226  * that the lack of mic bias for this NID is intentional we could change the
5227  * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
5228  *
5229  * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
5230  * don't appear to make the mic bias available from the "line" jack, even
5231  * though the NID used for this jack (0x14) can supply it.  The theory is
5232  * that perhaps Acer have included blocking capacitors between the ALC260
5233  * and the output jack.  If this turns out to be the case for all such
5234  * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
5235  * to ALC_PIN_DIR_INOUT_NOMICBIAS.
5236  *
5237  * The C20x Tablet series have a mono internal speaker which is controlled
5238  * via the chip's Mono sum widget and pin complex, so include the necessary
5239  * controls for such models.  On models without a "mono speaker" the control
5240  * won't do anything.
5241  */
5242 static struct snd_kcontrol_new alc260_acer_mixer[] = {
5243         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5244         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
5245         ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
5246         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
5247                               HDA_OUTPUT),
5248         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2,
5249                            HDA_INPUT),
5250         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5251         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5252         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
5253         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
5254         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
5255         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
5256         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
5257         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
5258         { } /* end */
5259 };
5260
5261 /* Maxdata Favorit 100XS: one output and one input (0x12) jack
5262  */
5263 static struct snd_kcontrol_new alc260_favorit100_mixer[] = {
5264         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5265         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
5266         ALC_PIN_MODE("Output Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
5267         HDA_CODEC_VOLUME("Line/Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
5268         HDA_CODEC_MUTE("Line/Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
5269         ALC_PIN_MODE("Line/Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
5270         { } /* end */
5271 };
5272
5273 /* Packard bell V7900  ALC260 pin usage: HP = 0x0f, Mic jack = 0x12,
5274  * Line In jack = 0x14, CD audio =  0x16, pc beep = 0x17.
5275  */
5276 static struct snd_kcontrol_new alc260_will_mixer[] = {
5277         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5278         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
5279         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
5280         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
5281         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
5282         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
5283         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
5284         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
5285         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5286         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5287         { } /* end */
5288 };
5289
5290 /* Replacer 672V ALC260 pin usage: Mic jack = 0x12,
5291  * Line In jack = 0x14, ATAPI Mic = 0x13, speaker = 0x0f.
5292  */
5293 static struct snd_kcontrol_new alc260_replacer_672v_mixer[] = {
5294         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5295         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
5296         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
5297         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
5298         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
5299         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x07, 0x1, HDA_INPUT),
5300         HDA_CODEC_MUTE("ATATI Mic Playback Switch", 0x07, 0x1, HDA_INPUT),
5301         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
5302         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
5303         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
5304         { } /* end */
5305 };
5306
5307 /*
5308  * initialization verbs
5309  */
5310 static struct hda_verb alc260_init_verbs[] = {
5311         /* Line In pin widget for input */
5312         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5313         /* CD pin widget for input */
5314         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5315         /* Mic1 (rear panel) pin widget for input and vref at 80% */
5316         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5317         /* Mic2 (front panel) pin widget for input and vref at 80% */
5318         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5319         /* LINE-2 is used for line-out in rear */
5320         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5321         /* select line-out */
5322         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
5323         /* LINE-OUT pin */
5324         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5325         /* enable HP */
5326         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5327         /* enable Mono */
5328         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5329         /* mute capture amp left and right */
5330         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5331         /* set connection select to line in (default select for this ADC) */
5332         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
5333         /* mute capture amp left and right */
5334         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5335         /* set connection select to line in (default select for this ADC) */
5336         {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
5337         /* set vol=0 Line-Out mixer amp left and right */
5338         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5339         /* unmute pin widget amp left and right (no gain on this amp) */
5340         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5341         /* set vol=0 HP mixer amp left and right */
5342         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5343         /* unmute pin widget amp left and right (no gain on this amp) */
5344         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5345         /* set vol=0 Mono mixer amp left and right */
5346         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5347         /* unmute pin widget amp left and right (no gain on this amp) */
5348         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5349         /* unmute LINE-2 out pin */
5350         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5351         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
5352          * Line In 2 = 0x03
5353          */
5354         /* mute analog inputs */
5355         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5356         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5357         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5358         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5359         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5360         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
5361         /* mute Front out path */
5362         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5363         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5364         /* mute Headphone out path */
5365         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5366         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5367         /* mute Mono out path */
5368         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5369         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5370         { }
5371 };
5372
5373 #if 0 /* should be identical with alc260_init_verbs? */
5374 static struct hda_verb alc260_hp_init_verbs[] = {
5375         /* Headphone and output */
5376         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
5377         /* mono output */
5378         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5379         /* Mic1 (rear panel) pin widget for input and vref at 80% */
5380         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
5381         /* Mic2 (front panel) pin widget for input and vref at 80% */
5382         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
5383         /* Line In pin widget for input */
5384         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
5385         /* Line-2 pin widget for output */
5386         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5387         /* CD pin widget for input */
5388         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
5389         /* unmute amp left and right */
5390         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
5391         /* set connection select to line in (default select for this ADC) */
5392         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
5393         /* unmute Line-Out mixer amp left and right (volume = 0) */
5394         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5395         /* mute pin widget amp left and right (no gain on this amp) */
5396         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5397         /* unmute HP mixer amp left and right (volume = 0) */
5398         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5399         /* mute pin widget amp left and right (no gain on this amp) */
5400         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5401         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
5402          * Line In 2 = 0x03
5403          */
5404         /* mute analog inputs */
5405         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5406         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5407         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5408         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5409         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5410         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
5411         /* Unmute Front out path */
5412         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5413         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5414         /* Unmute Headphone out path */
5415         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5416         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5417         /* Unmute Mono out path */
5418         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5419         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5420         { }
5421 };
5422 #endif
5423
5424 static struct hda_verb alc260_hp_3013_init_verbs[] = {
5425         /* Line out and output */
5426         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5427         /* mono output */
5428         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5429         /* Mic1 (rear panel) pin widget for input and vref at 80% */
5430         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
5431         /* Mic2 (front panel) pin widget for input and vref at 80% */
5432         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
5433         /* Line In pin widget for input */
5434         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
5435         /* Headphone pin widget for output */
5436         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
5437         /* CD pin widget for input */
5438         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
5439         /* unmute amp left and right */
5440         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
5441         /* set connection select to line in (default select for this ADC) */
5442         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
5443         /* unmute Line-Out mixer amp left and right (volume = 0) */
5444         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5445         /* mute pin widget amp left and right (no gain on this amp) */
5446         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5447         /* unmute HP mixer amp left and right (volume = 0) */
5448         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5449         /* mute pin widget amp left and right (no gain on this amp) */
5450         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5451         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
5452          * Line In 2 = 0x03
5453          */
5454         /* mute analog inputs */
5455         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5456         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5457         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5458         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5459         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5460         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
5461         /* Unmute Front out path */
5462         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5463         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5464         /* Unmute Headphone out path */
5465         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5466         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5467         /* Unmute Mono out path */
5468         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5469         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5470         { }
5471 };
5472
5473 /* Initialisation sequence for ALC260 as configured in Fujitsu S702x
5474  * laptops.  ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
5475  * audio = 0x16, internal speaker = 0x10.
5476  */
5477 static struct hda_verb alc260_fujitsu_init_verbs[] = {
5478         /* Disable all GPIOs */
5479         {0x01, AC_VERB_SET_GPIO_MASK, 0},
5480         /* Internal speaker is connected to headphone pin */
5481         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5482         /* Headphone/Line-out jack connects to Line1 pin; make it an output */
5483         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5484         /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
5485         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5486         /* Ensure all other unused pins are disabled and muted. */
5487         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5488         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5489         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5490         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5491         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5492         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5493         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5494         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5495
5496         /* Disable digital (SPDIF) pins */
5497         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5498         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5499
5500         /* Ensure Line1 pin widget takes its input from the OUT1 sum bus
5501          * when acting as an output.
5502          */
5503         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5504
5505         /* Start with output sum widgets muted and their output gains at min */
5506         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5507         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5508         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5509         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5510         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5511         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5512         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5513         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5514         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5515
5516         /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
5517         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5518         /* Unmute Line1 pin widget output buffer since it starts as an output.
5519          * If the pin mode is changed by the user the pin mode control will
5520          * take care of enabling the pin's input/output buffers as needed.
5521          * Therefore there's no need to enable the input buffer at this
5522          * stage.
5523          */
5524         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5525         /* Unmute input buffer of pin widget used for Line-in (no equiv
5526          * mixer ctrl)
5527          */
5528         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5529
5530         /* Mute capture amp left and right */
5531         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5532         /* Set ADC connection select to match default mixer setting - line
5533          * in (on mic1 pin)
5534          */
5535         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5536
5537         /* Do the same for the second ADC: mute capture input amp and
5538          * set ADC connection to line in (on mic1 pin)
5539          */
5540         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5541         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5542
5543         /* Mute all inputs to mixer widget (even unconnected ones) */
5544         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5545         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5546         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5547         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5548         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5549         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5550         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5551         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5552
5553         { }
5554 };
5555
5556 /* Initialisation sequence for ALC260 as configured in Acer TravelMate and
5557  * similar laptops (adapted from Fujitsu init verbs).
5558  */
5559 static struct hda_verb alc260_acer_init_verbs[] = {
5560         /* On TravelMate laptops, GPIO 0 enables the internal speaker and
5561          * the headphone jack.  Turn this on and rely on the standard mute
5562          * methods whenever the user wants to turn these outputs off.
5563          */
5564         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5565         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5566         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5567         /* Internal speaker/Headphone jack is connected to Line-out pin */
5568         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5569         /* Internal microphone/Mic jack is connected to Mic1 pin */
5570         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
5571         /* Line In jack is connected to Line1 pin */
5572         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5573         /* Some Acers (eg: C20x Tablets) use Mono pin for internal speaker */
5574         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5575         /* Ensure all other unused pins are disabled and muted. */
5576         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5577         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5578         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5579         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5580         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5581         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5582         /* Disable digital (SPDIF) pins */
5583         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5584         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5585
5586         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
5587          * bus when acting as outputs.
5588          */
5589         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5590         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5591
5592         /* Start with output sum widgets muted and their output gains at min */
5593         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5594         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5595         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5596         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5597         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5598         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5599         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5600         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5601         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5602
5603         /* Unmute Line-out pin widget amp left and right
5604          * (no equiv mixer ctrl)
5605          */
5606         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5607         /* Unmute mono pin widget amp output (no equiv mixer ctrl) */
5608         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5609         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
5610          * inputs. If the pin mode is changed by the user the pin mode control
5611          * will take care of enabling the pin's input/output buffers as needed.
5612          * Therefore there's no need to enable the input buffer at this
5613          * stage.
5614          */
5615         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5616         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5617
5618         /* Mute capture amp left and right */
5619         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5620         /* Set ADC connection select to match default mixer setting - mic
5621          * (on mic1 pin)
5622          */
5623         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5624
5625         /* Do similar with the second ADC: mute capture input amp and
5626          * set ADC connection to mic to match ALSA's default state.
5627          */
5628         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5629         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5630
5631         /* Mute all inputs to mixer widget (even unconnected ones) */
5632         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5633         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5634         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5635         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5636         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5637         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5638         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5639         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5640
5641         { }
5642 };
5643
5644 /* Initialisation sequence for Maxdata Favorit 100XS
5645  * (adapted from Acer init verbs).
5646  */
5647 static struct hda_verb alc260_favorit100_init_verbs[] = {
5648         /* GPIO 0 enables the output jack.
5649          * Turn this on and rely on the standard mute
5650          * methods whenever the user wants to turn these outputs off.
5651          */
5652         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5653         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5654         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5655         /* Line/Mic input jack is connected to Mic1 pin */
5656         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
5657         /* Ensure all other unused pins are disabled and muted. */
5658         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5659         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5660         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5661         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5662         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5663         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5664         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5665         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5666         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5667         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5668         /* Disable digital (SPDIF) pins */
5669         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5670         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5671
5672         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
5673          * bus when acting as outputs.
5674          */
5675         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5676         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5677
5678         /* Start with output sum widgets muted and their output gains at min */
5679         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5680         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5681         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5682         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5683         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5684         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5685         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5686         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5687         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5688
5689         /* Unmute Line-out pin widget amp left and right
5690          * (no equiv mixer ctrl)
5691          */
5692         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5693         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
5694          * inputs. If the pin mode is changed by the user the pin mode control
5695          * will take care of enabling the pin's input/output buffers as needed.
5696          * Therefore there's no need to enable the input buffer at this
5697          * stage.
5698          */
5699         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5700
5701         /* Mute capture amp left and right */
5702         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5703         /* Set ADC connection select to match default mixer setting - mic
5704          * (on mic1 pin)
5705          */
5706         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5707
5708         /* Do similar with the second ADC: mute capture input amp and
5709          * set ADC connection to mic to match ALSA's default state.
5710          */
5711         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5712         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5713
5714         /* Mute all inputs to mixer widget (even unconnected ones) */
5715         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5716         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5717         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5718         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5719         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5720         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5721         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5722         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5723
5724         { }
5725 };
5726
5727 static struct hda_verb alc260_will_verbs[] = {
5728         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5729         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x00},
5730         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
5731         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
5732         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
5733         {0x1a, AC_VERB_SET_PROC_COEF, 0x3040},
5734         {}
5735 };
5736
5737 static struct hda_verb alc260_replacer_672v_verbs[] = {
5738         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
5739         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
5740         {0x1a, AC_VERB_SET_PROC_COEF, 0x3050},
5741
5742         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5743         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5744         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5745
5746         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5747         {}
5748 };
5749
5750 /* toggle speaker-output according to the hp-jack state */
5751 static void alc260_replacer_672v_automute(struct hda_codec *codec)
5752 {
5753         unsigned int present;
5754
5755         /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
5756         present = snd_hda_codec_read(codec, 0x0f, 0,
5757                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5758         if (present) {
5759                 snd_hda_codec_write_cache(codec, 0x01, 0,
5760                                           AC_VERB_SET_GPIO_DATA, 1);
5761                 snd_hda_codec_write_cache(codec, 0x0f, 0,
5762                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
5763                                           PIN_HP);
5764         } else {
5765                 snd_hda_codec_write_cache(codec, 0x01, 0,
5766                                           AC_VERB_SET_GPIO_DATA, 0);
5767                 snd_hda_codec_write_cache(codec, 0x0f, 0,
5768                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
5769                                           PIN_OUT);
5770         }
5771 }
5772
5773 static void alc260_replacer_672v_unsol_event(struct hda_codec *codec,
5774                                        unsigned int res)
5775 {
5776         if ((res >> 26) == ALC880_HP_EVENT)
5777                 alc260_replacer_672v_automute(codec);
5778 }
5779
5780 static struct hda_verb alc260_hp_dc7600_verbs[] = {
5781         {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
5782         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
5783         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5784         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5785         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5786         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5787         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5788         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5789         {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5790         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5791         {}
5792 };
5793
5794 /* Test configuration for debugging, modelled after the ALC880 test
5795  * configuration.
5796  */
5797 #ifdef CONFIG_SND_DEBUG
5798 static hda_nid_t alc260_test_dac_nids[1] = {
5799         0x02,
5800 };
5801 static hda_nid_t alc260_test_adc_nids[2] = {
5802         0x04, 0x05,
5803 };
5804 /* For testing the ALC260, each input MUX needs its own definition since
5805  * the signal assignments are different.  This assumes that the first ADC
5806  * is NID 0x04.
5807  */
5808 static struct hda_input_mux alc260_test_capture_sources[2] = {
5809         {
5810                 .num_items = 7,
5811                 .items = {
5812                         { "MIC1 pin", 0x0 },
5813                         { "MIC2 pin", 0x1 },
5814                         { "LINE1 pin", 0x2 },
5815                         { "LINE2 pin", 0x3 },
5816                         { "CD pin", 0x4 },
5817                         { "LINE-OUT pin", 0x5 },
5818                         { "HP-OUT pin", 0x6 },
5819                 },
5820         },
5821         {
5822                 .num_items = 8,
5823                 .items = {
5824                         { "MIC1 pin", 0x0 },
5825                         { "MIC2 pin", 0x1 },
5826                         { "LINE1 pin", 0x2 },
5827                         { "LINE2 pin", 0x3 },
5828                         { "CD pin", 0x4 },
5829                         { "Mixer", 0x5 },
5830                         { "LINE-OUT pin", 0x6 },
5831                         { "HP-OUT pin", 0x7 },
5832                 },
5833         },
5834 };
5835 static struct snd_kcontrol_new alc260_test_mixer[] = {
5836         /* Output driver widgets */
5837         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
5838         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
5839         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5840         HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
5841         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5842         HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),
5843
5844         /* Modes for retasking pin widgets
5845          * Note: the ALC260 doesn't seem to act on requests to enable mic
5846          * bias from NIDs 0x0f and 0x10.  The ALC260 datasheet doesn't
5847          * mention this restriction.  At this stage it's not clear whether
5848          * this behaviour is intentional or is a hardware bug in chip
5849          * revisions available at least up until early 2006.  Therefore for
5850          * now allow the "HP-OUT" and "LINE-OUT" Mode controls to span all
5851          * choices, but if it turns out that the lack of mic bias for these
5852          * NIDs is intentional we could change their modes from
5853          * ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
5854          */
5855         ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
5856         ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
5857         ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
5858         ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
5859         ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
5860         ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),
5861
5862         /* Loopback mixer controls */
5863         HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
5864         HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
5865         HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
5866         HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
5867         HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
5868         HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
5869         HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
5870         HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
5871         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5872         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5873         HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
5874         HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
5875         HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
5876         HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
5877
5878         /* Controls for GPIO pins, assuming they are configured as outputs */
5879         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
5880         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
5881         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
5882         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
5883
5884         /* Switches to allow the digital IO pins to be enabled.  The datasheet
5885          * is ambigious as to which NID is which; testing on laptops which
5886          * make this output available should provide clarification.
5887          */
5888         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
5889         ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),
5890
5891         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
5892          * this output to turn on an external amplifier.
5893          */
5894         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
5895         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
5896
5897         { } /* end */
5898 };
5899 static struct hda_verb alc260_test_init_verbs[] = {
5900         /* Enable all GPIOs as outputs with an initial value of 0 */
5901         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
5902         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5903         {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
5904
5905         /* Enable retasking pins as output, initially without power amp */
5906         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5907         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5908         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5909         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5910         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5911         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5912
5913         /* Disable digital (SPDIF) pins initially, but users can enable
5914          * them via a mixer switch.  In the case of SPDIF-out, this initverb
5915          * payload also sets the generation to 0, output to be in "consumer"
5916          * PCM format, copyright asserted, no pre-emphasis and no validity
5917          * control.
5918          */
5919         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5920         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5921
5922         /* Ensure mic1, mic2, line1 and line2 pin widgets take input from the
5923          * OUT1 sum bus when acting as an output.
5924          */
5925         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5926         {0x0c, AC_VERB_SET_CONNECT_SEL, 0},
5927         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5928         {0x0e, AC_VERB_SET_CONNECT_SEL, 0},
5929
5930         /* Start with output sum widgets muted and their output gains at min */
5931         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5932         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5933         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5934         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5935         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5936         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5937         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5938         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5939         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5940
5941         /* Unmute retasking pin widget output buffers since the default
5942          * state appears to be output.  As the pin mode is changed by the
5943          * user the pin mode control will take care of enabling the pin's
5944          * input/output buffers as needed.
5945          */
5946         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5947         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5948         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5949         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5950         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5951         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5952         /* Also unmute the mono-out pin widget */
5953         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5954
5955         /* Mute capture amp left and right */
5956         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5957         /* Set ADC connection select to match default mixer setting (mic1
5958          * pin)
5959          */
5960         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5961
5962         /* Do the same for the second ADC: mute capture input amp and
5963          * set ADC connection to mic1 pin
5964          */
5965         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5966         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5967
5968         /* Mute all inputs to mixer widget (even unconnected ones) */
5969         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5970         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5971         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5972         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5973         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5974         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5975         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5976         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5977
5978         { }
5979 };
5980 #endif
5981
5982 #define alc260_pcm_analog_playback      alc880_pcm_analog_alt_playback
5983 #define alc260_pcm_analog_capture       alc880_pcm_analog_capture
5984
5985 #define alc260_pcm_digital_playback     alc880_pcm_digital_playback
5986 #define alc260_pcm_digital_capture      alc880_pcm_digital_capture
5987
5988 /*
5989  * for BIOS auto-configuration
5990  */
5991
5992 static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
5993                                         const char *pfx, int *vol_bits)
5994 {
5995         hda_nid_t nid_vol;
5996         unsigned long vol_val, sw_val;
5997         int err;
5998
5999         if (nid >= 0x0f && nid < 0x11) {
6000                 nid_vol = nid - 0x7;
6001                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
6002                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
6003         } else if (nid == 0x11) {
6004                 nid_vol = nid - 0x7;
6005                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT);
6006                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
6007         } else if (nid >= 0x12 && nid <= 0x15) {
6008                 nid_vol = 0x08;
6009                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
6010                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
6011         } else
6012                 return 0; /* N/A */
6013
6014         if (!(*vol_bits & (1 << nid_vol))) {
6015                 /* first control for the volume widget */
6016                 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx, vol_val);
6017                 if (err < 0)
6018                         return err;
6019                 *vol_bits |= (1 << nid_vol);
6020         }
6021         err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, sw_val);
6022         if (err < 0)
6023                 return err;
6024         return 1;
6025 }
6026
6027 /* add playback controls from the parsed DAC table */
6028 static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
6029                                              const struct auto_pin_cfg *cfg)
6030 {
6031         hda_nid_t nid;
6032         int err;
6033         int vols = 0;
6034
6035         spec->multiout.num_dacs = 1;
6036         spec->multiout.dac_nids = spec->private_dac_nids;
6037         spec->multiout.dac_nids[0] = 0x02;
6038
6039         nid = cfg->line_out_pins[0];
6040         if (nid) {
6041                 const char *pfx;
6042                 if (!cfg->speaker_pins[0] && !cfg->hp_pins[0])
6043                         pfx = "Master";
6044                 else if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
6045                         pfx = "Speaker";
6046                 else
6047                         pfx = "Front";
6048                 err = alc260_add_playback_controls(spec, nid, pfx, &vols);
6049                 if (err < 0)
6050                         return err;
6051         }
6052
6053         nid = cfg->speaker_pins[0];
6054         if (nid) {
6055                 err = alc260_add_playback_controls(spec, nid, "Speaker", &vols);
6056                 if (err < 0)
6057                         return err;
6058         }
6059
6060         nid = cfg->hp_pins[0];
6061         if (nid) {
6062                 err = alc260_add_playback_controls(spec, nid, "Headphone",
6063                                                    &vols);
6064                 if (err < 0)
6065                         return err;
6066         }
6067         return 0;
6068 }
6069
6070 /* create playback/capture controls for input pins */
6071 static int alc260_auto_create_input_ctls(struct hda_codec *codec,
6072                                                 const struct auto_pin_cfg *cfg)
6073 {
6074         return alc_auto_create_input_ctls(codec, cfg, 0x07, 0x04, 0x05);
6075 }
6076
6077 static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
6078                                               hda_nid_t nid, int pin_type,
6079                                               int sel_idx)
6080 {
6081         alc_set_pin_output(codec, nid, pin_type);
6082         /* need the manual connection? */
6083         if (nid >= 0x12) {
6084                 int idx = nid - 0x12;
6085                 snd_hda_codec_write(codec, idx + 0x0b, 0,
6086                                     AC_VERB_SET_CONNECT_SEL, sel_idx);
6087         }
6088 }
6089
6090 static void alc260_auto_init_multi_out(struct hda_codec *codec)
6091 {
6092         struct alc_spec *spec = codec->spec;
6093         hda_nid_t nid;
6094
6095         nid = spec->autocfg.line_out_pins[0];
6096         if (nid) {
6097                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
6098                 alc260_auto_set_output_and_unmute(codec, nid, pin_type, 0);
6099         }
6100
6101         nid = spec->autocfg.speaker_pins[0];
6102         if (nid)
6103                 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
6104
6105         nid = spec->autocfg.hp_pins[0];
6106         if (nid)
6107                 alc260_auto_set_output_and_unmute(codec, nid, PIN_HP, 0);
6108 }
6109
6110 #define ALC260_PIN_CD_NID               0x16
6111 static void alc260_auto_init_analog_input(struct hda_codec *codec)
6112 {
6113         struct alc_spec *spec = codec->spec;
6114         int i;
6115
6116         for (i = 0; i < AUTO_PIN_LAST; i++) {
6117                 hda_nid_t nid = spec->autocfg.input_pins[i];
6118                 if (nid >= 0x12) {
6119                         alc_set_input_pin(codec, nid, i);
6120                         if (nid != ALC260_PIN_CD_NID &&
6121                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
6122                                 snd_hda_codec_write(codec, nid, 0,
6123                                                     AC_VERB_SET_AMP_GAIN_MUTE,
6124                                                     AMP_OUT_MUTE);
6125                 }
6126         }
6127 }
6128
6129 /*
6130  * generic initialization of ADC, input mixers and output mixers
6131  */
6132 static struct hda_verb alc260_volume_init_verbs[] = {
6133         /*
6134          * Unmute ADC0-1 and set the default input to mic-in
6135          */
6136         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
6137         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6138         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
6139         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6140
6141         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
6142          * mixer widget
6143          * Note: PASD motherboards uses the Line In 2 as the input for
6144          * front panel mic (mic 2)
6145          */
6146         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
6147         /* mute analog inputs */
6148         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6149         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6150         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6151         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6152         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6153
6154         /*
6155          * Set up output mixers (0x08 - 0x0a)
6156          */
6157         /* set vol=0 to output mixers */
6158         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6159         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6160         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6161         /* set up input amps for analog loopback */
6162         /* Amp Indices: DAC = 0, mixer = 1 */
6163         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6164         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6165         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6166         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6167         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6168         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6169
6170         { }
6171 };
6172
6173 static int alc260_parse_auto_config(struct hda_codec *codec)
6174 {
6175         struct alc_spec *spec = codec->spec;
6176         int err;
6177         static hda_nid_t alc260_ignore[] = { 0x17, 0 };
6178
6179         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
6180                                            alc260_ignore);
6181         if (err < 0)
6182                 return err;
6183         err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg);
6184         if (err < 0)
6185                 return err;
6186         if (!spec->kctls.list)
6187                 return 0; /* can't find valid BIOS pin config */
6188         err = alc260_auto_create_input_ctls(codec, &spec->autocfg);
6189         if (err < 0)
6190                 return err;
6191
6192         spec->multiout.max_channels = 2;
6193
6194         if (spec->autocfg.dig_outs)
6195                 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
6196         if (spec->kctls.list)
6197                 add_mixer(spec, spec->kctls.list);
6198
6199         add_verb(spec, alc260_volume_init_verbs);
6200
6201         spec->num_mux_defs = 1;
6202         spec->input_mux = &spec->private_imux[0];
6203
6204         alc_ssid_check(codec, 0x10, 0x15, 0x0f);
6205
6206         return 1;
6207 }
6208
6209 /* additional initialization for auto-configuration model */
6210 static void alc260_auto_init(struct hda_codec *codec)
6211 {
6212         struct alc_spec *spec = codec->spec;
6213         alc260_auto_init_multi_out(codec);
6214         alc260_auto_init_analog_input(codec);
6215         if (spec->unsol_event)
6216                 alc_inithook(codec);
6217 }
6218
6219 #ifdef CONFIG_SND_HDA_POWER_SAVE
6220 static struct hda_amp_list alc260_loopbacks[] = {
6221         { 0x07, HDA_INPUT, 0 },
6222         { 0x07, HDA_INPUT, 1 },
6223         { 0x07, HDA_INPUT, 2 },
6224         { 0x07, HDA_INPUT, 3 },
6225         { 0x07, HDA_INPUT, 4 },
6226         { } /* end */
6227 };
6228 #endif
6229
6230 /*
6231  * ALC260 configurations
6232  */
6233 static const char *alc260_models[ALC260_MODEL_LAST] = {
6234         [ALC260_BASIC]          = "basic",
6235         [ALC260_HP]             = "hp",
6236         [ALC260_HP_3013]        = "hp-3013",
6237         [ALC260_HP_DC7600]      = "hp-dc7600",
6238         [ALC260_FUJITSU_S702X]  = "fujitsu",
6239         [ALC260_ACER]           = "acer",
6240         [ALC260_WILL]           = "will",
6241         [ALC260_REPLACER_672V]  = "replacer",
6242         [ALC260_FAVORIT100]     = "favorit100",
6243 #ifdef CONFIG_SND_DEBUG
6244         [ALC260_TEST]           = "test",
6245 #endif
6246         [ALC260_AUTO]           = "auto",
6247 };
6248
6249 static struct snd_pci_quirk alc260_cfg_tbl[] = {
6250         SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER),
6251         SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
6252         SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FAVORIT100),
6253         SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
6254         SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_AUTO), /* no quirk */
6255         SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
6256         SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP_3013),
6257         SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_DC7600),
6258         SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
6259         SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
6260         SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP),
6261         SND_PCI_QUIRK(0x103c, 0x3016, "HP", ALC260_HP),
6262         SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_BASIC),
6263         SND_PCI_QUIRK(0x104d, 0x81cc, "Sony VAIO", ALC260_BASIC),
6264         SND_PCI_QUIRK(0x104d, 0x81cd, "Sony VAIO", ALC260_BASIC),
6265         SND_PCI_QUIRK(0x10cf, 0x1326, "Fujitsu S702X", ALC260_FUJITSU_S702X),
6266         SND_PCI_QUIRK(0x152d, 0x0729, "CTL U553W", ALC260_BASIC),
6267         SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_REPLACER_672V),
6268         SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_WILL),
6269         {}
6270 };
6271
6272 static struct alc_config_preset alc260_presets[] = {
6273         [ALC260_BASIC] = {
6274                 .mixers = { alc260_base_output_mixer,
6275                             alc260_input_mixer },
6276                 .init_verbs = { alc260_init_verbs },
6277                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6278                 .dac_nids = alc260_dac_nids,
6279                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
6280                 .adc_nids = alc260_adc_nids,
6281                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6282                 .channel_mode = alc260_modes,
6283                 .input_mux = &alc260_capture_source,
6284         },
6285         [ALC260_HP] = {
6286                 .mixers = { alc260_hp_output_mixer,
6287                             alc260_input_mixer },
6288                 .init_verbs = { alc260_init_verbs,
6289                                 alc260_hp_unsol_verbs },
6290                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6291                 .dac_nids = alc260_dac_nids,
6292                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
6293                 .adc_nids = alc260_adc_nids_alt,
6294                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6295                 .channel_mode = alc260_modes,
6296                 .input_mux = &alc260_capture_source,
6297                 .unsol_event = alc260_hp_unsol_event,
6298                 .init_hook = alc260_hp_automute,
6299         },
6300         [ALC260_HP_DC7600] = {
6301                 .mixers = { alc260_hp_dc7600_mixer,
6302                             alc260_input_mixer },
6303                 .init_verbs = { alc260_init_verbs,
6304                                 alc260_hp_dc7600_verbs },
6305                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6306                 .dac_nids = alc260_dac_nids,
6307                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
6308                 .adc_nids = alc260_adc_nids_alt,
6309                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6310                 .channel_mode = alc260_modes,
6311                 .input_mux = &alc260_capture_source,
6312                 .unsol_event = alc260_hp_3012_unsol_event,
6313                 .init_hook = alc260_hp_3012_automute,
6314         },
6315         [ALC260_HP_3013] = {
6316                 .mixers = { alc260_hp_3013_mixer,
6317                             alc260_input_mixer },
6318                 .init_verbs = { alc260_hp_3013_init_verbs,
6319                                 alc260_hp_3013_unsol_verbs },
6320                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6321                 .dac_nids = alc260_dac_nids,
6322                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
6323                 .adc_nids = alc260_adc_nids_alt,
6324                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6325                 .channel_mode = alc260_modes,
6326                 .input_mux = &alc260_capture_source,
6327                 .unsol_event = alc260_hp_3013_unsol_event,
6328                 .init_hook = alc260_hp_3013_automute,
6329         },
6330         [ALC260_FUJITSU_S702X] = {
6331                 .mixers = { alc260_fujitsu_mixer },
6332                 .init_verbs = { alc260_fujitsu_init_verbs },
6333                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6334                 .dac_nids = alc260_dac_nids,
6335                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
6336                 .adc_nids = alc260_dual_adc_nids,
6337                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6338                 .channel_mode = alc260_modes,
6339                 .num_mux_defs = ARRAY_SIZE(alc260_fujitsu_capture_sources),
6340                 .input_mux = alc260_fujitsu_capture_sources,
6341         },
6342         [ALC260_ACER] = {
6343                 .mixers = { alc260_acer_mixer },
6344                 .init_verbs = { alc260_acer_init_verbs },
6345                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6346                 .dac_nids = alc260_dac_nids,
6347                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
6348                 .adc_nids = alc260_dual_adc_nids,
6349                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6350                 .channel_mode = alc260_modes,
6351                 .num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources),
6352                 .input_mux = alc260_acer_capture_sources,
6353         },
6354         [ALC260_FAVORIT100] = {
6355                 .mixers = { alc260_favorit100_mixer },
6356                 .init_verbs = { alc260_favorit100_init_verbs },
6357                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6358                 .dac_nids = alc260_dac_nids,
6359                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
6360                 .adc_nids = alc260_dual_adc_nids,
6361                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6362                 .channel_mode = alc260_modes,
6363                 .num_mux_defs = ARRAY_SIZE(alc260_favorit100_capture_sources),
6364                 .input_mux = alc260_favorit100_capture_sources,
6365         },
6366         [ALC260_WILL] = {
6367                 .mixers = { alc260_will_mixer },
6368                 .init_verbs = { alc260_init_verbs, alc260_will_verbs },
6369                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6370                 .dac_nids = alc260_dac_nids,
6371                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
6372                 .adc_nids = alc260_adc_nids,
6373                 .dig_out_nid = ALC260_DIGOUT_NID,
6374                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6375                 .channel_mode = alc260_modes,
6376                 .input_mux = &alc260_capture_source,
6377         },
6378         [ALC260_REPLACER_672V] = {
6379                 .mixers = { alc260_replacer_672v_mixer },
6380                 .init_verbs = { alc260_init_verbs, alc260_replacer_672v_verbs },
6381                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6382                 .dac_nids = alc260_dac_nids,
6383                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
6384                 .adc_nids = alc260_adc_nids,
6385                 .dig_out_nid = ALC260_DIGOUT_NID,
6386                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6387                 .channel_mode = alc260_modes,
6388                 .input_mux = &alc260_capture_source,
6389                 .unsol_event = alc260_replacer_672v_unsol_event,
6390                 .init_hook = alc260_replacer_672v_automute,
6391         },
6392 #ifdef CONFIG_SND_DEBUG
6393         [ALC260_TEST] = {
6394                 .mixers = { alc260_test_mixer },
6395                 .init_verbs = { alc260_test_init_verbs },
6396                 .num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
6397                 .dac_nids = alc260_test_dac_nids,
6398                 .num_adc_nids = ARRAY_SIZE(alc260_test_adc_nids),
6399                 .adc_nids = alc260_test_adc_nids,
6400                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6401                 .channel_mode = alc260_modes,
6402                 .num_mux_defs = ARRAY_SIZE(alc260_test_capture_sources),
6403                 .input_mux = alc260_test_capture_sources,
6404         },
6405 #endif
6406 };
6407
6408 static int patch_alc260(struct hda_codec *codec)
6409 {
6410         struct alc_spec *spec;
6411         int err, board_config;
6412
6413         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6414         if (spec == NULL)
6415                 return -ENOMEM;
6416
6417         codec->spec = spec;
6418
6419         board_config = snd_hda_check_board_config(codec, ALC260_MODEL_LAST,
6420                                                   alc260_models,
6421                                                   alc260_cfg_tbl);
6422         if (board_config < 0) {
6423                 snd_printd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6424                            codec->chip_name);
6425                 board_config = ALC260_AUTO;
6426         }
6427
6428         if (board_config == ALC260_AUTO) {
6429                 /* automatic parse from the BIOS config */
6430                 err = alc260_parse_auto_config(codec);
6431                 if (err < 0) {
6432                         alc_free(codec);
6433                         return err;
6434                 } else if (!err) {
6435                         printk(KERN_INFO
6436                                "hda_codec: Cannot set up configuration "
6437                                "from BIOS.  Using base mode...\n");
6438                         board_config = ALC260_BASIC;
6439                 }
6440         }
6441
6442         err = snd_hda_attach_beep_device(codec, 0x1);
6443         if (err < 0) {
6444                 alc_free(codec);
6445                 return err;
6446         }
6447
6448         if (board_config != ALC260_AUTO)
6449                 setup_preset(codec, &alc260_presets[board_config]);
6450
6451         spec->stream_analog_playback = &alc260_pcm_analog_playback;
6452         spec->stream_analog_capture = &alc260_pcm_analog_capture;
6453
6454         spec->stream_digital_playback = &alc260_pcm_digital_playback;
6455         spec->stream_digital_capture = &alc260_pcm_digital_capture;
6456
6457         if (!spec->adc_nids && spec->input_mux) {
6458                 /* check whether NID 0x04 is valid */
6459                 unsigned int wcap = get_wcaps(codec, 0x04);
6460                 wcap = get_wcaps_type(wcap);
6461                 /* get type */
6462                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
6463                         spec->adc_nids = alc260_adc_nids_alt;
6464                         spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
6465                 } else {
6466                         spec->adc_nids = alc260_adc_nids;
6467                         spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
6468                 }
6469         }
6470         set_capture_mixer(codec);
6471         set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
6472
6473         spec->vmaster_nid = 0x08;
6474
6475         codec->patch_ops = alc_patch_ops;
6476         if (board_config == ALC260_AUTO)
6477                 spec->init_hook = alc260_auto_init;
6478 #ifdef CONFIG_SND_HDA_POWER_SAVE
6479         if (!spec->loopback.amplist)
6480                 spec->loopback.amplist = alc260_loopbacks;
6481 #endif
6482         codec->proc_widget_hook = print_realtek_coef;
6483
6484         return 0;
6485 }
6486
6487
6488 /*
6489  * ALC882/883/885/888/889 support
6490  *
6491  * ALC882 is almost identical with ALC880 but has cleaner and more flexible
6492  * configuration.  Each pin widget can choose any input DACs and a mixer.
6493  * Each ADC is connected from a mixer of all inputs.  This makes possible
6494  * 6-channel independent captures.
6495  *
6496  * In addition, an independent DAC for the multi-playback (not used in this
6497  * driver yet).
6498  */
6499 #define ALC882_DIGOUT_NID       0x06
6500 #define ALC882_DIGIN_NID        0x0a
6501 #define ALC883_DIGOUT_NID       ALC882_DIGOUT_NID
6502 #define ALC883_DIGIN_NID        ALC882_DIGIN_NID
6503 #define ALC1200_DIGOUT_NID      0x10
6504
6505
6506 static struct hda_channel_mode alc882_ch_modes[1] = {
6507         { 8, NULL }
6508 };
6509
6510 /* DACs */
6511 static hda_nid_t alc882_dac_nids[4] = {
6512         /* front, rear, clfe, rear_surr */
6513         0x02, 0x03, 0x04, 0x05
6514 };
6515 #define alc883_dac_nids         alc882_dac_nids
6516
6517 /* ADCs */
6518 #define alc882_adc_nids         alc880_adc_nids
6519 #define alc882_adc_nids_alt     alc880_adc_nids_alt
6520 #define alc883_adc_nids         alc882_adc_nids_alt
6521 static hda_nid_t alc883_adc_nids_alt[1] = { 0x08 };
6522 static hda_nid_t alc883_adc_nids_rev[2] = { 0x09, 0x08 };
6523 #define alc889_adc_nids         alc880_adc_nids
6524
6525 static hda_nid_t alc882_capsrc_nids[3] = { 0x24, 0x23, 0x22 };
6526 static hda_nid_t alc882_capsrc_nids_alt[2] = { 0x23, 0x22 };
6527 #define alc883_capsrc_nids      alc882_capsrc_nids_alt
6528 static hda_nid_t alc883_capsrc_nids_rev[2] = { 0x22, 0x23 };
6529 #define alc889_capsrc_nids      alc882_capsrc_nids
6530
6531 /* input MUX */
6532 /* FIXME: should be a matrix-type input source selection */
6533
6534 static struct hda_input_mux alc882_capture_source = {
6535         .num_items = 4,
6536         .items = {
6537                 { "Mic", 0x0 },
6538                 { "Front Mic", 0x1 },
6539                 { "Line", 0x2 },
6540                 { "CD", 0x4 },
6541         },
6542 };
6543
6544 #define alc883_capture_source   alc882_capture_source
6545
6546 static struct hda_input_mux alc889_capture_source = {
6547         .num_items = 3,
6548         .items = {
6549                 { "Front Mic", 0x0 },
6550                 { "Mic", 0x3 },
6551                 { "Line", 0x2 },
6552         },
6553 };
6554
6555 static struct hda_input_mux mb5_capture_source = {
6556         .num_items = 3,
6557         .items = {
6558                 { "Mic", 0x1 },
6559                 { "Line", 0x2 },
6560                 { "CD", 0x4 },
6561         },
6562 };
6563
6564 static struct hda_input_mux alc883_3stack_6ch_intel = {
6565         .num_items = 4,
6566         .items = {
6567                 { "Mic", 0x1 },
6568                 { "Front Mic", 0x0 },
6569                 { "Line", 0x2 },
6570                 { "CD", 0x4 },
6571         },
6572 };
6573
6574 static struct hda_input_mux alc883_lenovo_101e_capture_source = {
6575         .num_items = 2,
6576         .items = {
6577                 { "Mic", 0x1 },
6578                 { "Line", 0x2 },
6579         },
6580 };
6581
6582 static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
6583         .num_items = 4,
6584         .items = {
6585                 { "Mic", 0x0 },
6586                 { "iMic", 0x1 },
6587                 { "Line", 0x2 },
6588                 { "CD", 0x4 },
6589         },
6590 };
6591
6592 static struct hda_input_mux alc883_fujitsu_pi2515_capture_source = {
6593         .num_items = 2,
6594         .items = {
6595                 { "Mic", 0x0 },
6596                 { "Int Mic", 0x1 },
6597         },
6598 };
6599
6600 static struct hda_input_mux alc883_lenovo_sky_capture_source = {
6601         .num_items = 3,
6602         .items = {
6603                 { "Mic", 0x0 },
6604                 { "Front Mic", 0x1 },
6605                 { "Line", 0x4 },
6606         },
6607 };
6608
6609 static struct hda_input_mux alc883_asus_eee1601_capture_source = {
6610         .num_items = 2,
6611         .items = {
6612                 { "Mic", 0x0 },
6613                 { "Line", 0x2 },
6614         },
6615 };
6616
6617 static struct hda_input_mux alc889A_mb31_capture_source = {
6618         .num_items = 2,
6619         .items = {
6620                 { "Mic", 0x0 },
6621                 /* Front Mic (0x01) unused */
6622                 { "Line", 0x2 },
6623                 /* Line 2 (0x03) unused */
6624                 /* CD (0x04) unsused? */
6625         },
6626 };
6627
6628 /*
6629  * 2ch mode
6630  */
6631 static struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
6632         { 2, NULL }
6633 };
6634
6635 /*
6636  * 2ch mode
6637  */
6638 static struct hda_verb alc882_3ST_ch2_init[] = {
6639         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6640         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6641         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6642         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6643         { } /* end */
6644 };
6645
6646 /*
6647  * 4ch mode
6648  */
6649 static struct hda_verb alc882_3ST_ch4_init[] = {
6650         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6651         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6652         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6653         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6654         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6655         { } /* end */
6656 };
6657
6658 /*
6659  * 6ch mode
6660  */
6661 static struct hda_verb alc882_3ST_ch6_init[] = {
6662         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6663         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6664         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6665         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6666         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6667         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6668         { } /* end */
6669 };
6670
6671 static struct hda_channel_mode alc882_3ST_6ch_modes[3] = {
6672         { 2, alc882_3ST_ch2_init },
6673         { 4, alc882_3ST_ch4_init },
6674         { 6, alc882_3ST_ch6_init },
6675 };
6676
6677 #define alc883_3ST_6ch_modes    alc882_3ST_6ch_modes
6678
6679 /*
6680  * 2ch mode
6681  */
6682 static struct hda_verb alc883_3ST_ch2_clevo_init[] = {
6683         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
6684         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6685         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6686         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6687         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6688         { } /* end */
6689 };
6690
6691 /*
6692  * 4ch mode
6693  */
6694 static struct hda_verb alc883_3ST_ch4_clevo_init[] = {
6695         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6696         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6697         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6698         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6699         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6700         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6701         { } /* end */
6702 };
6703
6704 /*
6705  * 6ch mode
6706  */
6707 static struct hda_verb alc883_3ST_ch6_clevo_init[] = {
6708         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6709         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6710         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6711         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6712         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6713         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6714         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6715         { } /* end */
6716 };
6717
6718 static struct hda_channel_mode alc883_3ST_6ch_clevo_modes[3] = {
6719         { 2, alc883_3ST_ch2_clevo_init },
6720         { 4, alc883_3ST_ch4_clevo_init },
6721         { 6, alc883_3ST_ch6_clevo_init },
6722 };
6723
6724
6725 /*
6726  * 6ch mode
6727  */
6728 static struct hda_verb alc882_sixstack_ch6_init[] = {
6729         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
6730         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6731         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6732         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6733         { } /* end */
6734 };
6735
6736 /*
6737  * 8ch mode
6738  */
6739 static struct hda_verb alc882_sixstack_ch8_init[] = {
6740         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6741         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6742         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6743         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6744         { } /* end */
6745 };
6746
6747 static struct hda_channel_mode alc882_sixstack_modes[2] = {
6748         { 6, alc882_sixstack_ch6_init },
6749         { 8, alc882_sixstack_ch8_init },
6750 };
6751
6752 /*
6753  * macbook pro ALC885 can switch LineIn to LineOut without losing Mic
6754  */
6755
6756 /*
6757  * 2ch mode
6758  */
6759 static struct hda_verb alc885_mbp_ch2_init[] = {
6760         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6761         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6762         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6763         { } /* end */
6764 };
6765
6766 /*
6767  * 4ch mode
6768  */
6769 static struct hda_verb alc885_mbp_ch4_init[] = {
6770         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6771         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6772         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6773         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6774         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6775         { } /* end */
6776 };
6777
6778 static struct hda_channel_mode alc885_mbp_4ch_modes[2] = {
6779         { 2, alc885_mbp_ch2_init },
6780         { 4, alc885_mbp_ch4_init },
6781 };
6782
6783 /*
6784  * 2ch
6785  * Speakers/Woofer/HP = Front
6786  * LineIn = Input
6787  */
6788 static struct hda_verb alc885_mb5_ch2_init[] = {
6789         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6790         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6791         { } /* end */
6792 };
6793
6794 /*
6795  * 6ch mode
6796  * Speakers/HP = Front
6797  * Woofer = LFE
6798  * LineIn = Surround
6799  */
6800 static struct hda_verb alc885_mb5_ch6_init[] = {
6801         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6802         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6803         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
6804         { } /* end */
6805 };
6806
6807 static struct hda_channel_mode alc885_mb5_6ch_modes[2] = {
6808         { 2, alc885_mb5_ch2_init },
6809         { 6, alc885_mb5_ch6_init },
6810 };
6811
6812
6813 /*
6814  * 2ch mode
6815  */
6816 static struct hda_verb alc883_4ST_ch2_init[] = {
6817         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6818         { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6819         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6820         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6821         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6822         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6823         { } /* end */
6824 };
6825
6826 /*
6827  * 4ch mode
6828  */
6829 static struct hda_verb alc883_4ST_ch4_init[] = {
6830         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6831         { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6832         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6833         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6834         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6835         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6836         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6837         { } /* end */
6838 };
6839
6840 /*
6841  * 6ch mode
6842  */
6843 static struct hda_verb alc883_4ST_ch6_init[] = {
6844         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6845         { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6846         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6847         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6848         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6849         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6850         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6851         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6852         { } /* end */
6853 };
6854
6855 /*
6856  * 8ch mode
6857  */
6858 static struct hda_verb alc883_4ST_ch8_init[] = {
6859         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6860         { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6861         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03 },
6862         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6863         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6864         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6865         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6866         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6867         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6868         { } /* end */
6869 };
6870
6871 static struct hda_channel_mode alc883_4ST_8ch_modes[4] = {
6872         { 2, alc883_4ST_ch2_init },
6873         { 4, alc883_4ST_ch4_init },
6874         { 6, alc883_4ST_ch6_init },
6875         { 8, alc883_4ST_ch8_init },
6876 };
6877
6878
6879 /*
6880  * 2ch mode
6881  */
6882 static struct hda_verb alc883_3ST_ch2_intel_init[] = {
6883         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6884         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6885         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6886         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6887         { } /* end */
6888 };
6889
6890 /*
6891  * 4ch mode
6892  */
6893 static struct hda_verb alc883_3ST_ch4_intel_init[] = {
6894         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6895         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6896         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6897         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6898         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6899         { } /* end */
6900 };
6901
6902 /*
6903  * 6ch mode
6904  */
6905 static struct hda_verb alc883_3ST_ch6_intel_init[] = {
6906         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6907         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6908         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x02 },
6909         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6910         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6911         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6912         { } /* end */
6913 };
6914
6915 static struct hda_channel_mode alc883_3ST_6ch_intel_modes[3] = {
6916         { 2, alc883_3ST_ch2_intel_init },
6917         { 4, alc883_3ST_ch4_intel_init },
6918         { 6, alc883_3ST_ch6_intel_init },
6919 };
6920
6921 /*
6922  * 2ch mode
6923  */
6924 static struct hda_verb alc889_ch2_intel_init[] = {
6925         { 0x14, AC_VERB_SET_CONNECT_SEL, 0x00 },
6926         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x00 },
6927         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x00 },
6928         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00 },
6929         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6930         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6931         { } /* end */
6932 };
6933
6934 /*
6935  * 6ch mode
6936  */
6937 static struct hda_verb alc889_ch6_intel_init[] = {
6938         { 0x14, AC_VERB_SET_CONNECT_SEL, 0x00 },
6939         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x01 },
6940         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x02 },
6941         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03 },
6942         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6943         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6944         { } /* end */
6945 };
6946
6947 /*
6948  * 8ch mode
6949  */
6950 static struct hda_verb alc889_ch8_intel_init[] = {
6951         { 0x14, AC_VERB_SET_CONNECT_SEL, 0x00 },
6952         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x01 },
6953         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x02 },
6954         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03 },
6955         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x03 },
6956         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6957         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6958         { } /* end */
6959 };
6960
6961 static struct hda_channel_mode alc889_8ch_intel_modes[3] = {
6962         { 2, alc889_ch2_intel_init },
6963         { 6, alc889_ch6_intel_init },
6964         { 8, alc889_ch8_intel_init },
6965 };
6966
6967 /*
6968  * 6ch mode
6969  */
6970 static struct hda_verb alc883_sixstack_ch6_init[] = {
6971         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
6972         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6973         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6974         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6975         { } /* end */
6976 };
6977
6978 /*
6979  * 8ch mode
6980  */
6981 static struct hda_verb alc883_sixstack_ch8_init[] = {
6982         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6983         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6984         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6985         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6986         { } /* end */
6987 };
6988
6989 static struct hda_channel_mode alc883_sixstack_modes[2] = {
6990         { 6, alc883_sixstack_ch6_init },
6991         { 8, alc883_sixstack_ch8_init },
6992 };
6993
6994
6995 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
6996  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
6997  */
6998 static struct snd_kcontrol_new alc882_base_mixer[] = {
6999         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7000         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7001         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7002         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7003         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7004         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7005         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7006         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7007         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7008         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7009         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7010         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7011         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7012         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7013         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7014         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7015         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7016         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7017         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7018         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7019         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7020         { } /* end */
7021 };
7022
7023 static struct snd_kcontrol_new alc885_mbp3_mixer[] = {
7024         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
7025         HDA_BIND_MUTE   ("Speaker Playback Switch", 0x0c, 0x02, HDA_INPUT),
7026         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0e, 0x00, HDA_OUTPUT),
7027         HDA_BIND_MUTE   ("Headphone Playback Switch", 0x0e, 0x02, HDA_INPUT),
7028         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
7029         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7030         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7031         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
7032         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
7033         HDA_CODEC_VOLUME("Line Boost", 0x1a, 0x00, HDA_INPUT),
7034         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
7035         { } /* end */
7036 };
7037
7038 static struct snd_kcontrol_new alc885_mb5_mixer[] = {
7039         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
7040         HDA_BIND_MUTE   ("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
7041         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
7042         HDA_BIND_MUTE   ("Surround Playback Switch", 0x0d, 0x02, HDA_INPUT),
7043         HDA_CODEC_VOLUME("LFE Playback Volume", 0x0e, 0x00, HDA_OUTPUT),
7044         HDA_BIND_MUTE   ("LFE Playback Switch", 0x0e, 0x02, HDA_INPUT),
7045         HDA_CODEC_VOLUME("HP Playback Volume", 0x0f, 0x00, HDA_OUTPUT),
7046         HDA_BIND_MUTE   ("HP Playback Switch", 0x0f, 0x02, HDA_INPUT),
7047         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7048         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7049         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
7050         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
7051         HDA_CODEC_VOLUME("Line Boost", 0x15, 0x00, HDA_INPUT),
7052         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0x00, HDA_INPUT),
7053         { } /* end */
7054 };
7055
7056 static struct snd_kcontrol_new alc882_w2jc_mixer[] = {
7057         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7058         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7059         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7060         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7061         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7062         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7063         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7064         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7065         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7066         { } /* end */
7067 };
7068
7069 static struct snd_kcontrol_new alc882_targa_mixer[] = {
7070         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7071         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7072         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7073         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7074         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7075         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7076         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7077         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7078         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7079         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7080         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7081         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7082         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7083         { } /* end */
7084 };
7085
7086 /* Pin assignment: Front=0x14, HP = 0x15, Front = 0x16, ???
7087  *                 Front Mic=0x18, Line In = 0x1a, Line In = 0x1b, CD = 0x1c
7088  */
7089 static struct snd_kcontrol_new alc882_asus_a7j_mixer[] = {
7090         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7091         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7092         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7093         HDA_CODEC_MUTE("Mobile Front Playback Switch", 0x16, 0x0, HDA_OUTPUT),
7094         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7095         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7096         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7097         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7098         HDA_CODEC_VOLUME("Mobile Line Playback Volume", 0x0b, 0x03, HDA_INPUT),
7099         HDA_CODEC_MUTE("Mobile Line Playback Switch", 0x0b, 0x03, HDA_INPUT),
7100         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7101         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7102         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7103         { } /* end */
7104 };
7105
7106 static struct snd_kcontrol_new alc882_asus_a7m_mixer[] = {
7107         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7108         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7109         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7110         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7111         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7112         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7113         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7114         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7115         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7116         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7117         { } /* end */
7118 };
7119
7120 static struct snd_kcontrol_new alc882_chmode_mixer[] = {
7121         {
7122                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7123                 .name = "Channel Mode",
7124                 .info = alc_ch_mode_info,
7125                 .get = alc_ch_mode_get,
7126                 .put = alc_ch_mode_put,
7127         },
7128         { } /* end */
7129 };
7130
7131 static struct hda_verb alc882_base_init_verbs[] = {
7132         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7133         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7134         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7135         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7136         /* Rear mixer */
7137         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7138         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7139         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7140         /* CLFE mixer */
7141         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7142         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7143         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7144         /* Side mixer */
7145         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7146         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7147         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7148
7149         /* mute analog input loopbacks */
7150         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7151         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7152         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7153         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7154         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7155
7156         /* Front Pin: output 0 (0x0c) */
7157         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7158         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7159         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7160         /* Rear Pin: output 1 (0x0d) */
7161         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7162         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7163         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7164         /* CLFE Pin: output 2 (0x0e) */
7165         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7166         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7167         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
7168         /* Side Pin: output 3 (0x0f) */
7169         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7170         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7171         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
7172         /* Mic (rear) pin: input vref at 80% */
7173         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7174         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7175         /* Front Mic pin: input vref at 80% */
7176         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7177         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7178         /* Line In pin: input */
7179         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7180         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7181         /* Line-2 In: Headphone output (output 0 - 0x0c) */
7182         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7183         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7184         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7185         /* CD pin widget for input */
7186         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7187
7188         /* FIXME: use matrix-type input source selection */
7189         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7190         /* Input mixer2 */
7191         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7192         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7193         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7194         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7195         /* Input mixer3 */
7196         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7197         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7198         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7199         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7200         /* ADC2: mute amp left and right */
7201         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7202         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7203         /* ADC3: mute amp left and right */
7204         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7205         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7206
7207         { }
7208 };
7209
7210 static struct hda_verb alc882_adc1_init_verbs[] = {
7211         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
7212         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7213         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7214         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7215         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7216         /* ADC1: mute amp left and right */
7217         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7218         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
7219         { }
7220 };
7221
7222 static struct hda_verb alc882_eapd_verbs[] = {
7223         /* change to EAPD mode */
7224         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7225         {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
7226         { }
7227 };
7228
7229 static struct hda_verb alc889_eapd_verbs[] = {
7230         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
7231         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
7232         { }
7233 };
7234
7235 static struct hda_verb alc_hp15_unsol_verbs[] = {
7236         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
7237         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7238         {}
7239 };
7240
7241 static struct hda_verb alc885_init_verbs[] = {
7242         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7243         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7244         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7245         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7246         /* Rear mixer */
7247         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7248         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7249         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7250         /* CLFE mixer */
7251         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7252         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7253         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7254         /* Side mixer */
7255         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7256         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7257         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7258
7259         /* mute analog input loopbacks */
7260         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7261         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7262         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7263
7264         /* Front HP Pin: output 0 (0x0c) */
7265         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7266         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7267         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7268         /* Front Pin: output 0 (0x0c) */
7269         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7270         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7271         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7272         /* Rear Pin: output 1 (0x0d) */
7273         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7274         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7275         {0x19, AC_VERB_SET_CONNECT_SEL, 0x01},
7276         /* CLFE Pin: output 2 (0x0e) */
7277         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7278         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7279         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
7280         /* Side Pin: output 3 (0x0f) */
7281         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7282         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7283         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
7284         /* Mic (rear) pin: input vref at 80% */
7285         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7286         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7287         /* Front Mic pin: input vref at 80% */
7288         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7289         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7290         /* Line In pin: input */
7291         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7292         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7293
7294         /* Mixer elements: 0x18, , 0x1a, 0x1b */
7295         /* Input mixer1 */
7296         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
7297         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7298         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7299         /* Input mixer2 */
7300         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7301         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7302         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7303         /* Input mixer3 */
7304         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7305         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7306         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7307         /* ADC2: mute amp left and right */
7308         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7309         /* ADC3: mute amp left and right */
7310         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7311
7312         { }
7313 };
7314
7315 static struct hda_verb alc885_init_input_verbs[] = {
7316         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7317         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
7318         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
7319         { }
7320 };
7321
7322
7323 /* Unmute Selector 24h and set the default input to front mic */
7324 static struct hda_verb alc889_init_input_verbs[] = {
7325         {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
7326         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7327         { }
7328 };
7329
7330
7331 #define alc883_init_verbs       alc882_base_init_verbs
7332
7333 /* Mac Pro test */
7334 static struct snd_kcontrol_new alc882_macpro_mixer[] = {
7335         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7336         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7337         HDA_CODEC_MUTE("Headphone Playback Switch", 0x18, 0x0, HDA_OUTPUT),
7338         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
7339         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
7340         /* FIXME: this looks suspicious...
7341         HDA_CODEC_VOLUME("Beep Playback Volume", 0x0b, 0x02, HDA_INPUT),
7342         HDA_CODEC_MUTE("Beep Playback Switch", 0x0b, 0x02, HDA_INPUT),
7343         */
7344         { } /* end */
7345 };
7346
7347 static struct hda_verb alc882_macpro_init_verbs[] = {
7348         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7349         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7350         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7351         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7352         /* Front Pin: output 0 (0x0c) */
7353         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7354         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7355         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7356         /* Front Mic pin: input vref at 80% */
7357         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7358         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7359         /* Speaker:  output */
7360         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7361         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7362         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x04},
7363         /* Headphone output (output 0 - 0x0c) */
7364         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7365         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7366         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
7367
7368         /* FIXME: use matrix-type input source selection */
7369         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7370         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
7371         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7372         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7373         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7374         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7375         /* Input mixer2 */
7376         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7377         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7378         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7379         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7380         /* Input mixer3 */
7381         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7382         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7383         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7384         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7385         /* ADC1: mute amp left and right */
7386         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7387         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
7388         /* ADC2: mute amp left and right */
7389         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7390         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7391         /* ADC3: mute amp left and right */
7392         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7393         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7394
7395         { }
7396 };
7397
7398 /* Macbook 5,1 */
7399 static struct hda_verb alc885_mb5_init_verbs[] = {
7400         /* DACs */
7401         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7402         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7403         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7404         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7405         /* Front mixer */
7406         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7407         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7408         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7409         /* Surround mixer */
7410         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7411         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7412         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7413         /* LFE mixer */
7414         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7415         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7416         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7417         /* HP mixer */
7418         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7419         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7420         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7421         /* Front Pin (0x0c) */
7422         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x01},
7423         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7424         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
7425         /* LFE Pin (0x0e) */
7426         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x01},
7427         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7428         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x02},
7429         /* HP Pin (0x0f) */
7430         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7431         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7432         {0x14, AC_VERB_SET_CONNECT_SEL, 0x03},
7433         /* Front Mic pin: input vref at 80% */
7434         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7435         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7436         /* Line In pin */
7437         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7438         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7439
7440         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7441         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7442         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7443         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7444         { }
7445 };
7446
7447 /* Macbook Pro rev3 */
7448 static struct hda_verb alc885_mbp3_init_verbs[] = {
7449         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7450         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7451         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7452         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7453         /* Rear mixer */
7454         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7455         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7456         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7457         /* HP mixer */
7458         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7459         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7460         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7461         /* Front Pin: output 0 (0x0c) */
7462         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7463         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7464         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7465         /* HP Pin: output 0 (0x0e) */
7466         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},
7467         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7468         {0x15, AC_VERB_SET_CONNECT_SEL, 0x02},
7469         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7470         /* Mic (rear) pin: input vref at 80% */
7471         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7472         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7473         /* Front Mic pin: input vref at 80% */
7474         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7475         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7476         /* Line In pin: use output 1 when in LineOut mode */
7477         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7478         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7479         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
7480
7481         /* FIXME: use matrix-type input source selection */
7482         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7483         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
7484         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7485         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7486         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7487         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7488         /* Input mixer2 */
7489         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7490         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7491         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7492         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7493         /* Input mixer3 */
7494         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7495         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7496         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7497         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7498         /* ADC1: mute amp left and right */
7499         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7500         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
7501         /* ADC2: mute amp left and right */
7502         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7503         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7504         /* ADC3: mute amp left and right */
7505         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7506         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7507
7508         { }
7509 };
7510
7511 /* iMac 24 mixer. */
7512 static struct snd_kcontrol_new alc885_imac24_mixer[] = {
7513         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
7514         HDA_CODEC_MUTE("Master Playback Switch", 0x0c, 0x00, HDA_INPUT),
7515         { } /* end */
7516 };
7517
7518 /* iMac 24 init verbs. */
7519 static struct hda_verb alc885_imac24_init_verbs[] = {
7520         /* Internal speakers: output 0 (0x0c) */
7521         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7522         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7523         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
7524         /* Internal speakers: output 0 (0x0c) */
7525         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7526         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7527         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
7528         /* Headphone: output 0 (0x0c) */
7529         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7530         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7531         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7532         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7533         /* Front Mic: input vref at 80% */
7534         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7535         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7536         { }
7537 };
7538
7539 /* Toggle speaker-output according to the hp-jack state */
7540 static void alc885_imac24_setup(struct hda_codec *codec)
7541 {
7542         struct alc_spec *spec = codec->spec;
7543
7544         spec->autocfg.hp_pins[0] = 0x14;
7545         spec->autocfg.speaker_pins[0] = 0x18;
7546         spec->autocfg.speaker_pins[1] = 0x1a;
7547 }
7548
7549 static void alc885_mbp3_setup(struct hda_codec *codec)
7550 {
7551         struct alc_spec *spec = codec->spec;
7552
7553         spec->autocfg.hp_pins[0] = 0x15;
7554         spec->autocfg.speaker_pins[0] = 0x14;
7555 }
7556
7557
7558 static struct hda_verb alc882_targa_verbs[] = {
7559         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7560         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7561
7562         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7563         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7564
7565         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
7566         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
7567         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7568
7569         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7570         { } /* end */
7571 };
7572
7573 /* toggle speaker-output according to the hp-jack state */
7574 static void alc882_targa_automute(struct hda_codec *codec)
7575 {
7576         struct alc_spec *spec = codec->spec;
7577         alc_automute_amp(codec);
7578         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
7579                                   spec->jack_present ? 1 : 3);
7580 }
7581
7582 static void alc882_targa_setup(struct hda_codec *codec)
7583 {
7584         struct alc_spec *spec = codec->spec;
7585
7586         spec->autocfg.hp_pins[0] = 0x14;
7587         spec->autocfg.speaker_pins[0] = 0x1b;
7588 }
7589
7590 static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res)
7591 {
7592         if ((res >> 26) == ALC880_HP_EVENT)
7593                 alc882_targa_automute(codec);
7594 }
7595
7596 static struct hda_verb alc882_asus_a7j_verbs[] = {
7597         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7598         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7599
7600         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7601         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7602         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7603
7604         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
7605         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7606         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
7607
7608         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
7609         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
7610         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7611         { } /* end */
7612 };
7613
7614 static struct hda_verb alc882_asus_a7m_verbs[] = {
7615         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7616         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7617
7618         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7619         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7620         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7621
7622         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
7623         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7624         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
7625
7626         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
7627         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
7628         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7629         { } /* end */
7630 };
7631
7632 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
7633 {
7634         unsigned int gpiostate, gpiomask, gpiodir;
7635
7636         gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
7637                                        AC_VERB_GET_GPIO_DATA, 0);
7638
7639         if (!muted)
7640                 gpiostate |= (1 << pin);
7641         else
7642                 gpiostate &= ~(1 << pin);
7643
7644         gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
7645                                       AC_VERB_GET_GPIO_MASK, 0);
7646         gpiomask |= (1 << pin);
7647
7648         gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
7649                                      AC_VERB_GET_GPIO_DIRECTION, 0);
7650         gpiodir |= (1 << pin);
7651
7652
7653         snd_hda_codec_write(codec, codec->afg, 0,
7654                             AC_VERB_SET_GPIO_MASK, gpiomask);
7655         snd_hda_codec_write(codec, codec->afg, 0,
7656                             AC_VERB_SET_GPIO_DIRECTION, gpiodir);
7657
7658         msleep(1);
7659
7660         snd_hda_codec_write(codec, codec->afg, 0,
7661                             AC_VERB_SET_GPIO_DATA, gpiostate);
7662 }
7663
7664 /* set up GPIO at initialization */
7665 static void alc885_macpro_init_hook(struct hda_codec *codec)
7666 {
7667         alc882_gpio_mute(codec, 0, 0);
7668         alc882_gpio_mute(codec, 1, 0);
7669 }
7670
7671 /* set up GPIO and update auto-muting at initialization */
7672 static void alc885_imac24_init_hook(struct hda_codec *codec)
7673 {
7674         alc885_macpro_init_hook(codec);
7675         alc_automute_amp(codec);
7676 }
7677
7678 /*
7679  * generic initialization of ADC, input mixers and output mixers
7680  */
7681 static struct hda_verb alc883_auto_init_verbs[] = {
7682         /*
7683          * Unmute ADC0-2 and set the default input to mic-in
7684          */
7685         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7686         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7687         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7688         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7689
7690         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
7691          * mixer widget
7692          * Note: PASD motherboards uses the Line In 2 as the input for
7693          * front panel mic (mic 2)
7694          */
7695         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
7696         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7697         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7698         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7699         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7700         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7701
7702         /*
7703          * Set up output mixers (0x0c - 0x0f)
7704          */
7705         /* set vol=0 to output mixers */
7706         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7707         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7708         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7709         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7710         /* set up input amps for analog loopback */
7711         /* Amp Indices: DAC = 0, mixer = 1 */
7712         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7713         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7714         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7715         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7716         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7717         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7718         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7719         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7720         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7721         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7722
7723         /* FIXME: use matrix-type input source selection */
7724         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7725         /* Input mixer2 */
7726         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7727         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7728         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
7729         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
7730         /* Input mixer3 */
7731         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7732         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7733         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
7734         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
7735
7736         { }
7737 };
7738
7739 /* 2ch mode (Speaker:front, Subwoofer:CLFE, Line:input, Headphones:front) */
7740 static struct hda_verb alc889A_mb31_ch2_init[] = {
7741         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},             /* HP as front */
7742         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Subwoofer on */
7743         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},    /* Line as input */
7744         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},   /* Line off */
7745         { } /* end */
7746 };
7747
7748 /* 4ch mode (Speaker:front, Subwoofer:CLFE, Line:CLFE, Headphones:front) */
7749 static struct hda_verb alc889A_mb31_ch4_init[] = {
7750         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},             /* HP as front */
7751         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Subwoofer on */
7752         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},   /* Line as output */
7753         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Line on */
7754         { } /* end */
7755 };
7756
7757 /* 5ch mode (Speaker:front, Subwoofer:CLFE, Line:input, Headphones:rear) */
7758 static struct hda_verb alc889A_mb31_ch5_init[] = {
7759         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},             /* HP as rear */
7760         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Subwoofer on */
7761         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},    /* Line as input */
7762         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},   /* Line off */
7763         { } /* end */
7764 };
7765
7766 /* 6ch mode (Speaker:front, Subwoofer:off, Line:CLFE, Headphones:Rear) */
7767 static struct hda_verb alc889A_mb31_ch6_init[] = {
7768         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},             /* HP as front */
7769         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},   /* Subwoofer off */
7770         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},   /* Line as output */
7771         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Line on */
7772         { } /* end */
7773 };
7774
7775 static struct hda_channel_mode alc889A_mb31_6ch_modes[4] = {
7776         { 2, alc889A_mb31_ch2_init },
7777         { 4, alc889A_mb31_ch4_init },
7778         { 5, alc889A_mb31_ch5_init },
7779         { 6, alc889A_mb31_ch6_init },
7780 };
7781
7782 static struct hda_verb alc883_medion_eapd_verbs[] = {
7783         /* eanable EAPD on medion laptop */
7784         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7785         {0x20, AC_VERB_SET_PROC_COEF, 0x3070},
7786         { }
7787 };
7788
7789 #define alc883_base_mixer       alc882_base_mixer
7790
7791 static struct snd_kcontrol_new alc883_mitac_mixer[] = {
7792         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7793         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7794         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7795         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7796         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7797         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7798         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7799         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7800         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7801         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7802         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7803         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7804         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7805         { } /* end */
7806 };
7807
7808 static struct snd_kcontrol_new alc883_clevo_m720_mixer[] = {
7809         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7810         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7811         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7812         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7813         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7814         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7815         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7816         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7817         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7818         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7819         { } /* end */
7820 };
7821
7822 static struct snd_kcontrol_new alc883_2ch_fujitsu_pi2515_mixer[] = {
7823         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7824         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7825         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7826         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7827         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7828         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7829         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7830         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7831         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7832         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7833         { } /* end */
7834 };
7835
7836 static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
7837         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7838         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7839         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7840         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7841         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7842         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7843         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7844         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7845         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7846         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7847         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7848         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7849         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7850         { } /* end */
7851 };
7852
7853 static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
7854         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7855         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7856         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7857         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7858         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7859         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7860         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7861         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7862         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7863         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7864         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7865         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7866         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7867         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7868         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7869         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7870         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7871         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7872         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7873         { } /* end */
7874 };
7875
7876 static struct snd_kcontrol_new alc883_3ST_6ch_intel_mixer[] = {
7877         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7878         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7879         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7880         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7881         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
7882                               HDA_OUTPUT),
7883         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7884         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7885         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7886         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7887         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7888         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7889         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7890         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7891         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7892         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
7893         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7894         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7895         HDA_CODEC_VOLUME("Front Mic Boost", 0x18, 0, HDA_INPUT),
7896         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7897         { } /* end */
7898 };
7899
7900 static struct snd_kcontrol_new alc885_8ch_intel_mixer[] = {
7901         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7902         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7903         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7904         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7905         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
7906                               HDA_OUTPUT),
7907         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7908         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7909         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7910         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7911         HDA_BIND_MUTE("Speaker Playback Switch", 0x0f, 2, HDA_INPUT),
7912         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7913         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7914         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7915         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
7916         HDA_CODEC_VOLUME("Mic Boost", 0x1b, 0, HDA_INPUT),
7917         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
7918         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7919         HDA_CODEC_VOLUME("Front Mic Boost", 0x18, 0, HDA_INPUT),
7920         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7921         { } /* end */
7922 };
7923
7924 static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
7925         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7926         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7927         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7928         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7929         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7930         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7931         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7932         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7933         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7934         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7935         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7936         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7937         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7938         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7939         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7940         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7941         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7942         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7943         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7944         { } /* end */
7945 };
7946
7947 static struct snd_kcontrol_new alc883_targa_mixer[] = {
7948         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7949         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7950         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7951         HDA_CODEC_MUTE("Speaker Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7952         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7953         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7954         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7955         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7956         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7957         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7958         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7959         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7960         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7961         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7962         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7963         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7964         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7965         { } /* end */
7966 };
7967
7968 static struct snd_kcontrol_new alc883_targa_2ch_mixer[] = {
7969         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7970         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7971         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7972         HDA_CODEC_MUTE("Speaker Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7973         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7974         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7975         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7976         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7977         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7978         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7979         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7980         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7981         { } /* end */
7982 };
7983
7984 static struct snd_kcontrol_new alc883_targa_8ch_mixer[] = {
7985         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7986         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7987         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7988         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7989         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7990         { } /* end */
7991 };
7992
7993 static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
7994         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7995         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7996         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7997         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7998         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7999         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8000         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8001         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8002         { } /* end */
8003 };
8004
8005 static struct snd_kcontrol_new alc883_lenovo_nb0763_mixer[] = {
8006         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8007         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
8008         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8009         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8010         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8011         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8012         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8013         HDA_CODEC_VOLUME("iMic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8014         HDA_CODEC_MUTE("iMic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8015         { } /* end */
8016 };
8017
8018 static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
8019         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8020         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8021         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8022         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8023         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8024         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8025         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8026         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8027         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8028         { } /* end */
8029 };
8030
8031 static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
8032         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8033         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8034         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8035         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8036         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8037         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8038         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8039         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8040         { } /* end */
8041 };
8042
8043 static struct snd_kcontrol_new alc888_acer_aspire_6530_mixer[] = {
8044         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8045         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8046         HDA_CODEC_VOLUME("LFE Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
8047         HDA_BIND_MUTE("LFE Playback Switch", 0x0f, 2, HDA_INPUT),
8048         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8049         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8050         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8051         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8052         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8053         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8054         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8055         { } /* end */
8056 };
8057
8058 static struct snd_kcontrol_new alc888_lenovo_sky_mixer[] = {
8059         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8060         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8061         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
8062         HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
8063         HDA_CODEC_VOLUME_MONO("Center Playback Volume",
8064                                                 0x0d, 1, 0x0, HDA_OUTPUT),
8065         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
8066         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
8067         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
8068         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
8069         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
8070         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8071         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8072         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8073         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8074         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8075         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8076         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8077         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8078         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8079         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8080         { } /* end */
8081 };
8082
8083 static struct snd_kcontrol_new alc889A_mb31_mixer[] = {
8084         /* Output mixers */
8085         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
8086         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
8087         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
8088         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 0x02, HDA_INPUT),
8089         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x00,
8090                 HDA_OUTPUT),
8091         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x02, HDA_INPUT),
8092         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x00, HDA_OUTPUT),
8093         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x02, HDA_INPUT),
8094         /* Output switches */
8095         HDA_CODEC_MUTE("Enable Speaker", 0x14, 0x00, HDA_OUTPUT),
8096         HDA_CODEC_MUTE("Enable Headphones", 0x15, 0x00, HDA_OUTPUT),
8097         HDA_CODEC_MUTE_MONO("Enable LFE", 0x16, 2, 0x00, HDA_OUTPUT),
8098         /* Boost mixers */
8099         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
8100         HDA_CODEC_VOLUME("Line Boost", 0x1a, 0x00, HDA_INPUT),
8101         /* Input mixers */
8102         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
8103         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
8104         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8105         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8106         { } /* end */
8107 };
8108
8109 static struct snd_kcontrol_new alc883_vaiott_mixer[] = {
8110         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8111         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8112         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8113         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8114         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
8115         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8116         { } /* end */
8117 };
8118
8119 static struct hda_bind_ctls alc883_bind_cap_vol = {
8120         .ops = &snd_hda_bind_vol,
8121         .values = {
8122                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
8123                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
8124                 0
8125         },
8126 };
8127
8128 static struct hda_bind_ctls alc883_bind_cap_switch = {
8129         .ops = &snd_hda_bind_sw,
8130         .values = {
8131                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
8132                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
8133                 0
8134         },
8135 };
8136
8137 static struct snd_kcontrol_new alc883_asus_eee1601_mixer[] = {
8138         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8139         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8140         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8141         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8142         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8143         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8144         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8145         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8146         { } /* end */
8147 };
8148
8149 static struct snd_kcontrol_new alc883_asus_eee1601_cap_mixer[] = {
8150         HDA_BIND_VOL("Capture Volume", &alc883_bind_cap_vol),
8151         HDA_BIND_SW("Capture Switch", &alc883_bind_cap_switch),
8152         {
8153                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8154                 /* .name = "Capture Source", */
8155                 .name = "Input Source",
8156                 .count = 1,
8157                 .info = alc_mux_enum_info,
8158                 .get = alc_mux_enum_get,
8159                 .put = alc_mux_enum_put,
8160         },
8161         { } /* end */
8162 };
8163
8164 static struct snd_kcontrol_new alc883_chmode_mixer[] = {
8165         {
8166                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8167                 .name = "Channel Mode",
8168                 .info = alc_ch_mode_info,
8169                 .get = alc_ch_mode_get,
8170                 .put = alc_ch_mode_put,
8171         },
8172         { } /* end */
8173 };
8174
8175 /* toggle speaker-output according to the hp-jack state */
8176 static void alc883_mitac_setup(struct hda_codec *codec)
8177 {
8178         struct alc_spec *spec = codec->spec;
8179
8180         spec->autocfg.hp_pins[0] = 0x15;
8181         spec->autocfg.speaker_pins[0] = 0x14;
8182         spec->autocfg.speaker_pins[1] = 0x17;
8183 }
8184
8185 /* auto-toggle front mic */
8186 /*
8187 static void alc883_mitac_mic_automute(struct hda_codec *codec)
8188 {
8189         unsigned int present;
8190         unsigned char bits;
8191
8192         present = snd_hda_codec_read(codec, 0x18, 0,
8193                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8194         bits = present ? HDA_AMP_MUTE : 0;
8195         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
8196 }
8197 */
8198
8199 static struct hda_verb alc883_mitac_verbs[] = {
8200         /* HP */
8201         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8202         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8203         /* Subwoofer */
8204         {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
8205         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8206
8207         /* enable unsolicited event */
8208         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8209         /* {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN}, */
8210
8211         { } /* end */
8212 };
8213
8214 static struct hda_verb alc883_clevo_m540r_verbs[] = {
8215         /* HP */
8216         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8217         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8218         /* Int speaker */
8219         /*{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},*/
8220
8221         /* enable unsolicited event */
8222         /*
8223         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8224         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
8225         */
8226
8227         { } /* end */
8228 };
8229
8230 static struct hda_verb alc883_clevo_m720_verbs[] = {
8231         /* HP */
8232         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8233         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8234         /* Int speaker */
8235         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
8236         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8237
8238         /* enable unsolicited event */
8239         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8240         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
8241
8242         { } /* end */
8243 };
8244
8245 static struct hda_verb alc883_2ch_fujitsu_pi2515_verbs[] = {
8246         /* HP */
8247         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8248         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8249         /* Subwoofer */
8250         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
8251         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8252
8253         /* enable unsolicited event */
8254         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8255
8256         { } /* end */
8257 };
8258
8259 static struct hda_verb alc883_targa_verbs[] = {
8260         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8261         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8262
8263         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8264         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8265
8266 /* Connect Line-Out side jack (SPDIF) to Side */
8267         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8268         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8269         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
8270 /* Connect Mic jack to CLFE */
8271         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8272         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8273         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},
8274 /* Connect Line-in jack to Surround */
8275         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8276         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8277         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
8278 /* Connect HP out jack to Front */
8279         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8280         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8281         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8282
8283         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8284
8285         { } /* end */
8286 };
8287
8288 static struct hda_verb alc883_lenovo_101e_verbs[] = {
8289         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8290         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT|AC_USRSP_EN},
8291         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT|AC_USRSP_EN},
8292         { } /* end */
8293 };
8294
8295 static struct hda_verb alc883_lenovo_nb0763_verbs[] = {
8296         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8297         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8298         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8299         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8300         { } /* end */
8301 };
8302
8303 static struct hda_verb alc888_lenovo_ms7195_verbs[] = {
8304         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8305         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8306         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8307         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT | AC_USRSP_EN},
8308         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT    | AC_USRSP_EN},
8309         { } /* end */
8310 };
8311
8312 static struct hda_verb alc883_haier_w66_verbs[] = {
8313         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8314         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8315
8316         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8317
8318         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8319         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8320         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8321         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8322         { } /* end */
8323 };
8324
8325 static struct hda_verb alc888_lenovo_sky_verbs[] = {
8326         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8327         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8328         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8329         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8330         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8331         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8332         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
8333         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8334         { } /* end */
8335 };
8336
8337 static struct hda_verb alc888_6st_dell_verbs[] = {
8338         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8339         { }
8340 };
8341
8342 static struct hda_verb alc883_vaiott_verbs[] = {
8343         /* HP */
8344         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8345         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8346
8347         /* enable unsolicited event */
8348         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8349
8350         { } /* end */
8351 };
8352
8353 static void alc888_3st_hp_setup(struct hda_codec *codec)
8354 {
8355         struct alc_spec *spec = codec->spec;
8356
8357         spec->autocfg.hp_pins[0] = 0x1b;
8358         spec->autocfg.speaker_pins[0] = 0x14;
8359         spec->autocfg.speaker_pins[1] = 0x16;
8360         spec->autocfg.speaker_pins[2] = 0x18;
8361 }
8362
8363 static struct hda_verb alc888_3st_hp_verbs[] = {
8364         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
8365         {0x16, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Rear : output 1 (0x0d) */
8366         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},  /* CLFE : output 2 (0x0e) */
8367         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8368         { } /* end */
8369 };
8370
8371 /*
8372  * 2ch mode
8373  */
8374 static struct hda_verb alc888_3st_hp_2ch_init[] = {
8375         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
8376         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8377         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
8378         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8379         { } /* end */
8380 };
8381
8382 /*
8383  * 4ch mode
8384  */
8385 static struct hda_verb alc888_3st_hp_4ch_init[] = {
8386         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
8387         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8388         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8389         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8390         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x01 },
8391         { } /* end */
8392 };
8393
8394 /*
8395  * 6ch mode
8396  */
8397 static struct hda_verb alc888_3st_hp_6ch_init[] = {
8398         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8399         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8400         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
8401         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8402         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8403         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x01 },
8404         { } /* end */
8405 };
8406
8407 static struct hda_channel_mode alc888_3st_hp_modes[3] = {
8408         { 2, alc888_3st_hp_2ch_init },
8409         { 4, alc888_3st_hp_4ch_init },
8410         { 6, alc888_3st_hp_6ch_init },
8411 };
8412
8413 /* toggle front-jack and RCA according to the hp-jack state */
8414 static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
8415 {
8416         unsigned int present;
8417
8418         present = snd_hda_codec_read(codec, 0x1b, 0,
8419                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8420         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8421                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8422         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8423                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8424 }
8425
8426 /* toggle RCA according to the front-jack state */
8427 static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
8428 {
8429         unsigned int present;
8430
8431         present = snd_hda_codec_read(codec, 0x14, 0,
8432                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8433         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8434                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8435 }
8436
8437 static void alc883_lenovo_ms7195_unsol_event(struct hda_codec *codec,
8438                                              unsigned int res)
8439 {
8440         if ((res >> 26) == ALC880_HP_EVENT)
8441                 alc888_lenovo_ms7195_front_automute(codec);
8442         if ((res >> 26) == ALC880_FRONT_EVENT)
8443                 alc888_lenovo_ms7195_rca_automute(codec);
8444 }
8445
8446 static struct hda_verb alc883_medion_md2_verbs[] = {
8447         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8448         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8449
8450         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8451
8452         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8453         { } /* end */
8454 };
8455
8456 /* toggle speaker-output according to the hp-jack state */
8457 static void alc883_medion_md2_setup(struct hda_codec *codec)
8458 {
8459         struct alc_spec *spec = codec->spec;
8460
8461         spec->autocfg.hp_pins[0] = 0x14;
8462         spec->autocfg.speaker_pins[0] = 0x15;
8463 }
8464
8465 /* toggle speaker-output according to the hp-jack state */
8466 #define alc883_targa_init_hook          alc882_targa_init_hook
8467 #define alc883_targa_unsol_event        alc882_targa_unsol_event
8468
8469 static void alc883_clevo_m720_mic_automute(struct hda_codec *codec)
8470 {
8471         unsigned int present;
8472
8473         present = snd_hda_codec_read(codec, 0x18, 0,
8474                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8475         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
8476                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8477 }
8478
8479 static void alc883_clevo_m720_setup(struct hda_codec *codec)
8480 {
8481         struct alc_spec *spec = codec->spec;
8482
8483         spec->autocfg.hp_pins[0] = 0x15;
8484         spec->autocfg.speaker_pins[0] = 0x14;
8485 }
8486
8487 static void alc883_clevo_m720_init_hook(struct hda_codec *codec)
8488 {
8489         alc_automute_amp(codec);
8490         alc883_clevo_m720_mic_automute(codec);
8491 }
8492
8493 static void alc883_clevo_m720_unsol_event(struct hda_codec *codec,
8494                                            unsigned int res)
8495 {
8496         switch (res >> 26) {
8497         case ALC880_MIC_EVENT:
8498                 alc883_clevo_m720_mic_automute(codec);
8499                 break;
8500         default:
8501                 alc_automute_amp_unsol_event(codec, res);
8502                 break;
8503         }
8504 }
8505
8506 /* toggle speaker-output according to the hp-jack state */
8507 static void alc883_2ch_fujitsu_pi2515_setup(struct hda_codec *codec)
8508 {
8509         struct alc_spec *spec = codec->spec;
8510
8511         spec->autocfg.hp_pins[0] = 0x14;
8512         spec->autocfg.speaker_pins[0] = 0x15;
8513 }
8514
8515 static void alc883_haier_w66_setup(struct hda_codec *codec)
8516 {
8517         struct alc_spec *spec = codec->spec;
8518
8519         spec->autocfg.hp_pins[0] = 0x1b;
8520         spec->autocfg.speaker_pins[0] = 0x14;
8521 }
8522
8523 static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
8524 {
8525         unsigned int present;
8526         unsigned char bits;
8527
8528         present = snd_hda_codec_read(codec, 0x14, 0, AC_VERB_GET_PIN_SENSE, 0)
8529                 & AC_PINSENSE_PRESENCE;
8530         bits = present ? HDA_AMP_MUTE : 0;
8531         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8532                                  HDA_AMP_MUTE, bits);
8533 }
8534
8535 static void alc883_lenovo_101e_all_automute(struct hda_codec *codec)
8536 {
8537         unsigned int present;
8538         unsigned char bits;
8539
8540         present = snd_hda_codec_read(codec, 0x1b, 0,
8541                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8542         bits = present ? HDA_AMP_MUTE : 0;
8543         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8544                                  HDA_AMP_MUTE, bits);
8545         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8546                                  HDA_AMP_MUTE, bits);
8547 }
8548
8549 static void alc883_lenovo_101e_unsol_event(struct hda_codec *codec,
8550                                            unsigned int res)
8551 {
8552         if ((res >> 26) == ALC880_HP_EVENT)
8553                 alc883_lenovo_101e_all_automute(codec);
8554         if ((res >> 26) == ALC880_FRONT_EVENT)
8555                 alc883_lenovo_101e_ispeaker_automute(codec);
8556 }
8557
8558 /* toggle speaker-output according to the hp-jack state */
8559 static void alc883_acer_aspire_setup(struct hda_codec *codec)
8560 {
8561         struct alc_spec *spec = codec->spec;
8562
8563         spec->autocfg.hp_pins[0] = 0x14;
8564         spec->autocfg.speaker_pins[0] = 0x15;
8565         spec->autocfg.speaker_pins[1] = 0x16;
8566 }
8567
8568 static struct hda_verb alc883_acer_eapd_verbs[] = {
8569         /* HP Pin: output 0 (0x0c) */
8570         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8571         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8572         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8573         /* Front Pin: output 0 (0x0c) */
8574         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8575         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8576         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8577         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
8578         /* eanable EAPD on medion laptop */
8579         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
8580         {0x20, AC_VERB_SET_PROC_COEF, 0x3050},
8581         /* enable unsolicited event */
8582         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8583         { }
8584 };
8585
8586 static struct hda_verb alc888_acer_aspire_7730G_verbs[] = {
8587         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8588         {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
8589         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8590         { } /* end */
8591 };
8592
8593 static void alc888_6st_dell_setup(struct hda_codec *codec)
8594 {
8595         struct alc_spec *spec = codec->spec;
8596
8597         spec->autocfg.hp_pins[0] = 0x1b;
8598         spec->autocfg.speaker_pins[0] = 0x14;
8599         spec->autocfg.speaker_pins[1] = 0x15;
8600         spec->autocfg.speaker_pins[2] = 0x16;
8601         spec->autocfg.speaker_pins[3] = 0x17;
8602 }
8603
8604 static void alc888_lenovo_sky_setup(struct hda_codec *codec)
8605 {
8606         struct alc_spec *spec = codec->spec;
8607
8608         spec->autocfg.hp_pins[0] = 0x1b;
8609         spec->autocfg.speaker_pins[0] = 0x14;
8610         spec->autocfg.speaker_pins[1] = 0x15;
8611         spec->autocfg.speaker_pins[2] = 0x16;
8612         spec->autocfg.speaker_pins[3] = 0x17;
8613         spec->autocfg.speaker_pins[4] = 0x1a;
8614 }
8615
8616 static void alc883_vaiott_setup(struct hda_codec *codec)
8617 {
8618         struct alc_spec *spec = codec->spec;
8619
8620         spec->autocfg.hp_pins[0] = 0x15;
8621         spec->autocfg.speaker_pins[0] = 0x14;
8622         spec->autocfg.speaker_pins[1] = 0x17;
8623 }
8624
8625 static struct hda_verb alc888_asus_m90v_verbs[] = {
8626         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8627         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8628         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8629         /* enable unsolicited event */
8630         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8631         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
8632         { } /* end */
8633 };
8634
8635 static void alc883_mode2_setup(struct hda_codec *codec)
8636 {
8637         struct alc_spec *spec = codec->spec;
8638
8639         spec->autocfg.hp_pins[0] = 0x1b;
8640         spec->autocfg.speaker_pins[0] = 0x14;
8641         spec->autocfg.speaker_pins[1] = 0x15;
8642         spec->autocfg.speaker_pins[2] = 0x16;
8643         spec->ext_mic.pin = 0x18;
8644         spec->int_mic.pin = 0x19;
8645         spec->ext_mic.mux_idx = 0;
8646         spec->int_mic.mux_idx = 1;
8647         spec->auto_mic = 1;
8648 }
8649
8650 static struct hda_verb alc888_asus_eee1601_verbs[] = {
8651         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8652         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8653         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8654         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8655         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8656         {0x20, AC_VERB_SET_COEF_INDEX, 0x0b},
8657         {0x20, AC_VERB_SET_PROC_COEF,  0x0838},
8658         /* enable unsolicited event */
8659         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8660         { } /* end */
8661 };
8662
8663 static void alc883_eee1601_inithook(struct hda_codec *codec)
8664 {
8665         struct alc_spec *spec = codec->spec;
8666
8667         spec->autocfg.hp_pins[0] = 0x14;
8668         spec->autocfg.speaker_pins[0] = 0x1b;
8669         alc_automute_pin(codec);
8670 }
8671
8672 static struct hda_verb alc889A_mb31_verbs[] = {
8673         /* Init rear pin (used as headphone output) */
8674         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},    /* Apple Headphones */
8675         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},           /* Connect to front */
8676         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8677         /* Init line pin (used as output in 4ch and 6ch mode) */
8678         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x02},           /* Connect to CLFE */
8679         /* Init line 2 pin (used as headphone out by default) */
8680         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},  /* Use as input */
8681         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Mute output */
8682         { } /* end */
8683 };
8684
8685 /* Mute speakers according to the headphone jack state */
8686 static void alc889A_mb31_automute(struct hda_codec *codec)
8687 {
8688         unsigned int present;
8689
8690         /* Mute only in 2ch or 4ch mode */
8691         if (snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_CONNECT_SEL, 0)
8692             == 0x00) {
8693                 present = snd_hda_codec_read(codec, 0x15, 0,
8694                         AC_VERB_GET_PIN_SENSE, 0) & AC_PINSENSE_PRESENCE;
8695                 snd_hda_codec_amp_stereo(codec, 0x14,  HDA_OUTPUT, 0,
8696                         HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8697                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8698                         HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8699         }
8700 }
8701
8702 static void alc889A_mb31_unsol_event(struct hda_codec *codec, unsigned int res)
8703 {
8704         if ((res >> 26) == ALC880_HP_EVENT)
8705                 alc889A_mb31_automute(codec);
8706 }
8707
8708
8709 #ifdef CONFIG_SND_HDA_POWER_SAVE
8710 #define alc882_loopbacks        alc880_loopbacks
8711 #endif
8712
8713 /* pcm configuration: identical with ALC880 */
8714 #define alc882_pcm_analog_playback      alc880_pcm_analog_playback
8715 #define alc882_pcm_analog_capture       alc880_pcm_analog_capture
8716 #define alc882_pcm_digital_playback     alc880_pcm_digital_playback
8717 #define alc882_pcm_digital_capture      alc880_pcm_digital_capture
8718
8719 static hda_nid_t alc883_slave_dig_outs[] = {
8720         ALC1200_DIGOUT_NID, 0,
8721 };
8722
8723 static hda_nid_t alc1200_slave_dig_outs[] = {
8724         ALC883_DIGOUT_NID, 0,
8725 };
8726
8727 /*
8728  * configuration and preset
8729  */
8730 static const char *alc882_models[ALC882_MODEL_LAST] = {
8731         [ALC882_3ST_DIG]        = "3stack-dig",
8732         [ALC882_6ST_DIG]        = "6stack-dig",
8733         [ALC882_ARIMA]          = "arima",
8734         [ALC882_W2JC]           = "w2jc",
8735         [ALC882_TARGA]          = "targa",
8736         [ALC882_ASUS_A7J]       = "asus-a7j",
8737         [ALC882_ASUS_A7M]       = "asus-a7m",
8738         [ALC885_MACPRO]         = "macpro",
8739         [ALC885_MB5]            = "mb5",
8740         [ALC885_MBP3]           = "mbp3",
8741         [ALC885_IMAC24]         = "imac24",
8742         [ALC883_3ST_2ch_DIG]    = "3stack-2ch-dig",
8743         [ALC883_3ST_6ch_DIG]    = "3stack-6ch-dig",
8744         [ALC883_3ST_6ch]        = "3stack-6ch",
8745         [ALC883_6ST_DIG]        = "alc883-6stack-dig",
8746         [ALC883_TARGA_DIG]      = "targa-dig",
8747         [ALC883_TARGA_2ch_DIG]  = "targa-2ch-dig",
8748         [ALC883_TARGA_8ch_DIG]  = "targa-8ch-dig",
8749         [ALC883_ACER]           = "acer",
8750         [ALC883_ACER_ASPIRE]    = "acer-aspire",
8751         [ALC888_ACER_ASPIRE_4930G]      = "acer-aspire-4930g",
8752         [ALC888_ACER_ASPIRE_6530G]      = "acer-aspire-6530g",
8753         [ALC888_ACER_ASPIRE_8930G]      = "acer-aspire-8930g",
8754         [ALC888_ACER_ASPIRE_7730G]      = "acer-aspire-7730g",
8755         [ALC883_MEDION]         = "medion",
8756         [ALC883_MEDION_MD2]     = "medion-md2",
8757         [ALC883_LAPTOP_EAPD]    = "laptop-eapd",
8758         [ALC883_LENOVO_101E_2ch] = "lenovo-101e",
8759         [ALC883_LENOVO_NB0763]  = "lenovo-nb0763",
8760         [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
8761         [ALC888_LENOVO_SKY] = "lenovo-sky",
8762         [ALC883_HAIER_W66]      = "haier-w66",
8763         [ALC888_3ST_HP]         = "3stack-hp",
8764         [ALC888_6ST_DELL]       = "6stack-dell",
8765         [ALC883_MITAC]          = "mitac",
8766         [ALC883_CLEVO_M540R]    = "clevo-m540r",
8767         [ALC883_CLEVO_M720]     = "clevo-m720",
8768         [ALC883_FUJITSU_PI2515] = "fujitsu-pi2515",
8769         [ALC888_FUJITSU_XA3530] = "fujitsu-xa3530",
8770         [ALC883_3ST_6ch_INTEL]  = "3stack-6ch-intel",
8771         [ALC889A_INTEL]         = "intel-alc889a",
8772         [ALC889_INTEL]          = "intel-x58",
8773         [ALC1200_ASUS_P5Q]      = "asus-p5q",
8774         [ALC889A_MB31]          = "mb31",
8775         [ALC883_SONY_VAIO_TT]   = "sony-vaio-tt",
8776         [ALC882_AUTO]           = "auto",
8777 };
8778
8779 static struct snd_pci_quirk alc882_cfg_tbl[] = {
8780         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),
8781
8782         SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE),
8783         SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_ACER_ASPIRE),
8784         SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_ACER_ASPIRE),
8785         SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE),
8786         SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE),
8787         SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_ACER_ASPIRE),
8788         SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
8789                 ALC888_ACER_ASPIRE_4930G),
8790         SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
8791                 ALC888_ACER_ASPIRE_4930G),
8792         SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
8793                 ALC888_ACER_ASPIRE_8930G),
8794         SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
8795                 ALC888_ACER_ASPIRE_8930G),
8796         SND_PCI_QUIRK(0x1025, 0x0157, "Acer X3200", ALC882_AUTO),
8797         SND_PCI_QUIRK(0x1025, 0x0158, "Acer AX1700-U3700A", ALC882_AUTO),
8798         SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
8799                 ALC888_ACER_ASPIRE_6530G),
8800         SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
8801                 ALC888_ACER_ASPIRE_6530G),
8802         SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
8803                 ALC888_ACER_ASPIRE_7730G),
8804         /* default Acer -- disabled as it causes more problems.
8805          *    model=auto should work fine now
8806          */
8807         /* SND_PCI_QUIRK_VENDOR(0x1025, "Acer laptop", ALC883_ACER), */
8808
8809         SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL),
8810
8811         SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
8812         SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
8813         SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
8814         SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG),
8815         SND_PCI_QUIRK(0x103c, 0x2a66, "HP Acacia", ALC888_3ST_HP),
8816         SND_PCI_QUIRK(0x103c, 0x2a72, "HP Educ.ar", ALC888_3ST_HP),
8817
8818         SND_PCI_QUIRK(0x1043, 0x060d, "Asus A7J", ALC882_ASUS_A7J),
8819         SND_PCI_QUIRK(0x1043, 0x1243, "Asus A7J", ALC882_ASUS_A7J),
8820         SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_ASUS_A7M),
8821         SND_PCI_QUIRK(0x1043, 0x1873, "Asus M90V", ALC888_ASUS_M90V),
8822         SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_W2JC),
8823         SND_PCI_QUIRK(0x1043, 0x817f, "Asus P5LD2", ALC882_6ST_DIG),
8824         SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
8825         SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG),
8826         SND_PCI_QUIRK(0x1043, 0x8284, "Asus Z37E", ALC883_6ST_DIG),
8827         SND_PCI_QUIRK(0x1043, 0x82fe, "Asus P5Q-EM HDMI", ALC1200_ASUS_P5Q),
8828         SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_ASUS_EEE1601),
8829
8830         SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC883_SONY_VAIO_TT),
8831         SND_PCI_QUIRK(0x105b, 0x0ce8, "Foxconn P35AX-S", ALC883_6ST_DIG),
8832         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
8833         SND_PCI_QUIRK(0x1071, 0x8227, "Mitac 82801H", ALC883_MITAC),
8834         SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC),
8835         SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
8836         SND_PCI_QUIRK(0x10f1, 0x2350, "TYAN-S2350", ALC888_6ST_DELL),
8837         SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
8838         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte P35 DS3R", ALC882_6ST_DIG),
8839
8840         SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
8841         SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG),
8842         SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
8843         SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8  */
8844         SND_PCI_QUIRK(0x1462, 0x2fb3, "MSI", ALC883_TARGA_2ch_DIG),
8845         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
8846         SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
8847         SND_PCI_QUIRK(0x1462, 0x3783, "NEC S970", ALC883_TARGA_DIG),
8848         SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
8849         SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
8850         SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
8851         SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG),
8852         SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG),
8853         SND_PCI_QUIRK(0x1462, 0x3fdf, "MSI", ALC883_TARGA_DIG),
8854         SND_PCI_QUIRK(0x1462, 0x42cd, "MSI", ALC883_TARGA_DIG),
8855         SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
8856         SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
8857         SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
8858         SND_PCI_QUIRK(0x1462, 0x6510, "MSI GX620", ALC883_TARGA_8ch_DIG),
8859         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
8860         SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
8861         SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
8862         SND_PCI_QUIRK(0x1462, 0x7260, "MSI 7260", ALC883_TARGA_DIG),
8863         SND_PCI_QUIRK(0x1462, 0x7267, "MSI", ALC883_3ST_6ch_DIG),
8864         SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
8865         SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
8866         SND_PCI_QUIRK(0x1462, 0x7350, "MSI", ALC883_6ST_DIG),
8867         SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
8868         SND_PCI_QUIRK(0x1462, 0xaa08, "MSI", ALC883_TARGA_2ch_DIG),
8869
8870         SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG),
8871         SND_PCI_QUIRK(0x1558, 0x0721, "Clevo laptop M720R", ALC883_CLEVO_M720),
8872         SND_PCI_QUIRK(0x1558, 0x0722, "Clevo laptop M720SR", ALC883_CLEVO_M720),
8873         SND_PCI_QUIRK(0x1558, 0x5409, "Clevo laptop M540R", ALC883_CLEVO_M540R),
8874         SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC883_LAPTOP_EAPD),
8875         SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
8876         /* SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA), */
8877         SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
8878         SND_PCI_QUIRK_MASK(0x1734, 0xfff0, 0x1100, "FSC AMILO Xi/Pi25xx",
8879                       ALC883_FUJITSU_PI2515),
8880         SND_PCI_QUIRK_MASK(0x1734, 0xfff0, 0x1130, "Fujitsu AMILO Xa35xx",
8881                 ALC888_FUJITSU_XA3530),
8882         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
8883         SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8884         SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8885         SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8886         SND_PCI_QUIRK(0x17aa, 0x101d, "Lenovo Sky", ALC888_LENOVO_SKY),
8887         SND_PCI_QUIRK(0x17c0, 0x4071, "MEDION MD2", ALC883_MEDION_MD2),
8888         SND_PCI_QUIRK(0x17c0, 0x4085, "MEDION MD96630", ALC888_LENOVO_MS7195_DIG),
8889         SND_PCI_QUIRK(0x17f2, 0x5000, "Albatron KI690-AM2", ALC883_6ST_DIG),
8890         SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66),
8891
8892         SND_PCI_QUIRK(0x8086, 0x0001, "DG33BUC", ALC883_3ST_6ch_INTEL),
8893         SND_PCI_QUIRK(0x8086, 0x0002, "DG33FBC", ALC883_3ST_6ch_INTEL),
8894         SND_PCI_QUIRK(0x8086, 0x2503, "82801H", ALC883_MITAC),
8895         SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_INTEL),
8896         SND_PCI_QUIRK(0x8086, 0x0021, "Intel IbexPeak", ALC889A_INTEL),
8897         SND_PCI_QUIRK(0x8086, 0x3b56, "Intel IbexPeak", ALC889A_INTEL),
8898         SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch),
8899
8900         {}
8901 };
8902
8903 /* codec SSID table for Intel Mac */
8904 static struct snd_pci_quirk alc882_ssid_cfg_tbl[] = {
8905         SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC885_MBP3),
8906         SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC885_MBP3),
8907         SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC885_MBP3),
8908         SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_MACPRO),
8909         SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_IMAC24),
8910         SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_IMAC24),
8911         SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC885_MBP3),
8912         SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889A_MB31),
8913         SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC885_MBP3),
8914         SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_IMAC24),
8915         SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC885_MB5),
8916         /* FIXME: HP jack sense seems not working for MBP 5,1 or 5,2,
8917          * so apparently no perfect solution yet
8918          */
8919         SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC885_MB5),
8920         SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC885_MB5),
8921         {} /* terminator */
8922 };
8923
8924 static struct alc_config_preset alc882_presets[] = {
8925         [ALC882_3ST_DIG] = {
8926                 .mixers = { alc882_base_mixer },
8927                 .init_verbs = { alc882_base_init_verbs,
8928                                 alc882_adc1_init_verbs },
8929                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
8930                 .dac_nids = alc882_dac_nids,
8931                 .dig_out_nid = ALC882_DIGOUT_NID,
8932                 .dig_in_nid = ALC882_DIGIN_NID,
8933                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
8934                 .channel_mode = alc882_ch_modes,
8935                 .need_dac_fix = 1,
8936                 .input_mux = &alc882_capture_source,
8937         },
8938         [ALC882_6ST_DIG] = {
8939                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
8940                 .init_verbs = { alc882_base_init_verbs,
8941                                 alc882_adc1_init_verbs },
8942                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
8943                 .dac_nids = alc882_dac_nids,
8944                 .dig_out_nid = ALC882_DIGOUT_NID,
8945                 .dig_in_nid = ALC882_DIGIN_NID,
8946                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
8947                 .channel_mode = alc882_sixstack_modes,
8948                 .input_mux = &alc882_capture_source,
8949         },
8950         [ALC882_ARIMA] = {
8951                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
8952                 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
8953                                 alc882_eapd_verbs },
8954                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
8955                 .dac_nids = alc882_dac_nids,
8956                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
8957                 .channel_mode = alc882_sixstack_modes,
8958                 .input_mux = &alc882_capture_source,
8959         },
8960         [ALC882_W2JC] = {
8961                 .mixers = { alc882_w2jc_mixer, alc882_chmode_mixer },
8962                 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
8963                                 alc882_eapd_verbs, alc880_gpio1_init_verbs },
8964                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
8965                 .dac_nids = alc882_dac_nids,
8966                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
8967                 .channel_mode = alc880_threestack_modes,
8968                 .need_dac_fix = 1,
8969                 .input_mux = &alc882_capture_source,
8970                 .dig_out_nid = ALC882_DIGOUT_NID,
8971         },
8972         [ALC885_MBP3] = {
8973                 .mixers = { alc885_mbp3_mixer, alc882_chmode_mixer },
8974                 .init_verbs = { alc885_mbp3_init_verbs,
8975                                 alc880_gpio1_init_verbs },
8976                 .num_dacs = 2,
8977                 .dac_nids = alc882_dac_nids,
8978                 .hp_nid = 0x04,
8979                 .channel_mode = alc885_mbp_4ch_modes,
8980                 .num_channel_mode = ARRAY_SIZE(alc885_mbp_4ch_modes),
8981                 .input_mux = &alc882_capture_source,
8982                 .dig_out_nid = ALC882_DIGOUT_NID,
8983                 .dig_in_nid = ALC882_DIGIN_NID,
8984                 .unsol_event = alc_automute_amp_unsol_event,
8985                 .setup = alc885_mbp3_setup,
8986                 .init_hook = alc_automute_amp,
8987         },
8988         [ALC885_MB5] = {
8989                 .mixers = { alc885_mb5_mixer, alc882_chmode_mixer },
8990                 .init_verbs = { alc885_mb5_init_verbs,
8991                                 alc880_gpio1_init_verbs },
8992                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
8993                 .dac_nids = alc882_dac_nids,
8994                 .channel_mode = alc885_mb5_6ch_modes,
8995                 .num_channel_mode = ARRAY_SIZE(alc885_mb5_6ch_modes),
8996                 .input_mux = &mb5_capture_source,
8997                 .dig_out_nid = ALC882_DIGOUT_NID,
8998                 .dig_in_nid = ALC882_DIGIN_NID,
8999         },
9000         [ALC885_MACPRO] = {
9001                 .mixers = { alc882_macpro_mixer },
9002                 .init_verbs = { alc882_macpro_init_verbs },
9003                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
9004                 .dac_nids = alc882_dac_nids,
9005                 .dig_out_nid = ALC882_DIGOUT_NID,
9006                 .dig_in_nid = ALC882_DIGIN_NID,
9007                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
9008                 .channel_mode = alc882_ch_modes,
9009                 .input_mux = &alc882_capture_source,
9010                 .init_hook = alc885_macpro_init_hook,
9011         },
9012         [ALC885_IMAC24] = {
9013                 .mixers = { alc885_imac24_mixer },
9014                 .init_verbs = { alc885_imac24_init_verbs },
9015                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
9016                 .dac_nids = alc882_dac_nids,
9017                 .dig_out_nid = ALC882_DIGOUT_NID,
9018                 .dig_in_nid = ALC882_DIGIN_NID,
9019                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
9020                 .channel_mode = alc882_ch_modes,
9021                 .input_mux = &alc882_capture_source,
9022                 .unsol_event = alc_automute_amp_unsol_event,
9023                 .setup = alc885_imac24_setup,
9024                 .init_hook = alc885_imac24_init_hook,
9025         },
9026         [ALC882_TARGA] = {
9027                 .mixers = { alc882_targa_mixer, alc882_chmode_mixer },
9028                 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
9029                                 alc880_gpio3_init_verbs, alc882_targa_verbs},
9030                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
9031                 .dac_nids = alc882_dac_nids,
9032                 .dig_out_nid = ALC882_DIGOUT_NID,
9033                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
9034                 .adc_nids = alc882_adc_nids,
9035                 .capsrc_nids = alc882_capsrc_nids,
9036                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
9037                 .channel_mode = alc882_3ST_6ch_modes,
9038                 .need_dac_fix = 1,
9039                 .input_mux = &alc882_capture_source,
9040                 .unsol_event = alc882_targa_unsol_event,
9041                 .setup = alc882_targa_setup,
9042                 .init_hook = alc882_targa_automute,
9043         },
9044         [ALC882_ASUS_A7J] = {
9045                 .mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer },
9046                 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
9047                                 alc882_asus_a7j_verbs},
9048                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
9049                 .dac_nids = alc882_dac_nids,
9050                 .dig_out_nid = ALC882_DIGOUT_NID,
9051                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
9052                 .adc_nids = alc882_adc_nids,
9053                 .capsrc_nids = alc882_capsrc_nids,
9054                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
9055                 .channel_mode = alc882_3ST_6ch_modes,
9056                 .need_dac_fix = 1,
9057                 .input_mux = &alc882_capture_source,
9058         },
9059         [ALC882_ASUS_A7M] = {
9060                 .mixers = { alc882_asus_a7m_mixer, alc882_chmode_mixer },
9061                 .init_verbs = { alc882_base_init_verbs, alc882_adc1_init_verbs,
9062                                 alc882_eapd_verbs, alc880_gpio1_init_verbs,
9063                                 alc882_asus_a7m_verbs },
9064                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
9065                 .dac_nids = alc882_dac_nids,
9066                 .dig_out_nid = ALC882_DIGOUT_NID,
9067                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
9068                 .channel_mode = alc880_threestack_modes,
9069                 .need_dac_fix = 1,
9070                 .input_mux = &alc882_capture_source,
9071         },
9072         [ALC883_3ST_2ch_DIG] = {
9073                 .mixers = { alc883_3ST_2ch_mixer },
9074                 .init_verbs = { alc883_init_verbs },
9075                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9076                 .dac_nids = alc883_dac_nids,
9077                 .dig_out_nid = ALC883_DIGOUT_NID,
9078                 .dig_in_nid = ALC883_DIGIN_NID,
9079                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9080                 .channel_mode = alc883_3ST_2ch_modes,
9081                 .input_mux = &alc883_capture_source,
9082         },
9083         [ALC883_3ST_6ch_DIG] = {
9084                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9085                 .init_verbs = { alc883_init_verbs },
9086                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9087                 .dac_nids = alc883_dac_nids,
9088                 .dig_out_nid = ALC883_DIGOUT_NID,
9089                 .dig_in_nid = ALC883_DIGIN_NID,
9090                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9091                 .channel_mode = alc883_3ST_6ch_modes,
9092                 .need_dac_fix = 1,
9093                 .input_mux = &alc883_capture_source,
9094         },
9095         [ALC883_3ST_6ch] = {
9096                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9097                 .init_verbs = { alc883_init_verbs },
9098                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9099                 .dac_nids = alc883_dac_nids,
9100                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9101                 .channel_mode = alc883_3ST_6ch_modes,
9102                 .need_dac_fix = 1,
9103                 .input_mux = &alc883_capture_source,
9104         },
9105         [ALC883_3ST_6ch_INTEL] = {
9106                 .mixers = { alc883_3ST_6ch_intel_mixer, alc883_chmode_mixer },
9107                 .init_verbs = { alc883_init_verbs },
9108                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9109                 .dac_nids = alc883_dac_nids,
9110                 .dig_out_nid = ALC883_DIGOUT_NID,
9111                 .dig_in_nid = ALC883_DIGIN_NID,
9112                 .slave_dig_outs = alc883_slave_dig_outs,
9113                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_intel_modes),
9114                 .channel_mode = alc883_3ST_6ch_intel_modes,
9115                 .need_dac_fix = 1,
9116                 .input_mux = &alc883_3stack_6ch_intel,
9117         },
9118         [ALC889A_INTEL] = {
9119                 .mixers = { alc885_8ch_intel_mixer, alc883_chmode_mixer },
9120                 .init_verbs = { alc885_init_verbs, alc885_init_input_verbs,
9121                                 alc_hp15_unsol_verbs },
9122                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9123                 .dac_nids = alc883_dac_nids,
9124                 .num_adc_nids = ARRAY_SIZE(alc889_adc_nids),
9125                 .adc_nids = alc889_adc_nids,
9126                 .dig_out_nid = ALC883_DIGOUT_NID,
9127                 .dig_in_nid = ALC883_DIGIN_NID,
9128                 .slave_dig_outs = alc883_slave_dig_outs,
9129                 .num_channel_mode = ARRAY_SIZE(alc889_8ch_intel_modes),
9130                 .channel_mode = alc889_8ch_intel_modes,
9131                 .capsrc_nids = alc889_capsrc_nids,
9132                 .input_mux = &alc889_capture_source,
9133                 .setup = alc889_automute_setup,
9134                 .init_hook = alc_automute_amp,
9135                 .unsol_event = alc_automute_amp_unsol_event,
9136                 .need_dac_fix = 1,
9137         },
9138         [ALC889_INTEL] = {
9139                 .mixers = { alc885_8ch_intel_mixer, alc883_chmode_mixer },
9140                 .init_verbs = { alc885_init_verbs, alc889_init_input_verbs,
9141                                 alc889_eapd_verbs, alc_hp15_unsol_verbs},
9142                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9143                 .dac_nids = alc883_dac_nids,
9144                 .num_adc_nids = ARRAY_SIZE(alc889_adc_nids),
9145                 .adc_nids = alc889_adc_nids,
9146                 .dig_out_nid = ALC883_DIGOUT_NID,
9147                 .dig_in_nid = ALC883_DIGIN_NID,
9148                 .slave_dig_outs = alc883_slave_dig_outs,
9149                 .num_channel_mode = ARRAY_SIZE(alc889_8ch_intel_modes),
9150                 .channel_mode = alc889_8ch_intel_modes,
9151                 .capsrc_nids = alc889_capsrc_nids,
9152                 .input_mux = &alc889_capture_source,
9153                 .setup = alc889_automute_setup,
9154                 .init_hook = alc889_intel_init_hook,
9155                 .unsol_event = alc_automute_amp_unsol_event,
9156                 .need_dac_fix = 1,
9157         },
9158         [ALC883_6ST_DIG] = {
9159                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
9160                 .init_verbs = { alc883_init_verbs },
9161                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9162                 .dac_nids = alc883_dac_nids,
9163                 .dig_out_nid = ALC883_DIGOUT_NID,
9164                 .dig_in_nid = ALC883_DIGIN_NID,
9165                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9166                 .channel_mode = alc883_sixstack_modes,
9167                 .input_mux = &alc883_capture_source,
9168         },
9169         [ALC883_TARGA_DIG] = {
9170                 .mixers = { alc883_targa_mixer, alc883_chmode_mixer },
9171                 .init_verbs = { alc883_init_verbs, alc880_gpio3_init_verbs,
9172                                 alc883_targa_verbs},
9173                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9174                 .dac_nids = alc883_dac_nids,
9175                 .dig_out_nid = ALC883_DIGOUT_NID,
9176                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9177                 .channel_mode = alc883_3ST_6ch_modes,
9178                 .need_dac_fix = 1,
9179                 .input_mux = &alc883_capture_source,
9180                 .unsol_event = alc883_targa_unsol_event,
9181                 .setup = alc882_targa_setup,
9182                 .init_hook = alc882_targa_automute,
9183         },
9184         [ALC883_TARGA_2ch_DIG] = {
9185                 .mixers = { alc883_targa_2ch_mixer},
9186                 .init_verbs = { alc883_init_verbs, alc880_gpio3_init_verbs,
9187                                 alc883_targa_verbs},
9188                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9189                 .dac_nids = alc883_dac_nids,
9190                 .adc_nids = alc883_adc_nids_alt,
9191                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
9192                 .dig_out_nid = ALC883_DIGOUT_NID,
9193                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9194                 .channel_mode = alc883_3ST_2ch_modes,
9195                 .input_mux = &alc883_capture_source,
9196                 .unsol_event = alc883_targa_unsol_event,
9197                 .setup = alc882_targa_setup,
9198                 .init_hook = alc882_targa_automute,
9199         },
9200         [ALC883_TARGA_8ch_DIG] = {
9201                 .mixers = { alc883_targa_mixer, alc883_targa_8ch_mixer,
9202                             alc883_chmode_mixer },
9203                 .init_verbs = { alc883_init_verbs, alc880_gpio3_init_verbs,
9204                                 alc883_targa_verbs },
9205                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9206                 .dac_nids = alc883_dac_nids,
9207                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
9208                 .adc_nids = alc883_adc_nids_rev,
9209                 .capsrc_nids = alc883_capsrc_nids_rev,
9210                 .dig_out_nid = ALC883_DIGOUT_NID,
9211                 .dig_in_nid = ALC883_DIGIN_NID,
9212                 .num_channel_mode = ARRAY_SIZE(alc883_4ST_8ch_modes),
9213                 .channel_mode = alc883_4ST_8ch_modes,
9214                 .need_dac_fix = 1,
9215                 .input_mux = &alc883_capture_source,
9216                 .unsol_event = alc883_targa_unsol_event,
9217                 .setup = alc882_targa_setup,
9218                 .init_hook = alc882_targa_automute,
9219         },
9220         [ALC883_ACER] = {
9221                 .mixers = { alc883_base_mixer },
9222                 /* On TravelMate laptops, GPIO 0 enables the internal speaker
9223                  * and the headphone jack.  Turn this on and rely on the
9224                  * standard mute methods whenever the user wants to turn
9225                  * these outputs off.
9226                  */
9227                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
9228                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9229                 .dac_nids = alc883_dac_nids,
9230                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9231                 .channel_mode = alc883_3ST_2ch_modes,
9232                 .input_mux = &alc883_capture_source,
9233         },
9234         [ALC883_ACER_ASPIRE] = {
9235                 .mixers = { alc883_acer_aspire_mixer },
9236                 .init_verbs = { alc883_init_verbs, alc883_acer_eapd_verbs },
9237                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9238                 .dac_nids = alc883_dac_nids,
9239                 .dig_out_nid = ALC883_DIGOUT_NID,
9240                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9241                 .channel_mode = alc883_3ST_2ch_modes,
9242                 .input_mux = &alc883_capture_source,
9243                 .unsol_event = alc_automute_amp_unsol_event,
9244                 .setup = alc883_acer_aspire_setup,
9245                 .init_hook = alc_automute_amp,
9246         },
9247         [ALC888_ACER_ASPIRE_4930G] = {
9248                 .mixers = { alc888_base_mixer,
9249                                 alc883_chmode_mixer },
9250                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
9251                                 alc888_acer_aspire_4930g_verbs },
9252                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9253                 .dac_nids = alc883_dac_nids,
9254                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
9255                 .adc_nids = alc883_adc_nids_rev,
9256                 .capsrc_nids = alc883_capsrc_nids_rev,
9257                 .dig_out_nid = ALC883_DIGOUT_NID,
9258                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9259                 .channel_mode = alc883_3ST_6ch_modes,
9260                 .need_dac_fix = 1,
9261                 .num_mux_defs =
9262                         ARRAY_SIZE(alc888_2_capture_sources),
9263                 .input_mux = alc888_2_capture_sources,
9264                 .unsol_event = alc_automute_amp_unsol_event,
9265                 .setup = alc888_acer_aspire_4930g_setup,
9266                 .init_hook = alc_automute_amp,
9267         },
9268         [ALC888_ACER_ASPIRE_6530G] = {
9269                 .mixers = { alc888_acer_aspire_6530_mixer },
9270                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
9271                                 alc888_acer_aspire_6530g_verbs },
9272                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9273                 .dac_nids = alc883_dac_nids,
9274                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
9275                 .adc_nids = alc883_adc_nids_rev,
9276                 .capsrc_nids = alc883_capsrc_nids_rev,
9277                 .dig_out_nid = ALC883_DIGOUT_NID,
9278                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9279                 .channel_mode = alc883_3ST_2ch_modes,
9280                 .num_mux_defs =
9281                         ARRAY_SIZE(alc888_2_capture_sources),
9282                 .input_mux = alc888_acer_aspire_6530_sources,
9283                 .unsol_event = alc_automute_amp_unsol_event,
9284                 .setup = alc888_acer_aspire_6530g_setup,
9285                 .init_hook = alc_automute_amp,
9286         },
9287         [ALC888_ACER_ASPIRE_8930G] = {
9288                 .mixers = { alc888_base_mixer,
9289                                 alc883_chmode_mixer },
9290                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
9291                                 alc889_acer_aspire_8930g_verbs },
9292                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9293                 .dac_nids = alc883_dac_nids,
9294                 .num_adc_nids = ARRAY_SIZE(alc889_adc_nids),
9295                 .adc_nids = alc889_adc_nids,
9296                 .capsrc_nids = alc889_capsrc_nids,
9297                 .dig_out_nid = ALC883_DIGOUT_NID,
9298                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9299                 .channel_mode = alc883_3ST_6ch_modes,
9300                 .need_dac_fix = 1,
9301                 .const_channel_count = 6,
9302                 .num_mux_defs =
9303                         ARRAY_SIZE(alc889_capture_sources),
9304                 .input_mux = alc889_capture_sources,
9305                 .unsol_event = alc_automute_amp_unsol_event,
9306                 .setup = alc889_acer_aspire_8930g_setup,
9307                 .init_hook = alc_automute_amp,
9308         },
9309         [ALC888_ACER_ASPIRE_7730G] = {
9310                 .mixers = { alc883_3ST_6ch_mixer,
9311                                 alc883_chmode_mixer },
9312                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
9313                                 alc888_acer_aspire_7730G_verbs },
9314                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9315                 .dac_nids = alc883_dac_nids,
9316                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
9317                 .adc_nids = alc883_adc_nids_rev,
9318                 .capsrc_nids = alc883_capsrc_nids_rev,
9319                 .dig_out_nid = ALC883_DIGOUT_NID,
9320                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9321                 .channel_mode = alc883_3ST_6ch_modes,
9322                 .need_dac_fix = 1,
9323                 .const_channel_count = 6,
9324                 .input_mux = &alc883_capture_source,
9325                 .unsol_event = alc_automute_amp_unsol_event,
9326                 .setup = alc888_acer_aspire_6530g_setup,
9327                 .init_hook = alc_automute_amp,
9328         },
9329         [ALC883_MEDION] = {
9330                 .mixers = { alc883_fivestack_mixer,
9331                             alc883_chmode_mixer },
9332                 .init_verbs = { alc883_init_verbs,
9333                                 alc883_medion_eapd_verbs },
9334                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9335                 .dac_nids = alc883_dac_nids,
9336                 .adc_nids = alc883_adc_nids_alt,
9337                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
9338                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9339                 .channel_mode = alc883_sixstack_modes,
9340                 .input_mux = &alc883_capture_source,
9341         },
9342         [ALC883_MEDION_MD2] = {
9343                 .mixers = { alc883_medion_md2_mixer},
9344                 .init_verbs = { alc883_init_verbs, alc883_medion_md2_verbs},
9345                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9346                 .dac_nids = alc883_dac_nids,
9347                 .dig_out_nid = ALC883_DIGOUT_NID,
9348                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9349                 .channel_mode = alc883_3ST_2ch_modes,
9350                 .input_mux = &alc883_capture_source,
9351                 .unsol_event = alc_automute_amp_unsol_event,
9352                 .setup = alc883_medion_md2_setup,
9353                 .init_hook = alc_automute_amp,
9354         },
9355         [ALC883_LAPTOP_EAPD] = {
9356                 .mixers = { alc883_base_mixer },
9357                 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
9358                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9359                 .dac_nids = alc883_dac_nids,
9360                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9361                 .channel_mode = alc883_3ST_2ch_modes,
9362                 .input_mux = &alc883_capture_source,
9363         },
9364         [ALC883_CLEVO_M540R] = {
9365                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9366                 .init_verbs = { alc883_init_verbs, alc883_clevo_m540r_verbs },
9367                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9368                 .dac_nids = alc883_dac_nids,
9369                 .dig_out_nid = ALC883_DIGOUT_NID,
9370                 .dig_in_nid = ALC883_DIGIN_NID,
9371                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_clevo_modes),
9372                 .channel_mode = alc883_3ST_6ch_clevo_modes,
9373                 .need_dac_fix = 1,
9374                 .input_mux = &alc883_capture_source,
9375                 /* This machine has the hardware HP auto-muting, thus
9376                  * we need no software mute via unsol event
9377                  */
9378         },
9379         [ALC883_CLEVO_M720] = {
9380                 .mixers = { alc883_clevo_m720_mixer },
9381                 .init_verbs = { alc883_init_verbs, alc883_clevo_m720_verbs },
9382                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9383                 .dac_nids = alc883_dac_nids,
9384                 .dig_out_nid = ALC883_DIGOUT_NID,
9385                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9386                 .channel_mode = alc883_3ST_2ch_modes,
9387                 .input_mux = &alc883_capture_source,
9388                 .unsol_event = alc883_clevo_m720_unsol_event,
9389                 .setup = alc883_clevo_m720_setup,
9390                 .init_hook = alc883_clevo_m720_init_hook,
9391         },
9392         [ALC883_LENOVO_101E_2ch] = {
9393                 .mixers = { alc883_lenovo_101e_2ch_mixer},
9394                 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
9395                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9396                 .dac_nids = alc883_dac_nids,
9397                 .adc_nids = alc883_adc_nids_alt,
9398                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
9399                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9400                 .channel_mode = alc883_3ST_2ch_modes,
9401                 .input_mux = &alc883_lenovo_101e_capture_source,
9402                 .unsol_event = alc883_lenovo_101e_unsol_event,
9403                 .init_hook = alc883_lenovo_101e_all_automute,
9404         },
9405         [ALC883_LENOVO_NB0763] = {
9406                 .mixers = { alc883_lenovo_nb0763_mixer },
9407                 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs},
9408                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9409                 .dac_nids = alc883_dac_nids,
9410                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9411                 .channel_mode = alc883_3ST_2ch_modes,
9412                 .need_dac_fix = 1,
9413                 .input_mux = &alc883_lenovo_nb0763_capture_source,
9414                 .unsol_event = alc_automute_amp_unsol_event,
9415                 .setup = alc883_medion_md2_setup,
9416                 .init_hook = alc_automute_amp,
9417         },
9418         [ALC888_LENOVO_MS7195_DIG] = {
9419                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9420                 .init_verbs = { alc883_init_verbs, alc888_lenovo_ms7195_verbs},
9421                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9422                 .dac_nids = alc883_dac_nids,
9423                 .dig_out_nid = ALC883_DIGOUT_NID,
9424                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9425                 .channel_mode = alc883_3ST_6ch_modes,
9426                 .need_dac_fix = 1,
9427                 .input_mux = &alc883_capture_source,
9428                 .unsol_event = alc883_lenovo_ms7195_unsol_event,
9429                 .init_hook = alc888_lenovo_ms7195_front_automute,
9430         },
9431         [ALC883_HAIER_W66] = {
9432                 .mixers = { alc883_targa_2ch_mixer},
9433                 .init_verbs = { alc883_init_verbs, alc883_haier_w66_verbs},
9434                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9435                 .dac_nids = alc883_dac_nids,
9436                 .dig_out_nid = ALC883_DIGOUT_NID,
9437                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9438                 .channel_mode = alc883_3ST_2ch_modes,
9439                 .input_mux = &alc883_capture_source,
9440                 .unsol_event = alc_automute_amp_unsol_event,
9441                 .setup = alc883_haier_w66_setup,
9442                 .init_hook = alc_automute_amp,
9443         },
9444         [ALC888_3ST_HP] = {
9445                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9446                 .init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs },
9447                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9448                 .dac_nids = alc883_dac_nids,
9449                 .num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes),
9450                 .channel_mode = alc888_3st_hp_modes,
9451                 .need_dac_fix = 1,
9452                 .input_mux = &alc883_capture_source,
9453                 .unsol_event = alc_automute_amp_unsol_event,
9454                 .setup = alc888_3st_hp_setup,
9455                 .init_hook = alc_automute_amp,
9456         },
9457         [ALC888_6ST_DELL] = {
9458                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
9459                 .init_verbs = { alc883_init_verbs, alc888_6st_dell_verbs },
9460                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9461                 .dac_nids = alc883_dac_nids,
9462                 .dig_out_nid = ALC883_DIGOUT_NID,
9463                 .dig_in_nid = ALC883_DIGIN_NID,
9464                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9465                 .channel_mode = alc883_sixstack_modes,
9466                 .input_mux = &alc883_capture_source,
9467                 .unsol_event = alc_automute_amp_unsol_event,
9468                 .setup = alc888_6st_dell_setup,
9469                 .init_hook = alc_automute_amp,
9470         },
9471         [ALC883_MITAC] = {
9472                 .mixers = { alc883_mitac_mixer },
9473                 .init_verbs = { alc883_init_verbs, alc883_mitac_verbs },
9474                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9475                 .dac_nids = alc883_dac_nids,
9476                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9477                 .channel_mode = alc883_3ST_2ch_modes,
9478                 .input_mux = &alc883_capture_source,
9479                 .unsol_event = alc_automute_amp_unsol_event,
9480                 .setup = alc883_mitac_setup,
9481                 .init_hook = alc_automute_amp,
9482         },
9483         [ALC883_FUJITSU_PI2515] = {
9484                 .mixers = { alc883_2ch_fujitsu_pi2515_mixer },
9485                 .init_verbs = { alc883_init_verbs,
9486                                 alc883_2ch_fujitsu_pi2515_verbs},
9487                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9488                 .dac_nids = alc883_dac_nids,
9489                 .dig_out_nid = ALC883_DIGOUT_NID,
9490                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9491                 .channel_mode = alc883_3ST_2ch_modes,
9492                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
9493                 .unsol_event = alc_automute_amp_unsol_event,
9494                 .setup = alc883_2ch_fujitsu_pi2515_setup,
9495                 .init_hook = alc_automute_amp,
9496         },
9497         [ALC888_FUJITSU_XA3530] = {
9498                 .mixers = { alc888_base_mixer, alc883_chmode_mixer },
9499                 .init_verbs = { alc883_init_verbs,
9500                         alc888_fujitsu_xa3530_verbs },
9501                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9502                 .dac_nids = alc883_dac_nids,
9503                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
9504                 .adc_nids = alc883_adc_nids_rev,
9505                 .capsrc_nids = alc883_capsrc_nids_rev,
9506                 .dig_out_nid = ALC883_DIGOUT_NID,
9507                 .num_channel_mode = ARRAY_SIZE(alc888_4ST_8ch_intel_modes),
9508                 .channel_mode = alc888_4ST_8ch_intel_modes,
9509                 .num_mux_defs =
9510                         ARRAY_SIZE(alc888_2_capture_sources),
9511                 .input_mux = alc888_2_capture_sources,
9512                 .unsol_event = alc_automute_amp_unsol_event,
9513                 .setup = alc888_fujitsu_xa3530_setup,
9514                 .init_hook = alc_automute_amp,
9515         },
9516         [ALC888_LENOVO_SKY] = {
9517                 .mixers = { alc888_lenovo_sky_mixer, alc883_chmode_mixer },
9518                 .init_verbs = { alc883_init_verbs, alc888_lenovo_sky_verbs},
9519                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9520                 .dac_nids = alc883_dac_nids,
9521                 .dig_out_nid = ALC883_DIGOUT_NID,
9522                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9523                 .channel_mode = alc883_sixstack_modes,
9524                 .need_dac_fix = 1,
9525                 .input_mux = &alc883_lenovo_sky_capture_source,
9526                 .unsol_event = alc_automute_amp_unsol_event,
9527                 .setup = alc888_lenovo_sky_setup,
9528                 .init_hook = alc_automute_amp,
9529         },
9530         [ALC888_ASUS_M90V] = {
9531                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9532                 .init_verbs = { alc883_init_verbs, alc888_asus_m90v_verbs },
9533                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9534                 .dac_nids = alc883_dac_nids,
9535                 .dig_out_nid = ALC883_DIGOUT_NID,
9536                 .dig_in_nid = ALC883_DIGIN_NID,
9537                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9538                 .channel_mode = alc883_3ST_6ch_modes,
9539                 .need_dac_fix = 1,
9540                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
9541                 .unsol_event = alc_sku_unsol_event,
9542                 .setup = alc883_mode2_setup,
9543                 .init_hook = alc_inithook,
9544         },
9545         [ALC888_ASUS_EEE1601] = {
9546                 .mixers = { alc883_asus_eee1601_mixer },
9547                 .cap_mixer = alc883_asus_eee1601_cap_mixer,
9548                 .init_verbs = { alc883_init_verbs, alc888_asus_eee1601_verbs },
9549                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9550                 .dac_nids = alc883_dac_nids,
9551                 .dig_out_nid = ALC883_DIGOUT_NID,
9552                 .dig_in_nid = ALC883_DIGIN_NID,
9553                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9554                 .channel_mode = alc883_3ST_2ch_modes,
9555                 .need_dac_fix = 1,
9556                 .input_mux = &alc883_asus_eee1601_capture_source,
9557                 .unsol_event = alc_sku_unsol_event,
9558                 .init_hook = alc883_eee1601_inithook,
9559         },
9560         [ALC1200_ASUS_P5Q] = {
9561                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
9562                 .init_verbs = { alc883_init_verbs },
9563                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9564                 .dac_nids = alc883_dac_nids,
9565                 .dig_out_nid = ALC1200_DIGOUT_NID,
9566                 .dig_in_nid = ALC883_DIGIN_NID,
9567                 .slave_dig_outs = alc1200_slave_dig_outs,
9568                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9569                 .channel_mode = alc883_sixstack_modes,
9570                 .input_mux = &alc883_capture_source,
9571         },
9572         [ALC889A_MB31] = {
9573                 .mixers = { alc889A_mb31_mixer, alc883_chmode_mixer},
9574                 .init_verbs = { alc883_init_verbs, alc889A_mb31_verbs,
9575                         alc880_gpio1_init_verbs },
9576                 .adc_nids = alc883_adc_nids,
9577                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
9578                 .dac_nids = alc883_dac_nids,
9579                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9580                 .channel_mode = alc889A_mb31_6ch_modes,
9581                 .num_channel_mode = ARRAY_SIZE(alc889A_mb31_6ch_modes),
9582                 .input_mux = &alc889A_mb31_capture_source,
9583                 .dig_out_nid = ALC883_DIGOUT_NID,
9584                 .unsol_event = alc889A_mb31_unsol_event,
9585                 .init_hook = alc889A_mb31_automute,
9586         },
9587         [ALC883_SONY_VAIO_TT] = {
9588                 .mixers = { alc883_vaiott_mixer },
9589                 .init_verbs = { alc883_init_verbs, alc883_vaiott_verbs },
9590                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9591                 .dac_nids = alc883_dac_nids,
9592                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9593                 .channel_mode = alc883_3ST_2ch_modes,
9594                 .input_mux = &alc883_capture_source,
9595                 .unsol_event = alc_automute_amp_unsol_event,
9596                 .setup = alc883_vaiott_setup,
9597                 .init_hook = alc_automute_amp,
9598         },
9599 };
9600
9601
9602 /*
9603  * Pin config fixes
9604  */
9605 enum {
9606         PINFIX_ABIT_AW9D_MAX
9607 };
9608
9609 static struct alc_pincfg alc882_abit_aw9d_pinfix[] = {
9610         { 0x15, 0x01080104 }, /* side */
9611         { 0x16, 0x01011012 }, /* rear */
9612         { 0x17, 0x01016011 }, /* clfe */
9613         { }
9614 };
9615
9616 static const struct alc_fixup alc882_fixups[] = {
9617         [PINFIX_ABIT_AW9D_MAX] = {
9618                 .pins = alc882_abit_aw9d_pinfix
9619         },
9620 };
9621
9622 static struct snd_pci_quirk alc882_fixup_tbl[] = {
9623         SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
9624         {}
9625 };
9626
9627 /*
9628  * BIOS auto configuration
9629  */
9630 static int alc882_auto_create_input_ctls(struct hda_codec *codec,
9631                                                 const struct auto_pin_cfg *cfg)
9632 {
9633         return alc_auto_create_input_ctls(codec, cfg, 0x0b, 0x23, 0x22);
9634 }
9635
9636 static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
9637                                               hda_nid_t nid, int pin_type,
9638                                               int dac_idx)
9639 {
9640         /* set as output */
9641         struct alc_spec *spec = codec->spec;
9642         int idx;
9643
9644         alc_set_pin_output(codec, nid, pin_type);
9645         if (spec->multiout.dac_nids[dac_idx] == 0x25)
9646                 idx = 4;
9647         else
9648                 idx = spec->multiout.dac_nids[dac_idx] - 2;
9649         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
9650
9651 }
9652
9653 static void alc882_auto_init_multi_out(struct hda_codec *codec)
9654 {
9655         struct alc_spec *spec = codec->spec;
9656         int i;
9657
9658         for (i = 0; i <= HDA_SIDE; i++) {
9659                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
9660                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
9661                 if (nid)
9662                         alc882_auto_set_output_and_unmute(codec, nid, pin_type,
9663                                                           i);
9664         }
9665 }
9666
9667 static void alc882_auto_init_hp_out(struct hda_codec *codec)
9668 {
9669         struct alc_spec *spec = codec->spec;
9670         hda_nid_t pin;
9671
9672         pin = spec->autocfg.hp_pins[0];
9673         if (pin) /* connect to front */
9674                 /* use dac 0 */
9675                 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
9676         pin = spec->autocfg.speaker_pins[0];
9677         if (pin)
9678                 alc882_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
9679 }
9680
9681 static void alc882_auto_init_analog_input(struct hda_codec *codec)
9682 {
9683         struct alc_spec *spec = codec->spec;
9684         int i;
9685
9686         for (i = 0; i < AUTO_PIN_LAST; i++) {
9687                 hda_nid_t nid = spec->autocfg.input_pins[i];
9688                 if (!nid)
9689                         continue;
9690                 alc_set_input_pin(codec, nid, i);
9691                 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
9692                         snd_hda_codec_write(codec, nid, 0,
9693                                             AC_VERB_SET_AMP_GAIN_MUTE,
9694                                             AMP_OUT_MUTE);
9695         }
9696 }
9697
9698 static void alc882_auto_init_input_src(struct hda_codec *codec)
9699 {
9700         struct alc_spec *spec = codec->spec;
9701         int c;
9702
9703         for (c = 0; c < spec->num_adc_nids; c++) {
9704                 hda_nid_t conn_list[HDA_MAX_NUM_INPUTS];
9705                 hda_nid_t nid = spec->capsrc_nids[c];
9706                 unsigned int mux_idx;
9707                 const struct hda_input_mux *imux;
9708                 int conns, mute, idx, item;
9709
9710                 conns = snd_hda_get_connections(codec, nid, conn_list,
9711                                                 ARRAY_SIZE(conn_list));
9712                 if (conns < 0)
9713                         continue;
9714                 mux_idx = c >= spec->num_mux_defs ? 0 : c;
9715                 imux = &spec->input_mux[mux_idx];
9716                 for (idx = 0; idx < conns; idx++) {
9717                         /* if the current connection is the selected one,
9718                          * unmute it as default - otherwise mute it
9719                          */
9720                         mute = AMP_IN_MUTE(idx);
9721                         for (item = 0; item < imux->num_items; item++) {
9722                                 if (imux->items[item].index == idx) {
9723                                         if (spec->cur_mux[c] == item)
9724                                                 mute = AMP_IN_UNMUTE(idx);
9725                                         break;
9726                                 }
9727                         }
9728                         /* check if we have a selector or mixer
9729                          * we could check for the widget type instead, but
9730                          * just check for Amp-In presence (in case of mixer
9731                          * without amp-in there is something wrong, this
9732                          * function shouldn't be used or capsrc nid is wrong)
9733                          */
9734                         if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)
9735                                 snd_hda_codec_write(codec, nid, 0,
9736                                                     AC_VERB_SET_AMP_GAIN_MUTE,
9737                                                     mute);
9738                         else if (mute != AMP_IN_MUTE(idx))
9739                                 snd_hda_codec_write(codec, nid, 0,
9740                                                     AC_VERB_SET_CONNECT_SEL,
9741                                                     idx);
9742                 }
9743         }
9744 }
9745
9746 /* add mic boosts if needed */
9747 static int alc_auto_add_mic_boost(struct hda_codec *codec)
9748 {
9749         struct alc_spec *spec = codec->spec;
9750         int err;
9751         hda_nid_t nid;
9752
9753         nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
9754         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
9755                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
9756                                   "Mic Boost",
9757                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
9758                 if (err < 0)
9759                         return err;
9760         }
9761         nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
9762         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
9763                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
9764                                   "Front Mic Boost",
9765                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
9766                 if (err < 0)
9767                         return err;
9768         }
9769         return 0;
9770 }
9771
9772 /* almost identical with ALC880 parser... */
9773 static int alc882_parse_auto_config(struct hda_codec *codec)
9774 {
9775         struct alc_spec *spec = codec->spec;
9776         static hda_nid_t alc882_ignore[] = { 0x1d, 0 };
9777         int i, err;
9778
9779         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
9780                                            alc882_ignore);
9781         if (err < 0)
9782                 return err;
9783         if (!spec->autocfg.line_outs)
9784                 return 0; /* can't find valid BIOS pin config */
9785
9786         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
9787         if (err < 0)
9788                 return err;
9789         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
9790         if (err < 0)
9791                 return err;
9792         err = alc880_auto_create_extra_out(spec,
9793                                            spec->autocfg.speaker_pins[0],
9794                                            "Speaker");
9795         if (err < 0)
9796                 return err;
9797         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
9798                                            "Headphone");
9799         if (err < 0)
9800                 return err;
9801         err = alc882_auto_create_input_ctls(codec, &spec->autocfg);
9802         if (err < 0)
9803                 return err;
9804
9805         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
9806
9807         /* check multiple SPDIF-out (for recent codecs) */
9808         for (i = 0; i < spec->autocfg.dig_outs; i++) {
9809                 hda_nid_t dig_nid;
9810                 err = snd_hda_get_connections(codec,
9811                                               spec->autocfg.dig_out_pins[i],
9812                                               &dig_nid, 1);
9813                 if (err < 0)
9814                         continue;
9815                 if (!i)
9816                         spec->multiout.dig_out_nid = dig_nid;
9817                 else {
9818                         spec->multiout.slave_dig_outs = spec->slave_dig_outs;
9819                         if (i >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
9820                                 break;
9821                         spec->slave_dig_outs[i - 1] = dig_nid;
9822                 }
9823         }
9824         if (spec->autocfg.dig_in_pin)
9825                 spec->dig_in_nid = ALC880_DIGIN_NID;
9826
9827         if (spec->kctls.list)
9828                 add_mixer(spec, spec->kctls.list);
9829
9830         add_verb(spec, alc883_auto_init_verbs);
9831         /* if ADC 0x07 is available, initialize it, too */
9832         if (get_wcaps_type(get_wcaps(codec, 0x07)) == AC_WID_AUD_IN)
9833                 add_verb(spec, alc882_adc1_init_verbs);
9834
9835         spec->num_mux_defs = 1;
9836         spec->input_mux = &spec->private_imux[0];
9837
9838         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
9839
9840         err = alc_auto_add_mic_boost(codec);
9841         if (err < 0)
9842                 return err;
9843
9844         return 1; /* config found */
9845 }
9846
9847 /* additional initialization for auto-configuration model */
9848 static void alc882_auto_init(struct hda_codec *codec)
9849 {
9850         struct alc_spec *spec = codec->spec;
9851         alc882_auto_init_multi_out(codec);
9852         alc882_auto_init_hp_out(codec);
9853         alc882_auto_init_analog_input(codec);
9854         alc882_auto_init_input_src(codec);
9855         if (spec->unsol_event)
9856                 alc_inithook(codec);
9857 }
9858
9859 static int patch_alc882(struct hda_codec *codec)
9860 {
9861         struct alc_spec *spec;
9862         int err, board_config;
9863
9864         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
9865         if (spec == NULL)
9866                 return -ENOMEM;
9867
9868         codec->spec = spec;
9869
9870         switch (codec->vendor_id) {
9871         case 0x10ec0882:
9872         case 0x10ec0885:
9873                 break;
9874         default:
9875                 /* ALC883 and variants */
9876                 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
9877                 break;
9878         }
9879
9880         board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
9881                                                   alc882_models,
9882                                                   alc882_cfg_tbl);
9883
9884         if (board_config < 0 || board_config >= ALC882_MODEL_LAST)
9885                 board_config = snd_hda_check_board_codec_sid_config(codec,
9886                         ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl);
9887
9888         if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
9889                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
9890                        codec->chip_name);
9891                 board_config = ALC882_AUTO;
9892         }
9893
9894         alc_pick_fixup(codec, alc882_fixup_tbl, alc882_fixups);
9895
9896         if (board_config == ALC882_AUTO) {
9897                 /* automatic parse from the BIOS config */
9898                 err = alc882_parse_auto_config(codec);
9899                 if (err < 0) {
9900                         alc_free(codec);
9901                         return err;
9902                 } else if (!err) {
9903                         printk(KERN_INFO
9904                                "hda_codec: Cannot set up configuration "
9905                                "from BIOS.  Using base mode...\n");
9906                         board_config = ALC882_3ST_DIG;
9907                 }
9908         }
9909
9910         err = snd_hda_attach_beep_device(codec, 0x1);
9911         if (err < 0) {
9912                 alc_free(codec);
9913                 return err;
9914         }
9915
9916         if (board_config != ALC882_AUTO)
9917                 setup_preset(codec, &alc882_presets[board_config]);
9918
9919         spec->stream_analog_playback = &alc882_pcm_analog_playback;
9920         spec->stream_analog_capture = &alc882_pcm_analog_capture;
9921         /* FIXME: setup DAC5 */
9922         /*spec->stream_analog_alt_playback = &alc880_pcm_analog_alt_playback;*/
9923         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
9924
9925         spec->stream_digital_playback = &alc882_pcm_digital_playback;
9926         spec->stream_digital_capture = &alc882_pcm_digital_capture;
9927
9928         if (codec->vendor_id == 0x10ec0888)
9929                 spec->init_amp = ALC_INIT_DEFAULT; /* always initialize */
9930
9931         if (!spec->adc_nids && spec->input_mux) {
9932                 int i;
9933                 spec->num_adc_nids = 0;
9934                 for (i = 0; i < ARRAY_SIZE(alc882_adc_nids); i++) {
9935                         hda_nid_t cap;
9936                         hda_nid_t nid = alc882_adc_nids[i];
9937                         unsigned int wcap = get_wcaps(codec, nid);
9938                         /* get type */
9939                         wcap = get_wcaps_type(wcap);
9940                         if (wcap != AC_WID_AUD_IN)
9941                                 continue;
9942                         spec->private_adc_nids[spec->num_adc_nids] = nid;
9943                         err = snd_hda_get_connections(codec, nid, &cap, 1);
9944                         if (err < 0)
9945                                 continue;
9946                         spec->private_capsrc_nids[spec->num_adc_nids] = cap;
9947                         spec->num_adc_nids++;
9948                 }
9949                 spec->adc_nids = spec->private_adc_nids;
9950                 spec->capsrc_nids = spec->private_capsrc_nids;
9951         }
9952
9953         set_capture_mixer(codec);
9954         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
9955
9956         spec->vmaster_nid = 0x0c;
9957
9958         codec->patch_ops = alc_patch_ops;
9959         if (board_config == ALC882_AUTO)
9960                 spec->init_hook = alc882_auto_init;
9961 #ifdef CONFIG_SND_HDA_POWER_SAVE
9962         if (!spec->loopback.amplist)
9963                 spec->loopback.amplist = alc882_loopbacks;
9964 #endif
9965         codec->proc_widget_hook = print_realtek_coef;
9966
9967         return 0;
9968 }
9969
9970
9971 /*
9972  * ALC262 support
9973  */
9974
9975 #define ALC262_DIGOUT_NID       ALC880_DIGOUT_NID
9976 #define ALC262_DIGIN_NID        ALC880_DIGIN_NID
9977
9978 #define alc262_dac_nids         alc260_dac_nids
9979 #define alc262_adc_nids         alc882_adc_nids
9980 #define alc262_adc_nids_alt     alc882_adc_nids_alt
9981 #define alc262_capsrc_nids      alc882_capsrc_nids
9982 #define alc262_capsrc_nids_alt  alc882_capsrc_nids_alt
9983
9984 #define alc262_modes            alc260_modes
9985 #define alc262_capture_source   alc882_capture_source
9986
9987 static hda_nid_t alc262_dmic_adc_nids[1] = {
9988         /* ADC0 */
9989         0x09
9990 };
9991
9992 static hda_nid_t alc262_dmic_capsrc_nids[1] = { 0x22 };
9993
9994 static struct snd_kcontrol_new alc262_base_mixer[] = {
9995         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9996         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9997         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9998         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9999         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10000         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10001         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10002         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10003         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10004         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10005         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10006         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10007         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
10008         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10009         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
10010         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
10011         { } /* end */
10012 };
10013
10014 /* update HP, line and mono-out pins according to the master switch */
10015 static void alc262_hp_master_update(struct hda_codec *codec)
10016 {
10017         struct alc_spec *spec = codec->spec;
10018         int val = spec->master_sw;
10019
10020         /* HP & line-out */
10021         snd_hda_codec_write_cache(codec, 0x1b, 0,
10022                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
10023                                   val ? PIN_HP : 0);
10024         snd_hda_codec_write_cache(codec, 0x15, 0,
10025                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
10026                                   val ? PIN_HP : 0);
10027         /* mono (speaker) depending on the HP jack sense */
10028         val = val && !spec->jack_present;
10029         snd_hda_codec_write_cache(codec, 0x16, 0,
10030                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
10031                                   val ? PIN_OUT : 0);
10032 }
10033
10034 static void alc262_hp_bpc_automute(struct hda_codec *codec)
10035 {
10036         struct alc_spec *spec = codec->spec;
10037         unsigned int presence;
10038         presence = snd_hda_codec_read(codec, 0x1b, 0,
10039                                       AC_VERB_GET_PIN_SENSE, 0);
10040         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
10041         alc262_hp_master_update(codec);
10042 }
10043
10044 static void alc262_hp_bpc_unsol_event(struct hda_codec *codec, unsigned int res)
10045 {
10046         if ((res >> 26) != ALC880_HP_EVENT)
10047                 return;
10048         alc262_hp_bpc_automute(codec);
10049 }
10050
10051 static void alc262_hp_wildwest_automute(struct hda_codec *codec)
10052 {
10053         struct alc_spec *spec = codec->spec;
10054         unsigned int presence;
10055         presence = snd_hda_codec_read(codec, 0x15, 0,
10056                                       AC_VERB_GET_PIN_SENSE, 0);
10057         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
10058         alc262_hp_master_update(codec);
10059 }
10060
10061 static void alc262_hp_wildwest_unsol_event(struct hda_codec *codec,
10062                                            unsigned int res)
10063 {
10064         if ((res >> 26) != ALC880_HP_EVENT)
10065                 return;
10066         alc262_hp_wildwest_automute(codec);
10067 }
10068
10069 #define alc262_hp_master_sw_get         alc260_hp_master_sw_get
10070
10071 static int alc262_hp_master_sw_put(struct snd_kcontrol *kcontrol,
10072                                    struct snd_ctl_elem_value *ucontrol)
10073 {
10074         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10075         struct alc_spec *spec = codec->spec;
10076         int val = !!*ucontrol->value.integer.value;
10077
10078         if (val == spec->master_sw)
10079                 return 0;
10080         spec->master_sw = val;
10081         alc262_hp_master_update(codec);
10082         return 1;
10083 }
10084
10085 #define ALC262_HP_MASTER_SWITCH                                 \
10086         {                                                       \
10087                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,            \
10088                 .name = "Master Playback Switch",               \
10089                 .info = snd_ctl_boolean_mono_info,              \
10090                 .get = alc262_hp_master_sw_get,                 \
10091                 .put = alc262_hp_master_sw_put,                 \
10092         }
10093
10094 static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
10095         ALC262_HP_MASTER_SWITCH,
10096         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10097         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10098         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
10099         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
10100                               HDA_OUTPUT),
10101         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
10102                             HDA_OUTPUT),
10103         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10104         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10105         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10106         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10107         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10108         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10109         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10110         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10111         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10112         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10113         HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
10114         HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
10115         { } /* end */
10116 };
10117
10118 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
10119         ALC262_HP_MASTER_SWITCH,
10120         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10121         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
10122         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
10123         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10124         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
10125                               HDA_OUTPUT),
10126         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
10127                             HDA_OUTPUT),
10128         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
10129         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
10130         HDA_CODEC_VOLUME("Front Mic Boost", 0x1a, 0, HDA_INPUT),
10131         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
10132         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
10133         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10134         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10135         { } /* end */
10136 };
10137
10138 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
10139         HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10140         HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10141         HDA_CODEC_VOLUME("Rear Mic Boost", 0x18, 0, HDA_INPUT),
10142         { } /* end */
10143 };
10144
10145 /* mute/unmute internal speaker according to the hp jack and mute state */
10146 static void alc262_hp_t5735_setup(struct hda_codec *codec)
10147 {
10148         struct alc_spec *spec = codec->spec;
10149
10150         spec->autocfg.hp_pins[0] = 0x15;
10151         spec->autocfg.speaker_pins[0] = 0x0c; /* HACK: not actually a pin */
10152 }
10153
10154 static struct snd_kcontrol_new alc262_hp_t5735_mixer[] = {
10155         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10156         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10157         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
10158         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10159         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10160         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10161         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10162         { } /* end */
10163 };
10164
10165 static struct hda_verb alc262_hp_t5735_verbs[] = {
10166         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10167         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10168
10169         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10170         { }
10171 };
10172
10173 static struct snd_kcontrol_new alc262_hp_rp5700_mixer[] = {
10174         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10175         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
10176         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
10177         HDA_CODEC_MUTE("Speaker Playback Switch", 0x16, 0x0, HDA_OUTPUT),
10178         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
10179         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
10180         { } /* end */
10181 };
10182
10183 static struct hda_verb alc262_hp_rp5700_verbs[] = {
10184         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10185         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10186         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10187         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10188         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10189         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10190         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10191         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10192         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
10193         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
10194         {}
10195 };
10196
10197 static struct hda_input_mux alc262_hp_rp5700_capture_source = {
10198         .num_items = 1,
10199         .items = {
10200                 { "Line", 0x1 },
10201         },
10202 };
10203
10204 /* bind hp and internal speaker mute (with plug check) as master switch */
10205 static void alc262_hippo_master_update(struct hda_codec *codec)
10206 {
10207         struct alc_spec *spec = codec->spec;
10208         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
10209         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
10210         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
10211         unsigned int mute;
10212
10213         /* HP */
10214         mute = spec->master_sw ? 0 : HDA_AMP_MUTE;
10215         snd_hda_codec_amp_stereo(codec, hp_nid, HDA_OUTPUT, 0,
10216                                  HDA_AMP_MUTE, mute);
10217         /* mute internal speaker per jack sense */
10218         if (spec->jack_present)
10219                 mute = HDA_AMP_MUTE;
10220         if (line_nid)
10221                 snd_hda_codec_amp_stereo(codec, line_nid, HDA_OUTPUT, 0,
10222                                          HDA_AMP_MUTE, mute);
10223         if (speaker_nid && speaker_nid != line_nid)
10224                 snd_hda_codec_amp_stereo(codec, speaker_nid, HDA_OUTPUT, 0,
10225                                          HDA_AMP_MUTE, mute);
10226 }
10227
10228 #define alc262_hippo_master_sw_get      alc262_hp_master_sw_get
10229
10230 static int alc262_hippo_master_sw_put(struct snd_kcontrol *kcontrol,
10231                                       struct snd_ctl_elem_value *ucontrol)
10232 {
10233         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10234         struct alc_spec *spec = codec->spec;
10235         int val = !!*ucontrol->value.integer.value;
10236
10237         if (val == spec->master_sw)
10238                 return 0;
10239         spec->master_sw = val;
10240         alc262_hippo_master_update(codec);
10241         return 1;
10242 }
10243
10244 #define ALC262_HIPPO_MASTER_SWITCH                              \
10245         {                                                       \
10246                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,            \
10247                 .name = "Master Playback Switch",               \
10248                 .info = snd_ctl_boolean_mono_info,              \
10249                 .get = alc262_hippo_master_sw_get,              \
10250                 .put = alc262_hippo_master_sw_put,              \
10251         }
10252
10253 static struct snd_kcontrol_new alc262_hippo_mixer[] = {
10254         ALC262_HIPPO_MASTER_SWITCH,
10255         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10256         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10257         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10258         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10259         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10260         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10261         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10262         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10263         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10264         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10265         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10266         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
10267         { } /* end */
10268 };
10269
10270 static struct snd_kcontrol_new alc262_hippo1_mixer[] = {
10271         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10272         ALC262_HIPPO_MASTER_SWITCH,
10273         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10274         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10275         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10276         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10277         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10278         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10279         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10280         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10281         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10282         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10283         { } /* end */
10284 };
10285
10286 /* mute/unmute internal speaker according to the hp jack and mute state */
10287 static void alc262_hippo_automute(struct hda_codec *codec)
10288 {
10289         struct alc_spec *spec = codec->spec;
10290         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
10291         unsigned int present;
10292
10293         /* need to execute and sync at first */
10294         snd_hda_codec_read(codec, hp_nid, 0, AC_VERB_SET_PIN_SENSE, 0);
10295         present = snd_hda_codec_read(codec, hp_nid, 0,
10296                                      AC_VERB_GET_PIN_SENSE, 0);
10297         spec->jack_present = (present & 0x80000000) != 0;
10298         alc262_hippo_master_update(codec);
10299 }
10300
10301 static void alc262_hippo_unsol_event(struct hda_codec *codec, unsigned int res)
10302 {
10303         if ((res >> 26) != ALC880_HP_EVENT)
10304                 return;
10305         alc262_hippo_automute(codec);
10306 }
10307
10308 static void alc262_hippo_setup(struct hda_codec *codec)
10309 {
10310         struct alc_spec *spec = codec->spec;
10311
10312         spec->autocfg.hp_pins[0] = 0x15;
10313         spec->autocfg.speaker_pins[0] = 0x14;
10314 }
10315
10316 static void alc262_hippo1_setup(struct hda_codec *codec)
10317 {
10318         struct alc_spec *spec = codec->spec;
10319
10320         spec->autocfg.hp_pins[0] = 0x1b;
10321         spec->autocfg.speaker_pins[0] = 0x14;
10322 }
10323
10324
10325 static struct snd_kcontrol_new alc262_sony_mixer[] = {
10326         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10327         ALC262_HIPPO_MASTER_SWITCH,
10328         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10329         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10330         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10331         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10332         { } /* end */
10333 };
10334
10335 static struct snd_kcontrol_new alc262_benq_t31_mixer[] = {
10336         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10337         ALC262_HIPPO_MASTER_SWITCH,
10338         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10339         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10340         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10341         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10342         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10343         { } /* end */
10344 };
10345
10346 static struct snd_kcontrol_new alc262_tyan_mixer[] = {
10347         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10348         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
10349         HDA_CODEC_VOLUME("Aux Playback Volume", 0x0b, 0x06, HDA_INPUT),
10350         HDA_CODEC_MUTE("Aux Playback Switch", 0x0b, 0x06, HDA_INPUT),
10351         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10352         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10353         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10354         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10355         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10356         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10357         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10358         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10359         { } /* end */
10360 };
10361
10362 static struct hda_verb alc262_tyan_verbs[] = {
10363         /* Headphone automute */
10364         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10365         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10366         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10367
10368         /* P11 AUX_IN, white 4-pin connector */
10369         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10370         {0x14, AC_VERB_SET_CONFIG_DEFAULT_BYTES_1, 0xe1},
10371         {0x14, AC_VERB_SET_CONFIG_DEFAULT_BYTES_2, 0x93},
10372         {0x14, AC_VERB_SET_CONFIG_DEFAULT_BYTES_3, 0x19},
10373
10374         {}
10375 };
10376
10377 /* unsolicited event for HP jack sensing */
10378 static void alc262_tyan_setup(struct hda_codec *codec)
10379 {
10380         struct alc_spec *spec = codec->spec;
10381
10382         spec->autocfg.hp_pins[0] = 0x1b;
10383         spec->autocfg.speaker_pins[0] = 0x15;
10384 }
10385
10386
10387 #define alc262_capture_mixer            alc882_capture_mixer
10388 #define alc262_capture_alt_mixer        alc882_capture_alt_mixer
10389
10390 /*
10391  * generic initialization of ADC, input mixers and output mixers
10392  */
10393 static struct hda_verb alc262_init_verbs[] = {
10394         /*
10395          * Unmute ADC0-2 and set the default input to mic-in
10396          */
10397         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10398         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10399         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10400         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10401         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10402         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10403
10404         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10405          * mixer widget
10406          * Note: PASD motherboards uses the Line In 2 as the input for
10407          * front panel mic (mic 2)
10408          */
10409         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10410         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10411         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10412         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10413         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10414         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10415
10416         /*
10417          * Set up output mixers (0x0c - 0x0e)
10418          */
10419         /* set vol=0 to output mixers */
10420         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10421         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10422         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10423         /* set up input amps for analog loopback */
10424         /* Amp Indices: DAC = 0, mixer = 1 */
10425         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10426         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10427         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10428         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10429         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10430         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10431
10432         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
10433         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
10434         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
10435         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10436         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10437         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10438
10439         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10440         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10441         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10442         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10443         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10444
10445         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
10446         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
10447
10448         /* FIXME: use matrix-type input source selection */
10449         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10450         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10451         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10452         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10453         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10454         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10455         /* Input mixer2 */
10456         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10457         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10458         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10459         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10460         /* Input mixer3 */
10461         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10462         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10463         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10464         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10465
10466         { }
10467 };
10468
10469 static struct hda_verb alc262_eapd_verbs[] = {
10470         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
10471         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
10472         { }
10473 };
10474
10475 static struct hda_verb alc262_hippo1_unsol_verbs[] = {
10476         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
10477         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10478         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10479
10480         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10481         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10482         {}
10483 };
10484
10485 static struct hda_verb alc262_sony_unsol_verbs[] = {
10486         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
10487         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10488         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},   // Front Mic
10489
10490         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10491         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10492         {}
10493 };
10494
10495 static struct snd_kcontrol_new alc262_toshiba_s06_mixer[] = {
10496         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10497         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10498         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10499         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10500         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10501         { } /* end */
10502 };
10503
10504 static struct hda_verb alc262_toshiba_s06_verbs[] = {
10505         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10506         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10507         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10508         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10509         {0x22, AC_VERB_SET_CONNECT_SEL, 0x09},
10510         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10511         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
10512         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10513         {}
10514 };
10515
10516 static void alc262_toshiba_s06_setup(struct hda_codec *codec)
10517 {
10518         struct alc_spec *spec = codec->spec;
10519
10520         spec->autocfg.hp_pins[0] = 0x15;
10521         spec->autocfg.speaker_pins[0] = 0x14;
10522         spec->ext_mic.pin = 0x18;
10523         spec->ext_mic.mux_idx = 0;
10524         spec->int_mic.pin = 0x12;
10525         spec->int_mic.mux_idx = 9;
10526         spec->auto_mic = 1;
10527 }
10528
10529 /*
10530  * nec model
10531  *  0x15 = headphone
10532  *  0x16 = internal speaker
10533  *  0x18 = external mic
10534  */
10535
10536 static struct snd_kcontrol_new alc262_nec_mixer[] = {
10537         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
10538         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 0, 0x0, HDA_OUTPUT),
10539
10540         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10541         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10542         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10543
10544         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
10545         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10546         { } /* end */
10547 };
10548
10549 static struct hda_verb alc262_nec_verbs[] = {
10550         /* Unmute Speaker */
10551         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10552
10553         /* Headphone */
10554         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10555         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10556
10557         /* External mic to headphone */
10558         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10559         /* External mic to speaker */
10560         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10561         {}
10562 };
10563
10564 /*
10565  * fujitsu model
10566  *  0x14 = headphone/spdif-out, 0x15 = internal speaker,
10567  *  0x1b = port replicator headphone out
10568  */
10569
10570 #define ALC_HP_EVENT    0x37
10571
10572 static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
10573         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
10574         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10575         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
10576         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10577         {}
10578 };
10579
10580 static struct hda_verb alc262_lenovo_3000_unsol_verbs[] = {
10581         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
10582         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10583         {}
10584 };
10585
10586 static struct hda_input_mux alc262_fujitsu_capture_source = {
10587         .num_items = 3,
10588         .items = {
10589                 { "Mic", 0x0 },
10590                 { "Int Mic", 0x1 },
10591                 { "CD", 0x4 },
10592         },
10593 };
10594
10595 static struct hda_input_mux alc262_HP_capture_source = {
10596         .num_items = 5,
10597         .items = {
10598                 { "Mic", 0x0 },
10599                 { "Front Mic", 0x1 },
10600                 { "Line", 0x2 },
10601                 { "CD", 0x4 },
10602                 { "AUX IN", 0x6 },
10603         },
10604 };
10605
10606 static struct hda_input_mux alc262_HP_D7000_capture_source = {
10607         .num_items = 4,
10608         .items = {
10609                 { "Mic", 0x0 },
10610                 { "Front Mic", 0x2 },
10611                 { "Line", 0x1 },
10612                 { "CD", 0x4 },
10613         },
10614 };
10615
10616 /* mute/unmute internal speaker according to the hp jacks and mute state */
10617 static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
10618 {
10619         struct alc_spec *spec = codec->spec;
10620         unsigned int mute;
10621
10622         if (force || !spec->sense_updated) {
10623                 unsigned int present;
10624                 /* need to execute and sync at first */
10625                 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
10626                 /* check laptop HP jack */
10627                 present = snd_hda_codec_read(codec, 0x14, 0,
10628                                              AC_VERB_GET_PIN_SENSE, 0);
10629                 /* need to execute and sync at first */
10630                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
10631                 /* check docking HP jack */
10632                 present |= snd_hda_codec_read(codec, 0x1b, 0,
10633                                               AC_VERB_GET_PIN_SENSE, 0);
10634                 if (present & AC_PINSENSE_PRESENCE)
10635                         spec->jack_present = 1;
10636                 else
10637                         spec->jack_present = 0;
10638                 spec->sense_updated = 1;
10639         }
10640         /* unmute internal speaker only if both HPs are unplugged and
10641          * master switch is on
10642          */
10643         if (spec->jack_present)
10644                 mute = HDA_AMP_MUTE;
10645         else
10646                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
10647         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
10648                                  HDA_AMP_MUTE, mute);
10649 }
10650
10651 /* unsolicited event for HP jack sensing */
10652 static void alc262_fujitsu_unsol_event(struct hda_codec *codec,
10653                                        unsigned int res)
10654 {
10655         if ((res >> 26) != ALC_HP_EVENT)
10656                 return;
10657         alc262_fujitsu_automute(codec, 1);
10658 }
10659
10660 static void alc262_fujitsu_init_hook(struct hda_codec *codec)
10661 {
10662         alc262_fujitsu_automute(codec, 1);
10663 }
10664
10665 /* bind volumes of both NID 0x0c and 0x0d */
10666 static struct hda_bind_ctls alc262_fujitsu_bind_master_vol = {
10667         .ops = &snd_hda_bind_vol,
10668         .values = {
10669                 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
10670                 HDA_COMPOSE_AMP_VAL(0x0d, 3, 0, HDA_OUTPUT),
10671                 0
10672         },
10673 };
10674
10675 /* mute/unmute internal speaker according to the hp jack and mute state */
10676 static void alc262_lenovo_3000_automute(struct hda_codec *codec, int force)
10677 {
10678         struct alc_spec *spec = codec->spec;
10679         unsigned int mute;
10680
10681         if (force || !spec->sense_updated) {
10682                 unsigned int present_int_hp;
10683                 /* need to execute and sync at first */
10684                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
10685                 present_int_hp = snd_hda_codec_read(codec, 0x1b, 0,
10686                                         AC_VERB_GET_PIN_SENSE, 0);
10687                 spec->jack_present = (present_int_hp & 0x80000000) != 0;
10688                 spec->sense_updated = 1;
10689         }
10690         if (spec->jack_present) {
10691                 /* mute internal speaker */
10692                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10693                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
10694                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
10695                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
10696         } else {
10697                 /* unmute internal speaker if necessary */
10698                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
10699                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10700                                          HDA_AMP_MUTE, mute);
10701                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
10702                                          HDA_AMP_MUTE, mute);
10703         }
10704 }
10705
10706 /* unsolicited event for HP jack sensing */
10707 static void alc262_lenovo_3000_unsol_event(struct hda_codec *codec,
10708                                        unsigned int res)
10709 {
10710         if ((res >> 26) != ALC_HP_EVENT)
10711                 return;
10712         alc262_lenovo_3000_automute(codec, 1);
10713 }
10714
10715 static int amp_stereo_mute_update(struct hda_codec *codec, hda_nid_t nid,
10716                                   int dir, int idx, long *valp)
10717 {
10718         int i, change = 0;
10719
10720         for (i = 0; i < 2; i++, valp++)
10721                 change |= snd_hda_codec_amp_update(codec, nid, i, dir, idx,
10722                                                    HDA_AMP_MUTE,
10723                                                    *valp ? 0 : HDA_AMP_MUTE);
10724         return change;
10725 }
10726
10727 /* bind hp and internal speaker mute (with plug check) */
10728 static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
10729                                          struct snd_ctl_elem_value *ucontrol)
10730 {
10731         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10732         long *valp = ucontrol->value.integer.value;
10733         int change;
10734
10735         change = amp_stereo_mute_update(codec, 0x14, HDA_OUTPUT, 0, valp);
10736         change |= amp_stereo_mute_update(codec, 0x1b, HDA_OUTPUT, 0, valp);
10737         if (change)
10738                 alc262_fujitsu_automute(codec, 0);
10739         return change;
10740 }
10741
10742 static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
10743         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
10744         {
10745                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10746                 .name = "Master Playback Switch",
10747                 .info = snd_hda_mixer_amp_switch_info,
10748                 .get = snd_hda_mixer_amp_switch_get,
10749                 .put = alc262_fujitsu_master_sw_put,
10750                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
10751         },
10752         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10753         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10754         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10755         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10756         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10757         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
10758         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
10759         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
10760         { } /* end */
10761 };
10762
10763 /* bind hp and internal speaker mute (with plug check) */
10764 static int alc262_lenovo_3000_master_sw_put(struct snd_kcontrol *kcontrol,
10765                                          struct snd_ctl_elem_value *ucontrol)
10766 {
10767         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10768         long *valp = ucontrol->value.integer.value;
10769         int change;
10770
10771         change = amp_stereo_mute_update(codec, 0x1b, HDA_OUTPUT, 0, valp);
10772         if (change)
10773                 alc262_lenovo_3000_automute(codec, 0);
10774         return change;
10775 }
10776
10777 static struct snd_kcontrol_new alc262_lenovo_3000_mixer[] = {
10778         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
10779         {
10780                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10781                 .name = "Master Playback Switch",
10782                 .info = snd_hda_mixer_amp_switch_info,
10783                 .get = snd_hda_mixer_amp_switch_get,
10784                 .put = alc262_lenovo_3000_master_sw_put,
10785                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
10786         },
10787         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10788         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10789         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10790         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10791         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10792         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
10793         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
10794         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
10795         { } /* end */
10796 };
10797
10798 static struct snd_kcontrol_new alc262_toshiba_rx1_mixer[] = {
10799         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
10800         ALC262_HIPPO_MASTER_SWITCH,
10801         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10802         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10803         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10804         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10805         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10806         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10807         { } /* end */
10808 };
10809
10810 /* additional init verbs for Benq laptops */
10811 static struct hda_verb alc262_EAPD_verbs[] = {
10812         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
10813         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
10814         {}
10815 };
10816
10817 static struct hda_verb alc262_benq_t31_EAPD_verbs[] = {
10818         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10819         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10820
10821         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
10822         {0x20, AC_VERB_SET_PROC_COEF,  0x3050},
10823         {}
10824 };
10825
10826 /* Samsung Q1 Ultra Vista model setup */
10827 static struct snd_kcontrol_new alc262_ultra_mixer[] = {
10828         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10829         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
10830         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10831         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10832         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
10833         HDA_CODEC_VOLUME("Headphone Mic Boost", 0x15, 0, HDA_INPUT),
10834         { } /* end */
10835 };
10836
10837 static struct hda_verb alc262_ultra_verbs[] = {
10838         /* output mixer */
10839         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10840         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10841         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10842         /* speaker */
10843         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10844         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10845         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10846         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
10847         /* HP */
10848         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10849         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10850         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10851         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10852         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10853         /* internal mic */
10854         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10855         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10856         /* ADC, choose mic */
10857         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10858         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10859         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10860         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10861         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10862         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10863         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10864         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10865         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
10866         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(8)},
10867         {}
10868 };
10869
10870 /* mute/unmute internal speaker according to the hp jack and mute state */
10871 static void alc262_ultra_automute(struct hda_codec *codec)
10872 {
10873         struct alc_spec *spec = codec->spec;
10874         unsigned int mute;
10875
10876         mute = 0;
10877         /* auto-mute only when HP is used as HP */
10878         if (!spec->cur_mux[0]) {
10879                 unsigned int present;
10880                 /* need to execute and sync at first */
10881                 snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
10882                 present = snd_hda_codec_read(codec, 0x15, 0,
10883                                              AC_VERB_GET_PIN_SENSE, 0);
10884                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
10885                 if (spec->jack_present)
10886                         mute = HDA_AMP_MUTE;
10887         }
10888         /* mute/unmute internal speaker */
10889         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10890                                  HDA_AMP_MUTE, mute);
10891         /* mute/unmute HP */
10892         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
10893                                  HDA_AMP_MUTE, mute ? 0 : HDA_AMP_MUTE);
10894 }
10895
10896 /* unsolicited event for HP jack sensing */
10897 static void alc262_ultra_unsol_event(struct hda_codec *codec,
10898                                        unsigned int res)
10899 {
10900         if ((res >> 26) != ALC880_HP_EVENT)
10901                 return;
10902         alc262_ultra_automute(codec);
10903 }
10904
10905 static struct hda_input_mux alc262_ultra_capture_source = {
10906         .num_items = 2,
10907         .items = {
10908                 { "Mic", 0x1 },
10909                 { "Headphone", 0x7 },
10910         },
10911 };
10912
10913 static int alc262_ultra_mux_enum_put(struct snd_kcontrol *kcontrol,
10914                                      struct snd_ctl_elem_value *ucontrol)
10915 {
10916         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10917         struct alc_spec *spec = codec->spec;
10918         int ret;
10919
10920         ret = alc_mux_enum_put(kcontrol, ucontrol);
10921         if (!ret)
10922                 return 0;
10923         /* reprogram the HP pin as mic or HP according to the input source */
10924         snd_hda_codec_write_cache(codec, 0x15, 0,
10925                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
10926                                   spec->cur_mux[0] ? PIN_VREF80 : PIN_HP);
10927         alc262_ultra_automute(codec); /* mute/unmute HP */
10928         return ret;
10929 }
10930
10931 static struct snd_kcontrol_new alc262_ultra_capture_mixer[] = {
10932         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
10933         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
10934         {
10935                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10936                 .name = "Capture Source",
10937                 .info = alc_mux_enum_info,
10938                 .get = alc_mux_enum_get,
10939                 .put = alc262_ultra_mux_enum_put,
10940         },
10941         { } /* end */
10942 };
10943
10944 /* We use two mixers depending on the output pin; 0x16 is a mono output
10945  * and thus it's bound with a different mixer.
10946  * This function returns which mixer amp should be used.
10947  */
10948 static int alc262_check_volbit(hda_nid_t nid)
10949 {
10950         if (!nid)
10951                 return 0;
10952         else if (nid == 0x16)
10953                 return 2;
10954         else
10955                 return 1;
10956 }
10957
10958 static int alc262_add_out_vol_ctl(struct alc_spec *spec, hda_nid_t nid,
10959                                   const char *pfx, int *vbits)
10960 {
10961         unsigned long val;
10962         int vbit;
10963
10964         vbit = alc262_check_volbit(nid);
10965         if (!vbit)
10966                 return 0;
10967         if (*vbits & vbit) /* a volume control for this mixer already there */
10968                 return 0;
10969         *vbits |= vbit;
10970         if (vbit == 2)
10971                 val = HDA_COMPOSE_AMP_VAL(0x0e, 2, 0, HDA_OUTPUT);
10972         else
10973                 val = HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT);
10974         return add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx, val);
10975 }
10976
10977 static int alc262_add_out_sw_ctl(struct alc_spec *spec, hda_nid_t nid,
10978                                  const char *pfx)
10979 {
10980         unsigned long val;
10981
10982         if (!nid)
10983                 return 0;
10984         if (nid == 0x16)
10985                 val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
10986         else
10987                 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
10988         return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, val);
10989 }
10990
10991 /* add playback controls from the parsed DAC table */
10992 static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
10993                                              const struct auto_pin_cfg *cfg)
10994 {
10995         const char *pfx;
10996         int vbits;
10997         int err;
10998
10999         spec->multiout.num_dacs = 1;    /* only use one dac */
11000         spec->multiout.dac_nids = spec->private_dac_nids;
11001         spec->multiout.dac_nids[0] = 2;
11002
11003         if (!cfg->speaker_pins[0] && !cfg->hp_pins[0])
11004                 pfx = "Master";
11005         else if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
11006                 pfx = "Speaker";
11007         else
11008                 pfx = "Front";
11009         err = alc262_add_out_sw_ctl(spec, cfg->line_out_pins[0], pfx);
11010         if (err < 0)
11011                 return err;
11012         err = alc262_add_out_sw_ctl(spec, cfg->speaker_pins[0], "Speaker");
11013         if (err < 0)
11014                 return err;
11015         err = alc262_add_out_sw_ctl(spec, cfg->hp_pins[0], "Headphone");
11016         if (err < 0)
11017                 return err;
11018
11019         vbits = alc262_check_volbit(cfg->line_out_pins[0]) |
11020                 alc262_check_volbit(cfg->speaker_pins[0]) |
11021                 alc262_check_volbit(cfg->hp_pins[0]);
11022         if (vbits == 1 || vbits == 2)
11023                 pfx = "Master"; /* only one mixer is used */
11024         else if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
11025                 pfx = "Speaker";
11026         else
11027                 pfx = "Front";
11028         vbits = 0;
11029         err = alc262_add_out_vol_ctl(spec, cfg->line_out_pins[0], pfx, &vbits);
11030         if (err < 0)
11031                 return err;
11032         err = alc262_add_out_vol_ctl(spec, cfg->speaker_pins[0], "Speaker",
11033                                      &vbits);
11034         if (err < 0)
11035                 return err;
11036         err = alc262_add_out_vol_ctl(spec, cfg->hp_pins[0], "Headphone",
11037                                      &vbits);
11038         if (err < 0)
11039                 return err;
11040         return 0;
11041 }
11042
11043 #define alc262_auto_create_input_ctls \
11044         alc880_auto_create_input_ctls
11045
11046 /*
11047  * generic initialization of ADC, input mixers and output mixers
11048  */
11049 static struct hda_verb alc262_volume_init_verbs[] = {
11050         /*
11051          * Unmute ADC0-2 and set the default input to mic-in
11052          */
11053         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
11054         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11055         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11056         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11057         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
11058         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11059
11060         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
11061          * mixer widget
11062          * Note: PASD motherboards uses the Line In 2 as the input for
11063          * front panel mic (mic 2)
11064          */
11065         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
11066         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11067         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11068         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11069         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11070         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
11071
11072         /*
11073          * Set up output mixers (0x0c - 0x0f)
11074          */
11075         /* set vol=0 to output mixers */
11076         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11077         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11078         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11079
11080         /* set up input amps for analog loopback */
11081         /* Amp Indices: DAC = 0, mixer = 1 */
11082         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11083         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11084         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11085         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11086         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11087         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11088
11089         /* FIXME: use matrix-type input source selection */
11090         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
11091         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
11092         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11093         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11094         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11095         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11096         /* Input mixer2 */
11097         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11098         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11099         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11100         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11101         /* Input mixer3 */
11102         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11103         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11104         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11105         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11106
11107         { }
11108 };
11109
11110 static struct hda_verb alc262_HP_BPC_init_verbs[] = {
11111         /*
11112          * Unmute ADC0-2 and set the default input to mic-in
11113          */
11114         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
11115         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11116         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11117         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11118         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
11119         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11120
11121         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
11122          * mixer widget
11123          * Note: PASD motherboards uses the Line In 2 as the input for
11124          * front panel mic (mic 2)
11125          */
11126         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
11127         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11128         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11129         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11130         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11131         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
11132         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
11133         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
11134
11135         /*
11136          * Set up output mixers (0x0c - 0x0e)
11137          */
11138         /* set vol=0 to output mixers */
11139         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11140         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11141         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11142
11143         /* set up input amps for analog loopback */
11144         /* Amp Indices: DAC = 0, mixer = 1 */
11145         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11146         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11147         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11148         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11149         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11150         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11151
11152         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11153         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11154         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11155
11156         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11157         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11158
11159         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
11160         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
11161
11162         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11163         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11164         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11165         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11166         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11167
11168         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11169         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11170         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11171         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11172         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11173         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11174
11175
11176         /* FIXME: use matrix-type input source selection */
11177         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 0b, 12 */
11178         /* Input mixer1: only unmute Mic */
11179         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11180         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8))},
11181         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11182         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11183         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11184         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x05 << 8))},
11185         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x06 << 8))},
11186         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x07 << 8))},
11187         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x08 << 8))},
11188         /* Input mixer2 */
11189         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11190         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8))},
11191         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11192         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11193         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11194         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x05 << 8))},
11195         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x06 << 8))},
11196         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x07 << 8))},
11197         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x08 << 8))},
11198         /* Input mixer3 */
11199         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11200         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8))},
11201         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11202         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11203         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11204         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x05 << 8))},
11205         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x06 << 8))},
11206         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x07 << 8))},
11207         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x08 << 8))},
11208
11209         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11210
11211         { }
11212 };
11213
11214 static struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
11215         /*
11216          * Unmute ADC0-2 and set the default input to mic-in
11217          */
11218         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
11219         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11220         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11221         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11222         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
11223         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11224
11225         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
11226          * mixer widget
11227          * Note: PASD motherboards uses the Line In 2 as the input for front
11228          * panel mic (mic 2)
11229          */
11230         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
11231         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11232         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11233         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11234         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11235         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
11236         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
11237         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
11238         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
11239         /*
11240          * Set up output mixers (0x0c - 0x0e)
11241          */
11242         /* set vol=0 to output mixers */
11243         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11244         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11245         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11246
11247         /* set up input amps for analog loopback */
11248         /* Amp Indices: DAC = 0, mixer = 1 */
11249         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11250         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11251         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11252         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11253         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11254         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11255
11256
11257         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP */
11258         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Mono */
11259         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* rear MIC */
11260         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* Line in */
11261         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
11262         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Line out */
11263         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* CD in */
11264
11265         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11266         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11267
11268         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
11269         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
11270
11271         /* {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 }, */
11272         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11273         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11274         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
11275         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11276         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11277
11278         /* FIXME: use matrix-type input source selection */
11279         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
11280         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
11281         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, /*rear MIC*/
11282         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, /*Line in*/
11283         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))}, /*F MIC*/
11284         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))}, /*Front*/
11285         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))}, /*CD*/
11286         /* {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))},  */
11287         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))}, /*HP*/
11288         /* Input mixer2 */
11289         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11290         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
11291         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
11292         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
11293         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
11294         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
11295         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
11296         /* Input mixer3 */
11297         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11298         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
11299         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
11300         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
11301         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
11302         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
11303         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
11304
11305         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11306
11307         { }
11308 };
11309
11310 static struct hda_verb alc262_toshiba_rx1_unsol_verbs[] = {
11311
11312         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Front Speaker */
11313         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11314         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
11315
11316         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* MIC jack */
11317         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
11318         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
11319         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
11320
11321         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP  jack */
11322         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
11323         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
11324         {}
11325 };
11326
11327
11328 #ifdef CONFIG_SND_HDA_POWER_SAVE
11329 #define alc262_loopbacks        alc880_loopbacks
11330 #endif
11331
11332 /* pcm configuration: identical with ALC880 */
11333 #define alc262_pcm_analog_playback      alc880_pcm_analog_playback
11334 #define alc262_pcm_analog_capture       alc880_pcm_analog_capture
11335 #define alc262_pcm_digital_playback     alc880_pcm_digital_playback
11336 #define alc262_pcm_digital_capture      alc880_pcm_digital_capture
11337
11338 /*
11339  * BIOS auto configuration
11340  */
11341 static int alc262_parse_auto_config(struct hda_codec *codec)
11342 {
11343         struct alc_spec *spec = codec->spec;
11344         int err;
11345         static hda_nid_t alc262_ignore[] = { 0x1d, 0 };
11346
11347         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
11348                                            alc262_ignore);
11349         if (err < 0)
11350                 return err;
11351         if (!spec->autocfg.line_outs) {
11352                 if (spec->autocfg.dig_outs || spec->autocfg.dig_in_pin) {
11353                         spec->multiout.max_channels = 2;
11354                         spec->no_analog = 1;
11355                         goto dig_only;
11356                 }
11357                 return 0; /* can't find valid BIOS pin config */
11358         }
11359         err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
11360         if (err < 0)
11361                 return err;
11362         err = alc262_auto_create_input_ctls(codec, &spec->autocfg);
11363         if (err < 0)
11364                 return err;
11365
11366         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
11367
11368  dig_only:
11369         if (spec->autocfg.dig_outs) {
11370                 spec->multiout.dig_out_nid = ALC262_DIGOUT_NID;
11371                 spec->dig_out_type = spec->autocfg.dig_out_type[0];
11372         }
11373         if (spec->autocfg.dig_in_pin)
11374                 spec->dig_in_nid = ALC262_DIGIN_NID;
11375
11376         if (spec->kctls.list)
11377                 add_mixer(spec, spec->kctls.list);
11378
11379         add_verb(spec, alc262_volume_init_verbs);
11380         spec->num_mux_defs = 1;
11381         spec->input_mux = &spec->private_imux[0];
11382
11383         err = alc_auto_add_mic_boost(codec);
11384         if (err < 0)
11385                 return err;
11386
11387         alc_ssid_check(codec, 0x15, 0x14, 0x1b);
11388
11389         return 1;
11390 }
11391
11392 #define alc262_auto_init_multi_out      alc882_auto_init_multi_out
11393 #define alc262_auto_init_hp_out         alc882_auto_init_hp_out
11394 #define alc262_auto_init_analog_input   alc882_auto_init_analog_input
11395 #define alc262_auto_init_input_src      alc882_auto_init_input_src
11396
11397
11398 /* init callback for auto-configuration model -- overriding the default init */
11399 static void alc262_auto_init(struct hda_codec *codec)
11400 {
11401         struct alc_spec *spec = codec->spec;
11402         alc262_auto_init_multi_out(codec);
11403         alc262_auto_init_hp_out(codec);
11404         alc262_auto_init_analog_input(codec);
11405         alc262_auto_init_input_src(codec);
11406         if (spec->unsol_event)
11407                 alc_inithook(codec);
11408 }
11409
11410 /*
11411  * configuration and preset
11412  */
11413 static const char *alc262_models[ALC262_MODEL_LAST] = {
11414         [ALC262_BASIC]          = "basic",
11415         [ALC262_HIPPO]          = "hippo",
11416         [ALC262_HIPPO_1]        = "hippo_1",
11417         [ALC262_FUJITSU]        = "fujitsu",
11418         [ALC262_HP_BPC]         = "hp-bpc",
11419         [ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000",
11420         [ALC262_HP_TC_T5735]    = "hp-tc-t5735",
11421         [ALC262_HP_RP5700]      = "hp-rp5700",
11422         [ALC262_BENQ_ED8]       = "benq",
11423         [ALC262_BENQ_T31]       = "benq-t31",
11424         [ALC262_SONY_ASSAMD]    = "sony-assamd",
11425         [ALC262_TOSHIBA_S06]    = "toshiba-s06",
11426         [ALC262_TOSHIBA_RX1]    = "toshiba-rx1",
11427         [ALC262_ULTRA]          = "ultra",
11428         [ALC262_LENOVO_3000]    = "lenovo-3000",
11429         [ALC262_NEC]            = "nec",
11430         [ALC262_TYAN]           = "tyan",
11431         [ALC262_AUTO]           = "auto",
11432 };
11433
11434 static struct snd_pci_quirk alc262_cfg_tbl[] = {
11435         SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
11436         SND_PCI_QUIRK(0x1033, 0x8895, "NEC Versa S9100", ALC262_NEC),
11437         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1200, "HP xw series",
11438                            ALC262_HP_BPC),
11439         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1300, "HP xw series",
11440                            ALC262_HP_BPC),
11441         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1700, "HP xw series",
11442                            ALC262_HP_BPC),
11443         SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
11444         SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
11445         SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
11446         SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF),
11447         SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL),
11448         SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF),
11449         SND_PCI_QUIRK(0x103c, 0x2806, "HP D7000", ALC262_HP_BPC_D7000_WL),
11450         SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF),
11451         SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC),
11452         SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC),
11453         SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC),
11454         SND_PCI_QUIRK(0x103c, 0x302f, "HP Thin Client T5735",
11455                       ALC262_HP_TC_T5735),
11456         SND_PCI_QUIRK(0x103c, 0x2817, "HP RP5700", ALC262_HP_RP5700),
11457         SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD),
11458         SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
11459         SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
11460         SND_PCI_QUIRK(0x104d, 0x9016, "Sony VAIO", ALC262_AUTO), /* dig-only */
11461         SND_PCI_QUIRK(0x104d, 0x9025, "Sony VAIO Z21MN", ALC262_TOSHIBA_S06),
11462         SND_PCI_QUIRK(0x104d, 0x9035, "Sony VAIO VGN-FW170J", ALC262_AUTO),
11463         SND_PCI_QUIRK_MASK(0x104d, 0xff00, 0x9000, "Sony VAIO",
11464                            ALC262_SONY_ASSAMD),
11465         SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
11466                       ALC262_TOSHIBA_RX1),
11467         SND_PCI_QUIRK(0x1179, 0xff7b, "Toshiba S06", ALC262_TOSHIBA_S06),
11468         SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
11469         SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU),
11470         SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_TYAN),
11471         SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc032, "Samsung Q1",
11472                            ALC262_ULTRA),
11473         SND_PCI_QUIRK(0x144d, 0xc510, "Samsung Q45", ALC262_HIPPO),
11474         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 y410", ALC262_LENOVO_3000),
11475         SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
11476         SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
11477         SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
11478         {}
11479 };
11480
11481 static struct alc_config_preset alc262_presets[] = {
11482         [ALC262_BASIC] = {
11483                 .mixers = { alc262_base_mixer },
11484                 .init_verbs = { alc262_init_verbs },
11485                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11486                 .dac_nids = alc262_dac_nids,
11487                 .hp_nid = 0x03,
11488                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11489                 .channel_mode = alc262_modes,
11490                 .input_mux = &alc262_capture_source,
11491         },
11492         [ALC262_HIPPO] = {
11493                 .mixers = { alc262_hippo_mixer },
11494                 .init_verbs = { alc262_init_verbs, alc_hp15_unsol_verbs},
11495                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11496                 .dac_nids = alc262_dac_nids,
11497                 .hp_nid = 0x03,
11498                 .dig_out_nid = ALC262_DIGOUT_NID,
11499                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11500                 .channel_mode = alc262_modes,
11501                 .input_mux = &alc262_capture_source,
11502                 .unsol_event = alc262_hippo_unsol_event,
11503                 .setup = alc262_hippo_setup,
11504                 .init_hook = alc262_hippo_automute,
11505         },
11506         [ALC262_HIPPO_1] = {
11507                 .mixers = { alc262_hippo1_mixer },
11508                 .init_verbs = { alc262_init_verbs, alc262_hippo1_unsol_verbs},
11509                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11510                 .dac_nids = alc262_dac_nids,
11511                 .hp_nid = 0x02,
11512                 .dig_out_nid = ALC262_DIGOUT_NID,
11513                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11514                 .channel_mode = alc262_modes,
11515                 .input_mux = &alc262_capture_source,
11516                 .unsol_event = alc262_hippo_unsol_event,
11517                 .setup = alc262_hippo1_setup,
11518                 .init_hook = alc262_hippo_automute,
11519         },
11520         [ALC262_FUJITSU] = {
11521                 .mixers = { alc262_fujitsu_mixer },
11522                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
11523                                 alc262_fujitsu_unsol_verbs },
11524                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11525                 .dac_nids = alc262_dac_nids,
11526                 .hp_nid = 0x03,
11527                 .dig_out_nid = ALC262_DIGOUT_NID,
11528                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11529                 .channel_mode = alc262_modes,
11530                 .input_mux = &alc262_fujitsu_capture_source,
11531                 .unsol_event = alc262_fujitsu_unsol_event,
11532                 .init_hook = alc262_fujitsu_init_hook,
11533         },
11534         [ALC262_HP_BPC] = {
11535                 .mixers = { alc262_HP_BPC_mixer },
11536                 .init_verbs = { alc262_HP_BPC_init_verbs },
11537                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11538                 .dac_nids = alc262_dac_nids,
11539                 .hp_nid = 0x03,
11540                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11541                 .channel_mode = alc262_modes,
11542                 .input_mux = &alc262_HP_capture_source,
11543                 .unsol_event = alc262_hp_bpc_unsol_event,
11544                 .init_hook = alc262_hp_bpc_automute,
11545         },
11546         [ALC262_HP_BPC_D7000_WF] = {
11547                 .mixers = { alc262_HP_BPC_WildWest_mixer },
11548                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
11549                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11550                 .dac_nids = alc262_dac_nids,
11551                 .hp_nid = 0x03,
11552                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11553                 .channel_mode = alc262_modes,
11554                 .input_mux = &alc262_HP_D7000_capture_source,
11555                 .unsol_event = alc262_hp_wildwest_unsol_event,
11556                 .init_hook = alc262_hp_wildwest_automute,
11557         },
11558         [ALC262_HP_BPC_D7000_WL] = {
11559                 .mixers = { alc262_HP_BPC_WildWest_mixer,
11560                             alc262_HP_BPC_WildWest_option_mixer },
11561                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
11562                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11563                 .dac_nids = alc262_dac_nids,
11564                 .hp_nid = 0x03,
11565                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11566                 .channel_mode = alc262_modes,
11567                 .input_mux = &alc262_HP_D7000_capture_source,
11568                 .unsol_event = alc262_hp_wildwest_unsol_event,
11569                 .init_hook = alc262_hp_wildwest_automute,
11570         },
11571         [ALC262_HP_TC_T5735] = {
11572                 .mixers = { alc262_hp_t5735_mixer },
11573                 .init_verbs = { alc262_init_verbs, alc262_hp_t5735_verbs },
11574                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11575                 .dac_nids = alc262_dac_nids,
11576                 .hp_nid = 0x03,
11577                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11578                 .channel_mode = alc262_modes,
11579                 .input_mux = &alc262_capture_source,
11580                 .unsol_event = alc_automute_amp_unsol_event,
11581                 .setup = alc262_hp_t5735_setup,
11582                 .init_hook = alc_automute_amp,
11583         },
11584         [ALC262_HP_RP5700] = {
11585                 .mixers = { alc262_hp_rp5700_mixer },
11586                 .init_verbs = { alc262_init_verbs, alc262_hp_rp5700_verbs },
11587                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11588                 .dac_nids = alc262_dac_nids,
11589                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11590                 .channel_mode = alc262_modes,
11591                 .input_mux = &alc262_hp_rp5700_capture_source,
11592         },
11593         [ALC262_BENQ_ED8] = {
11594                 .mixers = { alc262_base_mixer },
11595                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs },
11596                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11597                 .dac_nids = alc262_dac_nids,
11598                 .hp_nid = 0x03,
11599                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11600                 .channel_mode = alc262_modes,
11601                 .input_mux = &alc262_capture_source,
11602         },
11603         [ALC262_SONY_ASSAMD] = {
11604                 .mixers = { alc262_sony_mixer },
11605                 .init_verbs = { alc262_init_verbs, alc262_sony_unsol_verbs},
11606                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11607                 .dac_nids = alc262_dac_nids,
11608                 .hp_nid = 0x02,
11609                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11610                 .channel_mode = alc262_modes,
11611                 .input_mux = &alc262_capture_source,
11612                 .unsol_event = alc262_hippo_unsol_event,
11613                 .setup = alc262_hippo_setup,
11614                 .init_hook = alc262_hippo_automute,
11615         },
11616         [ALC262_BENQ_T31] = {
11617                 .mixers = { alc262_benq_t31_mixer },
11618                 .init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs,
11619                                 alc_hp15_unsol_verbs },
11620                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11621                 .dac_nids = alc262_dac_nids,
11622                 .hp_nid = 0x03,
11623                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11624                 .channel_mode = alc262_modes,
11625                 .input_mux = &alc262_capture_source,
11626                 .unsol_event = alc262_hippo_unsol_event,
11627                 .setup = alc262_hippo_setup,
11628                 .init_hook = alc262_hippo_automute,
11629         },
11630         [ALC262_ULTRA] = {
11631                 .mixers = { alc262_ultra_mixer },
11632                 .cap_mixer = alc262_ultra_capture_mixer,
11633                 .init_verbs = { alc262_ultra_verbs },
11634                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11635                 .dac_nids = alc262_dac_nids,
11636                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11637                 .channel_mode = alc262_modes,
11638                 .input_mux = &alc262_ultra_capture_source,
11639                 .adc_nids = alc262_adc_nids, /* ADC0 */
11640                 .capsrc_nids = alc262_capsrc_nids,
11641                 .num_adc_nids = 1, /* single ADC */
11642                 .unsol_event = alc262_ultra_unsol_event,
11643                 .init_hook = alc262_ultra_automute,
11644         },
11645         [ALC262_LENOVO_3000] = {
11646                 .mixers = { alc262_lenovo_3000_mixer },
11647                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
11648                                 alc262_lenovo_3000_unsol_verbs },
11649                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11650                 .dac_nids = alc262_dac_nids,
11651                 .hp_nid = 0x03,
11652                 .dig_out_nid = ALC262_DIGOUT_NID,
11653                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11654                 .channel_mode = alc262_modes,
11655                 .input_mux = &alc262_fujitsu_capture_source,
11656                 .unsol_event = alc262_lenovo_3000_unsol_event,
11657         },
11658         [ALC262_NEC] = {
11659                 .mixers = { alc262_nec_mixer },
11660                 .init_verbs = { alc262_nec_verbs },
11661                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11662                 .dac_nids = alc262_dac_nids,
11663                 .hp_nid = 0x03,
11664                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11665                 .channel_mode = alc262_modes,
11666                 .input_mux = &alc262_capture_source,
11667         },
11668         [ALC262_TOSHIBA_S06] = {
11669                 .mixers = { alc262_toshiba_s06_mixer },
11670                 .init_verbs = { alc262_init_verbs, alc262_toshiba_s06_verbs,
11671                                                         alc262_eapd_verbs },
11672                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11673                 .capsrc_nids = alc262_dmic_capsrc_nids,
11674                 .dac_nids = alc262_dac_nids,
11675                 .adc_nids = alc262_dmic_adc_nids, /* ADC0 */
11676                 .num_adc_nids = 1, /* single ADC */
11677                 .dig_out_nid = ALC262_DIGOUT_NID,
11678                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11679                 .channel_mode = alc262_modes,
11680                 .unsol_event = alc_sku_unsol_event,
11681                 .setup = alc262_toshiba_s06_setup,
11682                 .init_hook = alc_inithook,
11683         },
11684         [ALC262_TOSHIBA_RX1] = {
11685                 .mixers = { alc262_toshiba_rx1_mixer },
11686                 .init_verbs = { alc262_init_verbs, alc262_toshiba_rx1_unsol_verbs },
11687                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11688                 .dac_nids = alc262_dac_nids,
11689                 .hp_nid = 0x03,
11690                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11691                 .channel_mode = alc262_modes,
11692                 .input_mux = &alc262_capture_source,
11693                 .unsol_event = alc262_hippo_unsol_event,
11694                 .setup = alc262_hippo_setup,
11695                 .init_hook = alc262_hippo_automute,
11696         },
11697         [ALC262_TYAN] = {
11698                 .mixers = { alc262_tyan_mixer },
11699                 .init_verbs = { alc262_init_verbs, alc262_tyan_verbs},
11700                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11701                 .dac_nids = alc262_dac_nids,
11702                 .hp_nid = 0x02,
11703                 .dig_out_nid = ALC262_DIGOUT_NID,
11704                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11705                 .channel_mode = alc262_modes,
11706                 .input_mux = &alc262_capture_source,
11707                 .unsol_event = alc_automute_amp_unsol_event,
11708                 .setup = alc262_tyan_setup,
11709                 .init_hook = alc_automute_amp,
11710         },
11711 };
11712
11713 static int patch_alc262(struct hda_codec *codec)
11714 {
11715         struct alc_spec *spec;
11716         int board_config;
11717         int err;
11718
11719         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
11720         if (spec == NULL)
11721                 return -ENOMEM;
11722
11723         codec->spec = spec;
11724 #if 0
11725         /* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is
11726          * under-run
11727          */
11728         {
11729         int tmp;
11730         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
11731         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
11732         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
11733         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
11734         }
11735 #endif
11736
11737         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
11738
11739         board_config = snd_hda_check_board_config(codec, ALC262_MODEL_LAST,
11740                                                   alc262_models,
11741                                                   alc262_cfg_tbl);
11742
11743         if (board_config < 0) {
11744                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
11745                        codec->chip_name);
11746                 board_config = ALC262_AUTO;
11747         }
11748
11749         if (board_config == ALC262_AUTO) {
11750                 /* automatic parse from the BIOS config */
11751                 err = alc262_parse_auto_config(codec);
11752                 if (err < 0) {
11753                         alc_free(codec);
11754                         return err;
11755                 } else if (!err) {
11756                         printk(KERN_INFO
11757                                "hda_codec: Cannot set up configuration "
11758                                "from BIOS.  Using base mode...\n");
11759                         board_config = ALC262_BASIC;
11760                 }
11761         }
11762
11763         if (!spec->no_analog) {
11764                 err = snd_hda_attach_beep_device(codec, 0x1);
11765                 if (err < 0) {
11766                         alc_free(codec);
11767                         return err;
11768                 }
11769         }
11770
11771         if (board_config != ALC262_AUTO)
11772                 setup_preset(codec, &alc262_presets[board_config]);
11773
11774         spec->stream_analog_playback = &alc262_pcm_analog_playback;
11775         spec->stream_analog_capture = &alc262_pcm_analog_capture;
11776
11777         spec->stream_digital_playback = &alc262_pcm_digital_playback;
11778         spec->stream_digital_capture = &alc262_pcm_digital_capture;
11779
11780         if (!spec->adc_nids && spec->input_mux) {
11781                 int i;
11782                 /* check whether the digital-mic has to be supported */
11783                 for (i = 0; i < spec->input_mux->num_items; i++) {
11784                         if (spec->input_mux->items[i].index >= 9)
11785                                 break;
11786                 }
11787                 if (i < spec->input_mux->num_items) {
11788                         /* use only ADC0 */
11789                         spec->adc_nids = alc262_dmic_adc_nids;
11790                         spec->num_adc_nids = 1;
11791                         spec->capsrc_nids = alc262_dmic_capsrc_nids;
11792                 } else {
11793                         /* all analog inputs */
11794                         /* check whether NID 0x07 is valid */
11795                         unsigned int wcap = get_wcaps(codec, 0x07);
11796
11797                         /* get type */
11798                         wcap = get_wcaps_type(wcap);
11799                         if (wcap != AC_WID_AUD_IN) {
11800                                 spec->adc_nids = alc262_adc_nids_alt;
11801                                 spec->num_adc_nids =
11802                                         ARRAY_SIZE(alc262_adc_nids_alt);
11803                                 spec->capsrc_nids = alc262_capsrc_nids_alt;
11804                         } else {
11805                                 spec->adc_nids = alc262_adc_nids;
11806                                 spec->num_adc_nids =
11807                                         ARRAY_SIZE(alc262_adc_nids);
11808                                 spec->capsrc_nids = alc262_capsrc_nids;
11809                         }
11810                 }
11811         }
11812         if (!spec->cap_mixer && !spec->no_analog)
11813                 set_capture_mixer(codec);
11814         if (!spec->no_analog)
11815                 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
11816
11817         spec->vmaster_nid = 0x0c;
11818
11819         codec->patch_ops = alc_patch_ops;
11820         if (board_config == ALC262_AUTO)
11821                 spec->init_hook = alc262_auto_init;
11822 #ifdef CONFIG_SND_HDA_POWER_SAVE
11823         if (!spec->loopback.amplist)
11824                 spec->loopback.amplist = alc262_loopbacks;
11825 #endif
11826         codec->proc_widget_hook = print_realtek_coef;
11827
11828         return 0;
11829 }
11830
11831 /*
11832  *  ALC268 channel source setting (2 channel)
11833  */
11834 #define ALC268_DIGOUT_NID       ALC880_DIGOUT_NID
11835 #define alc268_modes            alc260_modes
11836
11837 static hda_nid_t alc268_dac_nids[2] = {
11838         /* front, hp */
11839         0x02, 0x03
11840 };
11841
11842 static hda_nid_t alc268_adc_nids[2] = {
11843         /* ADC0-1 */
11844         0x08, 0x07
11845 };
11846
11847 static hda_nid_t alc268_adc_nids_alt[1] = {
11848         /* ADC0 */
11849         0x08
11850 };
11851
11852 static hda_nid_t alc268_capsrc_nids[2] = { 0x23, 0x24 };
11853
11854 static struct snd_kcontrol_new alc268_base_mixer[] = {
11855         /* output mixer control */
11856         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
11857         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11858         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
11859         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11860         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11861         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
11862         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11863         { }
11864 };
11865
11866 static struct snd_kcontrol_new alc268_toshiba_mixer[] = {
11867         /* output mixer control */
11868         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
11869         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
11870         ALC262_HIPPO_MASTER_SWITCH,
11871         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11872         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
11873         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11874         { }
11875 };
11876
11877 /* bind Beep switches of both NID 0x0f and 0x10 */
11878 static struct hda_bind_ctls alc268_bind_beep_sw = {
11879         .ops = &snd_hda_bind_sw,
11880         .values = {
11881                 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
11882                 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
11883                 0
11884         },
11885 };
11886
11887 static struct snd_kcontrol_new alc268_beep_mixer[] = {
11888         HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
11889         HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
11890         { }
11891 };
11892
11893 static struct hda_verb alc268_eapd_verbs[] = {
11894         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
11895         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
11896         { }
11897 };
11898
11899 /* Toshiba specific */
11900 static struct hda_verb alc268_toshiba_verbs[] = {
11901         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11902         { } /* end */
11903 };
11904
11905 /* Acer specific */
11906 /* bind volumes of both NID 0x02 and 0x03 */
11907 static struct hda_bind_ctls alc268_acer_bind_master_vol = {
11908         .ops = &snd_hda_bind_vol,
11909         .values = {
11910                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
11911                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
11912                 0
11913         },
11914 };
11915
11916 /* mute/unmute internal speaker according to the hp jack and mute state */
11917 static void alc268_acer_automute(struct hda_codec *codec, int force)
11918 {
11919         struct alc_spec *spec = codec->spec;
11920         unsigned int mute;
11921
11922         if (force || !spec->sense_updated) {
11923                 unsigned int present;
11924                 present = snd_hda_codec_read(codec, 0x14, 0,
11925                                          AC_VERB_GET_PIN_SENSE, 0);
11926                 spec->jack_present = (present & 0x80000000) != 0;
11927                 spec->sense_updated = 1;
11928         }
11929         if (spec->jack_present)
11930                 mute = HDA_AMP_MUTE; /* mute internal speaker */
11931         else /* unmute internal speaker if necessary */
11932                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
11933         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
11934                                  HDA_AMP_MUTE, mute);
11935 }
11936
11937
11938 /* bind hp and internal speaker mute (with plug check) */
11939 static int alc268_acer_master_sw_put(struct snd_kcontrol *kcontrol,
11940                                      struct snd_ctl_elem_value *ucontrol)
11941 {
11942         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
11943         long *valp = ucontrol->value.integer.value;
11944         int change;
11945
11946         change = amp_stereo_mute_update(codec, 0x14, HDA_OUTPUT, 0, valp);
11947         if (change)
11948                 alc268_acer_automute(codec, 0);
11949         return change;
11950 }
11951
11952 static struct snd_kcontrol_new alc268_acer_aspire_one_mixer[] = {
11953         /* output mixer control */
11954         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11955         {
11956                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11957                 .name = "Master Playback Switch",
11958                 .info = snd_hda_mixer_amp_switch_info,
11959                 .get = snd_hda_mixer_amp_switch_get,
11960                 .put = alc268_acer_master_sw_put,
11961                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11962         },
11963         HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x18, 0, HDA_INPUT),
11964         { }
11965 };
11966
11967 static struct snd_kcontrol_new alc268_acer_mixer[] = {
11968         /* output mixer control */
11969         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11970         {
11971                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11972                 .name = "Master Playback Switch",
11973                 .info = snd_hda_mixer_amp_switch_info,
11974                 .get = snd_hda_mixer_amp_switch_get,
11975                 .put = alc268_acer_master_sw_put,
11976                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11977         },
11978         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11979         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
11980         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11981         { }
11982 };
11983
11984 static struct snd_kcontrol_new alc268_acer_dmic_mixer[] = {
11985         /* output mixer control */
11986         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11987         {
11988                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11989                 .name = "Master Playback Switch",
11990                 .info = snd_hda_mixer_amp_switch_info,
11991                 .get = snd_hda_mixer_amp_switch_get,
11992                 .put = alc268_acer_master_sw_put,
11993                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11994         },
11995         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11996         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11997         { }
11998 };
11999
12000 static struct hda_verb alc268_acer_aspire_one_verbs[] = {
12001         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12002         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12003         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12004         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12005         {0x23, AC_VERB_SET_CONNECT_SEL, 0x06},
12006         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, 0xa017},
12007         { }
12008 };
12009
12010 static struct hda_verb alc268_acer_verbs[] = {
12011         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* internal dmic? */
12012         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12013         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12014         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12015         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12016         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12017         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12018         { }
12019 };
12020
12021 /* unsolicited event for HP jack sensing */
12022 #define alc268_toshiba_unsol_event      alc262_hippo_unsol_event
12023 #define alc268_toshiba_setup            alc262_hippo_setup
12024 #define alc268_toshiba_automute         alc262_hippo_automute
12025
12026 static void alc268_acer_unsol_event(struct hda_codec *codec,
12027                                        unsigned int res)
12028 {
12029         if ((res >> 26) != ALC880_HP_EVENT)
12030                 return;
12031         alc268_acer_automute(codec, 1);
12032 }
12033
12034 static void alc268_acer_init_hook(struct hda_codec *codec)
12035 {
12036         alc268_acer_automute(codec, 1);
12037 }
12038
12039 /* toggle speaker-output according to the hp-jack state */
12040 static void alc268_aspire_one_speaker_automute(struct hda_codec *codec)
12041 {
12042         unsigned int present;
12043         unsigned char bits;
12044
12045         present = snd_hda_codec_read(codec, 0x15, 0,
12046                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12047         bits = present ? AMP_IN_MUTE(0) : 0;
12048         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 0,
12049                                 AMP_IN_MUTE(0), bits);
12050         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 1,
12051                                 AMP_IN_MUTE(0), bits);
12052 }
12053
12054 static void alc268_acer_lc_unsol_event(struct hda_codec *codec,
12055                                     unsigned int res)
12056 {
12057         switch (res >> 26) {
12058         case ALC880_HP_EVENT:
12059                 alc268_aspire_one_speaker_automute(codec);
12060                 break;
12061         case ALC880_MIC_EVENT:
12062                 alc_mic_automute(codec);
12063                 break;
12064         }
12065 }
12066
12067 static void alc268_acer_lc_setup(struct hda_codec *codec)
12068 {
12069         struct alc_spec *spec = codec->spec;
12070         spec->ext_mic.pin = 0x18;
12071         spec->ext_mic.mux_idx = 0;
12072         spec->int_mic.pin = 0x12;
12073         spec->int_mic.mux_idx = 6;
12074         spec->auto_mic = 1;
12075 }
12076
12077 static void alc268_acer_lc_init_hook(struct hda_codec *codec)
12078 {
12079         alc268_aspire_one_speaker_automute(codec);
12080         alc_mic_automute(codec);
12081 }
12082
12083 static struct snd_kcontrol_new alc268_dell_mixer[] = {
12084         /* output mixer control */
12085         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12086         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12087         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12088         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12089         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12090         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
12091         { }
12092 };
12093
12094 static struct hda_verb alc268_dell_verbs[] = {
12095         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12096         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12097         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12098         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
12099         { }
12100 };
12101
12102 /* mute/unmute internal speaker according to the hp jack and mute state */
12103 static void alc268_dell_setup(struct hda_codec *codec)
12104 {
12105         struct alc_spec *spec = codec->spec;
12106
12107         spec->autocfg.hp_pins[0] = 0x15;
12108         spec->autocfg.speaker_pins[0] = 0x14;
12109         spec->ext_mic.pin = 0x18;
12110         spec->ext_mic.mux_idx = 0;
12111         spec->int_mic.pin = 0x19;
12112         spec->int_mic.mux_idx = 1;
12113         spec->auto_mic = 1;
12114 }
12115
12116 static struct snd_kcontrol_new alc267_quanta_il1_mixer[] = {
12117         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x2, 0x0, HDA_OUTPUT),
12118         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12119         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
12120         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12121         HDA_CODEC_VOLUME("Mic Capture Volume", 0x23, 0x0, HDA_OUTPUT),
12122         HDA_BIND_MUTE("Mic Capture Switch", 0x23, 2, HDA_OUTPUT),
12123         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
12124         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
12125         { }
12126 };
12127
12128 static struct hda_verb alc267_quanta_il1_verbs[] = {
12129         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12130         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
12131         { }
12132 };
12133
12134 static void alc267_quanta_il1_setup(struct hda_codec *codec)
12135 {
12136         struct alc_spec *spec = codec->spec;
12137         spec->autocfg.hp_pins[0] = 0x15;
12138         spec->autocfg.speaker_pins[0] = 0x14;
12139         spec->ext_mic.pin = 0x18;
12140         spec->ext_mic.mux_idx = 0;
12141         spec->int_mic.pin = 0x19;
12142         spec->int_mic.mux_idx = 1;
12143         spec->auto_mic = 1;
12144 }
12145
12146 /*
12147  * generic initialization of ADC, input mixers and output mixers
12148  */
12149 static struct hda_verb alc268_base_init_verbs[] = {
12150         /* Unmute DAC0-1 and set vol = 0 */
12151         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12152         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12153
12154         /*
12155          * Set up output mixers (0x0c - 0x0e)
12156          */
12157         /* set vol=0 to output mixers */
12158         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12159         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
12160
12161         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12162         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12163
12164         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
12165         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
12166         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
12167         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
12168         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
12169         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12170         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12171         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12172
12173         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12174         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12175         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12176         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12177         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12178
12179         /* set PCBEEP vol = 0, mute connections */
12180         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12181         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12182         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12183
12184         /* Unmute Selector 23h,24h and set the default input to mic-in */
12185
12186         {0x23, AC_VERB_SET_CONNECT_SEL, 0x00},
12187         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12188         {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
12189         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12190
12191         { }
12192 };
12193
12194 /*
12195  * generic initialization of ADC, input mixers and output mixers
12196  */
12197 static struct hda_verb alc268_volume_init_verbs[] = {
12198         /* set output DAC */
12199         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12200         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12201
12202         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
12203         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
12204         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12205         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12206         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12207
12208         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12209         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12210         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12211
12212         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12213         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12214
12215         /* set PCBEEP vol = 0, mute connections */
12216         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12217         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12218         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12219
12220         { }
12221 };
12222
12223 static struct snd_kcontrol_new alc268_capture_nosrc_mixer[] = {
12224         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
12225         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
12226         { } /* end */
12227 };
12228
12229 static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
12230         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
12231         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
12232         _DEFINE_CAPSRC(1),
12233         { } /* end */
12234 };
12235
12236 static struct snd_kcontrol_new alc268_capture_mixer[] = {
12237         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
12238         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
12239         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
12240         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
12241         _DEFINE_CAPSRC(2),
12242         { } /* end */
12243 };
12244
12245 static struct hda_input_mux alc268_capture_source = {
12246         .num_items = 4,
12247         .items = {
12248                 { "Mic", 0x0 },
12249                 { "Front Mic", 0x1 },
12250                 { "Line", 0x2 },
12251                 { "CD", 0x3 },
12252         },
12253 };
12254
12255 static struct hda_input_mux alc268_acer_capture_source = {
12256         .num_items = 3,
12257         .items = {
12258                 { "Mic", 0x0 },
12259                 { "Internal Mic", 0x1 },
12260                 { "Line", 0x2 },
12261         },
12262 };
12263
12264 static struct hda_input_mux alc268_acer_dmic_capture_source = {
12265         .num_items = 3,
12266         .items = {
12267                 { "Mic", 0x0 },
12268                 { "Internal Mic", 0x6 },
12269                 { "Line", 0x2 },
12270         },
12271 };
12272
12273 #ifdef CONFIG_SND_DEBUG
12274 static struct snd_kcontrol_new alc268_test_mixer[] = {
12275         /* Volume widgets */
12276         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12277         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12278         HDA_BIND_MUTE_MONO("Mono sum Playback Switch", 0x0e, 1, 2, HDA_INPUT),
12279         HDA_BIND_MUTE("LINE-OUT sum Playback Switch", 0x0f, 2, HDA_INPUT),
12280         HDA_BIND_MUTE("HP-OUT sum Playback Switch", 0x10, 2, HDA_INPUT),
12281         HDA_BIND_MUTE("LINE-OUT Playback Switch", 0x14, 2, HDA_OUTPUT),
12282         HDA_BIND_MUTE("HP-OUT Playback Switch", 0x15, 2, HDA_OUTPUT),
12283         HDA_BIND_MUTE("Mono Playback Switch", 0x16, 2, HDA_OUTPUT),
12284         HDA_CODEC_VOLUME("MIC1 Capture Volume", 0x18, 0x0, HDA_INPUT),
12285         HDA_BIND_MUTE("MIC1 Capture Switch", 0x18, 2, HDA_OUTPUT),
12286         HDA_CODEC_VOLUME("MIC2 Capture Volume", 0x19, 0x0, HDA_INPUT),
12287         HDA_CODEC_VOLUME("LINE1 Capture Volume", 0x1a, 0x0, HDA_INPUT),
12288         HDA_BIND_MUTE("LINE1 Capture Switch", 0x1a, 2, HDA_OUTPUT),
12289         /* The below appears problematic on some hardwares */
12290         /*HDA_CODEC_VOLUME("PCBEEP Playback Volume", 0x1d, 0x0, HDA_INPUT),*/
12291         HDA_CODEC_VOLUME("PCM-IN1 Capture Volume", 0x23, 0x0, HDA_OUTPUT),
12292         HDA_BIND_MUTE("PCM-IN1 Capture Switch", 0x23, 2, HDA_OUTPUT),
12293         HDA_CODEC_VOLUME("PCM-IN2 Capture Volume", 0x24, 0x0, HDA_OUTPUT),
12294         HDA_BIND_MUTE("PCM-IN2 Capture Switch", 0x24, 2, HDA_OUTPUT),
12295
12296         /* Modes for retasking pin widgets */
12297         ALC_PIN_MODE("LINE-OUT pin mode", 0x14, ALC_PIN_DIR_INOUT),
12298         ALC_PIN_MODE("HP-OUT pin mode", 0x15, ALC_PIN_DIR_INOUT),
12299         ALC_PIN_MODE("MIC1 pin mode", 0x18, ALC_PIN_DIR_INOUT),
12300         ALC_PIN_MODE("LINE1 pin mode", 0x1a, ALC_PIN_DIR_INOUT),
12301
12302         /* Controls for GPIO pins, assuming they are configured as outputs */
12303         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
12304         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
12305         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
12306         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
12307
12308         /* Switches to allow the digital SPDIF output pin to be enabled.
12309          * The ALC268 does not have an SPDIF input.
12310          */
12311         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x06, 0x01),
12312
12313         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
12314          * this output to turn on an external amplifier.
12315          */
12316         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
12317         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
12318
12319         { } /* end */
12320 };
12321 #endif
12322
12323 /* create input playback/capture controls for the given pin */
12324 static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
12325                                     const char *ctlname, int idx)
12326 {
12327         hda_nid_t dac;
12328         int err;
12329
12330         switch (nid) {
12331         case 0x14:
12332         case 0x16:
12333                 dac = 0x02;
12334                 break;
12335         case 0x15:
12336                 dac = 0x03;
12337                 break;
12338         default:
12339                 return 0;
12340         }
12341         if (spec->multiout.dac_nids[0] != dac &&
12342             spec->multiout.dac_nids[1] != dac) {
12343                 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname,
12344                                   HDA_COMPOSE_AMP_VAL(dac, 3, idx,
12345                                                       HDA_OUTPUT));
12346                 if (err < 0)
12347                         return err;
12348                 spec->multiout.dac_nids[spec->multiout.num_dacs++] = dac;
12349         }
12350
12351         if (nid != 0x16)
12352                 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname,
12353                           HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
12354         else /* mono */
12355                 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname,
12356                           HDA_COMPOSE_AMP_VAL(nid, 2, idx, HDA_OUTPUT));
12357         if (err < 0)
12358                 return err;
12359         return 0;
12360 }
12361
12362 /* add playback controls from the parsed DAC table */
12363 static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
12364                                              const struct auto_pin_cfg *cfg)
12365 {
12366         hda_nid_t nid;
12367         int err;
12368
12369         spec->multiout.dac_nids = spec->private_dac_nids;
12370
12371         nid = cfg->line_out_pins[0];
12372         if (nid) {
12373                 const char *name;
12374                 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
12375                         name = "Speaker";
12376                 else
12377                         name = "Front";
12378                 err = alc268_new_analog_output(spec, nid, name, 0);
12379                 if (err < 0)
12380                         return err;
12381         }
12382
12383         nid = cfg->speaker_pins[0];
12384         if (nid == 0x1d) {
12385                 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, "Speaker",
12386                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
12387                 if (err < 0)
12388                         return err;
12389         } else {
12390                 err = alc268_new_analog_output(spec, nid, "Speaker", 0);
12391                 if (err < 0)
12392                         return err;
12393         }
12394         nid = cfg->hp_pins[0];
12395         if (nid) {
12396                 err = alc268_new_analog_output(spec, nid, "Headphone", 0);
12397                 if (err < 0)
12398                         return err;
12399         }
12400
12401         nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
12402         if (nid == 0x16) {
12403                 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, "Mono",
12404                                   HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT));
12405                 if (err < 0)
12406                         return err;
12407         }
12408         return 0;
12409 }
12410
12411 /* create playback/capture controls for input pins */
12412 static int alc268_auto_create_input_ctls(struct hda_codec *codec,
12413                                                 const struct auto_pin_cfg *cfg)
12414 {
12415         return alc_auto_create_input_ctls(codec, cfg, 0, 0x23, 0x24);
12416 }
12417
12418 static void alc268_auto_set_output_and_unmute(struct hda_codec *codec,
12419                                               hda_nid_t nid, int pin_type)
12420 {
12421         int idx;
12422
12423         alc_set_pin_output(codec, nid, pin_type);
12424         if (nid == 0x14 || nid == 0x16)
12425                 idx = 0;
12426         else
12427                 idx = 1;
12428         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
12429 }
12430
12431 static void alc268_auto_init_multi_out(struct hda_codec *codec)
12432 {
12433         struct alc_spec *spec = codec->spec;
12434         hda_nid_t nid = spec->autocfg.line_out_pins[0];
12435         if (nid) {
12436                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
12437                 alc268_auto_set_output_and_unmute(codec, nid, pin_type);
12438         }
12439 }
12440
12441 static void alc268_auto_init_hp_out(struct hda_codec *codec)
12442 {
12443         struct alc_spec *spec = codec->spec;
12444         hda_nid_t pin;
12445
12446         pin = spec->autocfg.hp_pins[0];
12447         if (pin)
12448                 alc268_auto_set_output_and_unmute(codec, pin, PIN_HP);
12449         pin = spec->autocfg.speaker_pins[0];
12450         if (pin)
12451                 alc268_auto_set_output_and_unmute(codec, pin, PIN_OUT);
12452 }
12453
12454 static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
12455 {
12456         struct alc_spec *spec = codec->spec;
12457         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
12458         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
12459         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
12460         unsigned int    dac_vol1, dac_vol2;
12461
12462         if (line_nid == 0x1d || speaker_nid == 0x1d) {
12463                 snd_hda_codec_write(codec, speaker_nid, 0,
12464                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
12465                 /* mute mixer inputs from 0x1d */
12466                 snd_hda_codec_write(codec, 0x0f, 0,
12467                                     AC_VERB_SET_AMP_GAIN_MUTE,
12468                                     AMP_IN_UNMUTE(1));
12469                 snd_hda_codec_write(codec, 0x10, 0,
12470                                     AC_VERB_SET_AMP_GAIN_MUTE,
12471                                     AMP_IN_UNMUTE(1));
12472         } else {
12473                 /* unmute mixer inputs from 0x1d */
12474                 snd_hda_codec_write(codec, 0x0f, 0,
12475                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
12476                 snd_hda_codec_write(codec, 0x10, 0,
12477                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
12478         }
12479
12480         dac_vol1 = dac_vol2 = 0xb000 | 0x40;    /* set max volume  */
12481         if (line_nid == 0x14)
12482                 dac_vol2 = AMP_OUT_ZERO;
12483         else if (line_nid == 0x15)
12484                 dac_vol1 = AMP_OUT_ZERO;
12485         if (hp_nid == 0x14)
12486                 dac_vol2 = AMP_OUT_ZERO;
12487         else if (hp_nid == 0x15)
12488                 dac_vol1 = AMP_OUT_ZERO;
12489         if (line_nid != 0x16 || hp_nid != 0x16 ||
12490             spec->autocfg.line_out_pins[1] != 0x16 ||
12491             spec->autocfg.line_out_pins[2] != 0x16)
12492                 dac_vol1 = dac_vol2 = AMP_OUT_ZERO;
12493
12494         snd_hda_codec_write(codec, 0x02, 0,
12495                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol1);
12496         snd_hda_codec_write(codec, 0x03, 0,
12497                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol2);
12498 }
12499
12500 /* pcm configuration: identical with ALC880 */
12501 #define alc268_pcm_analog_playback      alc880_pcm_analog_playback
12502 #define alc268_pcm_analog_capture       alc880_pcm_analog_capture
12503 #define alc268_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
12504 #define alc268_pcm_digital_playback     alc880_pcm_digital_playback
12505
12506 /*
12507  * BIOS auto configuration
12508  */
12509 static int alc268_parse_auto_config(struct hda_codec *codec)
12510 {
12511         struct alc_spec *spec = codec->spec;
12512         int err;
12513         static hda_nid_t alc268_ignore[] = { 0 };
12514
12515         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
12516                                            alc268_ignore);
12517         if (err < 0)
12518                 return err;
12519         if (!spec->autocfg.line_outs) {
12520                 if (spec->autocfg.dig_outs || spec->autocfg.dig_in_pin) {
12521                         spec->multiout.max_channels = 2;
12522                         spec->no_analog = 1;
12523                         goto dig_only;
12524                 }
12525                 return 0; /* can't find valid BIOS pin config */
12526         }
12527         err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
12528         if (err < 0)
12529                 return err;
12530         err = alc268_auto_create_input_ctls(codec, &spec->autocfg);
12531         if (err < 0)
12532                 return err;
12533
12534         spec->multiout.max_channels = 2;
12535
12536  dig_only:
12537         /* digital only support output */
12538         if (spec->autocfg.dig_outs) {
12539                 spec->multiout.dig_out_nid = ALC268_DIGOUT_NID;
12540                 spec->dig_out_type = spec->autocfg.dig_out_type[0];
12541         }
12542         if (spec->kctls.list)
12543                 add_mixer(spec, spec->kctls.list);
12544
12545         if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d)
12546                 add_mixer(spec, alc268_beep_mixer);
12547
12548         add_verb(spec, alc268_volume_init_verbs);
12549         spec->num_mux_defs = 2;
12550         spec->input_mux = &spec->private_imux[0];
12551
12552         err = alc_auto_add_mic_boost(codec);
12553         if (err < 0)
12554                 return err;
12555
12556         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
12557
12558         return 1;
12559 }
12560
12561 #define alc268_auto_init_analog_input   alc882_auto_init_analog_input
12562
12563 /* init callback for auto-configuration model -- overriding the default init */
12564 static void alc268_auto_init(struct hda_codec *codec)
12565 {
12566         struct alc_spec *spec = codec->spec;
12567         alc268_auto_init_multi_out(codec);
12568         alc268_auto_init_hp_out(codec);
12569         alc268_auto_init_mono_speaker_out(codec);
12570         alc268_auto_init_analog_input(codec);
12571         if (spec->unsol_event)
12572                 alc_inithook(codec);
12573 }
12574
12575 /*
12576  * configuration and preset
12577  */
12578 static const char *alc268_models[ALC268_MODEL_LAST] = {
12579         [ALC267_QUANTA_IL1]     = "quanta-il1",
12580         [ALC268_3ST]            = "3stack",
12581         [ALC268_TOSHIBA]        = "toshiba",
12582         [ALC268_ACER]           = "acer",
12583         [ALC268_ACER_DMIC]      = "acer-dmic",
12584         [ALC268_ACER_ASPIRE_ONE]        = "acer-aspire",
12585         [ALC268_DELL]           = "dell",
12586         [ALC268_ZEPTO]          = "zepto",
12587 #ifdef CONFIG_SND_DEBUG
12588         [ALC268_TEST]           = "test",
12589 #endif
12590         [ALC268_AUTO]           = "auto",
12591 };
12592
12593 static struct snd_pci_quirk alc268_cfg_tbl[] = {
12594         SND_PCI_QUIRK(0x1025, 0x011e, "Acer Aspire 5720z", ALC268_ACER),
12595         SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
12596         SND_PCI_QUIRK(0x1025, 0x012e, "Acer Aspire 5310", ALC268_ACER),
12597         SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
12598         SND_PCI_QUIRK(0x1025, 0x0136, "Acer Aspire 5315", ALC268_ACER),
12599         SND_PCI_QUIRK(0x1025, 0x015b, "Acer Aspire One",
12600                                                 ALC268_ACER_ASPIRE_ONE),
12601         SND_PCI_QUIRK(0x1028, 0x0253, "Dell OEM", ALC268_DELL),
12602         SND_PCI_QUIRK_MASK(0x1028, 0xfff0, 0x02b0,
12603                         "Dell Inspiron Mini9/Vostro A90", ALC268_DELL),
12604         /* almost compatible with toshiba but with optional digital outs;
12605          * auto-probing seems working fine
12606          */
12607         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP TX25xx series",
12608                            ALC268_AUTO),
12609         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
12610         SND_PCI_QUIRK(0x1170, 0x0040, "ZEPTO", ALC268_ZEPTO),
12611         SND_PCI_QUIRK(0x14c0, 0x0025, "COMPAL IFL90/JFL-92", ALC268_TOSHIBA),
12612         SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER),
12613         SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1),
12614         SND_PCI_QUIRK(0x1854, 0x1775, "LG R510", ALC268_DELL),
12615         {}
12616 };
12617
12618 /* Toshiba laptops have no unique PCI SSID but only codec SSID */
12619 static struct snd_pci_quirk alc268_ssid_cfg_tbl[] = {
12620         SND_PCI_QUIRK(0x1179, 0xff0a, "TOSHIBA X-200", ALC268_AUTO),
12621         SND_PCI_QUIRK(0x1179, 0xff0e, "TOSHIBA X-200 HDMI", ALC268_AUTO),
12622         SND_PCI_QUIRK_MASK(0x1179, 0xff00, 0xff00, "TOSHIBA A/Lx05",
12623                            ALC268_TOSHIBA),
12624         {}
12625 };
12626
12627 static struct alc_config_preset alc268_presets[] = {
12628         [ALC267_QUANTA_IL1] = {
12629                 .mixers = { alc267_quanta_il1_mixer, alc268_beep_mixer,
12630                             alc268_capture_nosrc_mixer },
12631                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12632                                 alc267_quanta_il1_verbs },
12633                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12634                 .dac_nids = alc268_dac_nids,
12635                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12636                 .adc_nids = alc268_adc_nids_alt,
12637                 .hp_nid = 0x03,
12638                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12639                 .channel_mode = alc268_modes,
12640                 .unsol_event = alc_sku_unsol_event,
12641                 .setup = alc267_quanta_il1_setup,
12642                 .init_hook = alc_inithook,
12643         },
12644         [ALC268_3ST] = {
12645                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
12646                             alc268_beep_mixer },
12647                 .init_verbs = { alc268_base_init_verbs },
12648                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12649                 .dac_nids = alc268_dac_nids,
12650                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12651                 .adc_nids = alc268_adc_nids_alt,
12652                 .capsrc_nids = alc268_capsrc_nids,
12653                 .hp_nid = 0x03,
12654                 .dig_out_nid = ALC268_DIGOUT_NID,
12655                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12656                 .channel_mode = alc268_modes,
12657                 .input_mux = &alc268_capture_source,
12658         },
12659         [ALC268_TOSHIBA] = {
12660                 .mixers = { alc268_toshiba_mixer, alc268_capture_alt_mixer,
12661                             alc268_beep_mixer },
12662                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12663                                 alc268_toshiba_verbs },
12664                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12665                 .dac_nids = alc268_dac_nids,
12666                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12667                 .adc_nids = alc268_adc_nids_alt,
12668                 .capsrc_nids = alc268_capsrc_nids,
12669                 .hp_nid = 0x03,
12670                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12671                 .channel_mode = alc268_modes,
12672                 .input_mux = &alc268_capture_source,
12673                 .unsol_event = alc268_toshiba_unsol_event,
12674                 .setup = alc268_toshiba_setup,
12675                 .init_hook = alc268_toshiba_automute,
12676         },
12677         [ALC268_ACER] = {
12678                 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer,
12679                             alc268_beep_mixer },
12680                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12681                                 alc268_acer_verbs },
12682                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12683                 .dac_nids = alc268_dac_nids,
12684                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12685                 .adc_nids = alc268_adc_nids_alt,
12686                 .capsrc_nids = alc268_capsrc_nids,
12687                 .hp_nid = 0x02,
12688                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12689                 .channel_mode = alc268_modes,
12690                 .input_mux = &alc268_acer_capture_source,
12691                 .unsol_event = alc268_acer_unsol_event,
12692                 .init_hook = alc268_acer_init_hook,
12693         },
12694         [ALC268_ACER_DMIC] = {
12695                 .mixers = { alc268_acer_dmic_mixer, alc268_capture_alt_mixer,
12696                             alc268_beep_mixer },
12697                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12698                                 alc268_acer_verbs },
12699                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12700                 .dac_nids = alc268_dac_nids,
12701                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12702                 .adc_nids = alc268_adc_nids_alt,
12703                 .capsrc_nids = alc268_capsrc_nids,
12704                 .hp_nid = 0x02,
12705                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12706                 .channel_mode = alc268_modes,
12707                 .input_mux = &alc268_acer_dmic_capture_source,
12708                 .unsol_event = alc268_acer_unsol_event,
12709                 .init_hook = alc268_acer_init_hook,
12710         },
12711         [ALC268_ACER_ASPIRE_ONE] = {
12712                 .mixers = { alc268_acer_aspire_one_mixer,
12713                             alc268_beep_mixer,
12714                             alc268_capture_nosrc_mixer },
12715                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12716                                 alc268_acer_aspire_one_verbs },
12717                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12718                 .dac_nids = alc268_dac_nids,
12719                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12720                 .adc_nids = alc268_adc_nids_alt,
12721                 .capsrc_nids = alc268_capsrc_nids,
12722                 .hp_nid = 0x03,
12723                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12724                 .channel_mode = alc268_modes,
12725                 .unsol_event = alc268_acer_lc_unsol_event,
12726                 .setup = alc268_acer_lc_setup,
12727                 .init_hook = alc268_acer_lc_init_hook,
12728         },
12729         [ALC268_DELL] = {
12730                 .mixers = { alc268_dell_mixer, alc268_beep_mixer,
12731                             alc268_capture_nosrc_mixer },
12732                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12733                                 alc268_dell_verbs },
12734                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12735                 .dac_nids = alc268_dac_nids,
12736                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12737                 .adc_nids = alc268_adc_nids_alt,
12738                 .capsrc_nids = alc268_capsrc_nids,
12739                 .hp_nid = 0x02,
12740                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12741                 .channel_mode = alc268_modes,
12742                 .unsol_event = alc_sku_unsol_event,
12743                 .setup = alc268_dell_setup,
12744                 .init_hook = alc_inithook,
12745         },
12746         [ALC268_ZEPTO] = {
12747                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
12748                             alc268_beep_mixer },
12749                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12750                                 alc268_toshiba_verbs },
12751                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12752                 .dac_nids = alc268_dac_nids,
12753                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12754                 .adc_nids = alc268_adc_nids_alt,
12755                 .capsrc_nids = alc268_capsrc_nids,
12756                 .hp_nid = 0x03,
12757                 .dig_out_nid = ALC268_DIGOUT_NID,
12758                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12759                 .channel_mode = alc268_modes,
12760                 .input_mux = &alc268_capture_source,
12761                 .setup = alc268_toshiba_setup,
12762                 .init_hook = alc268_toshiba_automute,
12763         },
12764 #ifdef CONFIG_SND_DEBUG
12765         [ALC268_TEST] = {
12766                 .mixers = { alc268_test_mixer, alc268_capture_mixer },
12767                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12768                                 alc268_volume_init_verbs },
12769                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12770                 .dac_nids = alc268_dac_nids,
12771                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12772                 .adc_nids = alc268_adc_nids_alt,
12773                 .capsrc_nids = alc268_capsrc_nids,
12774                 .hp_nid = 0x03,
12775                 .dig_out_nid = ALC268_DIGOUT_NID,
12776                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12777                 .channel_mode = alc268_modes,
12778                 .input_mux = &alc268_capture_source,
12779         },
12780 #endif
12781 };
12782
12783 static int patch_alc268(struct hda_codec *codec)
12784 {
12785         struct alc_spec *spec;
12786         int board_config;
12787         int i, has_beep, err;
12788
12789         spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
12790         if (spec == NULL)
12791                 return -ENOMEM;
12792
12793         codec->spec = spec;
12794
12795         board_config = snd_hda_check_board_config(codec, ALC268_MODEL_LAST,
12796                                                   alc268_models,
12797                                                   alc268_cfg_tbl);
12798
12799         if (board_config < 0 || board_config >= ALC268_MODEL_LAST)
12800                 board_config = snd_hda_check_board_codec_sid_config(codec,
12801                         ALC882_MODEL_LAST, alc268_models, alc268_ssid_cfg_tbl);
12802
12803         if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
12804                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
12805                        codec->chip_name);
12806                 board_config = ALC268_AUTO;
12807         }
12808
12809         if (board_config == ALC268_AUTO) {
12810                 /* automatic parse from the BIOS config */
12811                 err = alc268_parse_auto_config(codec);
12812                 if (err < 0) {
12813                         alc_free(codec);
12814                         return err;
12815                 } else if (!err) {
12816                         printk(KERN_INFO
12817                                "hda_codec: Cannot set up configuration "
12818                                "from BIOS.  Using base mode...\n");
12819                         board_config = ALC268_3ST;
12820                 }
12821         }
12822
12823         if (board_config != ALC268_AUTO)
12824                 setup_preset(codec, &alc268_presets[board_config]);
12825
12826         spec->stream_analog_playback = &alc268_pcm_analog_playback;
12827         spec->stream_analog_capture = &alc268_pcm_analog_capture;
12828         spec->stream_analog_alt_capture = &alc268_pcm_analog_alt_capture;
12829
12830         spec->stream_digital_playback = &alc268_pcm_digital_playback;
12831
12832         has_beep = 0;
12833         for (i = 0; i < spec->num_mixers; i++) {
12834                 if (spec->mixers[i] == alc268_beep_mixer) {
12835                         has_beep = 1;
12836                         break;
12837                 }
12838         }
12839
12840         if (has_beep) {
12841                 err = snd_hda_attach_beep_device(codec, 0x1);
12842                 if (err < 0) {
12843                         alc_free(codec);
12844                         return err;
12845                 }
12846                 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
12847                         /* override the amp caps for beep generator */
12848                         snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
12849                                           (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
12850                                           (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
12851                                           (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
12852                                           (0 << AC_AMPCAP_MUTE_SHIFT));
12853         }
12854
12855         if (!spec->no_analog && !spec->adc_nids && spec->input_mux) {
12856                 /* check whether NID 0x07 is valid */
12857                 unsigned int wcap = get_wcaps(codec, 0x07);
12858                 int i;
12859
12860                 spec->capsrc_nids = alc268_capsrc_nids;
12861                 /* get type */
12862                 wcap = get_wcaps_type(wcap);
12863                 if (spec->auto_mic ||
12864                     wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
12865                         spec->adc_nids = alc268_adc_nids_alt;
12866                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt);
12867                         if (spec->auto_mic)
12868                                 fixup_automic_adc(codec);
12869                         if (spec->auto_mic || spec->input_mux->num_items == 1)
12870                                 add_mixer(spec, alc268_capture_nosrc_mixer);
12871                         else
12872                                 add_mixer(spec, alc268_capture_alt_mixer);
12873                 } else {
12874                         spec->adc_nids = alc268_adc_nids;
12875                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids);
12876                         add_mixer(spec, alc268_capture_mixer);
12877                 }
12878                 /* set default input source */
12879                 for (i = 0; i < spec->num_adc_nids; i++)
12880                         snd_hda_codec_write_cache(codec, alc268_capsrc_nids[i],
12881                                 0, AC_VERB_SET_CONNECT_SEL,
12882                                 i < spec->num_mux_defs ?
12883                                 spec->input_mux[i].items[0].index :
12884                                 spec->input_mux->items[0].index);
12885         }
12886
12887         spec->vmaster_nid = 0x02;
12888
12889         codec->patch_ops = alc_patch_ops;
12890         if (board_config == ALC268_AUTO)
12891                 spec->init_hook = alc268_auto_init;
12892
12893         codec->proc_widget_hook = print_realtek_coef;
12894
12895         return 0;
12896 }
12897
12898 /*
12899  *  ALC269 channel source setting (2 channel)
12900  */
12901 #define ALC269_DIGOUT_NID       ALC880_DIGOUT_NID
12902
12903 #define alc269_dac_nids         alc260_dac_nids
12904
12905 static hda_nid_t alc269_adc_nids[1] = {
12906         /* ADC1 */
12907         0x08,
12908 };
12909
12910 static hda_nid_t alc269_capsrc_nids[1] = {
12911         0x23,
12912 };
12913
12914 /* NOTE: ADC2 (0x07) is connected from a recording *MIXER* (0x24),
12915  *       not a mux!
12916  */
12917
12918 #define alc269_modes            alc260_modes
12919 #define alc269_capture_source   alc880_lg_lw_capture_source
12920
12921 static struct snd_kcontrol_new alc269_base_mixer[] = {
12922         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12923         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12924         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
12925         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
12926         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12927         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12928         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12929         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12930         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12931         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
12932         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12933         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
12934         { } /* end */
12935 };
12936
12937 static struct snd_kcontrol_new alc269_quanta_fl1_mixer[] = {
12938         /* output mixer control */
12939         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
12940         {
12941                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12942                 .name = "Master Playback Switch",
12943                 .info = snd_hda_mixer_amp_switch_info,
12944                 .get = snd_hda_mixer_amp_switch_get,
12945                 .put = alc268_acer_master_sw_put,
12946                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
12947         },
12948         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12949         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12950         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12951         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12952         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12953         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
12954         { }
12955 };
12956
12957 static struct snd_kcontrol_new alc269_lifebook_mixer[] = {
12958         /* output mixer control */
12959         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
12960         {
12961                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12962                 .name = "Master Playback Switch",
12963                 .info = snd_hda_mixer_amp_switch_info,
12964                 .get = snd_hda_mixer_amp_switch_get,
12965                 .put = alc268_acer_master_sw_put,
12966                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
12967         },
12968         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12969         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12970         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12971         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12972         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12973         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
12974         HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x0b, 0x03, HDA_INPUT),
12975         HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x0b, 0x03, HDA_INPUT),
12976         HDA_CODEC_VOLUME("Dock Mic Boost", 0x1b, 0, HDA_INPUT),
12977         { }
12978 };
12979
12980 static struct snd_kcontrol_new alc269_eeepc_mixer[] = {
12981         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12982         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12983         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12984         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12985         { } /* end */
12986 };
12987
12988 /* capture mixer elements */
12989 static struct snd_kcontrol_new alc269_epc_capture_mixer[] = {
12990         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
12991         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
12992         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12993         { } /* end */
12994 };
12995
12996 /* FSC amilo */
12997 #define alc269_fujitsu_mixer    alc269_eeepc_mixer
12998
12999 static struct hda_verb alc269_quanta_fl1_verbs[] = {
13000         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
13001         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13002         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13003         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
13004         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
13005         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13006         { }
13007 };
13008
13009 static struct hda_verb alc269_lifebook_verbs[] = {
13010         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
13011         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
13012         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13013         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13014         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
13015         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13016         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13017         {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
13018         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
13019         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13020         { }
13021 };
13022
13023 /* toggle speaker-output according to the hp-jack state */
13024 static void alc269_quanta_fl1_speaker_automute(struct hda_codec *codec)
13025 {
13026         unsigned int present;
13027         unsigned char bits;
13028
13029         present = snd_hda_codec_read(codec, 0x15, 0,
13030                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13031         bits = present ? AMP_IN_MUTE(0) : 0;
13032         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
13033                         AMP_IN_MUTE(0), bits);
13034         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
13035                         AMP_IN_MUTE(0), bits);
13036
13037         snd_hda_codec_write(codec, 0x20, 0,
13038                         AC_VERB_SET_COEF_INDEX, 0x0c);
13039         snd_hda_codec_write(codec, 0x20, 0,
13040                         AC_VERB_SET_PROC_COEF, 0x680);
13041
13042         snd_hda_codec_write(codec, 0x20, 0,
13043                         AC_VERB_SET_COEF_INDEX, 0x0c);
13044         snd_hda_codec_write(codec, 0x20, 0,
13045                         AC_VERB_SET_PROC_COEF, 0x480);
13046 }
13047
13048 /* toggle speaker-output according to the hp-jacks state */
13049 static void alc269_lifebook_speaker_automute(struct hda_codec *codec)
13050 {
13051         unsigned int present;
13052         unsigned char bits;
13053
13054         /* Check laptop headphone socket */
13055         present = snd_hda_codec_read(codec, 0x15, 0,
13056                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13057
13058         /* Check port replicator headphone socket */
13059         present |= snd_hda_codec_read(codec, 0x1a, 0,
13060                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13061
13062         bits = present ? AMP_IN_MUTE(0) : 0;
13063         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
13064                         AMP_IN_MUTE(0), bits);
13065         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
13066                         AMP_IN_MUTE(0), bits);
13067
13068         snd_hda_codec_write(codec, 0x20, 0,
13069                         AC_VERB_SET_COEF_INDEX, 0x0c);
13070         snd_hda_codec_write(codec, 0x20, 0,
13071                         AC_VERB_SET_PROC_COEF, 0x680);
13072
13073         snd_hda_codec_write(codec, 0x20, 0,
13074                         AC_VERB_SET_COEF_INDEX, 0x0c);
13075         snd_hda_codec_write(codec, 0x20, 0,
13076                         AC_VERB_SET_PROC_COEF, 0x480);
13077 }
13078
13079 static void alc269_lifebook_mic_autoswitch(struct hda_codec *codec)
13080 {
13081         unsigned int present_laptop;
13082         unsigned int present_dock;
13083
13084         present_laptop = snd_hda_codec_read(codec, 0x18, 0,
13085                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13086
13087         present_dock = snd_hda_codec_read(codec, 0x1b, 0,
13088                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13089
13090         /* Laptop mic port overrides dock mic port, design decision */
13091         if (present_dock)
13092                 snd_hda_codec_write(codec, 0x23, 0,
13093                                 AC_VERB_SET_CONNECT_SEL, 0x3);
13094         if (present_laptop)
13095                 snd_hda_codec_write(codec, 0x23, 0,
13096                                 AC_VERB_SET_CONNECT_SEL, 0x0);
13097         if (!present_dock && !present_laptop)
13098                 snd_hda_codec_write(codec, 0x23, 0,
13099                                 AC_VERB_SET_CONNECT_SEL, 0x1);
13100 }
13101
13102 static void alc269_quanta_fl1_unsol_event(struct hda_codec *codec,
13103                                     unsigned int res)
13104 {
13105         switch (res >> 26) {
13106         case ALC880_HP_EVENT:
13107                 alc269_quanta_fl1_speaker_automute(codec);
13108                 break;
13109         case ALC880_MIC_EVENT:
13110                 alc_mic_automute(codec);
13111                 break;
13112         }
13113 }
13114
13115 static void alc269_lifebook_unsol_event(struct hda_codec *codec,
13116                                         unsigned int res)
13117 {
13118         if ((res >> 26) == ALC880_HP_EVENT)
13119                 alc269_lifebook_speaker_automute(codec);
13120         if ((res >> 26) == ALC880_MIC_EVENT)
13121                 alc269_lifebook_mic_autoswitch(codec);
13122 }
13123
13124 static void alc269_quanta_fl1_setup(struct hda_codec *codec)
13125 {
13126         struct alc_spec *spec = codec->spec;
13127         spec->ext_mic.pin = 0x18;
13128         spec->ext_mic.mux_idx = 0;
13129         spec->int_mic.pin = 0x19;
13130         spec->int_mic.mux_idx = 1;
13131         spec->auto_mic = 1;
13132 }
13133
13134 static void alc269_quanta_fl1_init_hook(struct hda_codec *codec)
13135 {
13136         alc269_quanta_fl1_speaker_automute(codec);
13137         alc_mic_automute(codec);
13138 }
13139
13140 static void alc269_lifebook_init_hook(struct hda_codec *codec)
13141 {
13142         alc269_lifebook_speaker_automute(codec);
13143         alc269_lifebook_mic_autoswitch(codec);
13144 }
13145
13146 static struct hda_verb alc269_eeepc_dmic_init_verbs[] = {
13147         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
13148         {0x23, AC_VERB_SET_CONNECT_SEL, 0x05},
13149         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
13150         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))},
13151         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13152         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
13153         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13154         {}
13155 };
13156
13157 static struct hda_verb alc269_eeepc_amic_init_verbs[] = {
13158         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
13159         {0x23, AC_VERB_SET_CONNECT_SEL, 0x01},
13160         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
13161         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x701b | (0x00 << 8))},
13162         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
13163         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13164         {}
13165 };
13166
13167 /* toggle speaker-output according to the hp-jack state */
13168 static void alc269_speaker_automute(struct hda_codec *codec)
13169 {
13170         unsigned int present;
13171         unsigned char bits;
13172
13173         present = snd_hda_codec_read(codec, 0x15, 0,
13174                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13175         bits = present ? AMP_IN_MUTE(0) : 0;
13176         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
13177                                 AMP_IN_MUTE(0), bits);
13178         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
13179                                 AMP_IN_MUTE(0), bits);
13180 }
13181
13182 /* unsolicited event for HP jack sensing */
13183 static void alc269_eeepc_unsol_event(struct hda_codec *codec,
13184                                      unsigned int res)
13185 {
13186         switch (res >> 26) {
13187         case ALC880_HP_EVENT:
13188                 alc269_speaker_automute(codec);
13189                 break;
13190         case ALC880_MIC_EVENT:
13191                 alc_mic_automute(codec);
13192                 break;
13193         }
13194 }
13195
13196 static void alc269_eeepc_dmic_setup(struct hda_codec *codec)
13197 {
13198         struct alc_spec *spec = codec->spec;
13199         spec->ext_mic.pin = 0x18;
13200         spec->ext_mic.mux_idx = 0;
13201         spec->int_mic.pin = 0x12;
13202         spec->int_mic.mux_idx = 5;
13203         spec->auto_mic = 1;
13204 }
13205
13206 static void alc269_eeepc_amic_setup(struct hda_codec *codec)
13207 {
13208         struct alc_spec *spec = codec->spec;
13209         spec->ext_mic.pin = 0x18;
13210         spec->ext_mic.mux_idx = 0;
13211         spec->int_mic.pin = 0x19;
13212         spec->int_mic.mux_idx = 1;
13213         spec->auto_mic = 1;
13214 }
13215
13216 static void alc269_eeepc_inithook(struct hda_codec *codec)
13217 {
13218         alc269_speaker_automute(codec);
13219         alc_mic_automute(codec);
13220 }
13221
13222 /*
13223  * generic initialization of ADC, input mixers and output mixers
13224  */
13225 static struct hda_verb alc269_init_verbs[] = {
13226         /*
13227          * Unmute ADC0 and set the default input to mic-in
13228          */
13229         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13230
13231         /* Mute input amps (PCBeep, Line In, Mic 1 & Mic 2) of the
13232          * analog-loopback mixer widget
13233          * Note: PASD motherboards uses the Line In 2 as the input for
13234          * front panel mic (mic 2)
13235          */
13236         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
13237         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13238         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13239         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
13240         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
13241         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
13242
13243         /*
13244          * Set up output mixers (0x0c - 0x0e)
13245          */
13246         /* set vol=0 to output mixers */
13247         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13248         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13249
13250         /* set up input amps for analog loopback */
13251         /* Amp Indices: DAC = 0, mixer = 1 */
13252         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13253         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13254         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13255         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13256         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13257         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13258
13259         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13260         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13261         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13262         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13263         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13264         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13265         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13266
13267         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13268         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13269         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13270         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13271         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13272         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13273         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13274
13275         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
13276         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
13277
13278         /* FIXME: use matrix-type input source selection */
13279         /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
13280         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
13281         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13282         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13283         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
13284         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
13285
13286         /* set EAPD */
13287         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
13288         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
13289         { }
13290 };
13291
13292 #define alc269_auto_create_multi_out_ctls \
13293         alc268_auto_create_multi_out_ctls
13294 #define alc269_auto_create_input_ctls \
13295         alc268_auto_create_input_ctls
13296
13297 #ifdef CONFIG_SND_HDA_POWER_SAVE
13298 #define alc269_loopbacks        alc880_loopbacks
13299 #endif
13300
13301 /* pcm configuration: identical with ALC880 */
13302 #define alc269_pcm_analog_playback      alc880_pcm_analog_playback
13303 #define alc269_pcm_analog_capture       alc880_pcm_analog_capture
13304 #define alc269_pcm_digital_playback     alc880_pcm_digital_playback
13305 #define alc269_pcm_digital_capture      alc880_pcm_digital_capture
13306
13307 static struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
13308         .substreams = 1,
13309         .channels_min = 2,
13310         .channels_max = 8,
13311         .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
13312         /* NID is set in alc_build_pcms */
13313         .ops = {
13314                 .open = alc880_playback_pcm_open,
13315                 .prepare = alc880_playback_pcm_prepare,
13316                 .cleanup = alc880_playback_pcm_cleanup
13317         },
13318 };
13319
13320 static struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
13321         .substreams = 1,
13322         .channels_min = 2,
13323         .channels_max = 2,
13324         .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
13325         /* NID is set in alc_build_pcms */
13326 };
13327
13328 /*
13329  * BIOS auto configuration
13330  */
13331 static int alc269_parse_auto_config(struct hda_codec *codec)
13332 {
13333         struct alc_spec *spec = codec->spec;
13334         int err;
13335         static hda_nid_t alc269_ignore[] = { 0x1d, 0 };
13336
13337         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
13338                                            alc269_ignore);
13339         if (err < 0)
13340                 return err;
13341
13342         err = alc269_auto_create_multi_out_ctls(spec, &spec->autocfg);
13343         if (err < 0)
13344                 return err;
13345         err = alc269_auto_create_input_ctls(codec, &spec->autocfg);
13346         if (err < 0)
13347                 return err;
13348
13349         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
13350
13351         if (spec->autocfg.dig_outs)
13352                 spec->multiout.dig_out_nid = ALC269_DIGOUT_NID;
13353
13354         if (spec->kctls.list)
13355                 add_mixer(spec, spec->kctls.list);
13356
13357         add_verb(spec, alc269_init_verbs);
13358         spec->num_mux_defs = 1;
13359         spec->input_mux = &spec->private_imux[0];
13360         /* set default input source */
13361         snd_hda_codec_write_cache(codec, alc269_capsrc_nids[0],
13362                                   0, AC_VERB_SET_CONNECT_SEL,
13363                                   spec->input_mux->items[0].index);
13364
13365         err = alc_auto_add_mic_boost(codec);
13366         if (err < 0)
13367                 return err;
13368
13369         if (!spec->cap_mixer && !spec->no_analog)
13370                 set_capture_mixer(codec);
13371
13372         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
13373
13374         return 1;
13375 }
13376
13377 #define alc269_auto_init_multi_out      alc268_auto_init_multi_out
13378 #define alc269_auto_init_hp_out         alc268_auto_init_hp_out
13379 #define alc269_auto_init_analog_input   alc882_auto_init_analog_input
13380
13381
13382 /* init callback for auto-configuration model -- overriding the default init */
13383 static void alc269_auto_init(struct hda_codec *codec)
13384 {
13385         struct alc_spec *spec = codec->spec;
13386         alc269_auto_init_multi_out(codec);
13387         alc269_auto_init_hp_out(codec);
13388         alc269_auto_init_analog_input(codec);
13389         if (spec->unsol_event)
13390                 alc_inithook(codec);
13391 }
13392
13393 /*
13394  * configuration and preset
13395  */
13396 static const char *alc269_models[ALC269_MODEL_LAST] = {
13397         [ALC269_BASIC]                  = "basic",
13398         [ALC269_QUANTA_FL1]             = "quanta",
13399         [ALC269_ASUS_EEEPC_P703]        = "eeepc-p703",
13400         [ALC269_ASUS_EEEPC_P901]        = "eeepc-p901",
13401         [ALC269_FUJITSU]                = "fujitsu",
13402         [ALC269_LIFEBOOK]               = "lifebook",
13403         [ALC269_AUTO]                   = "auto",
13404 };
13405
13406 static struct snd_pci_quirk alc269_cfg_tbl[] = {
13407         SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_QUANTA_FL1),
13408         SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
13409                       ALC269_ASUS_EEEPC_P703),
13410         SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_ASUS_EEEPC_P703),
13411         SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_ASUS_EEEPC_P703),
13412         SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_ASUS_EEEPC_P703),
13413         SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_ASUS_EEEPC_P703),
13414         SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_ASUS_EEEPC_P703),
13415         SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_ASUS_EEEPC_P703),
13416         SND_PCI_QUIRK(0x1043, 0x831a, "ASUS Eeepc P901",
13417                       ALC269_ASUS_EEEPC_P901),
13418         SND_PCI_QUIRK(0x1043, 0x834a, "ASUS Eeepc S101",
13419                       ALC269_ASUS_EEEPC_P901),
13420         SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_ASUS_EEEPC_P901),
13421         SND_PCI_QUIRK(0x1734, 0x115d, "FSC Amilo", ALC269_FUJITSU),
13422         SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook ICH9M-based", ALC269_LIFEBOOK),
13423         {}
13424 };
13425
13426 static struct alc_config_preset alc269_presets[] = {
13427         [ALC269_BASIC] = {
13428                 .mixers = { alc269_base_mixer },
13429                 .init_verbs = { alc269_init_verbs },
13430                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13431                 .dac_nids = alc269_dac_nids,
13432                 .hp_nid = 0x03,
13433                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13434                 .channel_mode = alc269_modes,
13435                 .input_mux = &alc269_capture_source,
13436         },
13437         [ALC269_QUANTA_FL1] = {
13438                 .mixers = { alc269_quanta_fl1_mixer },
13439                 .init_verbs = { alc269_init_verbs, alc269_quanta_fl1_verbs },
13440                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13441                 .dac_nids = alc269_dac_nids,
13442                 .hp_nid = 0x03,
13443                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13444                 .channel_mode = alc269_modes,
13445                 .input_mux = &alc269_capture_source,
13446                 .unsol_event = alc269_quanta_fl1_unsol_event,
13447                 .setup = alc269_quanta_fl1_setup,
13448                 .init_hook = alc269_quanta_fl1_init_hook,
13449         },
13450         [ALC269_ASUS_EEEPC_P703] = {
13451                 .mixers = { alc269_eeepc_mixer },
13452                 .cap_mixer = alc269_epc_capture_mixer,
13453                 .init_verbs = { alc269_init_verbs,
13454                                 alc269_eeepc_amic_init_verbs },
13455                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13456                 .dac_nids = alc269_dac_nids,
13457                 .hp_nid = 0x03,
13458                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13459                 .channel_mode = alc269_modes,
13460                 .unsol_event = alc269_eeepc_unsol_event,
13461                 .setup = alc269_eeepc_amic_setup,
13462                 .init_hook = alc269_eeepc_inithook,
13463         },
13464         [ALC269_ASUS_EEEPC_P901] = {
13465                 .mixers = { alc269_eeepc_mixer },
13466                 .cap_mixer = alc269_epc_capture_mixer,
13467                 .init_verbs = { alc269_init_verbs,
13468                                 alc269_eeepc_dmic_init_verbs },
13469                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13470                 .dac_nids = alc269_dac_nids,
13471                 .hp_nid = 0x03,
13472                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13473                 .channel_mode = alc269_modes,
13474                 .unsol_event = alc269_eeepc_unsol_event,
13475                 .setup = alc269_eeepc_dmic_setup,
13476                 .init_hook = alc269_eeepc_inithook,
13477         },
13478         [ALC269_FUJITSU] = {
13479                 .mixers = { alc269_fujitsu_mixer },
13480                 .cap_mixer = alc269_epc_capture_mixer,
13481                 .init_verbs = { alc269_init_verbs,
13482                                 alc269_eeepc_dmic_init_verbs },
13483                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13484                 .dac_nids = alc269_dac_nids,
13485                 .hp_nid = 0x03,
13486                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13487                 .channel_mode = alc269_modes,
13488                 .unsol_event = alc269_eeepc_unsol_event,
13489                 .setup = alc269_eeepc_dmic_setup,
13490                 .init_hook = alc269_eeepc_inithook,
13491         },
13492         [ALC269_LIFEBOOK] = {
13493                 .mixers = { alc269_lifebook_mixer },
13494                 .init_verbs = { alc269_init_verbs, alc269_lifebook_verbs },
13495                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13496                 .dac_nids = alc269_dac_nids,
13497                 .hp_nid = 0x03,
13498                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13499                 .channel_mode = alc269_modes,
13500                 .input_mux = &alc269_capture_source,
13501                 .unsol_event = alc269_lifebook_unsol_event,
13502                 .init_hook = alc269_lifebook_init_hook,
13503         },
13504 };
13505
13506 static int patch_alc269(struct hda_codec *codec)
13507 {
13508         struct alc_spec *spec;
13509         int board_config;
13510         int err;
13511
13512         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
13513         if (spec == NULL)
13514                 return -ENOMEM;
13515
13516         codec->spec = spec;
13517
13518         alc_fix_pll_init(codec, 0x20, 0x04, 15);
13519
13520         board_config = snd_hda_check_board_config(codec, ALC269_MODEL_LAST,
13521                                                   alc269_models,
13522                                                   alc269_cfg_tbl);
13523
13524         if (board_config < 0) {
13525                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
13526                        codec->chip_name);
13527                 board_config = ALC269_AUTO;
13528         }
13529
13530         if (board_config == ALC269_AUTO) {
13531                 /* automatic parse from the BIOS config */
13532                 err = alc269_parse_auto_config(codec);
13533                 if (err < 0) {
13534                         alc_free(codec);
13535                         return err;
13536                 } else if (!err) {
13537                         printk(KERN_INFO
13538                                "hda_codec: Cannot set up configuration "
13539                                "from BIOS.  Using base mode...\n");
13540                         board_config = ALC269_BASIC;
13541                 }
13542         }
13543
13544         err = snd_hda_attach_beep_device(codec, 0x1);
13545         if (err < 0) {
13546                 alc_free(codec);
13547                 return err;
13548         }
13549
13550         if (board_config != ALC269_AUTO)
13551                 setup_preset(codec, &alc269_presets[board_config]);
13552
13553         if (codec->subsystem_id == 0x17aa3bf8) {
13554                 /* Due to a hardware problem on Lenovo Ideadpad, we need to
13555                  * fix the sample rate of analog I/O to 44.1kHz
13556                  */
13557                 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
13558                 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
13559         } else {
13560                 spec->stream_analog_playback = &alc269_pcm_analog_playback;
13561                 spec->stream_analog_capture = &alc269_pcm_analog_capture;
13562         }
13563         spec->stream_digital_playback = &alc269_pcm_digital_playback;
13564         spec->stream_digital_capture = &alc269_pcm_digital_capture;
13565
13566         spec->adc_nids = alc269_adc_nids;
13567         spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids);
13568         spec->capsrc_nids = alc269_capsrc_nids;
13569         if (!spec->cap_mixer)
13570                 set_capture_mixer(codec);
13571         set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
13572
13573         spec->vmaster_nid = 0x02;
13574
13575         codec->patch_ops = alc_patch_ops;
13576         if (board_config == ALC269_AUTO)
13577                 spec->init_hook = alc269_auto_init;
13578 #ifdef CONFIG_SND_HDA_POWER_SAVE
13579         if (!spec->loopback.amplist)
13580                 spec->loopback.amplist = alc269_loopbacks;
13581 #endif
13582         codec->proc_widget_hook = print_realtek_coef;
13583
13584         return 0;
13585 }
13586
13587 /*
13588  *  ALC861 channel source setting (2/6 channel selection for 3-stack)
13589  */
13590
13591 /*
13592  * set the path ways for 2 channel output
13593  * need to set the codec line out and mic 1 pin widgets to inputs
13594  */
13595 static struct hda_verb alc861_threestack_ch2_init[] = {
13596         /* set pin widget 1Ah (line in) for input */
13597         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13598         /* set pin widget 18h (mic1/2) for input, for mic also enable
13599          * the vref
13600          */
13601         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13602
13603         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
13604 #if 0
13605         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
13606         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
13607 #endif
13608         { } /* end */
13609 };
13610 /*
13611  * 6ch mode
13612  * need to set the codec line out and mic 1 pin widgets to outputs
13613  */
13614 static struct hda_verb alc861_threestack_ch6_init[] = {
13615         /* set pin widget 1Ah (line in) for output (Back Surround)*/
13616         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13617         /* set pin widget 18h (mic1) for output (CLFE)*/
13618         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13619
13620         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
13621         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
13622
13623         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
13624 #if 0
13625         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
13626         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
13627 #endif
13628         { } /* end */
13629 };
13630
13631 static struct hda_channel_mode alc861_threestack_modes[2] = {
13632         { 2, alc861_threestack_ch2_init },
13633         { 6, alc861_threestack_ch6_init },
13634 };
13635 /* Set mic1 as input and unmute the mixer */
13636 static struct hda_verb alc861_uniwill_m31_ch2_init[] = {
13637         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13638         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
13639         { } /* end */
13640 };
13641 /* Set mic1 as output and mute mixer */
13642 static struct hda_verb alc861_uniwill_m31_ch4_init[] = {
13643         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13644         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
13645         { } /* end */
13646 };
13647
13648 static struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
13649         { 2, alc861_uniwill_m31_ch2_init },
13650         { 4, alc861_uniwill_m31_ch4_init },
13651 };
13652
13653 /* Set mic1 and line-in as input and unmute the mixer */
13654 static struct hda_verb alc861_asus_ch2_init[] = {
13655         /* set pin widget 1Ah (line in) for input */
13656         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13657         /* set pin widget 18h (mic1/2) for input, for mic also enable
13658          * the vref
13659          */
13660         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13661
13662         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
13663 #if 0
13664         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
13665         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
13666 #endif
13667         { } /* end */
13668 };
13669 /* Set mic1 nad line-in as output and mute mixer */
13670 static struct hda_verb alc861_asus_ch6_init[] = {
13671         /* set pin widget 1Ah (line in) for output (Back Surround)*/
13672         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13673         /* { 0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
13674         /* set pin widget 18h (mic1) for output (CLFE)*/
13675         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13676         /* { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
13677         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
13678         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
13679
13680         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
13681 #if 0
13682         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
13683         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
13684 #endif
13685         { } /* end */
13686 };
13687
13688 static struct hda_channel_mode alc861_asus_modes[2] = {
13689         { 2, alc861_asus_ch2_init },
13690         { 6, alc861_asus_ch6_init },
13691 };
13692
13693 /* patch-ALC861 */
13694
13695 static struct snd_kcontrol_new alc861_base_mixer[] = {
13696         /* output mixer control */
13697         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13698         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
13699         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
13700         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13701         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
13702
13703         /*Input mixer control */
13704         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13705            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
13706         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13707         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13708         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13709         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13710         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13711         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13712         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13713         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
13714
13715         { } /* end */
13716 };
13717
13718 static struct snd_kcontrol_new alc861_3ST_mixer[] = {
13719         /* output mixer control */
13720         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13721         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
13722         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
13723         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13724         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
13725
13726         /* Input mixer control */
13727         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13728            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
13729         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13730         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13731         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13732         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13733         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13734         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13735         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13736         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
13737
13738         {
13739                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13740                 .name = "Channel Mode",
13741                 .info = alc_ch_mode_info,
13742                 .get = alc_ch_mode_get,
13743                 .put = alc_ch_mode_put,
13744                 .private_value = ARRAY_SIZE(alc861_threestack_modes),
13745         },
13746         { } /* end */
13747 };
13748
13749 static struct snd_kcontrol_new alc861_toshiba_mixer[] = {
13750         /* output mixer control */
13751         HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13752         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13753         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13754
13755         { } /* end */
13756 };
13757
13758 static struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
13759         /* output mixer control */
13760         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13761         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
13762         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
13763         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13764         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
13765
13766         /* Input mixer control */
13767         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13768            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
13769         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13770         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13771         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13772         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13773         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13774         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13775         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13776         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
13777
13778         {
13779                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13780                 .name = "Channel Mode",
13781                 .info = alc_ch_mode_info,
13782                 .get = alc_ch_mode_get,
13783                 .put = alc_ch_mode_put,
13784                 .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
13785         },
13786         { } /* end */
13787 };
13788
13789 static struct snd_kcontrol_new alc861_asus_mixer[] = {
13790         /* output mixer control */
13791         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13792         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
13793         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
13794         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13795         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
13796
13797         /* Input mixer control */
13798         HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13799         HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT),
13800         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13801         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13802         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13803         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13804         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13805         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13806         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13807         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT),
13808
13809         {
13810                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13811                 .name = "Channel Mode",
13812                 .info = alc_ch_mode_info,
13813                 .get = alc_ch_mode_get,
13814                 .put = alc_ch_mode_put,
13815                 .private_value = ARRAY_SIZE(alc861_asus_modes),
13816         },
13817         { }
13818 };
13819
13820 /* additional mixer */
13821 static struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
13822         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13823         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13824         { }
13825 };
13826
13827 /*
13828  * generic initialization of ADC, input mixers and output mixers
13829  */
13830 static struct hda_verb alc861_base_init_verbs[] = {
13831         /*
13832          * Unmute ADC0 and set the default input to mic-in
13833          */
13834         /* port-A for surround (rear panel) */
13835         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13836         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
13837         /* port-B for mic-in (rear panel) with vref */
13838         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13839         /* port-C for line-in (rear panel) */
13840         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13841         /* port-D for Front */
13842         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13843         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13844         /* port-E for HP out (front panel) */
13845         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
13846         /* route front PCM to HP */
13847         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13848         /* port-F for mic-in (front panel) with vref */
13849         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13850         /* port-G for CLFE (rear panel) */
13851         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13852         { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13853         /* port-H for side (rear panel) */
13854         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13855         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
13856         /* CD-in */
13857         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13858         /* route front mic to ADC1*/
13859         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13860         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13861
13862         /* Unmute DAC0~3 & spdif out*/
13863         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13864         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13865         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13866         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13867         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13868
13869         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13870         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13871         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13872         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13873         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13874
13875         /* Unmute Stereo Mixer 15 */
13876         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13877         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13878         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13879         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13880
13881         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13882         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13883         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13884         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13885         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13886         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13887         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13888         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13889         /* hp used DAC 3 (Front) */
13890         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13891         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13892
13893         { }
13894 };
13895
13896 static struct hda_verb alc861_threestack_init_verbs[] = {
13897         /*
13898          * Unmute ADC0 and set the default input to mic-in
13899          */
13900         /* port-A for surround (rear panel) */
13901         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13902         /* port-B for mic-in (rear panel) with vref */
13903         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13904         /* port-C for line-in (rear panel) */
13905         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13906         /* port-D for Front */
13907         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13908         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13909         /* port-E for HP out (front panel) */
13910         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
13911         /* route front PCM to HP */
13912         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13913         /* port-F for mic-in (front panel) with vref */
13914         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13915         /* port-G for CLFE (rear panel) */
13916         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13917         /* port-H for side (rear panel) */
13918         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13919         /* CD-in */
13920         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13921         /* route front mic to ADC1*/
13922         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13923         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13924         /* Unmute DAC0~3 & spdif out*/
13925         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13926         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13927         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13928         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13929         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13930
13931         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13932         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13933         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13934         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13935         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13936
13937         /* Unmute Stereo Mixer 15 */
13938         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13939         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13940         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13941         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13942
13943         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13944         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13945         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13946         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13947         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13948         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13949         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13950         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13951         /* hp used DAC 3 (Front) */
13952         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13953         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13954         { }
13955 };
13956
13957 static struct hda_verb alc861_uniwill_m31_init_verbs[] = {
13958         /*
13959          * Unmute ADC0 and set the default input to mic-in
13960          */
13961         /* port-A for surround (rear panel) */
13962         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13963         /* port-B for mic-in (rear panel) with vref */
13964         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13965         /* port-C for line-in (rear panel) */
13966         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13967         /* port-D for Front */
13968         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13969         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13970         /* port-E for HP out (front panel) */
13971         /* this has to be set to VREF80 */
13972         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13973         /* route front PCM to HP */
13974         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13975         /* port-F for mic-in (front panel) with vref */
13976         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13977         /* port-G for CLFE (rear panel) */
13978         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13979         /* port-H for side (rear panel) */
13980         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13981         /* CD-in */
13982         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13983         /* route front mic to ADC1*/
13984         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13985         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13986         /* Unmute DAC0~3 & spdif out*/
13987         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13988         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13989         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13990         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13991         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13992
13993         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13994         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13995         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13996         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13997         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13998
13999         /* Unmute Stereo Mixer 15 */
14000         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14001         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14002         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14003         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
14004
14005         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14006         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14007         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14008         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14009         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14010         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14011         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14012         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14013         /* hp used DAC 3 (Front) */
14014         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
14015         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14016         { }
14017 };
14018
14019 static struct hda_verb alc861_asus_init_verbs[] = {
14020         /*
14021          * Unmute ADC0 and set the default input to mic-in
14022          */
14023         /* port-A for surround (rear panel)
14024          * according to codec#0 this is the HP jack
14025          */
14026         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, /* was 0x00 */
14027         /* route front PCM to HP */
14028         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x01 },
14029         /* port-B for mic-in (rear panel) with vref */
14030         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
14031         /* port-C for line-in (rear panel) */
14032         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
14033         /* port-D for Front */
14034         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
14035         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
14036         /* port-E for HP out (front panel) */
14037         /* this has to be set to VREF80 */
14038         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
14039         /* route front PCM to HP */
14040         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
14041         /* port-F for mic-in (front panel) with vref */
14042         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
14043         /* port-G for CLFE (rear panel) */
14044         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
14045         /* port-H for side (rear panel) */
14046         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
14047         /* CD-in */
14048         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
14049         /* route front mic to ADC1*/
14050         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
14051         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14052         /* Unmute DAC0~3 & spdif out*/
14053         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14054         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14055         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14056         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14057         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14058         /* Unmute Mixer 14 (mic) 1c (Line in)*/
14059         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14060         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14061         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14062         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14063
14064         /* Unmute Stereo Mixer 15 */
14065         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14066         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14067         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14068         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
14069
14070         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14071         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14072         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14073         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14074         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14075         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14076         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14077         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14078         /* hp used DAC 3 (Front) */
14079         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
14080         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14081         { }
14082 };
14083
14084 /* additional init verbs for ASUS laptops */
14085 static struct hda_verb alc861_asus_laptop_init_verbs[] = {
14086         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x45 }, /* HP-out */
14087         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2) }, /* mute line-in */
14088         { }
14089 };
14090
14091 /*
14092  * generic initialization of ADC, input mixers and output mixers
14093  */
14094 static struct hda_verb alc861_auto_init_verbs[] = {
14095         /*
14096          * Unmute ADC0 and set the default input to mic-in
14097          */
14098         /* {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, */
14099         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14100
14101         /* Unmute DAC0~3 & spdif out*/
14102         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14103         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14104         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14105         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14106         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14107
14108         /* Unmute Mixer 14 (mic) 1c (Line in)*/
14109         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14110         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14111         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14112         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14113
14114         /* Unmute Stereo Mixer 15 */
14115         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14116         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14117         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14118         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c},
14119
14120         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14121         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14122         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14123         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14124         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14125         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14126         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14127         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14128
14129         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14130         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14131         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14132         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14133         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14134         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14135         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14136         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14137
14138         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},  /* set Mic 1 */
14139
14140         { }
14141 };
14142
14143 static struct hda_verb alc861_toshiba_init_verbs[] = {
14144         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14145
14146         { }
14147 };
14148
14149 /* toggle speaker-output according to the hp-jack state */
14150 static void alc861_toshiba_automute(struct hda_codec *codec)
14151 {
14152         unsigned int present;
14153
14154         present = snd_hda_codec_read(codec, 0x0f, 0,
14155                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14156         snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
14157                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
14158         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
14159                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
14160 }
14161
14162 static void alc861_toshiba_unsol_event(struct hda_codec *codec,
14163                                        unsigned int res)
14164 {
14165         if ((res >> 26) == ALC880_HP_EVENT)
14166                 alc861_toshiba_automute(codec);
14167 }
14168
14169 /* pcm configuration: identical with ALC880 */
14170 #define alc861_pcm_analog_playback      alc880_pcm_analog_playback
14171 #define alc861_pcm_analog_capture       alc880_pcm_analog_capture
14172 #define alc861_pcm_digital_playback     alc880_pcm_digital_playback
14173 #define alc861_pcm_digital_capture      alc880_pcm_digital_capture
14174
14175
14176 #define ALC861_DIGOUT_NID       0x07
14177
14178 static struct hda_channel_mode alc861_8ch_modes[1] = {
14179         { 8, NULL }
14180 };
14181
14182 static hda_nid_t alc861_dac_nids[4] = {
14183         /* front, surround, clfe, side */
14184         0x03, 0x06, 0x05, 0x04
14185 };
14186
14187 static hda_nid_t alc660_dac_nids[3] = {
14188         /* front, clfe, surround */
14189         0x03, 0x05, 0x06
14190 };
14191
14192 static hda_nid_t alc861_adc_nids[1] = {
14193         /* ADC0-2 */
14194         0x08,
14195 };
14196
14197 static struct hda_input_mux alc861_capture_source = {
14198         .num_items = 5,
14199         .items = {
14200                 { "Mic", 0x0 },
14201                 { "Front Mic", 0x3 },
14202                 { "Line", 0x1 },
14203                 { "CD", 0x4 },
14204                 { "Mixer", 0x5 },
14205         },
14206 };
14207
14208 static hda_nid_t alc861_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
14209 {
14210         struct alc_spec *spec = codec->spec;
14211         hda_nid_t mix, srcs[5];
14212         int i, j, num;
14213
14214         if (snd_hda_get_connections(codec, pin, &mix, 1) != 1)
14215                 return 0;
14216         num = snd_hda_get_connections(codec, mix, srcs, ARRAY_SIZE(srcs));
14217         if (num < 0)
14218                 return 0;
14219         for (i = 0; i < num; i++) {
14220                 unsigned int type;
14221                 type = get_wcaps_type(get_wcaps(codec, srcs[i]));
14222                 if (type != AC_WID_AUD_OUT)
14223                         continue;
14224                 for (j = 0; j < spec->multiout.num_dacs; j++)
14225                         if (spec->multiout.dac_nids[j] == srcs[i])
14226                                 break;
14227                 if (j >= spec->multiout.num_dacs)
14228                         return srcs[i];
14229         }
14230         return 0;
14231 }
14232
14233 /* fill in the dac_nids table from the parsed pin configuration */
14234 static int alc861_auto_fill_dac_nids(struct hda_codec *codec,
14235                                      const struct auto_pin_cfg *cfg)
14236 {
14237         struct alc_spec *spec = codec->spec;
14238         int i;
14239         hda_nid_t nid, dac;
14240
14241         spec->multiout.dac_nids = spec->private_dac_nids;
14242         for (i = 0; i < cfg->line_outs; i++) {
14243                 nid = cfg->line_out_pins[i];
14244                 dac = alc861_look_for_dac(codec, nid);
14245                 if (!dac)
14246                         continue;
14247                 spec->multiout.dac_nids[spec->multiout.num_dacs++] = dac;
14248         }
14249         return 0;
14250 }
14251
14252 static int alc861_create_out_sw(struct hda_codec *codec, const char *pfx,
14253                                 hda_nid_t nid, unsigned int chs)
14254 {
14255         return add_pb_sw_ctrl(codec->spec, ALC_CTL_WIDGET_MUTE, pfx,
14256                            HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
14257 }
14258
14259 /* add playback controls from the parsed DAC table */
14260 static int alc861_auto_create_multi_out_ctls(struct hda_codec *codec,
14261                                              const struct auto_pin_cfg *cfg)
14262 {
14263         struct alc_spec *spec = codec->spec;
14264         static const char *chname[4] = {
14265                 "Front", "Surround", NULL /*CLFE*/, "Side"
14266         };
14267         hda_nid_t nid;
14268         int i, err;
14269
14270         if (cfg->line_outs == 1) {
14271                 const char *pfx = NULL;
14272                 if (!cfg->hp_outs)
14273                         pfx = "Master";
14274                 else if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
14275                         pfx = "Speaker";
14276                 if (pfx) {
14277                         nid = spec->multiout.dac_nids[0];
14278                         return alc861_create_out_sw(codec, pfx, nid, 3);
14279                 }
14280         }
14281
14282         for (i = 0; i < cfg->line_outs; i++) {
14283                 nid = spec->multiout.dac_nids[i];
14284                 if (!nid)
14285                         continue;
14286                 if (i == 2) {
14287                         /* Center/LFE */
14288                         err = alc861_create_out_sw(codec, "Center", nid, 1);
14289                         if (err < 0)
14290                                 return err;
14291                         err = alc861_create_out_sw(codec, "LFE", nid, 2);
14292                         if (err < 0)
14293                                 return err;
14294                 } else {
14295                         err = alc861_create_out_sw(codec, chname[i], nid, 3);
14296                         if (err < 0)
14297                                 return err;
14298                 }
14299         }
14300         return 0;
14301 }
14302
14303 static int alc861_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin)
14304 {
14305         struct alc_spec *spec = codec->spec;
14306         int err;
14307         hda_nid_t nid;
14308
14309         if (!pin)
14310                 return 0;
14311
14312         if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
14313                 nid = alc861_look_for_dac(codec, pin);
14314                 if (nid) {
14315                         err = alc861_create_out_sw(codec, "Headphone", nid, 3);
14316                         if (err < 0)
14317                                 return err;
14318                         spec->multiout.hp_nid = nid;
14319                 }
14320         }
14321         return 0;
14322 }
14323
14324 /* create playback/capture controls for input pins */
14325 static int alc861_auto_create_input_ctls(struct hda_codec *codec,
14326                                                 const struct auto_pin_cfg *cfg)
14327 {
14328         return alc_auto_create_input_ctls(codec, cfg, 0x15, 0x08, 0);
14329 }
14330
14331 static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
14332                                               hda_nid_t nid,
14333                                               int pin_type, hda_nid_t dac)
14334 {
14335         hda_nid_t mix, srcs[5];
14336         int i, num;
14337
14338         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
14339                             pin_type);
14340         snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14341                             AMP_OUT_UNMUTE);
14342         if (snd_hda_get_connections(codec, nid, &mix, 1) != 1)
14343                 return;
14344         num = snd_hda_get_connections(codec, mix, srcs, ARRAY_SIZE(srcs));
14345         if (num < 0)
14346                 return;
14347         for (i = 0; i < num; i++) {
14348                 unsigned int mute;
14349                 if (srcs[i] == dac || srcs[i] == 0x15)
14350                         mute = AMP_IN_UNMUTE(i);
14351                 else
14352                         mute = AMP_IN_MUTE(i);
14353                 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14354                                     mute);
14355         }
14356 }
14357
14358 static void alc861_auto_init_multi_out(struct hda_codec *codec)
14359 {
14360         struct alc_spec *spec = codec->spec;
14361         int i;
14362
14363         for (i = 0; i < spec->autocfg.line_outs; i++) {
14364                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
14365                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
14366                 if (nid)
14367                         alc861_auto_set_output_and_unmute(codec, nid, pin_type,
14368                                                           spec->multiout.dac_nids[i]);
14369         }
14370 }
14371
14372 static void alc861_auto_init_hp_out(struct hda_codec *codec)
14373 {
14374         struct alc_spec *spec = codec->spec;
14375
14376         if (spec->autocfg.hp_outs)
14377                 alc861_auto_set_output_and_unmute(codec,
14378                                                   spec->autocfg.hp_pins[0],
14379                                                   PIN_HP,
14380                                                   spec->multiout.hp_nid);
14381         if (spec->autocfg.speaker_outs)
14382                 alc861_auto_set_output_and_unmute(codec,
14383                                                   spec->autocfg.speaker_pins[0],
14384                                                   PIN_OUT,
14385                                                   spec->multiout.dac_nids[0]);
14386 }
14387
14388 static void alc861_auto_init_analog_input(struct hda_codec *codec)
14389 {
14390         struct alc_spec *spec = codec->spec;
14391         int i;
14392
14393         for (i = 0; i < AUTO_PIN_LAST; i++) {
14394                 hda_nid_t nid = spec->autocfg.input_pins[i];
14395                 if (nid >= 0x0c && nid <= 0x11)
14396                         alc_set_input_pin(codec, nid, i);
14397         }
14398 }
14399
14400 /* parse the BIOS configuration and set up the alc_spec */
14401 /* return 1 if successful, 0 if the proper config is not found,
14402  * or a negative error code
14403  */
14404 static int alc861_parse_auto_config(struct hda_codec *codec)
14405 {
14406         struct alc_spec *spec = codec->spec;
14407         int err;
14408         static hda_nid_t alc861_ignore[] = { 0x1d, 0 };
14409
14410         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
14411                                            alc861_ignore);
14412         if (err < 0)
14413                 return err;
14414         if (!spec->autocfg.line_outs)
14415                 return 0; /* can't find valid BIOS pin config */
14416
14417         err = alc861_auto_fill_dac_nids(codec, &spec->autocfg);
14418         if (err < 0)
14419                 return err;
14420         err = alc861_auto_create_multi_out_ctls(codec, &spec->autocfg);
14421         if (err < 0)
14422                 return err;
14423         err = alc861_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
14424         if (err < 0)
14425                 return err;
14426         err = alc861_auto_create_input_ctls(codec, &spec->autocfg);
14427         if (err < 0)
14428                 return err;
14429
14430         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
14431
14432         if (spec->autocfg.dig_outs)
14433                 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;
14434
14435         if (spec->kctls.list)
14436                 add_mixer(spec, spec->kctls.list);
14437
14438         add_verb(spec, alc861_auto_init_verbs);
14439
14440         spec->num_mux_defs = 1;
14441         spec->input_mux = &spec->private_imux[0];
14442
14443         spec->adc_nids = alc861_adc_nids;
14444         spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
14445         set_capture_mixer(codec);
14446
14447         alc_ssid_check(codec, 0x0e, 0x0f, 0x0b);
14448
14449         return 1;
14450 }
14451
14452 /* additional initialization for auto-configuration model */
14453 static void alc861_auto_init(struct hda_codec *codec)
14454 {
14455         struct alc_spec *spec = codec->spec;
14456         alc861_auto_init_multi_out(codec);
14457         alc861_auto_init_hp_out(codec);
14458         alc861_auto_init_analog_input(codec);
14459         if (spec->unsol_event)
14460                 alc_inithook(codec);
14461 }
14462
14463 #ifdef CONFIG_SND_HDA_POWER_SAVE
14464 static struct hda_amp_list alc861_loopbacks[] = {
14465         { 0x15, HDA_INPUT, 0 },
14466         { 0x15, HDA_INPUT, 1 },
14467         { 0x15, HDA_INPUT, 2 },
14468         { 0x15, HDA_INPUT, 3 },
14469         { } /* end */
14470 };
14471 #endif
14472
14473
14474 /*
14475  * configuration and preset
14476  */
14477 static const char *alc861_models[ALC861_MODEL_LAST] = {
14478         [ALC861_3ST]            = "3stack",
14479         [ALC660_3ST]            = "3stack-660",
14480         [ALC861_3ST_DIG]        = "3stack-dig",
14481         [ALC861_6ST_DIG]        = "6stack-dig",
14482         [ALC861_UNIWILL_M31]    = "uniwill-m31",
14483         [ALC861_TOSHIBA]        = "toshiba",
14484         [ALC861_ASUS]           = "asus",
14485         [ALC861_ASUS_LAPTOP]    = "asus-laptop",
14486         [ALC861_AUTO]           = "auto",
14487 };
14488
14489 static struct snd_pci_quirk alc861_cfg_tbl[] = {
14490         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC861_3ST),
14491         SND_PCI_QUIRK(0x1043, 0x1335, "ASUS F2/3", ALC861_ASUS_LAPTOP),
14492         SND_PCI_QUIRK(0x1043, 0x1338, "ASUS F2/3", ALC861_ASUS_LAPTOP),
14493         SND_PCI_QUIRK(0x1043, 0x1393, "ASUS", ALC861_ASUS),
14494         SND_PCI_QUIRK(0x1043, 0x13d7, "ASUS A9rp", ALC861_ASUS_LAPTOP),
14495         SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS P1-AH2", ALC861_3ST_DIG),
14496         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba", ALC861_TOSHIBA),
14497         /* FIXME: the entry below breaks Toshiba A100 (model=auto works!)
14498          *        Any other models that need this preset?
14499          */
14500         /* SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba", ALC861_TOSHIBA), */
14501         SND_PCI_QUIRK(0x1462, 0x7254, "HP dx2200 (MSI MS-7254)", ALC861_3ST),
14502         SND_PCI_QUIRK(0x1462, 0x7297, "HP dx2250 (MSI MS-7297)", ALC861_3ST),
14503         SND_PCI_QUIRK(0x1584, 0x2b01, "Uniwill X40AIx", ALC861_UNIWILL_M31),
14504         SND_PCI_QUIRK(0x1584, 0x9072, "Uniwill m31", ALC861_UNIWILL_M31),
14505         SND_PCI_QUIRK(0x1584, 0x9075, "Airis Praxis N1212", ALC861_ASUS_LAPTOP),
14506         /* FIXME: the below seems conflict */
14507         /* SND_PCI_QUIRK(0x1584, 0x9075, "Uniwill", ALC861_UNIWILL_M31), */
14508         SND_PCI_QUIRK(0x1849, 0x0660, "Asrock 939SLI32", ALC660_3ST),
14509         SND_PCI_QUIRK(0x8086, 0xd600, "Intel", ALC861_3ST),
14510         {}
14511 };
14512
14513 static struct alc_config_preset alc861_presets[] = {
14514         [ALC861_3ST] = {
14515                 .mixers = { alc861_3ST_mixer },
14516                 .init_verbs = { alc861_threestack_init_verbs },
14517                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14518                 .dac_nids = alc861_dac_nids,
14519                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
14520                 .channel_mode = alc861_threestack_modes,
14521                 .need_dac_fix = 1,
14522                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14523                 .adc_nids = alc861_adc_nids,
14524                 .input_mux = &alc861_capture_source,
14525         },
14526         [ALC861_3ST_DIG] = {
14527                 .mixers = { alc861_base_mixer },
14528                 .init_verbs = { alc861_threestack_init_verbs },
14529                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14530                 .dac_nids = alc861_dac_nids,
14531                 .dig_out_nid = ALC861_DIGOUT_NID,
14532                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
14533                 .channel_mode = alc861_threestack_modes,
14534                 .need_dac_fix = 1,
14535                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14536                 .adc_nids = alc861_adc_nids,
14537                 .input_mux = &alc861_capture_source,
14538         },
14539         [ALC861_6ST_DIG] = {
14540                 .mixers = { alc861_base_mixer },
14541                 .init_verbs = { alc861_base_init_verbs },
14542                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14543                 .dac_nids = alc861_dac_nids,
14544                 .dig_out_nid = ALC861_DIGOUT_NID,
14545                 .num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
14546                 .channel_mode = alc861_8ch_modes,
14547                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14548                 .adc_nids = alc861_adc_nids,
14549                 .input_mux = &alc861_capture_source,
14550         },
14551         [ALC660_3ST] = {
14552                 .mixers = { alc861_3ST_mixer },
14553                 .init_verbs = { alc861_threestack_init_verbs },
14554                 .num_dacs = ARRAY_SIZE(alc660_dac_nids),
14555                 .dac_nids = alc660_dac_nids,
14556                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
14557                 .channel_mode = alc861_threestack_modes,
14558                 .need_dac_fix = 1,
14559                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14560                 .adc_nids = alc861_adc_nids,
14561                 .input_mux = &alc861_capture_source,
14562         },
14563         [ALC861_UNIWILL_M31] = {
14564                 .mixers = { alc861_uniwill_m31_mixer },
14565                 .init_verbs = { alc861_uniwill_m31_init_verbs },
14566                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14567                 .dac_nids = alc861_dac_nids,
14568                 .dig_out_nid = ALC861_DIGOUT_NID,
14569                 .num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
14570                 .channel_mode = alc861_uniwill_m31_modes,
14571                 .need_dac_fix = 1,
14572                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14573                 .adc_nids = alc861_adc_nids,
14574                 .input_mux = &alc861_capture_source,
14575         },
14576         [ALC861_TOSHIBA] = {
14577                 .mixers = { alc861_toshiba_mixer },
14578                 .init_verbs = { alc861_base_init_verbs,
14579                                 alc861_toshiba_init_verbs },
14580                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14581                 .dac_nids = alc861_dac_nids,
14582                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
14583                 .channel_mode = alc883_3ST_2ch_modes,
14584                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14585                 .adc_nids = alc861_adc_nids,
14586                 .input_mux = &alc861_capture_source,
14587                 .unsol_event = alc861_toshiba_unsol_event,
14588                 .init_hook = alc861_toshiba_automute,
14589         },
14590         [ALC861_ASUS] = {
14591                 .mixers = { alc861_asus_mixer },
14592                 .init_verbs = { alc861_asus_init_verbs },
14593                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14594                 .dac_nids = alc861_dac_nids,
14595                 .dig_out_nid = ALC861_DIGOUT_NID,
14596                 .num_channel_mode = ARRAY_SIZE(alc861_asus_modes),
14597                 .channel_mode = alc861_asus_modes,
14598                 .need_dac_fix = 1,
14599                 .hp_nid = 0x06,
14600                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14601                 .adc_nids = alc861_adc_nids,
14602                 .input_mux = &alc861_capture_source,
14603         },
14604         [ALC861_ASUS_LAPTOP] = {
14605                 .mixers = { alc861_toshiba_mixer, alc861_asus_laptop_mixer },
14606                 .init_verbs = { alc861_asus_init_verbs,
14607                                 alc861_asus_laptop_init_verbs },
14608                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14609                 .dac_nids = alc861_dac_nids,
14610                 .dig_out_nid = ALC861_DIGOUT_NID,
14611                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
14612                 .channel_mode = alc883_3ST_2ch_modes,
14613                 .need_dac_fix = 1,
14614                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14615                 .adc_nids = alc861_adc_nids,
14616                 .input_mux = &alc861_capture_source,
14617         },
14618 };
14619
14620
14621 static int patch_alc861(struct hda_codec *codec)
14622 {
14623         struct alc_spec *spec;
14624         int board_config;
14625         int err;
14626
14627         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
14628         if (spec == NULL)
14629                 return -ENOMEM;
14630
14631         codec->spec = spec;
14632
14633         board_config = snd_hda_check_board_config(codec, ALC861_MODEL_LAST,
14634                                                   alc861_models,
14635                                                   alc861_cfg_tbl);
14636
14637         if (board_config < 0) {
14638                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
14639                        codec->chip_name);
14640                 board_config = ALC861_AUTO;
14641         }
14642
14643         if (board_config == ALC861_AUTO) {
14644                 /* automatic parse from the BIOS config */
14645                 err = alc861_parse_auto_config(codec);
14646                 if (err < 0) {
14647                         alc_free(codec);
14648                         return err;
14649                 } else if (!err) {
14650                         printk(KERN_INFO
14651                                "hda_codec: Cannot set up configuration "
14652                                "from BIOS.  Using base mode...\n");
14653                    board_config = ALC861_3ST_DIG;
14654                 }
14655         }
14656
14657         err = snd_hda_attach_beep_device(codec, 0x23);
14658         if (err < 0) {
14659                 alc_free(codec);
14660                 return err;
14661         }
14662
14663         if (board_config != ALC861_AUTO)
14664                 setup_preset(codec, &alc861_presets[board_config]);
14665
14666         spec->stream_analog_playback = &alc861_pcm_analog_playback;
14667         spec->stream_analog_capture = &alc861_pcm_analog_capture;
14668
14669         spec->stream_digital_playback = &alc861_pcm_digital_playback;
14670         spec->stream_digital_capture = &alc861_pcm_digital_capture;
14671
14672         set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
14673
14674         spec->vmaster_nid = 0x03;
14675
14676         codec->patch_ops = alc_patch_ops;
14677         if (board_config == ALC861_AUTO)
14678                 spec->init_hook = alc861_auto_init;
14679 #ifdef CONFIG_SND_HDA_POWER_SAVE
14680         if (!spec->loopback.amplist)
14681                 spec->loopback.amplist = alc861_loopbacks;
14682 #endif
14683         codec->proc_widget_hook = print_realtek_coef;
14684
14685         return 0;
14686 }
14687
14688 /*
14689  * ALC861-VD support
14690  *
14691  * Based on ALC882
14692  *
14693  * In addition, an independent DAC
14694  */
14695 #define ALC861VD_DIGOUT_NID     0x06
14696
14697 static hda_nid_t alc861vd_dac_nids[4] = {
14698         /* front, surr, clfe, side surr */
14699         0x02, 0x03, 0x04, 0x05
14700 };
14701
14702 /* dac_nids for ALC660vd are in a different order - according to
14703  * Realtek's driver.
14704  * This should probably result in a different mixer for 6stack models
14705  * of ALC660vd codecs, but for now there is only 3stack mixer
14706  * - and it is the same as in 861vd.
14707  * adc_nids in ALC660vd are (is) the same as in 861vd
14708  */
14709 static hda_nid_t alc660vd_dac_nids[3] = {
14710         /* front, rear, clfe, rear_surr */
14711         0x02, 0x04, 0x03
14712 };
14713
14714 static hda_nid_t alc861vd_adc_nids[1] = {
14715         /* ADC0 */
14716         0x09,
14717 };
14718
14719 static hda_nid_t alc861vd_capsrc_nids[1] = { 0x22 };
14720
14721 /* input MUX */
14722 /* FIXME: should be a matrix-type input source selection */
14723 static struct hda_input_mux alc861vd_capture_source = {
14724         .num_items = 4,
14725         .items = {
14726                 { "Mic", 0x0 },
14727                 { "Front Mic", 0x1 },
14728                 { "Line", 0x2 },
14729                 { "CD", 0x4 },
14730         },
14731 };
14732
14733 static struct hda_input_mux alc861vd_dallas_capture_source = {
14734         .num_items = 2,
14735         .items = {
14736                 { "Ext Mic", 0x0 },
14737                 { "Int Mic", 0x1 },
14738         },
14739 };
14740
14741 static struct hda_input_mux alc861vd_hp_capture_source = {
14742         .num_items = 2,
14743         .items = {
14744                 { "Front Mic", 0x0 },
14745                 { "ATAPI Mic", 0x1 },
14746         },
14747 };
14748
14749 /*
14750  * 2ch mode
14751  */
14752 static struct hda_channel_mode alc861vd_3stack_2ch_modes[1] = {
14753         { 2, NULL }
14754 };
14755
14756 /*
14757  * 6ch mode
14758  */
14759 static struct hda_verb alc861vd_6stack_ch6_init[] = {
14760         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
14761         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14762         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14763         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14764         { } /* end */
14765 };
14766
14767 /*
14768  * 8ch mode
14769  */
14770 static struct hda_verb alc861vd_6stack_ch8_init[] = {
14771         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14772         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14773         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14774         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14775         { } /* end */
14776 };
14777
14778 static struct hda_channel_mode alc861vd_6stack_modes[2] = {
14779         { 6, alc861vd_6stack_ch6_init },
14780         { 8, alc861vd_6stack_ch8_init },
14781 };
14782
14783 static struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
14784         {
14785                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
14786                 .name = "Channel Mode",
14787                 .info = alc_ch_mode_info,
14788                 .get = alc_ch_mode_get,
14789                 .put = alc_ch_mode_put,
14790         },
14791         { } /* end */
14792 };
14793
14794 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
14795  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
14796  */
14797 static struct snd_kcontrol_new alc861vd_6st_mixer[] = {
14798         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14799         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14800
14801         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14802         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
14803
14804         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0,
14805                                 HDA_OUTPUT),
14806         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0,
14807                                 HDA_OUTPUT),
14808         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
14809         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
14810
14811         HDA_CODEC_VOLUME("Side Playback Volume", 0x05, 0x0, HDA_OUTPUT),
14812         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
14813
14814         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14815
14816         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
14817         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14818         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14819
14820         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
14821         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14822         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14823
14824         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14825         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14826
14827         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14828         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14829
14830         { } /* end */
14831 };
14832
14833 static struct snd_kcontrol_new alc861vd_3st_mixer[] = {
14834         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14835         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14836
14837         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14838
14839         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
14840         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14841         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14842
14843         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
14844         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14845         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14846
14847         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14848         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14849
14850         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14851         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14852
14853         { } /* end */
14854 };
14855
14856 static struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
14857         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14858         /*HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),*/
14859         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14860
14861         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14862
14863         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
14864         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14865         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14866
14867         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
14868         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14869         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14870
14871         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14872         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14873
14874         { } /* end */
14875 };
14876
14877 /* Pin assignment: Speaker=0x14, HP = 0x15,
14878  *                 Ext Mic=0x18, Int Mic = 0x19, CD = 0x1c, PC Beep = 0x1d
14879  */
14880 static struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
14881         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14882         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
14883         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14884         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
14885         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
14886         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14887         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14888         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
14889         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14890         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14891         { } /* end */
14892 };
14893
14894 /* Pin assignment: Speaker=0x14, Line-out = 0x15,
14895  *                 Front Mic=0x18, ATAPI Mic = 0x19,
14896  */
14897 static struct snd_kcontrol_new alc861vd_hp_mixer[] = {
14898         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14899         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14900         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14901         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
14902         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14903         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14904         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14905         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14906
14907         { } /* end */
14908 };
14909
14910 /*
14911  * generic initialization of ADC, input mixers and output mixers
14912  */
14913 static struct hda_verb alc861vd_volume_init_verbs[] = {
14914         /*
14915          * Unmute ADC0 and set the default input to mic-in
14916          */
14917         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
14918         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14919
14920         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of
14921          * the analog-loopback mixer widget
14922          */
14923         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
14924         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14925         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14926         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14927         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14928         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14929
14930         /* Capture mixer: unmute Mic, F-Mic, Line, CD inputs */
14931         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14932         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14933         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14934         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
14935
14936         /*
14937          * Set up output mixers (0x02 - 0x05)
14938          */
14939         /* set vol=0 to output mixers */
14940         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14941         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14942         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14943         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14944
14945         /* set up input amps for analog loopback */
14946         /* Amp Indices: DAC = 0, mixer = 1 */
14947         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14948         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14949         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14950         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14951         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14952         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14953         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14954         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14955
14956         { }
14957 };
14958
14959 /*
14960  * 3-stack pin configuration:
14961  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
14962  */
14963 static struct hda_verb alc861vd_3stack_init_verbs[] = {
14964         /*
14965          * Set pin mode and muting
14966          */
14967         /* set front pin widgets 0x14 for output */
14968         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14969         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14970         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
14971
14972         /* Mic (rear) pin: input vref at 80% */
14973         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14974         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14975         /* Front Mic pin: input vref at 80% */
14976         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14977         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14978         /* Line In pin: input */
14979         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14980         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14981         /* Line-2 In: Headphone output (output 0 - 0x0c) */
14982         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14983         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14984         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
14985         /* CD pin widget for input */
14986         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14987
14988         { }
14989 };
14990
14991 /*
14992  * 6-stack pin configuration:
14993  */
14994 static struct hda_verb alc861vd_6stack_init_verbs[] = {
14995         /*
14996          * Set pin mode and muting
14997          */
14998         /* set front pin widgets 0x14 for output */
14999         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15000         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15001         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
15002
15003         /* Rear Pin: output 1 (0x0d) */
15004         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15005         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15006         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
15007         /* CLFE Pin: output 2 (0x0e) */
15008         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15009         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15010         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
15011         /* Side Pin: output 3 (0x0f) */
15012         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15013         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15014         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
15015
15016         /* Mic (rear) pin: input vref at 80% */
15017         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
15018         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15019         /* Front Mic pin: input vref at 80% */
15020         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
15021         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15022         /* Line In pin: input */
15023         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15024         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15025         /* Line-2 In: Headphone output (output 0 - 0x0c) */
15026         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15027         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15028         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
15029         /* CD pin widget for input */
15030         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15031
15032         { }
15033 };
15034
15035 static struct hda_verb alc861vd_eapd_verbs[] = {
15036         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
15037         { }
15038 };
15039
15040 static struct hda_verb alc660vd_eapd_verbs[] = {
15041         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
15042         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
15043         { }
15044 };
15045
15046 static struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
15047         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15048         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15049         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
15050         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15051         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15052         {}
15053 };
15054
15055 static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
15056 {
15057         unsigned int present;
15058         unsigned char bits;
15059
15060         present = snd_hda_codec_read(codec, 0x18, 0,
15061                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15062         bits = present ? HDA_AMP_MUTE : 0;
15063         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
15064                                  HDA_AMP_MUTE, bits);
15065 }
15066
15067 static void alc861vd_lenovo_setup(struct hda_codec *codec)
15068 {
15069         struct alc_spec *spec = codec->spec;
15070         spec->autocfg.hp_pins[0] = 0x1b;
15071         spec->autocfg.speaker_pins[0] = 0x14;
15072 }
15073
15074 static void alc861vd_lenovo_init_hook(struct hda_codec *codec)
15075 {
15076         alc_automute_amp(codec);
15077         alc861vd_lenovo_mic_automute(codec);
15078 }
15079
15080 static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
15081                                         unsigned int res)
15082 {
15083         switch (res >> 26) {
15084         case ALC880_MIC_EVENT:
15085                 alc861vd_lenovo_mic_automute(codec);
15086                 break;
15087         default:
15088                 alc_automute_amp_unsol_event(codec, res);
15089                 break;
15090         }
15091 }
15092
15093 static struct hda_verb alc861vd_dallas_verbs[] = {
15094         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15095         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15096         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15097         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15098
15099         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15100         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15101         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15102         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15103         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15104         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15105         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15106         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15107
15108         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15109         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15110         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15111         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15112         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15113         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15114         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15115         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15116
15117         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
15118         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15119         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
15120         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15121         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15122         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15123         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15124         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15125
15126         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15127         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
15128         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
15129         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
15130
15131         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15132         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
15133         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15134
15135         { } /* end */
15136 };
15137
15138 /* toggle speaker-output according to the hp-jack state */
15139 static void alc861vd_dallas_setup(struct hda_codec *codec)
15140 {
15141         struct alc_spec *spec = codec->spec;
15142
15143         spec->autocfg.hp_pins[0] = 0x15;
15144         spec->autocfg.speaker_pins[0] = 0x14;
15145 }
15146
15147 #ifdef CONFIG_SND_HDA_POWER_SAVE
15148 #define alc861vd_loopbacks      alc880_loopbacks
15149 #endif
15150
15151 /* pcm configuration: identical with ALC880 */
15152 #define alc861vd_pcm_analog_playback    alc880_pcm_analog_playback
15153 #define alc861vd_pcm_analog_capture     alc880_pcm_analog_capture
15154 #define alc861vd_pcm_digital_playback   alc880_pcm_digital_playback
15155 #define alc861vd_pcm_digital_capture    alc880_pcm_digital_capture
15156
15157 /*
15158  * configuration and preset
15159  */
15160 static const char *alc861vd_models[ALC861VD_MODEL_LAST] = {
15161         [ALC660VD_3ST]          = "3stack-660",
15162         [ALC660VD_3ST_DIG]      = "3stack-660-digout",
15163         [ALC660VD_ASUS_V1S]     = "asus-v1s",
15164         [ALC861VD_3ST]          = "3stack",
15165         [ALC861VD_3ST_DIG]      = "3stack-digout",
15166         [ALC861VD_6ST_DIG]      = "6stack-digout",
15167         [ALC861VD_LENOVO]       = "lenovo",
15168         [ALC861VD_DALLAS]       = "dallas",
15169         [ALC861VD_HP]           = "hp",
15170         [ALC861VD_AUTO]         = "auto",
15171 };
15172
15173 static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
15174         SND_PCI_QUIRK(0x1019, 0xa88d, "Realtek ALC660 demo", ALC660VD_3ST),
15175         SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_HP),
15176         SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST),
15177         /*SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),*/ /* auto */
15178         SND_PCI_QUIRK(0x1043, 0x1633, "Asus V1Sn", ALC660VD_ASUS_V1S),
15179         SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG),
15180         SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
15181         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
15182         /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
15183         SND_PCI_QUIRK(0x1179, 0xff01, "Toshiba A135", ALC861VD_LENOVO),
15184         SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
15185         SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_DALLAS),
15186         SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
15187         SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", ALC861VD_LENOVO),
15188         SND_PCI_QUIRK(0x1849, 0x0862, "ASRock K8NF6G-VSTA", ALC861VD_6ST_DIG),
15189         {}
15190 };
15191
15192 static struct alc_config_preset alc861vd_presets[] = {
15193         [ALC660VD_3ST] = {
15194                 .mixers = { alc861vd_3st_mixer },
15195                 .init_verbs = { alc861vd_volume_init_verbs,
15196                                  alc861vd_3stack_init_verbs },
15197                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
15198                 .dac_nids = alc660vd_dac_nids,
15199                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15200                 .channel_mode = alc861vd_3stack_2ch_modes,
15201                 .input_mux = &alc861vd_capture_source,
15202         },
15203         [ALC660VD_3ST_DIG] = {
15204                 .mixers = { alc861vd_3st_mixer },
15205                 .init_verbs = { alc861vd_volume_init_verbs,
15206                                  alc861vd_3stack_init_verbs },
15207                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
15208                 .dac_nids = alc660vd_dac_nids,
15209                 .dig_out_nid = ALC861VD_DIGOUT_NID,
15210                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15211                 .channel_mode = alc861vd_3stack_2ch_modes,
15212                 .input_mux = &alc861vd_capture_source,
15213         },
15214         [ALC861VD_3ST] = {
15215                 .mixers = { alc861vd_3st_mixer },
15216                 .init_verbs = { alc861vd_volume_init_verbs,
15217                                  alc861vd_3stack_init_verbs },
15218                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
15219                 .dac_nids = alc861vd_dac_nids,
15220                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15221                 .channel_mode = alc861vd_3stack_2ch_modes,
15222                 .input_mux = &alc861vd_capture_source,
15223         },
15224         [ALC861VD_3ST_DIG] = {
15225                 .mixers = { alc861vd_3st_mixer },
15226                 .init_verbs = { alc861vd_volume_init_verbs,
15227                                  alc861vd_3stack_init_verbs },
15228                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
15229                 .dac_nids = alc861vd_dac_nids,
15230                 .dig_out_nid = ALC861VD_DIGOUT_NID,
15231                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15232                 .channel_mode = alc861vd_3stack_2ch_modes,
15233                 .input_mux = &alc861vd_capture_source,
15234         },
15235         [ALC861VD_6ST_DIG] = {
15236                 .mixers = { alc861vd_6st_mixer, alc861vd_chmode_mixer },
15237                 .init_verbs = { alc861vd_volume_init_verbs,
15238                                 alc861vd_6stack_init_verbs },
15239                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
15240                 .dac_nids = alc861vd_dac_nids,
15241                 .dig_out_nid = ALC861VD_DIGOUT_NID,
15242                 .num_channel_mode = ARRAY_SIZE(alc861vd_6stack_modes),
15243                 .channel_mode = alc861vd_6stack_modes,
15244                 .input_mux = &alc861vd_capture_source,
15245         },
15246         [ALC861VD_LENOVO] = {
15247                 .mixers = { alc861vd_lenovo_mixer },
15248                 .init_verbs = { alc861vd_volume_init_verbs,
15249                                 alc861vd_3stack_init_verbs,
15250                                 alc861vd_eapd_verbs,
15251                                 alc861vd_lenovo_unsol_verbs },
15252                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
15253                 .dac_nids = alc660vd_dac_nids,
15254                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15255                 .channel_mode = alc861vd_3stack_2ch_modes,
15256                 .input_mux = &alc861vd_capture_source,
15257                 .unsol_event = alc861vd_lenovo_unsol_event,
15258                 .setup = alc861vd_lenovo_setup,
15259                 .init_hook = alc861vd_lenovo_init_hook,
15260         },
15261         [ALC861VD_DALLAS] = {
15262                 .mixers = { alc861vd_dallas_mixer },
15263                 .init_verbs = { alc861vd_dallas_verbs },
15264                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
15265                 .dac_nids = alc861vd_dac_nids,
15266                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15267                 .channel_mode = alc861vd_3stack_2ch_modes,
15268                 .input_mux = &alc861vd_dallas_capture_source,
15269                 .unsol_event = alc_automute_amp_unsol_event,
15270                 .setup = alc861vd_dallas_setup,
15271                 .init_hook = alc_automute_amp,
15272         },
15273         [ALC861VD_HP] = {
15274                 .mixers = { alc861vd_hp_mixer },
15275                 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs },
15276                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
15277                 .dac_nids = alc861vd_dac_nids,
15278                 .dig_out_nid = ALC861VD_DIGOUT_NID,
15279                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15280                 .channel_mode = alc861vd_3stack_2ch_modes,
15281                 .input_mux = &alc861vd_hp_capture_source,
15282                 .unsol_event = alc_automute_amp_unsol_event,
15283                 .setup = alc861vd_dallas_setup,
15284                 .init_hook = alc_automute_amp,
15285         },
15286         [ALC660VD_ASUS_V1S] = {
15287                 .mixers = { alc861vd_lenovo_mixer },
15288                 .init_verbs = { alc861vd_volume_init_verbs,
15289                                 alc861vd_3stack_init_verbs,
15290                                 alc861vd_eapd_verbs,
15291                                 alc861vd_lenovo_unsol_verbs },
15292                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
15293                 .dac_nids = alc660vd_dac_nids,
15294                 .dig_out_nid = ALC861VD_DIGOUT_NID,
15295                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15296                 .channel_mode = alc861vd_3stack_2ch_modes,
15297                 .input_mux = &alc861vd_capture_source,
15298                 .unsol_event = alc861vd_lenovo_unsol_event,
15299                 .setup = alc861vd_lenovo_setup,
15300                 .init_hook = alc861vd_lenovo_init_hook,
15301         },
15302 };
15303
15304 /*
15305  * BIOS auto configuration
15306  */
15307 static int alc861vd_auto_create_input_ctls(struct hda_codec *codec,
15308                                                 const struct auto_pin_cfg *cfg)
15309 {
15310         return alc_auto_create_input_ctls(codec, cfg, 0x15, 0x09, 0);
15311 }
15312
15313
15314 static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
15315                                 hda_nid_t nid, int pin_type, int dac_idx)
15316 {
15317         alc_set_pin_output(codec, nid, pin_type);
15318 }
15319
15320 static void alc861vd_auto_init_multi_out(struct hda_codec *codec)
15321 {
15322         struct alc_spec *spec = codec->spec;
15323         int i;
15324
15325         for (i = 0; i <= HDA_SIDE; i++) {
15326                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
15327                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
15328                 if (nid)
15329                         alc861vd_auto_set_output_and_unmute(codec, nid,
15330                                                             pin_type, i);
15331         }
15332 }
15333
15334
15335 static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
15336 {
15337         struct alc_spec *spec = codec->spec;
15338         hda_nid_t pin;
15339
15340         pin = spec->autocfg.hp_pins[0];
15341         if (pin) /* connect to front and use dac 0 */
15342                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
15343         pin = spec->autocfg.speaker_pins[0];
15344         if (pin)
15345                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
15346 }
15347
15348 #define ALC861VD_PIN_CD_NID             ALC880_PIN_CD_NID
15349
15350 static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
15351 {
15352         struct alc_spec *spec = codec->spec;
15353         int i;
15354
15355         for (i = 0; i < AUTO_PIN_LAST; i++) {
15356                 hda_nid_t nid = spec->autocfg.input_pins[i];
15357                 if (alc_is_input_pin(codec, nid)) {
15358                         alc_set_input_pin(codec, nid, i);
15359                         if (nid != ALC861VD_PIN_CD_NID &&
15360                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
15361                                 snd_hda_codec_write(codec, nid, 0,
15362                                                 AC_VERB_SET_AMP_GAIN_MUTE,
15363                                                 AMP_OUT_MUTE);
15364                 }
15365         }
15366 }
15367
15368 #define alc861vd_auto_init_input_src    alc882_auto_init_input_src
15369
15370 #define alc861vd_idx_to_mixer_vol(nid)          ((nid) + 0x02)
15371 #define alc861vd_idx_to_mixer_switch(nid)       ((nid) + 0x0c)
15372
15373 /* add playback controls from the parsed DAC table */
15374 /* Based on ALC880 version. But ALC861VD has separate,
15375  * different NIDs for mute/unmute switch and volume control */
15376 static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
15377                                              const struct auto_pin_cfg *cfg)
15378 {
15379         static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"};
15380         hda_nid_t nid_v, nid_s;
15381         int i, err;
15382
15383         for (i = 0; i < cfg->line_outs; i++) {
15384                 if (!spec->multiout.dac_nids[i])
15385                         continue;
15386                 nid_v = alc861vd_idx_to_mixer_vol(
15387                                 alc880_dac_to_idx(
15388                                         spec->multiout.dac_nids[i]));
15389                 nid_s = alc861vd_idx_to_mixer_switch(
15390                                 alc880_dac_to_idx(
15391                                         spec->multiout.dac_nids[i]));
15392
15393                 if (i == 2) {
15394                         /* Center/LFE */
15395                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
15396                                               "Center",
15397                                           HDA_COMPOSE_AMP_VAL(nid_v, 1, 0,
15398                                                               HDA_OUTPUT));
15399                         if (err < 0)
15400                                 return err;
15401                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
15402                                               "LFE",
15403                                           HDA_COMPOSE_AMP_VAL(nid_v, 2, 0,
15404                                                               HDA_OUTPUT));
15405                         if (err < 0)
15406                                 return err;
15407                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
15408                                              "Center",
15409                                           HDA_COMPOSE_AMP_VAL(nid_s, 1, 2,
15410                                                               HDA_INPUT));
15411                         if (err < 0)
15412                                 return err;
15413                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
15414                                              "LFE",
15415                                           HDA_COMPOSE_AMP_VAL(nid_s, 2, 2,
15416                                                               HDA_INPUT));
15417                         if (err < 0)
15418                                 return err;
15419                 } else {
15420                         const char *pfx;
15421                         if (cfg->line_outs == 1 &&
15422                             cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
15423                                 if (!cfg->hp_pins)
15424                                         pfx = "Speaker";
15425                                 else
15426                                         pfx = "PCM";
15427                         } else
15428                                 pfx = chname[i];
15429                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
15430                                           HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
15431                                                               HDA_OUTPUT));
15432                         if (err < 0)
15433                                 return err;
15434                         if (cfg->line_outs == 1 &&
15435                             cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
15436                                 pfx = "Speaker";
15437                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE, pfx,
15438                                           HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
15439                                                               HDA_INPUT));
15440                         if (err < 0)
15441                                 return err;
15442                 }
15443         }
15444         return 0;
15445 }
15446
15447 /* add playback controls for speaker and HP outputs */
15448 /* Based on ALC880 version. But ALC861VD has separate,
15449  * different NIDs for mute/unmute switch and volume control */
15450 static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
15451                                         hda_nid_t pin, const char *pfx)
15452 {
15453         hda_nid_t nid_v, nid_s;
15454         int err;
15455
15456         if (!pin)
15457                 return 0;
15458
15459         if (alc880_is_fixed_pin(pin)) {
15460                 nid_v = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
15461                 /* specify the DAC as the extra output */
15462                 if (!spec->multiout.hp_nid)
15463                         spec->multiout.hp_nid = nid_v;
15464                 else
15465                         spec->multiout.extra_out_nid[0] = nid_v;
15466                 /* control HP volume/switch on the output mixer amp */
15467                 nid_v = alc861vd_idx_to_mixer_vol(
15468                                 alc880_fixed_pin_idx(pin));
15469                 nid_s = alc861vd_idx_to_mixer_switch(
15470                                 alc880_fixed_pin_idx(pin));
15471
15472                 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
15473                                   HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT));
15474                 if (err < 0)
15475                         return err;
15476                 err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE, pfx,
15477                                   HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT));
15478                 if (err < 0)
15479                         return err;
15480         } else if (alc880_is_multi_pin(pin)) {
15481                 /* set manual connection */
15482                 /* we have only a switch on HP-out PIN */
15483                 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
15484                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
15485                 if (err < 0)
15486                         return err;
15487         }
15488         return 0;
15489 }
15490
15491 /* parse the BIOS configuration and set up the alc_spec
15492  * return 1 if successful, 0 if the proper config is not found,
15493  * or a negative error code
15494  * Based on ALC880 version - had to change it to override
15495  * alc880_auto_create_extra_out and alc880_auto_create_multi_out_ctls */
15496 static int alc861vd_parse_auto_config(struct hda_codec *codec)
15497 {
15498         struct alc_spec *spec = codec->spec;
15499         int err;
15500         static hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
15501
15502         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
15503                                            alc861vd_ignore);
15504         if (err < 0)
15505                 return err;
15506         if (!spec->autocfg.line_outs)
15507                 return 0; /* can't find valid BIOS pin config */
15508
15509         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
15510         if (err < 0)
15511                 return err;
15512         err = alc861vd_auto_create_multi_out_ctls(spec, &spec->autocfg);
15513         if (err < 0)
15514                 return err;
15515         err = alc861vd_auto_create_extra_out(spec,
15516                                              spec->autocfg.speaker_pins[0],
15517                                              "Speaker");
15518         if (err < 0)
15519                 return err;
15520         err = alc861vd_auto_create_extra_out(spec,
15521                                              spec->autocfg.hp_pins[0],
15522                                              "Headphone");
15523         if (err < 0)
15524                 return err;
15525         err = alc861vd_auto_create_input_ctls(codec, &spec->autocfg);
15526         if (err < 0)
15527                 return err;
15528
15529         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
15530
15531         if (spec->autocfg.dig_outs)
15532                 spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID;
15533
15534         if (spec->kctls.list)
15535                 add_mixer(spec, spec->kctls.list);
15536
15537         add_verb(spec, alc861vd_volume_init_verbs);
15538
15539         spec->num_mux_defs = 1;
15540         spec->input_mux = &spec->private_imux[0];
15541
15542         err = alc_auto_add_mic_boost(codec);
15543         if (err < 0)
15544                 return err;
15545
15546         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
15547
15548         return 1;
15549 }
15550
15551 /* additional initialization for auto-configuration model */
15552 static void alc861vd_auto_init(struct hda_codec *codec)
15553 {
15554         struct alc_spec *spec = codec->spec;
15555         alc861vd_auto_init_multi_out(codec);
15556         alc861vd_auto_init_hp_out(codec);
15557         alc861vd_auto_init_analog_input(codec);
15558         alc861vd_auto_init_input_src(codec);
15559         if (spec->unsol_event)
15560                 alc_inithook(codec);
15561 }
15562
15563 enum {
15564         ALC660VD_FIX_ASUS_GPIO1
15565 };
15566
15567 /* reset GPIO1 */
15568 static const struct hda_verb alc660vd_fix_asus_gpio1_verbs[] = {
15569         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
15570         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
15571         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
15572         { }
15573 };
15574
15575 static const struct alc_fixup alc861vd_fixups[] = {
15576         [ALC660VD_FIX_ASUS_GPIO1] = {
15577                 .verbs = alc660vd_fix_asus_gpio1_verbs,
15578         },
15579 };
15580
15581 static struct snd_pci_quirk alc861vd_fixup_tbl[] = {
15582         SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
15583         {}
15584 };
15585
15586 static int patch_alc861vd(struct hda_codec *codec)
15587 {
15588         struct alc_spec *spec;
15589         int err, board_config;
15590
15591         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
15592         if (spec == NULL)
15593                 return -ENOMEM;
15594
15595         codec->spec = spec;
15596
15597         board_config = snd_hda_check_board_config(codec, ALC861VD_MODEL_LAST,
15598                                                   alc861vd_models,
15599                                                   alc861vd_cfg_tbl);
15600
15601         if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) {
15602                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
15603                        codec->chip_name);
15604                 board_config = ALC861VD_AUTO;
15605         }
15606
15607         alc_pick_fixup(codec, alc861vd_fixup_tbl, alc861vd_fixups);
15608
15609         if (board_config == ALC861VD_AUTO) {
15610                 /* automatic parse from the BIOS config */
15611                 err = alc861vd_parse_auto_config(codec);
15612                 if (err < 0) {
15613                         alc_free(codec);
15614                         return err;
15615                 } else if (!err) {
15616                         printk(KERN_INFO
15617                                "hda_codec: Cannot set up configuration "
15618                                "from BIOS.  Using base mode...\n");
15619                         board_config = ALC861VD_3ST;
15620                 }
15621         }
15622
15623         err = snd_hda_attach_beep_device(codec, 0x23);
15624         if (err < 0) {
15625                 alc_free(codec);
15626                 return err;
15627         }
15628
15629         if (board_config != ALC861VD_AUTO)
15630                 setup_preset(codec, &alc861vd_presets[board_config]);
15631
15632         if (codec->vendor_id == 0x10ec0660) {
15633                 /* always turn on EAPD */
15634                 add_verb(spec, alc660vd_eapd_verbs);
15635         }
15636
15637         spec->stream_analog_playback = &alc861vd_pcm_analog_playback;
15638         spec->stream_analog_capture = &alc861vd_pcm_analog_capture;
15639
15640         spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
15641         spec->stream_digital_capture = &alc861vd_pcm_digital_capture;
15642
15643         if (!spec->adc_nids) {
15644                 spec->adc_nids = alc861vd_adc_nids;
15645                 spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
15646         }
15647         if (!spec->capsrc_nids)
15648                 spec->capsrc_nids = alc861vd_capsrc_nids;
15649
15650         set_capture_mixer(codec);
15651         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
15652
15653         spec->vmaster_nid = 0x02;
15654
15655         codec->patch_ops = alc_patch_ops;
15656
15657         if (board_config == ALC861VD_AUTO)
15658                 spec->init_hook = alc861vd_auto_init;
15659 #ifdef CONFIG_SND_HDA_POWER_SAVE
15660         if (!spec->loopback.amplist)
15661                 spec->loopback.amplist = alc861vd_loopbacks;
15662 #endif
15663         codec->proc_widget_hook = print_realtek_coef;
15664
15665         return 0;
15666 }
15667
15668 /*
15669  * ALC662 support
15670  *
15671  * ALC662 is almost identical with ALC880 but has cleaner and more flexible
15672  * configuration.  Each pin widget can choose any input DACs and a mixer.
15673  * Each ADC is connected from a mixer of all inputs.  This makes possible
15674  * 6-channel independent captures.
15675  *
15676  * In addition, an independent DAC for the multi-playback (not used in this
15677  * driver yet).
15678  */
15679 #define ALC662_DIGOUT_NID       0x06
15680 #define ALC662_DIGIN_NID        0x0a
15681
15682 static hda_nid_t alc662_dac_nids[4] = {
15683         /* front, rear, clfe, rear_surr */
15684         0x02, 0x03, 0x04
15685 };
15686
15687 static hda_nid_t alc272_dac_nids[2] = {
15688         0x02, 0x03
15689 };
15690
15691 static hda_nid_t alc662_adc_nids[2] = {
15692         /* ADC1-2 */
15693         0x09, 0x08
15694 };
15695
15696 static hda_nid_t alc272_adc_nids[1] = {
15697         /* ADC1-2 */
15698         0x08,
15699 };
15700
15701 static hda_nid_t alc662_capsrc_nids[2] = { 0x22, 0x23 };
15702 static hda_nid_t alc272_capsrc_nids[1] = { 0x23 };
15703
15704
15705 /* input MUX */
15706 /* FIXME: should be a matrix-type input source selection */
15707 static struct hda_input_mux alc662_capture_source = {
15708         .num_items = 4,
15709         .items = {
15710                 { "Mic", 0x0 },
15711                 { "Front Mic", 0x1 },
15712                 { "Line", 0x2 },
15713                 { "CD", 0x4 },
15714         },
15715 };
15716
15717 static struct hda_input_mux alc662_lenovo_101e_capture_source = {
15718         .num_items = 2,
15719         .items = {
15720                 { "Mic", 0x1 },
15721                 { "Line", 0x2 },
15722         },
15723 };
15724
15725 static struct hda_input_mux alc663_capture_source = {
15726         .num_items = 3,
15727         .items = {
15728                 { "Mic", 0x0 },
15729                 { "Front Mic", 0x1 },
15730                 { "Line", 0x2 },
15731         },
15732 };
15733
15734 #if 0 /* set to 1 for testing other input sources below */
15735 static struct hda_input_mux alc272_nc10_capture_source = {
15736         .num_items = 16,
15737         .items = {
15738                 { "Autoselect Mic", 0x0 },
15739                 { "Internal Mic", 0x1 },
15740                 { "In-0x02", 0x2 },
15741                 { "In-0x03", 0x3 },
15742                 { "In-0x04", 0x4 },
15743                 { "In-0x05", 0x5 },
15744                 { "In-0x06", 0x6 },
15745                 { "In-0x07", 0x7 },
15746                 { "In-0x08", 0x8 },
15747                 { "In-0x09", 0x9 },
15748                 { "In-0x0a", 0x0a },
15749                 { "In-0x0b", 0x0b },
15750                 { "In-0x0c", 0x0c },
15751                 { "In-0x0d", 0x0d },
15752                 { "In-0x0e", 0x0e },
15753                 { "In-0x0f", 0x0f },
15754         },
15755 };
15756 #endif
15757
15758 /*
15759  * 2ch mode
15760  */
15761 static struct hda_channel_mode alc662_3ST_2ch_modes[1] = {
15762         { 2, NULL }
15763 };
15764
15765 /*
15766  * 2ch mode
15767  */
15768 static struct hda_verb alc662_3ST_ch2_init[] = {
15769         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
15770         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
15771         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
15772         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
15773         { } /* end */
15774 };
15775
15776 /*
15777  * 6ch mode
15778  */
15779 static struct hda_verb alc662_3ST_ch6_init[] = {
15780         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15781         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
15782         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
15783         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15784         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
15785         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
15786         { } /* end */
15787 };
15788
15789 static struct hda_channel_mode alc662_3ST_6ch_modes[2] = {
15790         { 2, alc662_3ST_ch2_init },
15791         { 6, alc662_3ST_ch6_init },
15792 };
15793
15794 /*
15795  * 2ch mode
15796  */
15797 static struct hda_verb alc662_sixstack_ch6_init[] = {
15798         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
15799         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
15800         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15801         { } /* end */
15802 };
15803
15804 /*
15805  * 6ch mode
15806  */
15807 static struct hda_verb alc662_sixstack_ch8_init[] = {
15808         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15809         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15810         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15811         { } /* end */
15812 };
15813
15814 static struct hda_channel_mode alc662_5stack_modes[2] = {
15815         { 2, alc662_sixstack_ch6_init },
15816         { 6, alc662_sixstack_ch8_init },
15817 };
15818
15819 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
15820  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
15821  */
15822
15823 static struct snd_kcontrol_new alc662_base_mixer[] = {
15824         /* output mixer control */
15825         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
15826         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
15827         HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
15828         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
15829         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15830         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15831         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
15832         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
15833         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15834
15835         /*Input mixer control */
15836         HDA_CODEC_VOLUME("CD Playback Volume", 0xb, 0x4, HDA_INPUT),
15837         HDA_CODEC_MUTE("CD Playback Switch", 0xb, 0x4, HDA_INPUT),
15838         HDA_CODEC_VOLUME("Line Playback Volume", 0xb, 0x02, HDA_INPUT),
15839         HDA_CODEC_MUTE("Line Playback Switch", 0xb, 0x02, HDA_INPUT),
15840         HDA_CODEC_VOLUME("Mic Playback Volume", 0xb, 0x0, HDA_INPUT),
15841         HDA_CODEC_MUTE("Mic Playback Switch", 0xb, 0x0, HDA_INPUT),
15842         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0xb, 0x01, HDA_INPUT),
15843         HDA_CODEC_MUTE("Front Mic Playback Switch", 0xb, 0x01, HDA_INPUT),
15844         { } /* end */
15845 };
15846
15847 static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
15848         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15849         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
15850         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15851         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
15852         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
15853         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15854         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15855         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15856         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15857         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15858         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15859         { } /* end */
15860 };
15861
15862 static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
15863         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15864         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
15865         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15866         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
15867         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15868         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15869         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
15870         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
15871         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15872         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
15873         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
15874         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15875         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15876         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15877         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15878         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15879         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15880         { } /* end */
15881 };
15882
15883 static struct snd_kcontrol_new alc662_lenovo_101e_mixer[] = {
15884         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15885         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
15886         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15887         HDA_BIND_MUTE("Speaker Playback Switch", 0x03, 2, HDA_INPUT),
15888         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15889         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15890         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15891         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15892         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15893         { } /* end */
15894 };
15895
15896 static struct snd_kcontrol_new alc662_eeepc_p701_mixer[] = {
15897         HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15898         ALC262_HIPPO_MASTER_SWITCH,
15899
15900         HDA_CODEC_VOLUME("e-Mic Boost", 0x18, 0, HDA_INPUT),
15901         HDA_CODEC_VOLUME("e-Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15902         HDA_CODEC_MUTE("e-Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15903
15904         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
15905         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15906         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15907         { } /* end */
15908 };
15909
15910 static struct snd_kcontrol_new alc662_eeepc_ep20_mixer[] = {
15911         ALC262_HIPPO_MASTER_SWITCH,
15912         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15913         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15914         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15915         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15916         HDA_BIND_MUTE("MuteCtrl Playback Switch", 0x0c, 2, HDA_INPUT),
15917         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15918         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15919         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15920         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15921         { } /* end */
15922 };
15923
15924 static struct hda_bind_ctls alc663_asus_bind_master_vol = {
15925         .ops = &snd_hda_bind_vol,
15926         .values = {
15927                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
15928                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
15929                 0
15930         },
15931 };
15932
15933 static struct hda_bind_ctls alc663_asus_one_bind_switch = {
15934         .ops = &snd_hda_bind_sw,
15935         .values = {
15936                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15937                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
15938                 0
15939         },
15940 };
15941
15942 static struct snd_kcontrol_new alc663_m51va_mixer[] = {
15943         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15944         HDA_BIND_SW("Master Playback Switch", &alc663_asus_one_bind_switch),
15945         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15946         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15947         { } /* end */
15948 };
15949
15950 static struct hda_bind_ctls alc663_asus_tree_bind_switch = {
15951         .ops = &snd_hda_bind_sw,
15952         .values = {
15953                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15954                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
15955                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
15956                 0
15957         },
15958 };
15959
15960 static struct snd_kcontrol_new alc663_two_hp_m1_mixer[] = {
15961         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15962         HDA_BIND_SW("Master Playback Switch", &alc663_asus_tree_bind_switch),
15963         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15964         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15965         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15966         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15967
15968         { } /* end */
15969 };
15970
15971 static struct hda_bind_ctls alc663_asus_four_bind_switch = {
15972         .ops = &snd_hda_bind_sw,
15973         .values = {
15974                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15975                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
15976                 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
15977                 0
15978         },
15979 };
15980
15981 static struct snd_kcontrol_new alc663_two_hp_m2_mixer[] = {
15982         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15983         HDA_BIND_SW("Master Playback Switch", &alc663_asus_four_bind_switch),
15984         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15985         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15986         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15987         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15988         { } /* end */
15989 };
15990
15991 static struct snd_kcontrol_new alc662_1bjd_mixer[] = {
15992         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15993         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15994         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15995         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15996         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15997         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15998         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15999         { } /* end */
16000 };
16001
16002 static struct hda_bind_ctls alc663_asus_two_bind_master_vol = {
16003         .ops = &snd_hda_bind_vol,
16004         .values = {
16005                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
16006                 HDA_COMPOSE_AMP_VAL(0x04, 3, 0, HDA_OUTPUT),
16007                 0
16008         },
16009 };
16010
16011 static struct hda_bind_ctls alc663_asus_two_bind_switch = {
16012         .ops = &snd_hda_bind_sw,
16013         .values = {
16014                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
16015                 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT),
16016                 0
16017         },
16018 };
16019
16020 static struct snd_kcontrol_new alc663_asus_21jd_clfe_mixer[] = {
16021         HDA_BIND_VOL("Master Playback Volume",
16022                                 &alc663_asus_two_bind_master_vol),
16023         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
16024         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
16025         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
16026         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16027         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16028         { } /* end */
16029 };
16030
16031 static struct snd_kcontrol_new alc663_asus_15jd_clfe_mixer[] = {
16032         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
16033         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
16034         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
16035         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
16036         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16037         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16038         { } /* end */
16039 };
16040
16041 static struct snd_kcontrol_new alc663_g71v_mixer[] = {
16042         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16043         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
16044         HDA_CODEC_VOLUME("Front Playback Volume", 0x03, 0x0, HDA_OUTPUT),
16045         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
16046         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
16047
16048         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16049         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16050         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16051         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16052         { } /* end */
16053 };
16054
16055 static struct snd_kcontrol_new alc663_g50v_mixer[] = {
16056         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16057         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
16058         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
16059
16060         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16061         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16062         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16063         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16064         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
16065         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
16066         { } /* end */
16067 };
16068
16069 static struct snd_kcontrol_new alc662_chmode_mixer[] = {
16070         {
16071                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
16072                 .name = "Channel Mode",
16073                 .info = alc_ch_mode_info,
16074                 .get = alc_ch_mode_get,
16075                 .put = alc_ch_mode_put,
16076         },
16077         { } /* end */
16078 };
16079
16080 static struct hda_verb alc662_init_verbs[] = {
16081         /* ADC: mute amp left and right */
16082         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16083         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
16084         /* Front mixer: unmute input/output amp left and right (volume = 0) */
16085
16086         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16087         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
16088         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
16089         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
16090         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
16091
16092         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16093         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16094         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16095         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16096         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16097         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16098
16099         /* Front Pin: output 0 (0x0c) */
16100         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16101         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16102
16103         /* Rear Pin: output 1 (0x0d) */
16104         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16105         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16106
16107         /* CLFE Pin: output 2 (0x0e) */
16108         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16109         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16110
16111         /* Mic (rear) pin: input vref at 80% */
16112         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
16113         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16114         /* Front Mic pin: input vref at 80% */
16115         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
16116         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16117         /* Line In pin: input */
16118         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16119         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16120         /* Line-2 In: Headphone output (output 0 - 0x0c) */
16121         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16122         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16123         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
16124         /* CD pin widget for input */
16125         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16126
16127         /* FIXME: use matrix-type input source selection */
16128         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
16129         /* Input mixer */
16130         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16131         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16132
16133         /* always trun on EAPD */
16134         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
16135         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
16136
16137         { }
16138 };
16139
16140 static struct hda_verb alc662_sue_init_verbs[] = {
16141         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
16142         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
16143         {}
16144 };
16145
16146 static struct hda_verb alc662_eeepc_sue_init_verbs[] = {
16147         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16148         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16149         {}
16150 };
16151
16152 /* Set Unsolicited Event*/
16153 static struct hda_verb alc662_eeepc_ep20_sue_init_verbs[] = {
16154         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16155         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16156         {}
16157 };
16158
16159 /*
16160  * generic initialization of ADC, input mixers and output mixers
16161  */
16162 static struct hda_verb alc662_auto_init_verbs[] = {
16163         /*
16164          * Unmute ADC and set the default input to mic-in
16165          */
16166         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
16167         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16168
16169         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
16170          * mixer widget
16171          * Note: PASD motherboards uses the Line In 2 as the input for front
16172          * panel mic (mic 2)
16173          */
16174         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
16175         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16176         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
16177         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
16178         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
16179         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
16180
16181         /*
16182          * Set up output mixers (0x0c - 0x0f)
16183          */
16184         /* set vol=0 to output mixers */
16185         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
16186         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
16187         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
16188
16189         /* set up input amps for analog loopback */
16190         /* Amp Indices: DAC = 0, mixer = 1 */
16191         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16192         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16193         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16194         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16195         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16196         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16197
16198
16199         /* FIXME: use matrix-type input source selection */
16200         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
16201         /* Input mixer */
16202         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16203         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16204         { }
16205 };
16206
16207 /* additional verbs for ALC663 */
16208 static struct hda_verb alc663_auto_init_verbs[] = {
16209         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16210         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16211         { }
16212 };
16213
16214 static struct hda_verb alc663_m51va_init_verbs[] = {
16215         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16216         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16217         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16218         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16219         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16220         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16221         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
16222         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16223         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16224         {}
16225 };
16226
16227 static struct hda_verb alc663_21jd_amic_init_verbs[] = {
16228         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16229         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16230         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16231         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16232         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16233         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16234         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16235         {}
16236 };
16237
16238 static struct hda_verb alc662_1bjd_amic_init_verbs[] = {
16239         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16240         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16241         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16242         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
16243         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16244         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16245         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16246         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16247         {}
16248 };
16249
16250 static struct hda_verb alc663_15jd_amic_init_verbs[] = {
16251         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16252         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16253         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16254         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16255         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16256         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16257         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16258         {}
16259 };
16260
16261 static struct hda_verb alc663_two_hp_amic_m1_init_verbs[] = {
16262         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16263         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16264         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16265         {0x21, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
16266         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16267         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16268         {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
16269         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16270         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16271         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16272         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16273         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16274         {}
16275 };
16276
16277 static struct hda_verb alc663_two_hp_amic_m2_init_verbs[] = {
16278         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16279         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16280         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16281         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16282         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16283         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16284         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16285         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16286         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16287         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16288         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16289         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16290         {}
16291 };
16292
16293 static struct hda_verb alc663_g71v_init_verbs[] = {
16294         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16295         /* {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
16296         /* {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, */ /* Headphone */
16297
16298         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16299         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16300         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
16301
16302         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
16303         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_MIC_EVENT},
16304         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
16305         {}
16306 };
16307
16308 static struct hda_verb alc663_g50v_init_verbs[] = {
16309         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16310         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16311         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
16312
16313         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16314         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16315         {}
16316 };
16317
16318 static struct hda_verb alc662_ecs_init_verbs[] = {
16319         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0x701f},
16320         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16321         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16322         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16323         {}
16324 };
16325
16326 static struct hda_verb alc272_dell_zm1_init_verbs[] = {
16327         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16328         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16329         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16330         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16331         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16332         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16333         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16334         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16335         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
16336         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16337         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16338         {}
16339 };
16340
16341 static struct hda_verb alc272_dell_init_verbs[] = {
16342         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16343         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16344         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16345         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16346         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16347         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16348         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16349         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16350         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
16351         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16352         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16353         {}
16354 };
16355
16356 static struct snd_kcontrol_new alc662_auto_capture_mixer[] = {
16357         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
16358         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
16359         { } /* end */
16360 };
16361
16362 static struct snd_kcontrol_new alc272_auto_capture_mixer[] = {
16363         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
16364         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
16365         { } /* end */
16366 };
16367
16368 static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
16369 {
16370         unsigned int present;
16371         unsigned char bits;
16372
16373         present = snd_hda_codec_read(codec, 0x14, 0,
16374                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
16375         bits = present ? HDA_AMP_MUTE : 0;
16376         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
16377                                  HDA_AMP_MUTE, bits);
16378 }
16379
16380 static void alc662_lenovo_101e_all_automute(struct hda_codec *codec)
16381 {
16382         unsigned int present;
16383         unsigned char bits;
16384
16385         present = snd_hda_codec_read(codec, 0x1b, 0,
16386                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
16387         bits = present ? HDA_AMP_MUTE : 0;
16388         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
16389                                  HDA_AMP_MUTE, bits);
16390         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
16391                                  HDA_AMP_MUTE, bits);
16392 }
16393
16394 static void alc662_lenovo_101e_unsol_event(struct hda_codec *codec,
16395                                            unsigned int res)
16396 {
16397         if ((res >> 26) == ALC880_HP_EVENT)
16398                 alc662_lenovo_101e_all_automute(codec);
16399         if ((res >> 26) == ALC880_FRONT_EVENT)
16400                 alc662_lenovo_101e_ispeaker_automute(codec);
16401 }
16402
16403 /* unsolicited event for HP jack sensing */
16404 static void alc662_eeepc_unsol_event(struct hda_codec *codec,
16405                                      unsigned int res)
16406 {
16407         if ((res >> 26) == ALC880_MIC_EVENT)
16408                 alc_mic_automute(codec);
16409         else
16410                 alc262_hippo_unsol_event(codec, res);
16411 }
16412
16413 static void alc662_eeepc_setup(struct hda_codec *codec)
16414 {
16415         struct alc_spec *spec = codec->spec;
16416
16417         alc262_hippo1_setup(codec);
16418         spec->ext_mic.pin = 0x18;
16419         spec->ext_mic.mux_idx = 0;
16420         spec->int_mic.pin = 0x19;
16421         spec->int_mic.mux_idx = 1;
16422         spec->auto_mic = 1;
16423 }
16424
16425 static void alc662_eeepc_inithook(struct hda_codec *codec)
16426 {
16427         alc262_hippo_automute(codec);
16428         alc_mic_automute(codec);
16429 }
16430
16431 static void alc662_eeepc_ep20_setup(struct hda_codec *codec)
16432 {
16433         struct alc_spec *spec = codec->spec;
16434
16435         spec->autocfg.hp_pins[0] = 0x14;
16436         spec->autocfg.speaker_pins[0] = 0x1b;
16437 }
16438
16439 #define alc662_eeepc_ep20_inithook      alc262_hippo_master_update
16440
16441 static void alc663_m51va_speaker_automute(struct hda_codec *codec)
16442 {
16443         unsigned int present;
16444         unsigned char bits;
16445
16446         present = snd_hda_codec_read(codec, 0x21, 0,
16447                         AC_VERB_GET_PIN_SENSE, 0)
16448                         & AC_PINSENSE_PRESENCE;
16449         bits = present ? HDA_AMP_MUTE : 0;
16450         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16451                                 AMP_IN_MUTE(0), bits);
16452         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16453                                 AMP_IN_MUTE(0), bits);
16454 }
16455
16456 static void alc663_21jd_two_speaker_automute(struct hda_codec *codec)
16457 {
16458         unsigned int present;
16459         unsigned char bits;
16460
16461         present = snd_hda_codec_read(codec, 0x21, 0,
16462                         AC_VERB_GET_PIN_SENSE, 0)
16463                         & AC_PINSENSE_PRESENCE;
16464         bits = present ? HDA_AMP_MUTE : 0;
16465         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16466                                 AMP_IN_MUTE(0), bits);
16467         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16468                                 AMP_IN_MUTE(0), bits);
16469         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
16470                                 AMP_IN_MUTE(0), bits);
16471         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
16472                                 AMP_IN_MUTE(0), bits);
16473 }
16474
16475 static void alc663_15jd_two_speaker_automute(struct hda_codec *codec)
16476 {
16477         unsigned int present;
16478         unsigned char bits;
16479
16480         present = snd_hda_codec_read(codec, 0x15, 0,
16481                         AC_VERB_GET_PIN_SENSE, 0)
16482                         & AC_PINSENSE_PRESENCE;
16483         bits = present ? HDA_AMP_MUTE : 0;
16484         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16485                                 AMP_IN_MUTE(0), bits);
16486         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16487                                 AMP_IN_MUTE(0), bits);
16488         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
16489                                 AMP_IN_MUTE(0), bits);
16490         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
16491                                 AMP_IN_MUTE(0), bits);
16492 }
16493
16494 static void alc662_f5z_speaker_automute(struct hda_codec *codec)
16495 {
16496         unsigned int present;
16497         unsigned char bits;
16498
16499         present = snd_hda_codec_read(codec, 0x1b, 0,
16500                         AC_VERB_GET_PIN_SENSE, 0)
16501                         & AC_PINSENSE_PRESENCE;
16502         bits = present ? 0 : PIN_OUT;
16503         snd_hda_codec_write(codec, 0x14, 0,
16504                          AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
16505 }
16506
16507 static void alc663_two_hp_m1_speaker_automute(struct hda_codec *codec)
16508 {
16509         unsigned int present1, present2;
16510
16511         present1 = snd_hda_codec_read(codec, 0x21, 0,
16512                         AC_VERB_GET_PIN_SENSE, 0)
16513                         & AC_PINSENSE_PRESENCE;
16514         present2 = snd_hda_codec_read(codec, 0x15, 0,
16515                         AC_VERB_GET_PIN_SENSE, 0)
16516                         & AC_PINSENSE_PRESENCE;
16517
16518         if (present1 || present2) {
16519                 snd_hda_codec_write_cache(codec, 0x14, 0,
16520                         AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
16521         } else {
16522                 snd_hda_codec_write_cache(codec, 0x14, 0,
16523                         AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
16524         }
16525 }
16526
16527 static void alc663_two_hp_m2_speaker_automute(struct hda_codec *codec)
16528 {
16529         unsigned int present1, present2;
16530
16531         present1 = snd_hda_codec_read(codec, 0x1b, 0,
16532                                 AC_VERB_GET_PIN_SENSE, 0)
16533                                 & AC_PINSENSE_PRESENCE;
16534         present2 = snd_hda_codec_read(codec, 0x15, 0,
16535                                 AC_VERB_GET_PIN_SENSE, 0)
16536                                 & AC_PINSENSE_PRESENCE;
16537
16538         if (present1 || present2) {
16539                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16540                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
16541                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16542                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
16543         } else {
16544                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16545                                 AMP_IN_MUTE(0), 0);
16546                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16547                                 AMP_IN_MUTE(0), 0);
16548         }
16549 }
16550
16551 static void alc663_m51va_unsol_event(struct hda_codec *codec,
16552                                            unsigned int res)
16553 {
16554         switch (res >> 26) {
16555         case ALC880_HP_EVENT:
16556                 alc663_m51va_speaker_automute(codec);
16557                 break;
16558         case ALC880_MIC_EVENT:
16559                 alc_mic_automute(codec);
16560                 break;
16561         }
16562 }
16563
16564 static void alc663_m51va_setup(struct hda_codec *codec)
16565 {
16566         struct alc_spec *spec = codec->spec;
16567         spec->ext_mic.pin = 0x18;
16568         spec->ext_mic.mux_idx = 0;
16569         spec->int_mic.pin = 0x12;
16570         spec->int_mic.mux_idx = 1;
16571         spec->auto_mic = 1;
16572 }
16573
16574 static void alc663_m51va_inithook(struct hda_codec *codec)
16575 {
16576         alc663_m51va_speaker_automute(codec);
16577         alc_mic_automute(codec);
16578 }
16579
16580 /* ***************** Mode1 ******************************/
16581 #define alc663_mode1_unsol_event        alc663_m51va_unsol_event
16582 #define alc663_mode1_setup              alc663_m51va_setup
16583 #define alc663_mode1_inithook           alc663_m51va_inithook
16584
16585 /* ***************** Mode2 ******************************/
16586 static void alc662_mode2_unsol_event(struct hda_codec *codec,
16587                                            unsigned int res)
16588 {
16589         switch (res >> 26) {
16590         case ALC880_HP_EVENT:
16591                 alc662_f5z_speaker_automute(codec);
16592                 break;
16593         case ALC880_MIC_EVENT:
16594                 alc_mic_automute(codec);
16595                 break;
16596         }
16597 }
16598
16599 #define alc662_mode2_setup      alc663_m51va_setup
16600
16601 static void alc662_mode2_inithook(struct hda_codec *codec)
16602 {
16603         alc662_f5z_speaker_automute(codec);
16604         alc_mic_automute(codec);
16605 }
16606 /* ***************** Mode3 ******************************/
16607 static void alc663_mode3_unsol_event(struct hda_codec *codec,
16608                                            unsigned int res)
16609 {
16610         switch (res >> 26) {
16611         case ALC880_HP_EVENT:
16612                 alc663_two_hp_m1_speaker_automute(codec);
16613                 break;
16614         case ALC880_MIC_EVENT:
16615                 alc_mic_automute(codec);
16616                 break;
16617         }
16618 }
16619
16620 #define alc663_mode3_setup      alc663_m51va_setup
16621
16622 static void alc663_mode3_inithook(struct hda_codec *codec)
16623 {
16624         alc663_two_hp_m1_speaker_automute(codec);
16625         alc_mic_automute(codec);
16626 }
16627 /* ***************** Mode4 ******************************/
16628 static void alc663_mode4_unsol_event(struct hda_codec *codec,
16629                                            unsigned int res)
16630 {
16631         switch (res >> 26) {
16632         case ALC880_HP_EVENT:
16633                 alc663_21jd_two_speaker_automute(codec);
16634                 break;
16635         case ALC880_MIC_EVENT:
16636                 alc_mic_automute(codec);
16637                 break;
16638         }
16639 }
16640
16641 #define alc663_mode4_setup      alc663_m51va_setup
16642
16643 static void alc663_mode4_inithook(struct hda_codec *codec)
16644 {
16645         alc663_21jd_two_speaker_automute(codec);
16646         alc_mic_automute(codec);
16647 }
16648 /* ***************** Mode5 ******************************/
16649 static void alc663_mode5_unsol_event(struct hda_codec *codec,
16650                                            unsigned int res)
16651 {
16652         switch (res >> 26) {
16653         case ALC880_HP_EVENT:
16654                 alc663_15jd_two_speaker_automute(codec);
16655                 break;
16656         case ALC880_MIC_EVENT:
16657                 alc_mic_automute(codec);
16658                 break;
16659         }
16660 }
16661
16662 #define alc663_mode5_setup      alc663_m51va_setup
16663
16664 static void alc663_mode5_inithook(struct hda_codec *codec)
16665 {
16666         alc663_15jd_two_speaker_automute(codec);
16667         alc_mic_automute(codec);
16668 }
16669 /* ***************** Mode6 ******************************/
16670 static void alc663_mode6_unsol_event(struct hda_codec *codec,
16671                                            unsigned int res)
16672 {
16673         switch (res >> 26) {
16674         case ALC880_HP_EVENT:
16675                 alc663_two_hp_m2_speaker_automute(codec);
16676                 break;
16677         case ALC880_MIC_EVENT:
16678                 alc_mic_automute(codec);
16679                 break;
16680         }
16681 }
16682
16683 #define alc663_mode6_setup      alc663_m51va_setup
16684
16685 static void alc663_mode6_inithook(struct hda_codec *codec)
16686 {
16687         alc663_two_hp_m2_speaker_automute(codec);
16688         alc_mic_automute(codec);
16689 }
16690
16691 static void alc663_g71v_hp_automute(struct hda_codec *codec)
16692 {
16693         unsigned int present;
16694         unsigned char bits;
16695
16696         present = snd_hda_codec_read(codec, 0x21, 0,
16697                                      AC_VERB_GET_PIN_SENSE, 0)
16698                 & AC_PINSENSE_PRESENCE;
16699         bits = present ? HDA_AMP_MUTE : 0;
16700         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
16701                                  HDA_AMP_MUTE, bits);
16702         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
16703                                  HDA_AMP_MUTE, bits);
16704 }
16705
16706 static void alc663_g71v_front_automute(struct hda_codec *codec)
16707 {
16708         unsigned int present;
16709         unsigned char bits;
16710
16711         present = snd_hda_codec_read(codec, 0x15, 0,
16712                                      AC_VERB_GET_PIN_SENSE, 0)
16713                 & AC_PINSENSE_PRESENCE;
16714         bits = present ? HDA_AMP_MUTE : 0;
16715         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
16716                                  HDA_AMP_MUTE, bits);
16717 }
16718
16719 static void alc663_g71v_unsol_event(struct hda_codec *codec,
16720                                            unsigned int res)
16721 {
16722         switch (res >> 26) {
16723         case ALC880_HP_EVENT:
16724                 alc663_g71v_hp_automute(codec);
16725                 break;
16726         case ALC880_FRONT_EVENT:
16727                 alc663_g71v_front_automute(codec);
16728                 break;
16729         case ALC880_MIC_EVENT:
16730                 alc_mic_automute(codec);
16731                 break;
16732         }
16733 }
16734
16735 #define alc663_g71v_setup       alc663_m51va_setup
16736
16737 static void alc663_g71v_inithook(struct hda_codec *codec)
16738 {
16739         alc663_g71v_front_automute(codec);
16740         alc663_g71v_hp_automute(codec);
16741         alc_mic_automute(codec);
16742 }
16743
16744 static void alc663_g50v_unsol_event(struct hda_codec *codec,
16745                                            unsigned int res)
16746 {
16747         switch (res >> 26) {
16748         case ALC880_HP_EVENT:
16749                 alc663_m51va_speaker_automute(codec);
16750                 break;
16751         case ALC880_MIC_EVENT:
16752                 alc_mic_automute(codec);
16753                 break;
16754         }
16755 }
16756
16757 #define alc663_g50v_setup       alc663_m51va_setup
16758
16759 static void alc663_g50v_inithook(struct hda_codec *codec)
16760 {
16761         alc663_m51va_speaker_automute(codec);
16762         alc_mic_automute(codec);
16763 }
16764
16765 static struct snd_kcontrol_new alc662_ecs_mixer[] = {
16766         HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16767         ALC262_HIPPO_MASTER_SWITCH,
16768
16769         HDA_CODEC_VOLUME("e-Mic/LineIn Boost", 0x18, 0, HDA_INPUT),
16770         HDA_CODEC_VOLUME("e-Mic/LineIn Playback Volume", 0x0b, 0x0, HDA_INPUT),
16771         HDA_CODEC_MUTE("e-Mic/LineIn Playback Switch", 0x0b, 0x0, HDA_INPUT),
16772
16773         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
16774         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16775         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16776         { } /* end */
16777 };
16778
16779 static struct snd_kcontrol_new alc272_nc10_mixer[] = {
16780         /* Master Playback automatically created from Speaker and Headphone */
16781         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16782         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
16783         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
16784         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
16785
16786         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16787         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16788         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
16789
16790         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16791         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16792         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
16793         { } /* end */
16794 };
16795
16796 #ifdef CONFIG_SND_HDA_POWER_SAVE
16797 #define alc662_loopbacks        alc880_loopbacks
16798 #endif
16799
16800
16801 /* pcm configuration: identical with ALC880 */
16802 #define alc662_pcm_analog_playback      alc880_pcm_analog_playback
16803 #define alc662_pcm_analog_capture       alc880_pcm_analog_capture
16804 #define alc662_pcm_digital_playback     alc880_pcm_digital_playback
16805 #define alc662_pcm_digital_capture      alc880_pcm_digital_capture
16806
16807 /*
16808  * configuration and preset
16809  */
16810 static const char *alc662_models[ALC662_MODEL_LAST] = {
16811         [ALC662_3ST_2ch_DIG]    = "3stack-dig",
16812         [ALC662_3ST_6ch_DIG]    = "3stack-6ch-dig",
16813         [ALC662_3ST_6ch]        = "3stack-6ch",
16814         [ALC662_5ST_DIG]        = "6stack-dig",
16815         [ALC662_LENOVO_101E]    = "lenovo-101e",
16816         [ALC662_ASUS_EEEPC_P701] = "eeepc-p701",
16817         [ALC662_ASUS_EEEPC_EP20] = "eeepc-ep20",
16818         [ALC662_ECS] = "ecs",
16819         [ALC663_ASUS_M51VA] = "m51va",
16820         [ALC663_ASUS_G71V] = "g71v",
16821         [ALC663_ASUS_H13] = "h13",
16822         [ALC663_ASUS_G50V] = "g50v",
16823         [ALC663_ASUS_MODE1] = "asus-mode1",
16824         [ALC662_ASUS_MODE2] = "asus-mode2",
16825         [ALC663_ASUS_MODE3] = "asus-mode3",
16826         [ALC663_ASUS_MODE4] = "asus-mode4",
16827         [ALC663_ASUS_MODE5] = "asus-mode5",
16828         [ALC663_ASUS_MODE6] = "asus-mode6",
16829         [ALC272_DELL]           = "dell",
16830         [ALC272_DELL_ZM1]       = "dell-zm1",
16831         [ALC272_SAMSUNG_NC10]   = "samsung-nc10",
16832         [ALC662_AUTO]           = "auto",
16833 };
16834
16835 static struct snd_pci_quirk alc662_cfg_tbl[] = {
16836         SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_ECS),
16837         SND_PCI_QUIRK(0x1028, 0x02d6, "DELL", ALC272_DELL),
16838         SND_PCI_QUIRK(0x1028, 0x02f4, "DELL ZM1", ALC272_DELL_ZM1),
16839         SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC663_ASUS_MODE1),
16840         SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC663_ASUS_MODE3),
16841         SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC663_ASUS_MODE3),
16842         SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC663_ASUS_MODE1),
16843         SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_ASUS_MODE2),
16844         SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC663_ASUS_MODE1),
16845         SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_ASUS_MODE2),
16846         SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_ASUS_MODE2),
16847         SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_ASUS_MODE2),
16848         SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC663_ASUS_MODE6),
16849         SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC663_ASUS_MODE6),
16850         SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_ASUS_MODE2),
16851         SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC663_ASUS_MODE3),
16852         SND_PCI_QUIRK(0x1043, 0x17c3, "ASUS UX20", ALC663_ASUS_M51VA),
16853         SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_ASUS_MODE2),
16854         SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_ASUS_MODE2),
16855         SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC663_ASUS_MODE5),
16856         SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC663_ASUS_MODE6),
16857         SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_ASUS_MODE2),
16858         SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC663_ASUS_MODE1),
16859         SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_ASUS_MODE2),
16860         SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_ASUS_MODE2),
16861         SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M51VA", ALC663_ASUS_M51VA),
16862         /*SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M50Vr", ALC663_ASUS_MODE1),*/
16863         SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC663_ASUS_MODE3),
16864         SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC663_ASUS_MODE3),
16865         SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC663_ASUS_MODE1),
16866         SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC663_ASUS_MODE1),
16867         SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC663_ASUS_MODE1),
16868         SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC663_ASUS_MODE1),
16869         SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_ASUS_MODE2),
16870         SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_ASUS_MODE2),
16871         SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC663_ASUS_MODE1),
16872         SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC663_ASUS_MODE1),
16873         SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC663_ASUS_MODE3),
16874         SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC663_ASUS_MODE1),
16875         SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC663_ASUS_MODE1),
16876         SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS G50V", ALC663_ASUS_G50V),
16877         /*SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS NB", ALC663_ASUS_MODE1),*/
16878         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC663_ASUS_MODE1),
16879         SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_ASUS_MODE2),
16880         SND_PCI_QUIRK(0x1043, 0x19d3, "ASUS NB", ALC663_ASUS_M51VA),
16881         SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC663_ASUS_MODE1),
16882         SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC663_ASUS_MODE4),
16883         SND_PCI_QUIRK(0x1043, 0x8290, "ASUS P5GC-MX", ALC662_3ST_6ch_DIG),
16884         SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
16885         SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20),
16886         SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_ECS),
16887         SND_PCI_QUIRK(0x105b, 0x0d47, "Foxconn 45CMX/45GMX/45CMX-K",
16888                       ALC662_3ST_6ch_DIG),
16889         SND_PCI_QUIRK(0x1179, 0xff6e, "Toshiba NB200", ALC663_ASUS_MODE4),
16890         SND_PCI_QUIRK(0x144d, 0xca00, "Samsung NC10", ALC272_SAMSUNG_NC10),
16891         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte 945GCM-S2L",
16892                       ALC662_3ST_6ch_DIG),
16893         SND_PCI_QUIRK(0x1565, 0x820f, "Biostar TA780G M2+", ALC662_3ST_6ch_DIG),
16894         SND_PCI_QUIRK(0x1631, 0xc10c, "PB RS65", ALC663_ASUS_M51VA),
16895         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
16896         SND_PCI_QUIRK(0x1849, 0x3662, "ASROCK K10N78FullHD-hSLI R3.0",
16897                                         ALC662_3ST_6ch_DIG),
16898         SND_PCI_QUIRK_MASK(0x1854, 0xf000, 0x2000, "ASUS H13-200x",
16899                            ALC663_ASUS_H13),
16900         {}
16901 };
16902
16903 static struct alc_config_preset alc662_presets[] = {
16904         [ALC662_3ST_2ch_DIG] = {
16905                 .mixers = { alc662_3ST_2ch_mixer },
16906                 .init_verbs = { alc662_init_verbs },
16907                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16908                 .dac_nids = alc662_dac_nids,
16909                 .dig_out_nid = ALC662_DIGOUT_NID,
16910                 .dig_in_nid = ALC662_DIGIN_NID,
16911                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16912                 .channel_mode = alc662_3ST_2ch_modes,
16913                 .input_mux = &alc662_capture_source,
16914         },
16915         [ALC662_3ST_6ch_DIG] = {
16916                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
16917                 .init_verbs = { alc662_init_verbs },
16918                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16919                 .dac_nids = alc662_dac_nids,
16920                 .dig_out_nid = ALC662_DIGOUT_NID,
16921                 .dig_in_nid = ALC662_DIGIN_NID,
16922                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16923                 .channel_mode = alc662_3ST_6ch_modes,
16924                 .need_dac_fix = 1,
16925                 .input_mux = &alc662_capture_source,
16926         },
16927         [ALC662_3ST_6ch] = {
16928                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
16929                 .init_verbs = { alc662_init_verbs },
16930                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16931                 .dac_nids = alc662_dac_nids,
16932                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16933                 .channel_mode = alc662_3ST_6ch_modes,
16934                 .need_dac_fix = 1,
16935                 .input_mux = &alc662_capture_source,
16936         },
16937         [ALC662_5ST_DIG] = {
16938                 .mixers = { alc662_base_mixer, alc662_chmode_mixer },
16939                 .init_verbs = { alc662_init_verbs },
16940                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16941                 .dac_nids = alc662_dac_nids,
16942                 .dig_out_nid = ALC662_DIGOUT_NID,
16943                 .dig_in_nid = ALC662_DIGIN_NID,
16944                 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
16945                 .channel_mode = alc662_5stack_modes,
16946                 .input_mux = &alc662_capture_source,
16947         },
16948         [ALC662_LENOVO_101E] = {
16949                 .mixers = { alc662_lenovo_101e_mixer },
16950                 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs },
16951                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16952                 .dac_nids = alc662_dac_nids,
16953                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16954                 .channel_mode = alc662_3ST_2ch_modes,
16955                 .input_mux = &alc662_lenovo_101e_capture_source,
16956                 .unsol_event = alc662_lenovo_101e_unsol_event,
16957                 .init_hook = alc662_lenovo_101e_all_automute,
16958         },
16959         [ALC662_ASUS_EEEPC_P701] = {
16960                 .mixers = { alc662_eeepc_p701_mixer },
16961                 .init_verbs = { alc662_init_verbs,
16962                                 alc662_eeepc_sue_init_verbs },
16963                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16964                 .dac_nids = alc662_dac_nids,
16965                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16966                 .channel_mode = alc662_3ST_2ch_modes,
16967                 .unsol_event = alc662_eeepc_unsol_event,
16968                 .setup = alc662_eeepc_setup,
16969                 .init_hook = alc662_eeepc_inithook,
16970         },
16971         [ALC662_ASUS_EEEPC_EP20] = {
16972                 .mixers = { alc662_eeepc_ep20_mixer,
16973                             alc662_chmode_mixer },
16974                 .init_verbs = { alc662_init_verbs,
16975                                 alc662_eeepc_ep20_sue_init_verbs },
16976                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16977                 .dac_nids = alc662_dac_nids,
16978                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16979                 .channel_mode = alc662_3ST_6ch_modes,
16980                 .input_mux = &alc662_lenovo_101e_capture_source,
16981                 .unsol_event = alc662_eeepc_unsol_event,
16982                 .setup = alc662_eeepc_ep20_setup,
16983                 .init_hook = alc662_eeepc_ep20_inithook,
16984         },
16985         [ALC662_ECS] = {
16986                 .mixers = { alc662_ecs_mixer },
16987                 .init_verbs = { alc662_init_verbs,
16988                                 alc662_ecs_init_verbs },
16989                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16990                 .dac_nids = alc662_dac_nids,
16991                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16992                 .channel_mode = alc662_3ST_2ch_modes,
16993                 .unsol_event = alc662_eeepc_unsol_event,
16994                 .setup = alc662_eeepc_setup,
16995                 .init_hook = alc662_eeepc_inithook,
16996         },
16997         [ALC663_ASUS_M51VA] = {
16998                 .mixers = { alc663_m51va_mixer },
16999                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
17000                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17001                 .dac_nids = alc662_dac_nids,
17002                 .dig_out_nid = ALC662_DIGOUT_NID,
17003                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17004                 .channel_mode = alc662_3ST_2ch_modes,
17005                 .unsol_event = alc663_m51va_unsol_event,
17006                 .setup = alc663_m51va_setup,
17007                 .init_hook = alc663_m51va_inithook,
17008         },
17009         [ALC663_ASUS_G71V] = {
17010                 .mixers = { alc663_g71v_mixer },
17011                 .init_verbs = { alc662_init_verbs, alc663_g71v_init_verbs },
17012                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17013                 .dac_nids = alc662_dac_nids,
17014                 .dig_out_nid = ALC662_DIGOUT_NID,
17015                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17016                 .channel_mode = alc662_3ST_2ch_modes,
17017                 .unsol_event = alc663_g71v_unsol_event,
17018                 .setup = alc663_g71v_setup,
17019                 .init_hook = alc663_g71v_inithook,
17020         },
17021         [ALC663_ASUS_H13] = {
17022                 .mixers = { alc663_m51va_mixer },
17023                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
17024                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17025                 .dac_nids = alc662_dac_nids,
17026                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17027                 .channel_mode = alc662_3ST_2ch_modes,
17028                 .unsol_event = alc663_m51va_unsol_event,
17029                 .init_hook = alc663_m51va_inithook,
17030         },
17031         [ALC663_ASUS_G50V] = {
17032                 .mixers = { alc663_g50v_mixer },
17033                 .init_verbs = { alc662_init_verbs, alc663_g50v_init_verbs },
17034                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17035                 .dac_nids = alc662_dac_nids,
17036                 .dig_out_nid = ALC662_DIGOUT_NID,
17037                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
17038                 .channel_mode = alc662_3ST_6ch_modes,
17039                 .input_mux = &alc663_capture_source,
17040                 .unsol_event = alc663_g50v_unsol_event,
17041                 .setup = alc663_g50v_setup,
17042                 .init_hook = alc663_g50v_inithook,
17043         },
17044         [ALC663_ASUS_MODE1] = {
17045                 .mixers = { alc663_m51va_mixer },
17046                 .cap_mixer = alc662_auto_capture_mixer,
17047                 .init_verbs = { alc662_init_verbs,
17048                                 alc663_21jd_amic_init_verbs },
17049                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17050                 .hp_nid = 0x03,
17051                 .dac_nids = alc662_dac_nids,
17052                 .dig_out_nid = ALC662_DIGOUT_NID,
17053                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17054                 .channel_mode = alc662_3ST_2ch_modes,
17055                 .unsol_event = alc663_mode1_unsol_event,
17056                 .setup = alc663_mode1_setup,
17057                 .init_hook = alc663_mode1_inithook,
17058         },
17059         [ALC662_ASUS_MODE2] = {
17060                 .mixers = { alc662_1bjd_mixer },
17061                 .cap_mixer = alc662_auto_capture_mixer,
17062                 .init_verbs = { alc662_init_verbs,
17063                                 alc662_1bjd_amic_init_verbs },
17064                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17065                 .dac_nids = alc662_dac_nids,
17066                 .dig_out_nid = ALC662_DIGOUT_NID,
17067                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17068                 .channel_mode = alc662_3ST_2ch_modes,
17069                 .unsol_event = alc662_mode2_unsol_event,
17070                 .setup = alc662_mode2_setup,
17071                 .init_hook = alc662_mode2_inithook,
17072         },
17073         [ALC663_ASUS_MODE3] = {
17074                 .mixers = { alc663_two_hp_m1_mixer },
17075                 .cap_mixer = alc662_auto_capture_mixer,
17076                 .init_verbs = { alc662_init_verbs,
17077                                 alc663_two_hp_amic_m1_init_verbs },
17078                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17079                 .hp_nid = 0x03,
17080                 .dac_nids = alc662_dac_nids,
17081                 .dig_out_nid = ALC662_DIGOUT_NID,
17082                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17083                 .channel_mode = alc662_3ST_2ch_modes,
17084                 .unsol_event = alc663_mode3_unsol_event,
17085                 .setup = alc663_mode3_setup,
17086                 .init_hook = alc663_mode3_inithook,
17087         },
17088         [ALC663_ASUS_MODE4] = {
17089                 .mixers = { alc663_asus_21jd_clfe_mixer },
17090                 .cap_mixer = alc662_auto_capture_mixer,
17091                 .init_verbs = { alc662_init_verbs,
17092                                 alc663_21jd_amic_init_verbs},
17093                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17094                 .hp_nid = 0x03,
17095                 .dac_nids = alc662_dac_nids,
17096                 .dig_out_nid = ALC662_DIGOUT_NID,
17097                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17098                 .channel_mode = alc662_3ST_2ch_modes,
17099                 .unsol_event = alc663_mode4_unsol_event,
17100                 .setup = alc663_mode4_setup,
17101                 .init_hook = alc663_mode4_inithook,
17102         },
17103         [ALC663_ASUS_MODE5] = {
17104                 .mixers = { alc663_asus_15jd_clfe_mixer },
17105                 .cap_mixer = alc662_auto_capture_mixer,
17106                 .init_verbs = { alc662_init_verbs,
17107                                 alc663_15jd_amic_init_verbs },
17108                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17109                 .hp_nid = 0x03,
17110                 .dac_nids = alc662_dac_nids,
17111                 .dig_out_nid = ALC662_DIGOUT_NID,
17112                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17113                 .channel_mode = alc662_3ST_2ch_modes,
17114                 .unsol_event = alc663_mode5_unsol_event,
17115                 .setup = alc663_mode5_setup,
17116                 .init_hook = alc663_mode5_inithook,
17117         },
17118         [ALC663_ASUS_MODE6] = {
17119                 .mixers = { alc663_two_hp_m2_mixer },
17120                 .cap_mixer = alc662_auto_capture_mixer,
17121                 .init_verbs = { alc662_init_verbs,
17122                                 alc663_two_hp_amic_m2_init_verbs },
17123                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17124                 .hp_nid = 0x03,
17125                 .dac_nids = alc662_dac_nids,
17126                 .dig_out_nid = ALC662_DIGOUT_NID,
17127                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17128                 .channel_mode = alc662_3ST_2ch_modes,
17129                 .unsol_event = alc663_mode6_unsol_event,
17130                 .setup = alc663_mode6_setup,
17131                 .init_hook = alc663_mode6_inithook,
17132         },
17133         [ALC272_DELL] = {
17134                 .mixers = { alc663_m51va_mixer },
17135                 .cap_mixer = alc272_auto_capture_mixer,
17136                 .init_verbs = { alc662_init_verbs, alc272_dell_init_verbs },
17137                 .num_dacs = ARRAY_SIZE(alc272_dac_nids),
17138                 .dac_nids = alc662_dac_nids,
17139                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17140                 .adc_nids = alc272_adc_nids,
17141                 .num_adc_nids = ARRAY_SIZE(alc272_adc_nids),
17142                 .capsrc_nids = alc272_capsrc_nids,
17143                 .channel_mode = alc662_3ST_2ch_modes,
17144                 .unsol_event = alc663_m51va_unsol_event,
17145                 .setup = alc663_m51va_setup,
17146                 .init_hook = alc663_m51va_inithook,
17147         },
17148         [ALC272_DELL_ZM1] = {
17149                 .mixers = { alc663_m51va_mixer },
17150                 .cap_mixer = alc662_auto_capture_mixer,
17151                 .init_verbs = { alc662_init_verbs, alc272_dell_zm1_init_verbs },
17152                 .num_dacs = ARRAY_SIZE(alc272_dac_nids),
17153                 .dac_nids = alc662_dac_nids,
17154                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17155                 .adc_nids = alc662_adc_nids,
17156                 .num_adc_nids = 1,
17157                 .capsrc_nids = alc662_capsrc_nids,
17158                 .channel_mode = alc662_3ST_2ch_modes,
17159                 .unsol_event = alc663_m51va_unsol_event,
17160                 .setup = alc663_m51va_setup,
17161                 .init_hook = alc663_m51va_inithook,
17162         },
17163         [ALC272_SAMSUNG_NC10] = {
17164                 .mixers = { alc272_nc10_mixer },
17165                 .init_verbs = { alc662_init_verbs,
17166                                 alc663_21jd_amic_init_verbs },
17167                 .num_dacs = ARRAY_SIZE(alc272_dac_nids),
17168                 .dac_nids = alc272_dac_nids,
17169                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17170                 .channel_mode = alc662_3ST_2ch_modes,
17171                 /*.input_mux = &alc272_nc10_capture_source,*/
17172                 .unsol_event = alc663_mode4_unsol_event,
17173                 .setup = alc663_mode4_setup,
17174                 .init_hook = alc663_mode4_inithook,
17175         },
17176 };
17177
17178
17179 /*
17180  * BIOS auto configuration
17181  */
17182
17183 /* convert from MIX nid to DAC */
17184 static inline hda_nid_t alc662_mix_to_dac(hda_nid_t nid)
17185 {
17186         if (nid == 0x0f)
17187                 return 0x02;
17188         else if (nid >= 0x0c && nid <= 0x0e)
17189                 return nid - 0x0c + 0x02;
17190         else
17191                 return 0;
17192 }
17193
17194 /* get MIX nid connected to the given pin targeted to DAC */
17195 static hda_nid_t alc662_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
17196                                    hda_nid_t dac)
17197 {
17198         hda_nid_t mix[4];
17199         int i, num;
17200
17201         num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
17202         for (i = 0; i < num; i++) {
17203                 if (alc662_mix_to_dac(mix[i]) == dac)
17204                         return mix[i];
17205         }
17206         return 0;
17207 }
17208
17209 /* look for an empty DAC slot */
17210 static hda_nid_t alc662_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
17211 {
17212         struct alc_spec *spec = codec->spec;
17213         hda_nid_t srcs[5];
17214         int i, j, num;
17215
17216         num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
17217         if (num < 0)
17218                 return 0;
17219         for (i = 0; i < num; i++) {
17220                 hda_nid_t nid = alc662_mix_to_dac(srcs[i]);
17221                 if (!nid)
17222                         continue;
17223                 for (j = 0; j < spec->multiout.num_dacs; j++)
17224                         if (spec->multiout.dac_nids[j] == nid)
17225                                 break;
17226                 if (j >= spec->multiout.num_dacs)
17227                         return nid;
17228         }
17229         return 0;
17230 }
17231
17232 /* fill in the dac_nids table from the parsed pin configuration */
17233 static int alc662_auto_fill_dac_nids(struct hda_codec *codec,
17234                                      const struct auto_pin_cfg *cfg)
17235 {
17236         struct alc_spec *spec = codec->spec;
17237         int i;
17238         hda_nid_t dac;
17239
17240         spec->multiout.dac_nids = spec->private_dac_nids;
17241         for (i = 0; i < cfg->line_outs; i++) {
17242                 dac = alc662_look_for_dac(codec, cfg->line_out_pins[i]);
17243                 if (!dac)
17244                         continue;
17245                 spec->multiout.dac_nids[spec->multiout.num_dacs++] = dac;
17246         }
17247         return 0;
17248 }
17249
17250 static inline int alc662_add_vol_ctl(struct alc_spec *spec, const char *pfx,
17251                               hda_nid_t nid, unsigned int chs)
17252 {
17253         return add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
17254                            HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
17255 }
17256
17257 static inline int alc662_add_sw_ctl(struct alc_spec *spec, const char *pfx,
17258                              hda_nid_t nid, unsigned int chs)
17259 {
17260         return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
17261                            HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT));
17262 }
17263
17264 #define alc662_add_stereo_vol(spec, pfx, nid) \
17265         alc662_add_vol_ctl(spec, pfx, nid, 3)
17266 #define alc662_add_stereo_sw(spec, pfx, nid) \
17267         alc662_add_sw_ctl(spec, pfx, nid, 3)
17268
17269 /* add playback controls from the parsed DAC table */
17270 static int alc662_auto_create_multi_out_ctls(struct hda_codec *codec,
17271                                              const struct auto_pin_cfg *cfg)
17272 {
17273         struct alc_spec *spec = codec->spec;
17274         static const char *chname[4] = {
17275                 "Front", "Surround", NULL /*CLFE*/, "Side"
17276         };
17277         hda_nid_t nid, mix;
17278         int i, err;
17279
17280         for (i = 0; i < cfg->line_outs; i++) {
17281                 nid = spec->multiout.dac_nids[i];
17282                 if (!nid)
17283                         continue;
17284                 mix = alc662_dac_to_mix(codec, cfg->line_out_pins[i], nid);
17285                 if (!mix)
17286                         continue;
17287                 if (i == 2) {
17288                         /* Center/LFE */
17289                         err = alc662_add_vol_ctl(spec, "Center", nid, 1);
17290                         if (err < 0)
17291                                 return err;
17292                         err = alc662_add_vol_ctl(spec, "LFE", nid, 2);
17293                         if (err < 0)
17294                                 return err;
17295                         err = alc662_add_sw_ctl(spec, "Center", mix, 1);
17296                         if (err < 0)
17297                                 return err;
17298                         err = alc662_add_sw_ctl(spec, "LFE", mix, 2);
17299                         if (err < 0)
17300                                 return err;
17301                 } else {
17302                         const char *pfx;
17303                         if (cfg->line_outs == 1 &&
17304                             cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
17305                                 if (cfg->hp_outs)
17306                                         pfx = "Speaker";
17307                                 else
17308                                         pfx = "PCM";
17309                         } else
17310                                 pfx = chname[i];
17311                         err = alc662_add_vol_ctl(spec, pfx, nid, 3);
17312                         if (err < 0)
17313                                 return err;
17314                         if (cfg->line_outs == 1 &&
17315                             cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
17316                                 pfx = "Speaker";
17317                         err = alc662_add_sw_ctl(spec, pfx, mix, 3);
17318                         if (err < 0)
17319                                 return err;
17320                 }
17321         }
17322         return 0;
17323 }
17324
17325 /* add playback controls for speaker and HP outputs */
17326 /* return DAC nid if any new DAC is assigned */
17327 static int alc662_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
17328                                         const char *pfx)
17329 {
17330         struct alc_spec *spec = codec->spec;
17331         hda_nid_t nid, mix;
17332         int err;
17333
17334         if (!pin)
17335                 return 0;
17336         nid = alc662_look_for_dac(codec, pin);
17337         if (!nid) {
17338                 /* the corresponding DAC is already occupied */
17339                 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
17340                         return 0; /* no way */
17341                 /* create a switch only */
17342                 return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
17343                                    HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
17344         }
17345
17346         mix = alc662_dac_to_mix(codec, pin, nid);
17347         if (!mix)
17348                 return 0;
17349         err = alc662_add_vol_ctl(spec, pfx, nid, 3);
17350         if (err < 0)
17351                 return err;
17352         err = alc662_add_sw_ctl(spec, pfx, mix, 3);
17353         if (err < 0)
17354                 return err;
17355         return nid;
17356 }
17357
17358 /* create playback/capture controls for input pins */
17359 #define alc662_auto_create_input_ctls \
17360         alc882_auto_create_input_ctls
17361
17362 static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
17363                                               hda_nid_t nid, int pin_type,
17364                                               hda_nid_t dac)
17365 {
17366         int i, num;
17367         hda_nid_t srcs[4];
17368
17369         alc_set_pin_output(codec, nid, pin_type);
17370         /* need the manual connection? */
17371         num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
17372         if (num <= 1)
17373                 return;
17374         for (i = 0; i < num; i++) {
17375                 if (alc662_mix_to_dac(srcs[i]) != dac)
17376                         continue;
17377                 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
17378                 return;
17379         }
17380 }
17381
17382 static void alc662_auto_init_multi_out(struct hda_codec *codec)
17383 {
17384         struct alc_spec *spec = codec->spec;
17385         int pin_type = get_pin_type(spec->autocfg.line_out_type);
17386         int i;
17387
17388         for (i = 0; i <= HDA_SIDE; i++) {
17389                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
17390                 if (nid)
17391                         alc662_auto_set_output_and_unmute(codec, nid, pin_type,
17392                                         spec->multiout.dac_nids[i]);
17393         }
17394 }
17395
17396 static void alc662_auto_init_hp_out(struct hda_codec *codec)
17397 {
17398         struct alc_spec *spec = codec->spec;
17399         hda_nid_t pin;
17400
17401         pin = spec->autocfg.hp_pins[0];
17402         if (pin)
17403                 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP,
17404                                                   spec->multiout.hp_nid);
17405         pin = spec->autocfg.speaker_pins[0];
17406         if (pin)
17407                 alc662_auto_set_output_and_unmute(codec, pin, PIN_OUT,
17408                                         spec->multiout.extra_out_nid[0]);
17409 }
17410
17411 #define ALC662_PIN_CD_NID               ALC880_PIN_CD_NID
17412
17413 static void alc662_auto_init_analog_input(struct hda_codec *codec)
17414 {
17415         struct alc_spec *spec = codec->spec;
17416         int i;
17417
17418         for (i = 0; i < AUTO_PIN_LAST; i++) {
17419                 hda_nid_t nid = spec->autocfg.input_pins[i];
17420                 if (alc_is_input_pin(codec, nid)) {
17421                         alc_set_input_pin(codec, nid, i);
17422                         if (nid != ALC662_PIN_CD_NID &&
17423                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
17424                                 snd_hda_codec_write(codec, nid, 0,
17425                                                     AC_VERB_SET_AMP_GAIN_MUTE,
17426                                                     AMP_OUT_MUTE);
17427                 }
17428         }
17429 }
17430
17431 #define alc662_auto_init_input_src      alc882_auto_init_input_src
17432
17433 static int alc662_parse_auto_config(struct hda_codec *codec)
17434 {
17435         struct alc_spec *spec = codec->spec;
17436         int err;
17437         static hda_nid_t alc662_ignore[] = { 0x1d, 0 };
17438
17439         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
17440                                            alc662_ignore);
17441         if (err < 0)
17442                 return err;
17443         if (!spec->autocfg.line_outs)
17444                 return 0; /* can't find valid BIOS pin config */
17445
17446         err = alc662_auto_fill_dac_nids(codec, &spec->autocfg);
17447         if (err < 0)
17448                 return err;
17449         err = alc662_auto_create_multi_out_ctls(codec, &spec->autocfg);
17450         if (err < 0)
17451                 return err;
17452         err = alc662_auto_create_extra_out(codec,
17453                                            spec->autocfg.speaker_pins[0],
17454                                            "Speaker");
17455         if (err < 0)
17456                 return err;
17457         if (err)
17458                 spec->multiout.extra_out_nid[0] = err;
17459         err = alc662_auto_create_extra_out(codec, spec->autocfg.hp_pins[0],
17460                                            "Headphone");
17461         if (err < 0)
17462                 return err;
17463         if (err)
17464                 spec->multiout.hp_nid = err;
17465         err = alc662_auto_create_input_ctls(codec, &spec->autocfg);
17466         if (err < 0)
17467                 return err;
17468
17469         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
17470
17471         if (spec->autocfg.dig_outs)
17472                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
17473
17474         if (spec->kctls.list)
17475                 add_mixer(spec, spec->kctls.list);
17476
17477         spec->num_mux_defs = 1;
17478         spec->input_mux = &spec->private_imux[0];
17479
17480         add_verb(spec, alc662_auto_init_verbs);
17481         if (codec->vendor_id == 0x10ec0663)
17482                 add_verb(spec, alc663_auto_init_verbs);
17483
17484         err = alc_auto_add_mic_boost(codec);
17485         if (err < 0)
17486                 return err;
17487
17488         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
17489
17490         return 1;
17491 }
17492
17493 /* additional initialization for auto-configuration model */
17494 static void alc662_auto_init(struct hda_codec *codec)
17495 {
17496         struct alc_spec *spec = codec->spec;
17497         alc662_auto_init_multi_out(codec);
17498         alc662_auto_init_hp_out(codec);
17499         alc662_auto_init_analog_input(codec);
17500         alc662_auto_init_input_src(codec);
17501         if (spec->unsol_event)
17502                 alc_inithook(codec);
17503 }
17504
17505 static int patch_alc662(struct hda_codec *codec)
17506 {
17507         struct alc_spec *spec;
17508         int err, board_config;
17509
17510         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
17511         if (!spec)
17512                 return -ENOMEM;
17513
17514         codec->spec = spec;
17515
17516         alc_fix_pll_init(codec, 0x20, 0x04, 15);
17517
17518         board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
17519                                                   alc662_models,
17520                                                   alc662_cfg_tbl);
17521         if (board_config < 0) {
17522                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
17523                        codec->chip_name);
17524                 board_config = ALC662_AUTO;
17525         }
17526
17527         if (board_config == ALC662_AUTO) {
17528                 /* automatic parse from the BIOS config */
17529                 err = alc662_parse_auto_config(codec);
17530                 if (err < 0) {
17531                         alc_free(codec);
17532                         return err;
17533                 } else if (!err) {
17534                         printk(KERN_INFO
17535                                "hda_codec: Cannot set up configuration "
17536                                "from BIOS.  Using base mode...\n");
17537                         board_config = ALC662_3ST_2ch_DIG;
17538                 }
17539         }
17540
17541         err = snd_hda_attach_beep_device(codec, 0x1);
17542         if (err < 0) {
17543                 alc_free(codec);
17544                 return err;
17545         }
17546
17547         if (board_config != ALC662_AUTO)
17548                 setup_preset(codec, &alc662_presets[board_config]);
17549
17550         spec->stream_analog_playback = &alc662_pcm_analog_playback;
17551         spec->stream_analog_capture = &alc662_pcm_analog_capture;
17552
17553         spec->stream_digital_playback = &alc662_pcm_digital_playback;
17554         spec->stream_digital_capture = &alc662_pcm_digital_capture;
17555
17556         if (!spec->adc_nids) {
17557                 spec->adc_nids = alc662_adc_nids;
17558                 spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
17559         }
17560         if (!spec->capsrc_nids)
17561                 spec->capsrc_nids = alc662_capsrc_nids;
17562
17563         if (!spec->cap_mixer)
17564                 set_capture_mixer(codec);
17565         if (codec->vendor_id == 0x10ec0662)
17566                 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
17567         else
17568                 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
17569
17570         spec->vmaster_nid = 0x02;
17571
17572         codec->patch_ops = alc_patch_ops;
17573         if (board_config == ALC662_AUTO)
17574                 spec->init_hook = alc662_auto_init;
17575 #ifdef CONFIG_SND_HDA_POWER_SAVE
17576         if (!spec->loopback.amplist)
17577                 spec->loopback.amplist = alc662_loopbacks;
17578 #endif
17579         codec->proc_widget_hook = print_realtek_coef;
17580
17581         return 0;
17582 }
17583
17584 /*
17585  * patch entries
17586  */
17587 static struct hda_codec_preset snd_hda_preset_realtek[] = {
17588         { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
17589         { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
17590         { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
17591         { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
17592         { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
17593         { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
17594         { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
17595           .patch = patch_alc861 },
17596         { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
17597         { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
17598         { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
17599         { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
17600           .patch = patch_alc882 },
17601         { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
17602           .patch = patch_alc662 },
17603         { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
17604         { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
17605         { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
17606         { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
17607         { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
17608           .patch = patch_alc882 },
17609         { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
17610           .patch = patch_alc882 },
17611         { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
17612         { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
17613         { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
17614           .patch = patch_alc882 },
17615         { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
17616         { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
17617         {} /* terminator */
17618 };
17619
17620 MODULE_ALIAS("snd-hda-codec-id:10ec*");
17621
17622 MODULE_LICENSE("GPL");
17623 MODULE_DESCRIPTION("Realtek HD-audio codec");
17624
17625 static struct hda_codec_preset_list realtek_list = {
17626         .preset = snd_hda_preset_realtek,
17627         .owner = THIS_MODULE,
17628 };
17629
17630 static int __init patch_realtek_init(void)
17631 {
17632         return snd_hda_add_codec_preset(&realtek_list);
17633 }
17634
17635 static void __exit patch_realtek_exit(void)
17636 {
17637         snd_hda_delete_codec_preset(&realtek_list);
17638 }
17639
17640 module_init(patch_realtek_init)
17641 module_exit(patch_realtek_exit)