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