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