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