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