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