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