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