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