Merge branch 'fix/asoc' into for-linus
[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[5];   /* initialization verbs
279                                                  * don't forget NULL
280                                                  * termination!
281                                                  */
282         unsigned int num_init_verbs;
283
284         char stream_name_analog[32];    /* analog PCM stream */
285         struct hda_pcm_stream *stream_analog_playback;
286         struct hda_pcm_stream *stream_analog_capture;
287         struct hda_pcm_stream *stream_analog_alt_playback;
288         struct hda_pcm_stream *stream_analog_alt_capture;
289
290         char stream_name_digital[32];   /* digital PCM stream */
291         struct hda_pcm_stream *stream_digital_playback;
292         struct hda_pcm_stream *stream_digital_capture;
293
294         /* playback */
295         struct hda_multi_out multiout;  /* playback set-up
296                                          * max_channels, dacs must be set
297                                          * dig_out_nid and hp_nid are optional
298                                          */
299         hda_nid_t alt_dac_nid;
300         hda_nid_t slave_dig_outs[3];    /* optional - for auto-parsing */
301         int dig_out_type;
302
303         /* capture */
304         unsigned int num_adc_nids;
305         hda_nid_t *adc_nids;
306         hda_nid_t *capsrc_nids;
307         hda_nid_t dig_in_nid;           /* digital-in NID; optional */
308
309         /* capture source */
310         unsigned int num_mux_defs;
311         const struct hda_input_mux *input_mux;
312         unsigned int cur_mux[3];
313         struct alc_mic_route ext_mic;
314         struct alc_mic_route int_mic;
315
316         /* channel model */
317         const struct hda_channel_mode *channel_mode;
318         int num_channel_mode;
319         int need_dac_fix;
320         int const_channel_count;
321         int ext_channel_count;
322
323         /* PCM information */
324         struct hda_pcm pcm_rec[3];      /* used in alc_build_pcms() */
325
326         /* dynamic controls, init_verbs and input_mux */
327         struct auto_pin_cfg autocfg;
328         struct snd_array kctls;
329         struct hda_input_mux private_imux[3];
330         hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
331         hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
332         hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
333
334         /* hooks */
335         void (*init_hook)(struct hda_codec *codec);
336         void (*unsol_event)(struct hda_codec *codec, unsigned int res);
337
338         /* for pin sensing */
339         unsigned int sense_updated: 1;
340         unsigned int jack_present: 1;
341         unsigned int master_sw: 1;
342         unsigned int auto_mic:1;
343
344         /* other flags */
345         unsigned int no_analog :1; /* digital I/O only */
346         int init_amp;
347
348         /* for virtual master */
349         hda_nid_t vmaster_nid;
350 #ifdef CONFIG_SND_HDA_POWER_SAVE
351         struct hda_loopback_check loopback;
352 #endif
353
354         /* for PLL fix */
355         hda_nid_t pll_nid;
356         unsigned int pll_coef_idx, pll_coef_bit;
357 };
358
359 /*
360  * configuration template - to be copied to the spec instance
361  */
362 struct alc_config_preset {
363         struct snd_kcontrol_new *mixers[5]; /* should be identical size
364                                              * with spec
365                                              */
366         struct snd_kcontrol_new *cap_mixer; /* capture mixer */
367         const struct hda_verb *init_verbs[5];
368         unsigned int num_dacs;
369         hda_nid_t *dac_nids;
370         hda_nid_t dig_out_nid;          /* optional */
371         hda_nid_t hp_nid;               /* optional */
372         hda_nid_t *slave_dig_outs;
373         unsigned int num_adc_nids;
374         hda_nid_t *adc_nids;
375         hda_nid_t *capsrc_nids;
376         hda_nid_t dig_in_nid;
377         unsigned int num_channel_mode;
378         const struct hda_channel_mode *channel_mode;
379         int need_dac_fix;
380         int const_channel_count;
381         unsigned int num_mux_defs;
382         const struct hda_input_mux *input_mux;
383         void (*unsol_event)(struct hda_codec *, unsigned int);
384         void (*setup)(struct hda_codec *);
385         void (*init_hook)(struct hda_codec *);
386 #ifdef CONFIG_SND_HDA_POWER_SAVE
387         struct hda_amp_list *loopbacks;
388 #endif
389 };
390
391
392 /*
393  * input MUX handling
394  */
395 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
396                              struct snd_ctl_elem_info *uinfo)
397 {
398         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
399         struct alc_spec *spec = codec->spec;
400         unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
401         if (mux_idx >= spec->num_mux_defs)
402                 mux_idx = 0;
403         return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
404 }
405
406 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
407                             struct snd_ctl_elem_value *ucontrol)
408 {
409         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
410         struct alc_spec *spec = codec->spec;
411         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
412
413         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
414         return 0;
415 }
416
417 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
418                             struct snd_ctl_elem_value *ucontrol)
419 {
420         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
421         struct alc_spec *spec = codec->spec;
422         const struct hda_input_mux *imux;
423         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
424         unsigned int mux_idx;
425         hda_nid_t nid = spec->capsrc_nids ?
426                 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
427         unsigned int type;
428
429         mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
430         imux = &spec->input_mux[mux_idx];
431
432         type = get_wcaps_type(get_wcaps(codec, nid));
433         if (type == AC_WID_AUD_MIX) {
434                 /* Matrix-mixer style (e.g. ALC882) */
435                 unsigned int *cur_val = &spec->cur_mux[adc_idx];
436                 unsigned int i, idx;
437
438                 idx = ucontrol->value.enumerated.item[0];
439                 if (idx >= imux->num_items)
440                         idx = imux->num_items - 1;
441                 if (*cur_val == idx)
442                         return 0;
443                 for (i = 0; i < imux->num_items; i++) {
444                         unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
445                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
446                                                  imux->items[i].index,
447                                                  HDA_AMP_MUTE, v);
448                 }
449                 *cur_val = idx;
450                 return 1;
451         } else {
452                 /* MUX style (e.g. ALC880) */
453                 return snd_hda_input_mux_put(codec, imux, ucontrol, nid,
454                                              &spec->cur_mux[adc_idx]);
455         }
456 }
457
458 /*
459  * channel mode setting
460  */
461 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
462                             struct snd_ctl_elem_info *uinfo)
463 {
464         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
465         struct alc_spec *spec = codec->spec;
466         return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
467                                     spec->num_channel_mode);
468 }
469
470 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
471                            struct snd_ctl_elem_value *ucontrol)
472 {
473         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
474         struct alc_spec *spec = codec->spec;
475         return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
476                                    spec->num_channel_mode,
477                                    spec->ext_channel_count);
478 }
479
480 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
481                            struct snd_ctl_elem_value *ucontrol)
482 {
483         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
484         struct alc_spec *spec = codec->spec;
485         int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
486                                       spec->num_channel_mode,
487                                       &spec->ext_channel_count);
488         if (err >= 0 && !spec->const_channel_count) {
489                 spec->multiout.max_channels = spec->ext_channel_count;
490                 if (spec->need_dac_fix)
491                         spec->multiout.num_dacs = spec->multiout.max_channels / 2;
492         }
493         return err;
494 }
495
496 /*
497  * Control the mode of pin widget settings via the mixer.  "pc" is used
498  * instead of "%" to avoid consequences of accidently treating the % as
499  * being part of a format specifier.  Maximum allowed length of a value is
500  * 63 characters plus NULL terminator.
501  *
502  * Note: some retasking pin complexes seem to ignore requests for input
503  * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
504  * are requested.  Therefore order this list so that this behaviour will not
505  * cause problems when mixer clients move through the enum sequentially.
506  * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
507  * March 2006.
508  */
509 static char *alc_pin_mode_names[] = {
510         "Mic 50pc bias", "Mic 80pc bias",
511         "Line in", "Line out", "Headphone out",
512 };
513 static unsigned char alc_pin_mode_values[] = {
514         PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
515 };
516 /* The control can present all 5 options, or it can limit the options based
517  * in the pin being assumed to be exclusively an input or an output pin.  In
518  * addition, "input" pins may or may not process the mic bias option
519  * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
520  * accept requests for bias as of chip versions up to March 2006) and/or
521  * wiring in the computer.
522  */
523 #define ALC_PIN_DIR_IN              0x00
524 #define ALC_PIN_DIR_OUT             0x01
525 #define ALC_PIN_DIR_INOUT           0x02
526 #define ALC_PIN_DIR_IN_NOMICBIAS    0x03
527 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
528
529 /* Info about the pin modes supported by the different pin direction modes.
530  * For each direction the minimum and maximum values are given.
531  */
532 static signed char alc_pin_mode_dir_info[5][2] = {
533         { 0, 2 },    /* ALC_PIN_DIR_IN */
534         { 3, 4 },    /* ALC_PIN_DIR_OUT */
535         { 0, 4 },    /* ALC_PIN_DIR_INOUT */
536         { 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
537         { 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
538 };
539 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
540 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
541 #define alc_pin_mode_n_items(_dir) \
542         (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
543
544 static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
545                              struct snd_ctl_elem_info *uinfo)
546 {
547         unsigned int item_num = uinfo->value.enumerated.item;
548         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
549
550         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
551         uinfo->count = 1;
552         uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
553
554         if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
555                 item_num = alc_pin_mode_min(dir);
556         strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
557         return 0;
558 }
559
560 static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
561                             struct snd_ctl_elem_value *ucontrol)
562 {
563         unsigned int i;
564         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
565         hda_nid_t nid = kcontrol->private_value & 0xffff;
566         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
567         long *valp = ucontrol->value.integer.value;
568         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
569                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
570                                                  0x00);
571
572         /* Find enumerated value for current pinctl setting */
573         i = alc_pin_mode_min(dir);
574         while (i <= alc_pin_mode_max(dir) && alc_pin_mode_values[i] != pinctl)
575                 i++;
576         *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
577         return 0;
578 }
579
580 static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
581                             struct snd_ctl_elem_value *ucontrol)
582 {
583         signed int change;
584         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
585         hda_nid_t nid = kcontrol->private_value & 0xffff;
586         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
587         long val = *ucontrol->value.integer.value;
588         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
589                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
590                                                  0x00);
591
592         if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
593                 val = alc_pin_mode_min(dir);
594
595         change = pinctl != alc_pin_mode_values[val];
596         if (change) {
597                 /* Set pin mode to that requested */
598                 snd_hda_codec_write_cache(codec, nid, 0,
599                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
600                                           alc_pin_mode_values[val]);
601
602                 /* Also enable the retasking pin's input/output as required
603                  * for the requested pin mode.  Enum values of 2 or less are
604                  * input modes.
605                  *
606                  * Dynamically switching the input/output buffers probably
607                  * reduces noise slightly (particularly on input) so we'll
608                  * do it.  However, having both input and output buffers
609                  * enabled simultaneously doesn't seem to be problematic if
610                  * this turns out to be necessary in the future.
611                  */
612                 if (val <= 2) {
613                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
614                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
615                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
616                                                  HDA_AMP_MUTE, 0);
617                 } else {
618                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
619                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
620                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
621                                                  HDA_AMP_MUTE, 0);
622                 }
623         }
624         return change;
625 }
626
627 #define ALC_PIN_MODE(xname, nid, dir) \
628         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
629           .info = alc_pin_mode_info, \
630           .get = alc_pin_mode_get, \
631           .put = alc_pin_mode_put, \
632           .private_value = nid | (dir<<16) }
633
634 /* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
635  * together using a mask with more than one bit set.  This control is
636  * currently used only by the ALC260 test model.  At this stage they are not
637  * needed for any "production" models.
638  */
639 #ifdef CONFIG_SND_DEBUG
640 #define alc_gpio_data_info      snd_ctl_boolean_mono_info
641
642 static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
643                              struct snd_ctl_elem_value *ucontrol)
644 {
645         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
646         hda_nid_t nid = kcontrol->private_value & 0xffff;
647         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
648         long *valp = ucontrol->value.integer.value;
649         unsigned int val = snd_hda_codec_read(codec, nid, 0,
650                                               AC_VERB_GET_GPIO_DATA, 0x00);
651
652         *valp = (val & mask) != 0;
653         return 0;
654 }
655 static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
656                              struct snd_ctl_elem_value *ucontrol)
657 {
658         signed int change;
659         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
660         hda_nid_t nid = kcontrol->private_value & 0xffff;
661         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
662         long val = *ucontrol->value.integer.value;
663         unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
664                                                     AC_VERB_GET_GPIO_DATA,
665                                                     0x00);
666
667         /* Set/unset the masked GPIO bit(s) as needed */
668         change = (val == 0 ? 0 : mask) != (gpio_data & mask);
669         if (val == 0)
670                 gpio_data &= ~mask;
671         else
672                 gpio_data |= mask;
673         snd_hda_codec_write_cache(codec, nid, 0,
674                                   AC_VERB_SET_GPIO_DATA, gpio_data);
675
676         return change;
677 }
678 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
679         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
680           .info = alc_gpio_data_info, \
681           .get = alc_gpio_data_get, \
682           .put = alc_gpio_data_put, \
683           .private_value = nid | (mask<<16) }
684 #endif   /* CONFIG_SND_DEBUG */
685
686 /* A switch control to allow the enabling of the digital IO pins on the
687  * ALC260.  This is incredibly simplistic; the intention of this control is
688  * to provide something in the test model allowing digital outputs to be
689  * identified if present.  If models are found which can utilise these
690  * outputs a more complete mixer control can be devised for those models if
691  * necessary.
692  */
693 #ifdef CONFIG_SND_DEBUG
694 #define alc_spdif_ctrl_info     snd_ctl_boolean_mono_info
695
696 static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
697                               struct snd_ctl_elem_value *ucontrol)
698 {
699         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
700         hda_nid_t nid = kcontrol->private_value & 0xffff;
701         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
702         long *valp = ucontrol->value.integer.value;
703         unsigned int val = snd_hda_codec_read(codec, nid, 0,
704                                               AC_VERB_GET_DIGI_CONVERT_1, 0x00);
705
706         *valp = (val & mask) != 0;
707         return 0;
708 }
709 static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
710                               struct snd_ctl_elem_value *ucontrol)
711 {
712         signed int change;
713         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
714         hda_nid_t nid = kcontrol->private_value & 0xffff;
715         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
716         long val = *ucontrol->value.integer.value;
717         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
718                                                     AC_VERB_GET_DIGI_CONVERT_1,
719                                                     0x00);
720
721         /* Set/unset the masked control bit(s) as needed */
722         change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
723         if (val==0)
724                 ctrl_data &= ~mask;
725         else
726                 ctrl_data |= mask;
727         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
728                                   ctrl_data);
729
730         return change;
731 }
732 #define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
733         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
734           .info = alc_spdif_ctrl_info, \
735           .get = alc_spdif_ctrl_get, \
736           .put = alc_spdif_ctrl_put, \
737           .private_value = nid | (mask<<16) }
738 #endif   /* CONFIG_SND_DEBUG */
739
740 /* A switch control to allow the enabling EAPD digital outputs on the ALC26x.
741  * Again, this is only used in the ALC26x test models to help identify when
742  * the EAPD line must be asserted for features to work.
743  */
744 #ifdef CONFIG_SND_DEBUG
745 #define alc_eapd_ctrl_info      snd_ctl_boolean_mono_info
746
747 static int alc_eapd_ctrl_get(struct snd_kcontrol *kcontrol,
748                               struct snd_ctl_elem_value *ucontrol)
749 {
750         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
751         hda_nid_t nid = kcontrol->private_value & 0xffff;
752         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
753         long *valp = ucontrol->value.integer.value;
754         unsigned int val = snd_hda_codec_read(codec, nid, 0,
755                                               AC_VERB_GET_EAPD_BTLENABLE, 0x00);
756
757         *valp = (val & mask) != 0;
758         return 0;
759 }
760
761 static int alc_eapd_ctrl_put(struct snd_kcontrol *kcontrol,
762                               struct snd_ctl_elem_value *ucontrol)
763 {
764         int change;
765         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
766         hda_nid_t nid = kcontrol->private_value & 0xffff;
767         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
768         long val = *ucontrol->value.integer.value;
769         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
770                                                     AC_VERB_GET_EAPD_BTLENABLE,
771                                                     0x00);
772
773         /* Set/unset the masked control bit(s) as needed */
774         change = (!val ? 0 : mask) != (ctrl_data & mask);
775         if (!val)
776                 ctrl_data &= ~mask;
777         else
778                 ctrl_data |= mask;
779         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
780                                   ctrl_data);
781
782         return change;
783 }
784
785 #define ALC_EAPD_CTRL_SWITCH(xname, nid, mask) \
786         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
787           .info = alc_eapd_ctrl_info, \
788           .get = alc_eapd_ctrl_get, \
789           .put = alc_eapd_ctrl_put, \
790           .private_value = nid | (mask<<16) }
791 #endif   /* CONFIG_SND_DEBUG */
792
793 /*
794  * set up the input pin config (depending on the given auto-pin type)
795  */
796 static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
797                               int auto_pin_type)
798 {
799         unsigned int val = PIN_IN;
800
801         if (auto_pin_type <= AUTO_PIN_FRONT_MIC) {
802                 unsigned int pincap;
803                 pincap = snd_hda_query_pin_caps(codec, nid);
804                 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
805                 if (pincap & AC_PINCAP_VREF_80)
806                         val = PIN_VREF80;
807                 else if (pincap & AC_PINCAP_VREF_50)
808                         val = PIN_VREF50;
809                 else if (pincap & AC_PINCAP_VREF_100)
810                         val = PIN_VREF100;
811                 else if (pincap & AC_PINCAP_VREF_GRD)
812                         val = PIN_VREFGRD;
813         }
814         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
815 }
816
817 /*
818  */
819 static void add_mixer(struct alc_spec *spec, struct snd_kcontrol_new *mix)
820 {
821         if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
822                 return;
823         spec->mixers[spec->num_mixers++] = mix;
824 }
825
826 static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
827 {
828         if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
829                 return;
830         spec->init_verbs[spec->num_init_verbs++] = verb;
831 }
832
833 #ifdef CONFIG_PROC_FS
834 /*
835  * hook for proc
836  */
837 static void print_realtek_coef(struct snd_info_buffer *buffer,
838                                struct hda_codec *codec, hda_nid_t nid)
839 {
840         int coeff;
841
842         if (nid != 0x20)
843                 return;
844         coeff = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PROC_COEF, 0);
845         snd_iprintf(buffer, "  Processing Coefficient: 0x%02x\n", coeff);
846         coeff = snd_hda_codec_read(codec, nid, 0,
847                                    AC_VERB_GET_COEF_INDEX, 0);
848         snd_iprintf(buffer, "  Coefficient Index: 0x%02x\n", coeff);
849 }
850 #else
851 #define print_realtek_coef      NULL
852 #endif
853
854 /*
855  * set up from the preset table
856  */
857 static void setup_preset(struct hda_codec *codec,
858                          const struct alc_config_preset *preset)
859 {
860         struct alc_spec *spec = codec->spec;
861         int i;
862
863         for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
864                 add_mixer(spec, preset->mixers[i]);
865         spec->cap_mixer = preset->cap_mixer;
866         for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
867              i++)
868                 add_verb(spec, preset->init_verbs[i]);
869
870         spec->channel_mode = preset->channel_mode;
871         spec->num_channel_mode = preset->num_channel_mode;
872         spec->need_dac_fix = preset->need_dac_fix;
873         spec->const_channel_count = preset->const_channel_count;
874
875         if (preset->const_channel_count)
876                 spec->multiout.max_channels = preset->const_channel_count;
877         else
878                 spec->multiout.max_channels = spec->channel_mode[0].channels;
879         spec->ext_channel_count = spec->channel_mode[0].channels;
880
881         spec->multiout.num_dacs = preset->num_dacs;
882         spec->multiout.dac_nids = preset->dac_nids;
883         spec->multiout.dig_out_nid = preset->dig_out_nid;
884         spec->multiout.slave_dig_outs = preset->slave_dig_outs;
885         spec->multiout.hp_nid = preset->hp_nid;
886
887         spec->num_mux_defs = preset->num_mux_defs;
888         if (!spec->num_mux_defs)
889                 spec->num_mux_defs = 1;
890         spec->input_mux = preset->input_mux;
891
892         spec->num_adc_nids = preset->num_adc_nids;
893         spec->adc_nids = preset->adc_nids;
894         spec->capsrc_nids = preset->capsrc_nids;
895         spec->dig_in_nid = preset->dig_in_nid;
896
897         spec->unsol_event = preset->unsol_event;
898         spec->init_hook = preset->init_hook;
899 #ifdef CONFIG_SND_HDA_POWER_SAVE
900         spec->loopback.amplist = preset->loopbacks;
901 #endif
902
903         if (preset->setup)
904                 preset->setup(codec);
905 }
906
907 /* Enable GPIO mask and set output */
908 static struct hda_verb alc_gpio1_init_verbs[] = {
909         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
910         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
911         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
912         { }
913 };
914
915 static struct hda_verb alc_gpio2_init_verbs[] = {
916         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
917         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
918         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
919         { }
920 };
921
922 static struct hda_verb alc_gpio3_init_verbs[] = {
923         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
924         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
925         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
926         { }
927 };
928
929 /*
930  * Fix hardware PLL issue
931  * On some codecs, the analog PLL gating control must be off while
932  * the default value is 1.
933  */
934 static void alc_fix_pll(struct hda_codec *codec)
935 {
936         struct alc_spec *spec = codec->spec;
937         unsigned int val;
938
939         if (!spec->pll_nid)
940                 return;
941         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
942                             spec->pll_coef_idx);
943         val = snd_hda_codec_read(codec, spec->pll_nid, 0,
944                                  AC_VERB_GET_PROC_COEF, 0);
945         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
946                             spec->pll_coef_idx);
947         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
948                             val & ~(1 << spec->pll_coef_bit));
949 }
950
951 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
952                              unsigned int coef_idx, unsigned int coef_bit)
953 {
954         struct alc_spec *spec = codec->spec;
955         spec->pll_nid = nid;
956         spec->pll_coef_idx = coef_idx;
957         spec->pll_coef_bit = coef_bit;
958         alc_fix_pll(codec);
959 }
960
961 static void alc_automute_pin(struct hda_codec *codec)
962 {
963         struct alc_spec *spec = codec->spec;
964         unsigned int present, pincap;
965         unsigned int nid = spec->autocfg.hp_pins[0];
966         int i;
967
968         pincap = snd_hda_query_pin_caps(codec, nid);
969         if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */
970                 snd_hda_codec_read(codec, nid, 0, AC_VERB_SET_PIN_SENSE, 0);
971         present = snd_hda_codec_read(codec, nid, 0,
972                                      AC_VERB_GET_PIN_SENSE, 0);
973         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
974         for (i = 0; i < ARRAY_SIZE(spec->autocfg.speaker_pins); i++) {
975                 nid = spec->autocfg.speaker_pins[i];
976                 if (!nid)
977                         break;
978                 snd_hda_codec_write(codec, nid, 0,
979                                     AC_VERB_SET_PIN_WIDGET_CONTROL,
980                                     spec->jack_present ? 0 : PIN_OUT);
981         }
982 }
983
984 static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
985                                 hda_nid_t nid)
986 {
987         hda_nid_t conn[HDA_MAX_NUM_INPUTS];
988         int i, nums;
989
990         nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
991         for (i = 0; i < nums; i++)
992                 if (conn[i] == nid)
993                         return i;
994         return -1;
995 }
996
997 static void alc_mic_automute(struct hda_codec *codec)
998 {
999         struct alc_spec *spec = codec->spec;
1000         struct alc_mic_route *dead, *alive;
1001         unsigned int present, type;
1002         hda_nid_t cap_nid;
1003
1004         if (!spec->auto_mic)
1005                 return;
1006         if (!spec->int_mic.pin || !spec->ext_mic.pin)
1007                 return;
1008         if (snd_BUG_ON(!spec->adc_nids))
1009                 return;
1010
1011         cap_nid = spec->capsrc_nids ? spec->capsrc_nids[0] : spec->adc_nids[0];
1012
1013         present = snd_hda_codec_read(codec, spec->ext_mic.pin, 0,
1014                                      AC_VERB_GET_PIN_SENSE, 0);
1015         present &= AC_PINSENSE_PRESENCE;
1016         if (present) {
1017                 alive = &spec->ext_mic;
1018                 dead = &spec->int_mic;
1019         } else {
1020                 alive = &spec->int_mic;
1021                 dead = &spec->ext_mic;
1022         }
1023
1024         type = get_wcaps_type(get_wcaps(codec, cap_nid));
1025         if (type == AC_WID_AUD_MIX) {
1026                 /* Matrix-mixer style (e.g. ALC882) */
1027                 snd_hda_codec_amp_stereo(codec, cap_nid, HDA_INPUT,
1028                                          alive->mux_idx,
1029                                          HDA_AMP_MUTE, 0);
1030                 snd_hda_codec_amp_stereo(codec, cap_nid, HDA_INPUT,
1031                                          dead->mux_idx,
1032                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
1033         } else {
1034                 /* MUX style (e.g. ALC880) */
1035                 snd_hda_codec_write_cache(codec, cap_nid, 0,
1036                                           AC_VERB_SET_CONNECT_SEL,
1037                                           alive->mux_idx);
1038         }
1039
1040         /* FIXME: analog mixer */
1041 }
1042
1043 /* unsolicited event for HP jack sensing */
1044 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
1045 {
1046         if (codec->vendor_id == 0x10ec0880)
1047                 res >>= 28;
1048         else
1049                 res >>= 26;
1050         switch (res) {
1051         case ALC880_HP_EVENT:
1052                 alc_automute_pin(codec);
1053                 break;
1054         case ALC880_MIC_EVENT:
1055                 alc_mic_automute(codec);
1056                 break;
1057         }
1058 }
1059
1060 static void alc_inithook(struct hda_codec *codec)
1061 {
1062         alc_automute_pin(codec);
1063         alc_mic_automute(codec);
1064 }
1065
1066 /* additional initialization for ALC888 variants */
1067 static void alc888_coef_init(struct hda_codec *codec)
1068 {
1069         unsigned int tmp;
1070
1071         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
1072         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
1073         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
1074         if ((tmp & 0xf0) == 0x20)
1075                 /* alc888S-VC */
1076                 snd_hda_codec_read(codec, 0x20, 0,
1077                                    AC_VERB_SET_PROC_COEF, 0x830);
1078          else
1079                  /* alc888-VB */
1080                  snd_hda_codec_read(codec, 0x20, 0,
1081                                     AC_VERB_SET_PROC_COEF, 0x3030);
1082 }
1083
1084 static void alc889_coef_init(struct hda_codec *codec)
1085 {
1086         unsigned int tmp;
1087
1088         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
1089         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
1090         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
1091         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
1092 }
1093
1094 static void alc_auto_init_amp(struct hda_codec *codec, int type)
1095 {
1096         unsigned int tmp;
1097
1098         switch (type) {
1099         case ALC_INIT_GPIO1:
1100                 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
1101                 break;
1102         case ALC_INIT_GPIO2:
1103                 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
1104                 break;
1105         case ALC_INIT_GPIO3:
1106                 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
1107                 break;
1108         case ALC_INIT_DEFAULT:
1109                 switch (codec->vendor_id) {
1110                 case 0x10ec0260:
1111                         snd_hda_codec_write(codec, 0x0f, 0,
1112                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1113                         snd_hda_codec_write(codec, 0x10, 0,
1114                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1115                         break;
1116                 case 0x10ec0262:
1117                 case 0x10ec0267:
1118                 case 0x10ec0268:
1119                 case 0x10ec0269:
1120                 case 0x10ec0272:
1121                 case 0x10ec0660:
1122                 case 0x10ec0662:
1123                 case 0x10ec0663:
1124                 case 0x10ec0862:
1125                 case 0x10ec0889:
1126                         snd_hda_codec_write(codec, 0x14, 0,
1127                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1128                         snd_hda_codec_write(codec, 0x15, 0,
1129                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1130                         break;
1131                 }
1132                 switch (codec->vendor_id) {
1133                 case 0x10ec0260:
1134                         snd_hda_codec_write(codec, 0x1a, 0,
1135                                             AC_VERB_SET_COEF_INDEX, 7);
1136                         tmp = snd_hda_codec_read(codec, 0x1a, 0,
1137                                                  AC_VERB_GET_PROC_COEF, 0);
1138                         snd_hda_codec_write(codec, 0x1a, 0,
1139                                             AC_VERB_SET_COEF_INDEX, 7);
1140                         snd_hda_codec_write(codec, 0x1a, 0,
1141                                             AC_VERB_SET_PROC_COEF,
1142                                             tmp | 0x2010);
1143                         break;
1144                 case 0x10ec0262:
1145                 case 0x10ec0880:
1146                 case 0x10ec0882:
1147                 case 0x10ec0883:
1148                 case 0x10ec0885:
1149                 case 0x10ec0887:
1150                 case 0x10ec0889:
1151                         alc889_coef_init(codec);
1152                         break;
1153                 case 0x10ec0888:
1154                         alc888_coef_init(codec);
1155                         break;
1156                 case 0x10ec0267:
1157                 case 0x10ec0268:
1158                         snd_hda_codec_write(codec, 0x20, 0,
1159                                             AC_VERB_SET_COEF_INDEX, 7);
1160                         tmp = snd_hda_codec_read(codec, 0x20, 0,
1161                                                  AC_VERB_GET_PROC_COEF, 0);
1162                         snd_hda_codec_write(codec, 0x20, 0,
1163                                             AC_VERB_SET_COEF_INDEX, 7);
1164                         snd_hda_codec_write(codec, 0x20, 0,
1165                                             AC_VERB_SET_PROC_COEF,
1166                                             tmp | 0x3000);
1167                         break;
1168                 }
1169                 break;
1170         }
1171 }
1172
1173 static void alc_init_auto_hp(struct hda_codec *codec)
1174 {
1175         struct alc_spec *spec = codec->spec;
1176
1177         if (!spec->autocfg.hp_pins[0])
1178                 return;
1179
1180         if (!spec->autocfg.speaker_pins[0]) {
1181                 if (spec->autocfg.line_out_pins[0] &&
1182                     spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
1183                         spec->autocfg.speaker_pins[0] =
1184                                 spec->autocfg.line_out_pins[0];
1185                 else
1186                         return;
1187         }
1188
1189         snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
1190                     spec->autocfg.hp_pins[0]);
1191         snd_hda_codec_write_cache(codec, spec->autocfg.hp_pins[0], 0,
1192                                   AC_VERB_SET_UNSOLICITED_ENABLE,
1193                                   AC_USRSP_EN | ALC880_HP_EVENT);
1194         spec->unsol_event = alc_sku_unsol_event;
1195 }
1196
1197 static void alc_init_auto_mic(struct hda_codec *codec)
1198 {
1199         struct alc_spec *spec = codec->spec;
1200         struct auto_pin_cfg *cfg = &spec->autocfg;
1201         hda_nid_t fixed, ext;
1202         int i;
1203
1204         /* there must be only two mic inputs exclusively */
1205         for (i = AUTO_PIN_LINE; i < AUTO_PIN_LAST; i++)
1206                 if (cfg->input_pins[i])
1207                         return;
1208
1209         fixed = ext = 0;
1210         for (i = AUTO_PIN_MIC; i <= AUTO_PIN_FRONT_MIC; i++) {
1211                 hda_nid_t nid = cfg->input_pins[i];
1212                 unsigned int defcfg;
1213                 if (!nid)
1214                         return;
1215                 defcfg = snd_hda_codec_get_pincfg(codec, nid);
1216                 switch (get_defcfg_connect(defcfg)) {
1217                 case AC_JACK_PORT_FIXED:
1218                         if (fixed)
1219                                 return; /* already occupied */
1220                         fixed = nid;
1221                         break;
1222                 case AC_JACK_PORT_COMPLEX:
1223                         if (ext)
1224                                 return; /* already occupied */
1225                         ext = nid;
1226                         break;
1227                 default:
1228                         return; /* invalid entry */
1229                 }
1230         }
1231         if (!(get_wcaps(codec, ext) & AC_WCAP_UNSOL_CAP))
1232                 return; /* no unsol support */
1233         snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x\n",
1234                     ext, fixed);
1235         spec->ext_mic.pin = ext;
1236         spec->int_mic.pin = fixed;
1237         spec->ext_mic.mux_idx = MUX_IDX_UNDEF; /* set later */
1238         spec->int_mic.mux_idx = MUX_IDX_UNDEF; /* set later */
1239         spec->auto_mic = 1;
1240         snd_hda_codec_write_cache(codec, spec->ext_mic.pin, 0,
1241                                   AC_VERB_SET_UNSOLICITED_ENABLE,
1242                                   AC_USRSP_EN | ALC880_MIC_EVENT);
1243         spec->unsol_event = alc_sku_unsol_event;
1244 }
1245
1246 /* check subsystem ID and set up device-specific initialization;
1247  * return 1 if initialized, 0 if invalid SSID
1248  */
1249 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1250  *      31 ~ 16 :       Manufacture ID
1251  *      15 ~ 8  :       SKU ID
1252  *      7  ~ 0  :       Assembly ID
1253  *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1254  */
1255 static int alc_subsystem_id(struct hda_codec *codec,
1256                             hda_nid_t porta, hda_nid_t porte,
1257                             hda_nid_t portd)
1258 {
1259         unsigned int ass, tmp, i;
1260         unsigned nid;
1261         struct alc_spec *spec = codec->spec;
1262
1263         ass = codec->subsystem_id & 0xffff;
1264         if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1265                 goto do_sku;
1266
1267         /* invalid SSID, check the special NID pin defcfg instead */
1268         /*
1269          * 31~30        : port connectivity
1270          * 29~21        : reserve
1271          * 20           : PCBEEP input
1272          * 19~16        : Check sum (15:1)
1273          * 15~1         : Custom
1274          * 0            : override
1275         */
1276         nid = 0x1d;
1277         if (codec->vendor_id == 0x10ec0260)
1278                 nid = 0x17;
1279         ass = snd_hda_codec_get_pincfg(codec, nid);
1280         snd_printd("realtek: No valid SSID, "
1281                    "checking pincfg 0x%08x for NID 0x%x\n",
1282                    ass, nid);
1283         if (!(ass & 1) && !(ass & 0x100000))
1284                 return 0;
1285         if ((ass >> 30) != 1)   /* no physical connection */
1286                 return 0;
1287
1288         /* check sum */
1289         tmp = 0;
1290         for (i = 1; i < 16; i++) {
1291                 if ((ass >> i) & 1)
1292                         tmp++;
1293         }
1294         if (((ass >> 16) & 0xf) != tmp)
1295                 return 0;
1296 do_sku:
1297         snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1298                    ass & 0xffff, codec->vendor_id);
1299         /*
1300          * 0 : override
1301          * 1 :  Swap Jack
1302          * 2 : 0 --> Desktop, 1 --> Laptop
1303          * 3~5 : External Amplifier control
1304          * 7~6 : Reserved
1305         */
1306         tmp = (ass & 0x38) >> 3;        /* external Amp control */
1307         switch (tmp) {
1308         case 1:
1309                 spec->init_amp = ALC_INIT_GPIO1;
1310                 break;
1311         case 3:
1312                 spec->init_amp = ALC_INIT_GPIO2;
1313                 break;
1314         case 7:
1315                 spec->init_amp = ALC_INIT_GPIO3;
1316                 break;
1317         case 5:
1318                 spec->init_amp = ALC_INIT_DEFAULT;
1319                 break;
1320         }
1321
1322         /* is laptop or Desktop and enable the function "Mute internal speaker
1323          * when the external headphone out jack is plugged"
1324          */
1325         if (!(ass & 0x8000))
1326                 return 1;
1327         /*
1328          * 10~8 : Jack location
1329          * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1330          * 14~13: Resvered
1331          * 15   : 1 --> enable the function "Mute internal speaker
1332          *              when the external headphone out jack is plugged"
1333          */
1334         if (!spec->autocfg.hp_pins[0]) {
1335                 tmp = (ass >> 11) & 0x3;        /* HP to chassis */
1336                 if (tmp == 0)
1337                         spec->autocfg.hp_pins[0] = porta;
1338                 else if (tmp == 1)
1339                         spec->autocfg.hp_pins[0] = porte;
1340                 else if (tmp == 2)
1341                         spec->autocfg.hp_pins[0] = portd;
1342                 else
1343                         return 1;
1344         }
1345
1346         alc_init_auto_hp(codec);
1347         alc_init_auto_mic(codec);
1348         return 1;
1349 }
1350
1351 static void alc_ssid_check(struct hda_codec *codec,
1352                            hda_nid_t porta, hda_nid_t porte, hda_nid_t portd)
1353 {
1354         if (!alc_subsystem_id(codec, porta, porte, portd)) {
1355                 struct alc_spec *spec = codec->spec;
1356                 snd_printd("realtek: "
1357                            "Enable default setup for auto mode as fallback\n");
1358                 spec->init_amp = ALC_INIT_DEFAULT;
1359                 alc_init_auto_hp(codec);
1360                 alc_init_auto_mic(codec);
1361         }
1362 }
1363
1364 /*
1365  * Fix-up pin default configurations
1366  */
1367
1368 struct alc_pincfg {
1369         hda_nid_t nid;
1370         u32 val;
1371 };
1372
1373 static void alc_fix_pincfg(struct hda_codec *codec,
1374                            const struct snd_pci_quirk *quirk,
1375                            const struct alc_pincfg **pinfix)
1376 {
1377         const struct alc_pincfg *cfg;
1378
1379         quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1380         if (!quirk)
1381                 return;
1382
1383         cfg = pinfix[quirk->value];
1384         for (; cfg->nid; cfg++)
1385                 snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val);
1386 }
1387
1388 /*
1389  * ALC888
1390  */
1391
1392 /*
1393  * 2ch mode
1394  */
1395 static struct hda_verb alc888_4ST_ch2_intel_init[] = {
1396 /* Mic-in jack as mic in */
1397         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1398         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1399 /* Line-in jack as Line in */
1400         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1401         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1402 /* Line-Out as Front */
1403         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1404         { } /* end */
1405 };
1406
1407 /*
1408  * 4ch mode
1409  */
1410 static struct hda_verb alc888_4ST_ch4_intel_init[] = {
1411 /* Mic-in jack as mic in */
1412         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1413         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1414 /* Line-in jack as Surround */
1415         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1416         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1417 /* Line-Out as Front */
1418         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1419         { } /* end */
1420 };
1421
1422 /*
1423  * 6ch mode
1424  */
1425 static struct hda_verb alc888_4ST_ch6_intel_init[] = {
1426 /* Mic-in jack as CLFE */
1427         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1428         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1429 /* Line-in jack as Surround */
1430         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1431         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1432 /* Line-Out as CLFE (workaround because Mic-in is not loud enough) */
1433         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1434         { } /* end */
1435 };
1436
1437 /*
1438  * 8ch mode
1439  */
1440 static struct hda_verb alc888_4ST_ch8_intel_init[] = {
1441 /* Mic-in jack as CLFE */
1442         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1443         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1444 /* Line-in jack as Surround */
1445         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1446         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1447 /* Line-Out as Side */
1448         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1449         { } /* end */
1450 };
1451
1452 static struct hda_channel_mode alc888_4ST_8ch_intel_modes[4] = {
1453         { 2, alc888_4ST_ch2_intel_init },
1454         { 4, alc888_4ST_ch4_intel_init },
1455         { 6, alc888_4ST_ch6_intel_init },
1456         { 8, alc888_4ST_ch8_intel_init },
1457 };
1458
1459 /*
1460  * ALC888 Fujitsu Siemens Amillo xa3530
1461  */
1462
1463 static struct hda_verb alc888_fujitsu_xa3530_verbs[] = {
1464 /* Front Mic: set to PIN_IN (empty by default) */
1465         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1466 /* Connect Internal HP to Front */
1467         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1468         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1469         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1470 /* Connect Bass HP to Front */
1471         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1472         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1473         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1474 /* Connect Line-Out side jack (SPDIF) to Side */
1475         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1476         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1477         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1478 /* Connect Mic jack to CLFE */
1479         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1480         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1481         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},
1482 /* Connect Line-in jack to Surround */
1483         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1484         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1485         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
1486 /* Connect HP out jack to Front */
1487         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1488         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1489         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1490 /* Enable unsolicited event for HP jack and Line-out jack */
1491         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1492         {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1493         {}
1494 };
1495
1496 static void alc_automute_amp(struct hda_codec *codec)
1497 {
1498         struct alc_spec *spec = codec->spec;
1499         unsigned int val, mute, pincap;
1500         hda_nid_t nid;
1501         int i;
1502
1503         spec->jack_present = 0;
1504         for (i = 0; i < ARRAY_SIZE(spec->autocfg.hp_pins); i++) {
1505                 nid = spec->autocfg.hp_pins[i];
1506                 if (!nid)
1507                         break;
1508                 pincap = snd_hda_query_pin_caps(codec, nid);
1509                 if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */
1510                         snd_hda_codec_read(codec, nid, 0,
1511                                            AC_VERB_SET_PIN_SENSE, 0);
1512                 val = snd_hda_codec_read(codec, nid, 0,
1513                                          AC_VERB_GET_PIN_SENSE, 0);
1514                 if (val & AC_PINSENSE_PRESENCE) {
1515                         spec->jack_present = 1;
1516                         break;
1517                 }
1518         }
1519
1520         mute = spec->jack_present ? HDA_AMP_MUTE : 0;
1521         /* Toggle internal speakers muting */
1522         for (i = 0; i < ARRAY_SIZE(spec->autocfg.speaker_pins); i++) {
1523                 nid = spec->autocfg.speaker_pins[i];
1524                 if (!nid)
1525                         break;
1526                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
1527                                          HDA_AMP_MUTE, mute);
1528         }
1529 }
1530
1531 static void alc_automute_amp_unsol_event(struct hda_codec *codec,
1532                                          unsigned int res)
1533 {
1534         if (codec->vendor_id == 0x10ec0880)
1535                 res >>= 28;
1536         else
1537                 res >>= 26;
1538         if (res == ALC880_HP_EVENT)
1539                 alc_automute_amp(codec);
1540 }
1541
1542 static void alc889_automute_setup(struct hda_codec *codec)
1543 {
1544         struct alc_spec *spec = codec->spec;
1545
1546         spec->autocfg.hp_pins[0] = 0x15;
1547         spec->autocfg.speaker_pins[0] = 0x14;
1548         spec->autocfg.speaker_pins[1] = 0x16;
1549         spec->autocfg.speaker_pins[2] = 0x17;
1550         spec->autocfg.speaker_pins[3] = 0x19;
1551         spec->autocfg.speaker_pins[4] = 0x1a;
1552 }
1553
1554 static void alc889_intel_init_hook(struct hda_codec *codec)
1555 {
1556         alc889_coef_init(codec);
1557         alc_automute_amp(codec);
1558 }
1559
1560 static void alc888_fujitsu_xa3530_setup(struct hda_codec *codec)
1561 {
1562         struct alc_spec *spec = codec->spec;
1563
1564         spec->autocfg.hp_pins[0] = 0x17; /* line-out */
1565         spec->autocfg.hp_pins[1] = 0x1b; /* hp */
1566         spec->autocfg.speaker_pins[0] = 0x14; /* speaker */
1567         spec->autocfg.speaker_pins[1] = 0x15; /* bass */
1568 }
1569
1570 /*
1571  * ALC888 Acer Aspire 4930G model
1572  */
1573
1574 static struct hda_verb alc888_acer_aspire_4930g_verbs[] = {
1575 /* Front Mic: set to PIN_IN (empty by default) */
1576         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1577 /* Unselect Front Mic by default in input mixer 3 */
1578         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1579 /* Enable unsolicited event for HP jack */
1580         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1581 /* Connect Internal HP to front */
1582         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1583         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1584         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1585 /* Connect HP out to front */
1586         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1587         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1588         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1589         { }
1590 };
1591
1592 /*
1593  * ALC888 Acer Aspire 6530G model
1594  */
1595
1596 static struct hda_verb alc888_acer_aspire_6530g_verbs[] = {
1597 /* Bias voltage on for external mic port */
1598         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN | PIN_VREF80},
1599 /* Front Mic: set to PIN_IN (empty by default) */
1600         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1601 /* Unselect Front Mic by default in input mixer 3 */
1602         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1603 /* Enable unsolicited event for HP jack */
1604         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1605 /* Enable speaker output */
1606         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1607         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1608 /* Enable headphone output */
1609         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | PIN_HP},
1610         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1611         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1612         { }
1613 };
1614
1615 /*
1616  * ALC889 Acer Aspire 8930G model
1617  */
1618
1619 static struct hda_verb alc889_acer_aspire_8930g_verbs[] = {
1620 /* Front Mic: set to PIN_IN (empty by default) */
1621         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1622 /* Unselect Front Mic by default in input mixer 3 */
1623         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1624 /* Enable unsolicited event for HP jack */
1625         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1626 /* Connect Internal Front to Front */
1627         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1628         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1629         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1630 /* Connect Internal Rear to Rear */
1631         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1632         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1633         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},
1634 /* Connect Internal CLFE to CLFE */
1635         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1636         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1637         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
1638 /* Connect HP out to Front */
1639         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | PIN_HP},
1640         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1641         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1642 /* Enable all DACs */
1643 /*  DAC DISABLE/MUTE 1? */
1644 /*  setting bits 1-5 disables DAC nids 0x02-0x06 apparently. Init=0x38 */
1645         {0x20, AC_VERB_SET_COEF_INDEX, 0x03},
1646         {0x20, AC_VERB_SET_PROC_COEF, 0x0000},
1647 /*  DAC DISABLE/MUTE 2? */
1648 /*  some bit here disables the other DACs. Init=0x4900 */
1649         {0x20, AC_VERB_SET_COEF_INDEX, 0x08},
1650         {0x20, AC_VERB_SET_PROC_COEF, 0x0000},
1651 /* Enable amplifiers */
1652         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
1653         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
1654 /* DMIC fix
1655  * This laptop has a stereo digital microphone. The mics are only 1cm apart
1656  * which makes the stereo useless. However, either the mic or the ALC889
1657  * makes the signal become a difference/sum signal instead of standard
1658  * stereo, which is annoying. So instead we flip this bit which makes the
1659  * codec replicate the sum signal to both channels, turning it into a
1660  * normal mono mic.
1661  */
1662 /*  DMIC_CONTROL? Init value = 0x0001 */
1663         {0x20, AC_VERB_SET_COEF_INDEX, 0x0b},
1664         {0x20, AC_VERB_SET_PROC_COEF, 0x0003},
1665         { }
1666 };
1667
1668 static struct hda_input_mux alc888_2_capture_sources[2] = {
1669         /* Front mic only available on one ADC */
1670         {
1671                 .num_items = 4,
1672                 .items = {
1673                         { "Mic", 0x0 },
1674                         { "Line", 0x2 },
1675                         { "CD", 0x4 },
1676                         { "Front Mic", 0xb },
1677                 },
1678         },
1679         {
1680                 .num_items = 3,
1681                 .items = {
1682                         { "Mic", 0x0 },
1683                         { "Line", 0x2 },
1684                         { "CD", 0x4 },
1685                 },
1686         }
1687 };
1688
1689 static struct hda_input_mux alc888_acer_aspire_6530_sources[2] = {
1690         /* Interal mic only available on one ADC */
1691         {
1692                 .num_items = 5,
1693                 .items = {
1694                         { "Ext Mic", 0x0 },
1695                         { "Line In", 0x2 },
1696                         { "CD", 0x4 },
1697                         { "Input Mix", 0xa },
1698                         { "Int Mic", 0xb },
1699                 },
1700         },
1701         {
1702                 .num_items = 4,
1703                 .items = {
1704                         { "Ext Mic", 0x0 },
1705                         { "Line In", 0x2 },
1706                         { "CD", 0x4 },
1707                         { "Input Mix", 0xa },
1708                 },
1709         }
1710 };
1711
1712 static struct hda_input_mux alc889_capture_sources[3] = {
1713         /* Digital mic only available on first "ADC" */
1714         {
1715                 .num_items = 5,
1716                 .items = {
1717                         { "Mic", 0x0 },
1718                         { "Line", 0x2 },
1719                         { "CD", 0x4 },
1720                         { "Front Mic", 0xb },
1721                         { "Input Mix", 0xa },
1722                 },
1723         },
1724         {
1725                 .num_items = 4,
1726                 .items = {
1727                         { "Mic", 0x0 },
1728                         { "Line", 0x2 },
1729                         { "CD", 0x4 },
1730                         { "Input Mix", 0xa },
1731                 },
1732         },
1733         {
1734                 .num_items = 4,
1735                 .items = {
1736                         { "Mic", 0x0 },
1737                         { "Line", 0x2 },
1738                         { "CD", 0x4 },
1739                         { "Input Mix", 0xa },
1740                 },
1741         }
1742 };
1743
1744 static struct snd_kcontrol_new alc888_base_mixer[] = {
1745         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1746         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1747         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1748         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1749         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
1750                 HDA_OUTPUT),
1751         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1752         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1753         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1754         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1755         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1756         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1757         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1758         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1759         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1760         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1761         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
1762         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1763         { } /* end */
1764 };
1765
1766 static void alc888_acer_aspire_4930g_setup(struct hda_codec *codec)
1767 {
1768         struct alc_spec *spec = codec->spec;
1769
1770         spec->autocfg.hp_pins[0] = 0x15;
1771         spec->autocfg.speaker_pins[0] = 0x14;
1772 }
1773
1774 static void alc888_acer_aspire_6530g_setup(struct hda_codec *codec)
1775 {
1776         struct alc_spec *spec = codec->spec;
1777
1778         spec->autocfg.hp_pins[0] = 0x15;
1779         spec->autocfg.speaker_pins[0] = 0x14;
1780         spec->autocfg.speaker_pins[1] = 0x16;
1781         spec->autocfg.speaker_pins[2] = 0x17;
1782 }
1783
1784 static void alc889_acer_aspire_8930g_setup(struct hda_codec *codec)
1785 {
1786         struct alc_spec *spec = codec->spec;
1787
1788         spec->autocfg.hp_pins[0] = 0x15;
1789         spec->autocfg.speaker_pins[0] = 0x14;
1790         spec->autocfg.speaker_pins[1] = 0x16;
1791         spec->autocfg.speaker_pins[2] = 0x1b;
1792 }
1793
1794 /*
1795  * ALC880 3-stack model
1796  *
1797  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
1798  * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
1799  *                 F-Mic = 0x1b, HP = 0x19
1800  */
1801
1802 static hda_nid_t alc880_dac_nids[4] = {
1803         /* front, rear, clfe, rear_surr */
1804         0x02, 0x05, 0x04, 0x03
1805 };
1806
1807 static hda_nid_t alc880_adc_nids[3] = {
1808         /* ADC0-2 */
1809         0x07, 0x08, 0x09,
1810 };
1811
1812 /* The datasheet says the node 0x07 is connected from inputs,
1813  * but it shows zero connection in the real implementation on some devices.
1814  * Note: this is a 915GAV bug, fixed on 915GLV
1815  */
1816 static hda_nid_t alc880_adc_nids_alt[2] = {
1817         /* ADC1-2 */
1818         0x08, 0x09,
1819 };
1820
1821 #define ALC880_DIGOUT_NID       0x06
1822 #define ALC880_DIGIN_NID        0x0a
1823
1824 static struct hda_input_mux alc880_capture_source = {
1825         .num_items = 4,
1826         .items = {
1827                 { "Mic", 0x0 },
1828                 { "Front Mic", 0x3 },
1829                 { "Line", 0x2 },
1830                 { "CD", 0x4 },
1831         },
1832 };
1833
1834 /* channel source setting (2/6 channel selection for 3-stack) */
1835 /* 2ch mode */
1836 static struct hda_verb alc880_threestack_ch2_init[] = {
1837         /* set line-in to input, mute it */
1838         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1839         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1840         /* set mic-in to input vref 80%, mute it */
1841         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1842         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1843         { } /* end */
1844 };
1845
1846 /* 6ch mode */
1847 static struct hda_verb alc880_threestack_ch6_init[] = {
1848         /* set line-in to output, unmute it */
1849         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1850         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1851         /* set mic-in to output, unmute it */
1852         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1853         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1854         { } /* end */
1855 };
1856
1857 static struct hda_channel_mode alc880_threestack_modes[2] = {
1858         { 2, alc880_threestack_ch2_init },
1859         { 6, alc880_threestack_ch6_init },
1860 };
1861
1862 static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
1863         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1864         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1865         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1866         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
1867         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1868         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1869         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1870         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1871         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1872         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1873         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1874         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1875         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1876         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1877         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
1878         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
1879         HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
1880         {
1881                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1882                 .name = "Channel Mode",
1883                 .info = alc_ch_mode_info,
1884                 .get = alc_ch_mode_get,
1885                 .put = alc_ch_mode_put,
1886         },
1887         { } /* end */
1888 };
1889
1890 /* capture mixer elements */
1891 static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1892                             struct snd_ctl_elem_info *uinfo)
1893 {
1894         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1895         struct alc_spec *spec = codec->spec;
1896         int err;
1897
1898         mutex_lock(&codec->control_mutex);
1899         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1900                                                       HDA_INPUT);
1901         err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
1902         mutex_unlock(&codec->control_mutex);
1903         return err;
1904 }
1905
1906 static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1907                            unsigned int size, unsigned int __user *tlv)
1908 {
1909         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1910         struct alc_spec *spec = codec->spec;
1911         int err;
1912
1913         mutex_lock(&codec->control_mutex);
1914         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1915                                                       HDA_INPUT);
1916         err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
1917         mutex_unlock(&codec->control_mutex);
1918         return err;
1919 }
1920
1921 typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1922                              struct snd_ctl_elem_value *ucontrol);
1923
1924 static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1925                                  struct snd_ctl_elem_value *ucontrol,
1926                                  getput_call_t func)
1927 {
1928         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1929         struct alc_spec *spec = codec->spec;
1930         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1931         int err;
1932
1933         mutex_lock(&codec->control_mutex);
1934         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[adc_idx],
1935                                                       3, 0, HDA_INPUT);
1936         err = func(kcontrol, ucontrol);
1937         mutex_unlock(&codec->control_mutex);
1938         return err;
1939 }
1940
1941 static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1942                            struct snd_ctl_elem_value *ucontrol)
1943 {
1944         return alc_cap_getput_caller(kcontrol, ucontrol,
1945                                      snd_hda_mixer_amp_volume_get);
1946 }
1947
1948 static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1949                            struct snd_ctl_elem_value *ucontrol)
1950 {
1951         return alc_cap_getput_caller(kcontrol, ucontrol,
1952                                      snd_hda_mixer_amp_volume_put);
1953 }
1954
1955 /* capture mixer elements */
1956 #define alc_cap_sw_info         snd_ctl_boolean_stereo_info
1957
1958 static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1959                           struct snd_ctl_elem_value *ucontrol)
1960 {
1961         return alc_cap_getput_caller(kcontrol, ucontrol,
1962                                      snd_hda_mixer_amp_switch_get);
1963 }
1964
1965 static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1966                           struct snd_ctl_elem_value *ucontrol)
1967 {
1968         return alc_cap_getput_caller(kcontrol, ucontrol,
1969                                      snd_hda_mixer_amp_switch_put);
1970 }
1971
1972 #define _DEFINE_CAPMIX(num) \
1973         { \
1974                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1975                 .name = "Capture Switch", \
1976                 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1977                 .count = num, \
1978                 .info = alc_cap_sw_info, \
1979                 .get = alc_cap_sw_get, \
1980                 .put = alc_cap_sw_put, \
1981         }, \
1982         { \
1983                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1984                 .name = "Capture Volume", \
1985                 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1986                            SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1987                            SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1988                 .count = num, \
1989                 .info = alc_cap_vol_info, \
1990                 .get = alc_cap_vol_get, \
1991                 .put = alc_cap_vol_put, \
1992                 .tlv = { .c = alc_cap_vol_tlv }, \
1993         }
1994
1995 #define _DEFINE_CAPSRC(num) \
1996         { \
1997                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1998                 /* .name = "Capture Source", */ \
1999                 .name = "Input Source", \
2000                 .count = num, \
2001                 .info = alc_mux_enum_info, \
2002                 .get = alc_mux_enum_get, \
2003                 .put = alc_mux_enum_put, \
2004         }
2005
2006 #define DEFINE_CAPMIX(num) \
2007 static struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
2008         _DEFINE_CAPMIX(num),                                  \
2009         _DEFINE_CAPSRC(num),                                  \
2010         { } /* end */                                         \
2011 }
2012
2013 #define DEFINE_CAPMIX_NOSRC(num) \
2014 static struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
2015         _DEFINE_CAPMIX(num),                                        \
2016         { } /* end */                                               \
2017 }
2018
2019 /* up to three ADCs */
2020 DEFINE_CAPMIX(1);
2021 DEFINE_CAPMIX(2);
2022 DEFINE_CAPMIX(3);
2023 DEFINE_CAPMIX_NOSRC(1);
2024 DEFINE_CAPMIX_NOSRC(2);
2025 DEFINE_CAPMIX_NOSRC(3);
2026
2027 /*
2028  * ALC880 5-stack model
2029  *
2030  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
2031  *      Side = 0x02 (0xd)
2032  * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
2033  *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
2034  */
2035
2036 /* additional mixers to alc880_three_stack_mixer */
2037 static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
2038         HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2039         HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
2040         { } /* end */
2041 };
2042
2043 /* channel source setting (6/8 channel selection for 5-stack) */
2044 /* 6ch mode */
2045 static struct hda_verb alc880_fivestack_ch6_init[] = {
2046         /* set line-in to input, mute it */
2047         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2048         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2049         { } /* end */
2050 };
2051
2052 /* 8ch mode */
2053 static struct hda_verb alc880_fivestack_ch8_init[] = {
2054         /* set line-in to output, unmute it */
2055         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2056         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2057         { } /* end */
2058 };
2059
2060 static struct hda_channel_mode alc880_fivestack_modes[2] = {
2061         { 6, alc880_fivestack_ch6_init },
2062         { 8, alc880_fivestack_ch8_init },
2063 };
2064
2065
2066 /*
2067  * ALC880 6-stack model
2068  *
2069  * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
2070  *      Side = 0x05 (0x0f)
2071  * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
2072  *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
2073  */
2074
2075 static hda_nid_t alc880_6st_dac_nids[4] = {
2076         /* front, rear, clfe, rear_surr */
2077         0x02, 0x03, 0x04, 0x05
2078 };
2079
2080 static struct hda_input_mux alc880_6stack_capture_source = {
2081         .num_items = 4,
2082         .items = {
2083                 { "Mic", 0x0 },
2084                 { "Front Mic", 0x1 },
2085                 { "Line", 0x2 },
2086                 { "CD", 0x4 },
2087         },
2088 };
2089
2090 /* fixed 8-channels */
2091 static struct hda_channel_mode alc880_sixstack_modes[1] = {
2092         { 8, NULL },
2093 };
2094
2095 static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
2096         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2097         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2098         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2099         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2100         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2101         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2102         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2103         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2104         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2105         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
2106         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2107         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2108         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2109         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2110         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2111         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2112         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2113         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2114         {
2115                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2116                 .name = "Channel Mode",
2117                 .info = alc_ch_mode_info,
2118                 .get = alc_ch_mode_get,
2119                 .put = alc_ch_mode_put,
2120         },
2121         { } /* end */
2122 };
2123
2124
2125 /*
2126  * ALC880 W810 model
2127  *
2128  * W810 has rear IO for:
2129  * Front (DAC 02)
2130  * Surround (DAC 03)
2131  * Center/LFE (DAC 04)
2132  * Digital out (06)
2133  *
2134  * The system also has a pair of internal speakers, and a headphone jack.
2135  * These are both connected to Line2 on the codec, hence to DAC 02.
2136  *
2137  * There is a variable resistor to control the speaker or headphone
2138  * volume. This is a hardware-only device without a software API.
2139  *
2140  * Plugging headphones in will disable the internal speakers. This is
2141  * implemented in hardware, not via the driver using jack sense. In
2142  * a similar fashion, plugging into the rear socket marked "front" will
2143  * disable both the speakers and headphones.
2144  *
2145  * For input, there's a microphone jack, and an "audio in" jack.
2146  * These may not do anything useful with this driver yet, because I
2147  * haven't setup any initialization verbs for these yet...
2148  */
2149
2150 static hda_nid_t alc880_w810_dac_nids[3] = {
2151         /* front, rear/surround, clfe */
2152         0x02, 0x03, 0x04
2153 };
2154
2155 /* fixed 6 channels */
2156 static struct hda_channel_mode alc880_w810_modes[1] = {
2157         { 6, NULL }
2158 };
2159
2160 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
2161 static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
2162         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2163         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2164         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2165         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2166         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2167         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2168         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2169         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2170         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
2171         { } /* end */
2172 };
2173
2174
2175 /*
2176  * Z710V model
2177  *
2178  * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
2179  * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
2180  *                 Line = 0x1a
2181  */
2182
2183 static hda_nid_t alc880_z71v_dac_nids[1] = {
2184         0x02
2185 };
2186 #define ALC880_Z71V_HP_DAC      0x03
2187
2188 /* fixed 2 channels */
2189 static struct hda_channel_mode alc880_2_jack_modes[1] = {
2190         { 2, NULL }
2191 };
2192
2193 static struct snd_kcontrol_new alc880_z71v_mixer[] = {
2194         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2195         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2196         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2197         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
2198         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2199         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2200         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2201         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2202         { } /* end */
2203 };
2204
2205
2206 /*
2207  * ALC880 F1734 model
2208  *
2209  * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
2210  * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
2211  */
2212
2213 static hda_nid_t alc880_f1734_dac_nids[1] = {
2214         0x03
2215 };
2216 #define ALC880_F1734_HP_DAC     0x02
2217
2218 static struct snd_kcontrol_new alc880_f1734_mixer[] = {
2219         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2220         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2221         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2222         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2223         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2224         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2225         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2226         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2227         { } /* end */
2228 };
2229
2230 static struct hda_input_mux alc880_f1734_capture_source = {
2231         .num_items = 2,
2232         .items = {
2233                 { "Mic", 0x1 },
2234                 { "CD", 0x4 },
2235         },
2236 };
2237
2238
2239 /*
2240  * ALC880 ASUS model
2241  *
2242  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
2243  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
2244  *  Mic = 0x18, Line = 0x1a
2245  */
2246
2247 #define alc880_asus_dac_nids    alc880_w810_dac_nids    /* identical with w810 */
2248 #define alc880_asus_modes       alc880_threestack_modes /* 2/6 channel mode */
2249
2250 static struct snd_kcontrol_new alc880_asus_mixer[] = {
2251         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2252         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2253         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2254         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2255         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2256         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2257         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2258         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2259         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2260         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2261         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2262         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2263         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2264         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2265         {
2266                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2267                 .name = "Channel Mode",
2268                 .info = alc_ch_mode_info,
2269                 .get = alc_ch_mode_get,
2270                 .put = alc_ch_mode_put,
2271         },
2272         { } /* end */
2273 };
2274
2275 /*
2276  * ALC880 ASUS W1V model
2277  *
2278  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
2279  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
2280  *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
2281  */
2282
2283 /* additional mixers to alc880_asus_mixer */
2284 static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
2285         HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
2286         HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
2287         { } /* end */
2288 };
2289
2290 /* TCL S700 */
2291 static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
2292         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2293         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
2294         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
2295         HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
2296         HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
2297         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
2298         HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
2299         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
2300         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
2301         { } /* end */
2302 };
2303
2304 /* Uniwill */
2305 static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
2306         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2307         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2308         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2309         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2310         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2311         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2312         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2313         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2314         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2315         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2316         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2317         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2318         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2319         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2320         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2321         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2322         {
2323                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2324                 .name = "Channel Mode",
2325                 .info = alc_ch_mode_info,
2326                 .get = alc_ch_mode_get,
2327                 .put = alc_ch_mode_put,
2328         },
2329         { } /* end */
2330 };
2331
2332 static struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
2333         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2334         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2335         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2336         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2337         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2338         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2339         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2340         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2341         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2342         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2343         { } /* end */
2344 };
2345
2346 static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
2347         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2348         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2349         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2350         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2351         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2352         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2353         { } /* end */
2354 };
2355
2356 /*
2357  * virtual master controls
2358  */
2359
2360 /*
2361  * slave controls for virtual master
2362  */
2363 static const char *alc_slave_vols[] = {
2364         "Front Playback Volume",
2365         "Surround Playback Volume",
2366         "Center Playback Volume",
2367         "LFE Playback Volume",
2368         "Side Playback Volume",
2369         "Headphone Playback Volume",
2370         "Speaker Playback Volume",
2371         "Mono Playback Volume",
2372         "Line-Out Playback Volume",
2373         "PCM Playback Volume",
2374         NULL,
2375 };
2376
2377 static const char *alc_slave_sws[] = {
2378         "Front Playback Switch",
2379         "Surround Playback Switch",
2380         "Center Playback Switch",
2381         "LFE Playback Switch",
2382         "Side Playback Switch",
2383         "Headphone Playback Switch",
2384         "Speaker Playback Switch",
2385         "Mono Playback Switch",
2386         "IEC958 Playback Switch",
2387         NULL,
2388 };
2389
2390 /*
2391  * build control elements
2392  */
2393
2394 static void alc_free_kctls(struct hda_codec *codec);
2395
2396 /* additional beep mixers; the actual parameters are overwritten at build */
2397 static struct snd_kcontrol_new alc_beep_mixer[] = {
2398         HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
2399         HDA_CODEC_MUTE("Beep Playback Switch", 0, 0, HDA_INPUT),
2400         { } /* end */
2401 };
2402
2403 static int alc_build_controls(struct hda_codec *codec)
2404 {
2405         struct alc_spec *spec = codec->spec;
2406         int err;
2407         int i;
2408
2409         for (i = 0; i < spec->num_mixers; i++) {
2410                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
2411                 if (err < 0)
2412                         return err;
2413         }
2414         if (spec->cap_mixer) {
2415                 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
2416                 if (err < 0)
2417                         return err;
2418         }
2419         if (spec->multiout.dig_out_nid) {
2420                 err = snd_hda_create_spdif_out_ctls(codec,
2421                                                     spec->multiout.dig_out_nid);
2422                 if (err < 0)
2423                         return err;
2424                 if (!spec->no_analog) {
2425                         err = snd_hda_create_spdif_share_sw(codec,
2426                                                             &spec->multiout);
2427                         if (err < 0)
2428                                 return err;
2429                         spec->multiout.share_spdif = 1;
2430                 }
2431         }
2432         if (spec->dig_in_nid) {
2433                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
2434                 if (err < 0)
2435                         return err;
2436         }
2437
2438         /* create beep controls if needed */
2439         if (spec->beep_amp) {
2440                 struct snd_kcontrol_new *knew;
2441                 for (knew = alc_beep_mixer; knew->name; knew++) {
2442                         struct snd_kcontrol *kctl;
2443                         kctl = snd_ctl_new1(knew, codec);
2444                         if (!kctl)
2445                                 return -ENOMEM;
2446                         kctl->private_value = spec->beep_amp;
2447                         err = snd_hda_ctl_add(codec, kctl);
2448                         if (err < 0)
2449                                 return err;
2450                 }
2451         }
2452
2453         /* if we have no master control, let's create it */
2454         if (!spec->no_analog &&
2455             !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
2456                 unsigned int vmaster_tlv[4];
2457                 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
2458                                         HDA_OUTPUT, vmaster_tlv);
2459                 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
2460                                           vmaster_tlv, alc_slave_vols);
2461                 if (err < 0)
2462                         return err;
2463         }
2464         if (!spec->no_analog &&
2465             !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
2466                 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
2467                                           NULL, alc_slave_sws);
2468                 if (err < 0)
2469                         return err;
2470         }
2471
2472         alc_free_kctls(codec); /* no longer needed */
2473         return 0;
2474 }
2475
2476
2477 /*
2478  * initialize the codec volumes, etc
2479  */
2480
2481 /*
2482  * generic initialization of ADC, input mixers and output mixers
2483  */
2484 static struct hda_verb alc880_volume_init_verbs[] = {
2485         /*
2486          * Unmute ADC0-2 and set the default input to mic-in
2487          */
2488         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
2489         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2490         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
2491         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2492         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
2493         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2494
2495         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2496          * mixer widget
2497          * Note: PASD motherboards uses the Line In 2 as the input for front
2498          * panel mic (mic 2)
2499          */
2500         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
2501         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2502         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2503         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2504         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2505         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2506         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2507         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2508
2509         /*
2510          * Set up output mixers (0x0c - 0x0f)
2511          */
2512         /* set vol=0 to output mixers */
2513         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2514         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2515         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2516         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2517         /* set up input amps for analog loopback */
2518         /* Amp Indices: DAC = 0, mixer = 1 */
2519         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2520         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2521         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2522         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2523         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2524         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2525         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2526         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2527
2528         { }
2529 };
2530
2531 /*
2532  * 3-stack pin configuration:
2533  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
2534  */
2535 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
2536         /*
2537          * preset connection lists of input pins
2538          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2539          */
2540         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2541         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2542         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2543
2544         /*
2545          * Set pin mode and muting
2546          */
2547         /* set front pin widgets 0x14 for output */
2548         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2549         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2550         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2551         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2552         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2553         /* Mic2 (as headphone out) for HP output */
2554         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2555         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2556         /* Line In pin widget for input */
2557         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2558         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2559         /* Line2 (as front mic) pin widget for input and vref at 80% */
2560         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2561         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2562         /* CD pin widget for input */
2563         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2564
2565         { }
2566 };
2567
2568 /*
2569  * 5-stack pin configuration:
2570  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
2571  * line-in/side = 0x1a, f-mic = 0x1b
2572  */
2573 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
2574         /*
2575          * preset connection lists of input pins
2576          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2577          */
2578         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2579         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
2580
2581         /*
2582          * Set pin mode and muting
2583          */
2584         /* set pin widgets 0x14-0x17 for output */
2585         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2586         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2587         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2588         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2589         /* unmute pins for output (no gain on this amp) */
2590         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2591         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2592         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2593         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2594
2595         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2596         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2597         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2598         /* Mic2 (as headphone out) for HP output */
2599         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2600         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2601         /* Line In pin widget for input */
2602         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2603         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2604         /* Line2 (as front mic) pin widget for input and vref at 80% */
2605         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2606         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2607         /* CD pin widget for input */
2608         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2609
2610         { }
2611 };
2612
2613 /*
2614  * W810 pin configuration:
2615  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
2616  */
2617 static struct hda_verb alc880_pin_w810_init_verbs[] = {
2618         /* hphone/speaker input selector: front DAC */
2619         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
2620
2621         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2622         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2623         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2624         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2625         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2626         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2627
2628         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2629         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2630
2631         { }
2632 };
2633
2634 /*
2635  * Z71V pin configuration:
2636  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
2637  */
2638 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
2639         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2640         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2641         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2642         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2643
2644         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2645         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2646         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2647         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2648
2649         { }
2650 };
2651
2652 /*
2653  * 6-stack pin configuration:
2654  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
2655  * f-mic = 0x19, line = 0x1a, HP = 0x1b
2656  */
2657 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
2658         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2659
2660         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2661         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2662         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2663         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2664         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2665         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2666         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2667         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2668
2669         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2670         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2671         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2672         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2673         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2674         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2675         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2676         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2677         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2678
2679         { }
2680 };
2681
2682 /*
2683  * Uniwill pin configuration:
2684  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
2685  * line = 0x1a
2686  */
2687 static struct hda_verb alc880_uniwill_init_verbs[] = {
2688         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2689
2690         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2691         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2692         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2693         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2694         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2695         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2696         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2697         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2698         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2699         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2700         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2701         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2702         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2703         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2704
2705         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2706         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2707         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2708         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2709         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2710         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2711         /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
2712         /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
2713         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2714
2715         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2716         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
2717
2718         { }
2719 };
2720
2721 /*
2722 * Uniwill P53
2723 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19,
2724  */
2725 static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
2726         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2727
2728         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2729         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2730         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2731         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2732         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2733         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2734         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2735         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2736         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2737         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2738         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2739         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2740
2741         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2742         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2743         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2744         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2745         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2746         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2747
2748         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2749         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
2750
2751         { }
2752 };
2753
2754 static struct hda_verb alc880_beep_init_verbs[] = {
2755         { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
2756         { }
2757 };
2758
2759 /* auto-toggle front mic */
2760 static void alc880_uniwill_mic_automute(struct hda_codec *codec)
2761 {
2762         unsigned int present;
2763         unsigned char bits;
2764
2765         present = snd_hda_codec_read(codec, 0x18, 0,
2766                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2767         bits = present ? HDA_AMP_MUTE : 0;
2768         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
2769 }
2770
2771 static void alc880_uniwill_setup(struct hda_codec *codec)
2772 {
2773         struct alc_spec *spec = codec->spec;
2774
2775         spec->autocfg.hp_pins[0] = 0x14;
2776         spec->autocfg.speaker_pins[0] = 0x15;
2777         spec->autocfg.speaker_pins[0] = 0x16;
2778 }
2779
2780 static void alc880_uniwill_init_hook(struct hda_codec *codec)
2781 {
2782         alc_automute_amp(codec);
2783         alc880_uniwill_mic_automute(codec);
2784 }
2785
2786 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
2787                                        unsigned int res)
2788 {
2789         /* Looks like the unsol event is incompatible with the standard
2790          * definition.  4bit tag is placed at 28 bit!
2791          */
2792         switch (res >> 28) {
2793         case ALC880_MIC_EVENT:
2794                 alc880_uniwill_mic_automute(codec);
2795                 break;
2796         default:
2797                 alc_automute_amp_unsol_event(codec, res);
2798                 break;
2799         }
2800 }
2801
2802 static void alc880_uniwill_p53_setup(struct hda_codec *codec)
2803 {
2804         struct alc_spec *spec = codec->spec;
2805
2806         spec->autocfg.hp_pins[0] = 0x14;
2807         spec->autocfg.speaker_pins[0] = 0x15;
2808 }
2809
2810 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
2811 {
2812         unsigned int present;
2813
2814         present = snd_hda_codec_read(codec, 0x21, 0,
2815                                      AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
2816         present &= HDA_AMP_VOLMASK;
2817         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
2818                                  HDA_AMP_VOLMASK, present);
2819         snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
2820                                  HDA_AMP_VOLMASK, present);
2821 }
2822
2823 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
2824                                            unsigned int res)
2825 {
2826         /* Looks like the unsol event is incompatible with the standard
2827          * definition.  4bit tag is placed at 28 bit!
2828          */
2829         if ((res >> 28) == ALC880_DCVOL_EVENT)
2830                 alc880_uniwill_p53_dcvol_automute(codec);
2831         else
2832                 alc_automute_amp_unsol_event(codec, res);
2833 }
2834
2835 /*
2836  * F1734 pin configuration:
2837  * HP = 0x14, speaker-out = 0x15, mic = 0x18
2838  */
2839 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
2840         {0x07, AC_VERB_SET_CONNECT_SEL, 0x01},
2841         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2842         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2843         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2844         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2845
2846         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2847         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2848         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2849         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2850
2851         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2852         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2853         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
2854         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2855         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2856         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2857         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2858         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2859         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2860
2861         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
2862         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_DCVOL_EVENT},
2863
2864         { }
2865 };
2866
2867 /*
2868  * ASUS pin configuration:
2869  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
2870  */
2871 static struct hda_verb alc880_pin_asus_init_verbs[] = {
2872         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2873         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2874         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2875         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2876
2877         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2878         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2879         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2880         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2881         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2882         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2883         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2884         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2885
2886         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2887         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2888         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2889         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2890         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2891         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2892         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2893         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2894         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2895
2896         { }
2897 };
2898
2899 /* Enable GPIO mask and set output */
2900 #define alc880_gpio1_init_verbs alc_gpio1_init_verbs
2901 #define alc880_gpio2_init_verbs alc_gpio2_init_verbs
2902 #define alc880_gpio3_init_verbs alc_gpio3_init_verbs
2903
2904 /* Clevo m520g init */
2905 static struct hda_verb alc880_pin_clevo_init_verbs[] = {
2906         /* headphone output */
2907         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2908         /* line-out */
2909         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2910         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2911         /* Line-in */
2912         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2913         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2914         /* CD */
2915         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2916         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2917         /* Mic1 (rear panel) */
2918         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2919         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2920         /* Mic2 (front panel) */
2921         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2922         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2923         /* headphone */
2924         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2925         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2926         /* change to EAPD mode */
2927         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2928         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2929
2930         { }
2931 };
2932
2933 static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
2934         /* change to EAPD mode */
2935         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2936         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2937
2938         /* Headphone output */
2939         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2940         /* Front output*/
2941         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2942         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
2943
2944         /* Line In pin widget for input */
2945         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2946         /* CD pin widget for input */
2947         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2948         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2949         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2950
2951         /* change to EAPD mode */
2952         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2953         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
2954
2955         { }
2956 };
2957
2958 /*
2959  * LG m1 express dual
2960  *
2961  * Pin assignment:
2962  *   Rear Line-In/Out (blue): 0x14
2963  *   Build-in Mic-In: 0x15
2964  *   Speaker-out: 0x17
2965  *   HP-Out (green): 0x1b
2966  *   Mic-In/Out (red): 0x19
2967  *   SPDIF-Out: 0x1e
2968  */
2969
2970 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
2971 static hda_nid_t alc880_lg_dac_nids[3] = {
2972         0x05, 0x02, 0x03
2973 };
2974
2975 /* seems analog CD is not working */
2976 static struct hda_input_mux alc880_lg_capture_source = {
2977         .num_items = 3,
2978         .items = {
2979                 { "Mic", 0x1 },
2980                 { "Line", 0x5 },
2981                 { "Internal Mic", 0x6 },
2982         },
2983 };
2984
2985 /* 2,4,6 channel modes */
2986 static struct hda_verb alc880_lg_ch2_init[] = {
2987         /* set line-in and mic-in to input */
2988         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2989         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2990         { }
2991 };
2992
2993 static struct hda_verb alc880_lg_ch4_init[] = {
2994         /* set line-in to out and mic-in to input */
2995         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2996         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2997         { }
2998 };
2999
3000 static struct hda_verb alc880_lg_ch6_init[] = {
3001         /* set line-in and mic-in to output */
3002         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
3003         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
3004         { }
3005 };
3006
3007 static struct hda_channel_mode alc880_lg_ch_modes[3] = {
3008         { 2, alc880_lg_ch2_init },
3009         { 4, alc880_lg_ch4_init },
3010         { 6, alc880_lg_ch6_init },
3011 };
3012
3013 static struct snd_kcontrol_new alc880_lg_mixer[] = {
3014         HDA_CODEC_VOLUME("Front Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3015         HDA_BIND_MUTE("Front Playback Switch", 0x0f, 2, HDA_INPUT),
3016         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3017         HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
3018         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
3019         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
3020         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
3021         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
3022         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
3023         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
3024         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
3025         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
3026         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
3027         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
3028         {
3029                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3030                 .name = "Channel Mode",
3031                 .info = alc_ch_mode_info,
3032                 .get = alc_ch_mode_get,
3033                 .put = alc_ch_mode_put,
3034         },
3035         { } /* end */
3036 };
3037
3038 static struct hda_verb alc880_lg_init_verbs[] = {
3039         /* set capture source to mic-in */
3040         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3041         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3042         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3043         /* mute all amp mixer inputs */
3044         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
3045         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
3046         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
3047         /* line-in to input */
3048         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3049         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3050         /* built-in mic */
3051         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3052         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3053         /* speaker-out */
3054         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3055         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3056         /* mic-in to input */
3057         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
3058         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3059         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3060         /* HP-out */
3061         {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
3062         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3063         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3064         /* jack sense */
3065         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3066         { }
3067 };
3068
3069 /* toggle speaker-output according to the hp-jack state */
3070 static void alc880_lg_setup(struct hda_codec *codec)
3071 {
3072         struct alc_spec *spec = codec->spec;
3073
3074         spec->autocfg.hp_pins[0] = 0x1b;
3075         spec->autocfg.speaker_pins[0] = 0x17;
3076 }
3077
3078 /*
3079  * LG LW20
3080  *
3081  * Pin assignment:
3082  *   Speaker-out: 0x14
3083  *   Mic-In: 0x18
3084  *   Built-in Mic-In: 0x19
3085  *   Line-In: 0x1b
3086  *   HP-Out: 0x1a
3087  *   SPDIF-Out: 0x1e
3088  */
3089
3090 static struct hda_input_mux alc880_lg_lw_capture_source = {
3091         .num_items = 3,
3092         .items = {
3093                 { "Mic", 0x0 },
3094                 { "Internal Mic", 0x1 },
3095                 { "Line In", 0x2 },
3096         },
3097 };
3098
3099 #define alc880_lg_lw_modes alc880_threestack_modes
3100
3101 static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
3102         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3103         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
3104         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3105         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
3106         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
3107         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
3108         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
3109         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
3110         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
3111         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
3112         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
3113         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
3114         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
3115         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
3116         {
3117                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3118                 .name = "Channel Mode",
3119                 .info = alc_ch_mode_info,
3120                 .get = alc_ch_mode_get,
3121                 .put = alc_ch_mode_put,
3122         },
3123         { } /* end */
3124 };
3125
3126 static struct hda_verb alc880_lg_lw_init_verbs[] = {
3127         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3128         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
3129         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
3130
3131         /* set capture source to mic-in */
3132         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3133         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3134         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3135         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
3136         /* speaker-out */
3137         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3138         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3139         /* HP-out */
3140         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3141         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3142         /* mic-in to input */
3143         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3144         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},