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