Merge branch 'for-linus2' of git://git.profusion.mobi/users/lucas/linux-2.6
[linux-2.6.git] / sound / pci / hda / patch_realtek.c
1 /*
2  * Universal Interface for Intel High Definition Audio Codec
3  *
4  * HD audio interface patch for ALC 260/880/882 codecs
5  *
6  * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7  *                    PeiSen Hou <pshou@realtek.com.tw>
8  *                    Takashi Iwai <tiwai@suse.de>
9  *                    Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
10  *
11  *  This driver is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This driver is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
24  */
25
26 #include <linux/init.h>
27 #include <linux/delay.h>
28 #include <linux/slab.h>
29 #include <linux/pci.h>
30 #include <sound/core.h>
31 #include <sound/jack.h>
32 #include "hda_codec.h"
33 #include "hda_local.h"
34 #include "hda_beep.h"
35
36 #define ALC880_FRONT_EVENT              0x01
37 #define ALC880_DCVOL_EVENT              0x02
38 #define ALC880_HP_EVENT                 0x04
39 #define ALC880_MIC_EVENT                0x08
40
41 /* ALC880 board config type */
42 enum {
43         ALC880_3ST,
44         ALC880_3ST_DIG,
45         ALC880_5ST,
46         ALC880_5ST_DIG,
47         ALC880_W810,
48         ALC880_Z71V,
49         ALC880_6ST,
50         ALC880_6ST_DIG,
51         ALC880_F1734,
52         ALC880_ASUS,
53         ALC880_ASUS_DIG,
54         ALC880_ASUS_W1V,
55         ALC880_ASUS_DIG2,
56         ALC880_FUJITSU,
57         ALC880_UNIWILL_DIG,
58         ALC880_UNIWILL,
59         ALC880_UNIWILL_P53,
60         ALC880_CLEVO,
61         ALC880_TCL_S700,
62         ALC880_LG,
63         ALC880_LG_LW,
64         ALC880_MEDION_RIM,
65 #ifdef CONFIG_SND_DEBUG
66         ALC880_TEST,
67 #endif
68         ALC880_AUTO,
69         ALC880_MODEL_LAST /* last tag */
70 };
71
72 /* ALC260 models */
73 enum {
74         ALC260_BASIC,
75         ALC260_HP,
76         ALC260_HP_DC7600,
77         ALC260_HP_3013,
78         ALC260_FUJITSU_S702X,
79         ALC260_ACER,
80         ALC260_WILL,
81         ALC260_REPLACER_672V,
82         ALC260_FAVORIT100,
83 #ifdef CONFIG_SND_DEBUG
84         ALC260_TEST,
85 #endif
86         ALC260_AUTO,
87         ALC260_MODEL_LAST /* last tag */
88 };
89
90 /* ALC262 models */
91 enum {
92         ALC262_BASIC,
93         ALC262_HIPPO,
94         ALC262_HIPPO_1,
95         ALC262_FUJITSU,
96         ALC262_HP_BPC,
97         ALC262_HP_BPC_D7000_WL,
98         ALC262_HP_BPC_D7000_WF,
99         ALC262_HP_TC_T5735,
100         ALC262_HP_RP5700,
101         ALC262_BENQ_ED8,
102         ALC262_SONY_ASSAMD,
103         ALC262_BENQ_T31,
104         ALC262_ULTRA,
105         ALC262_LENOVO_3000,
106         ALC262_NEC,
107         ALC262_TOSHIBA_S06,
108         ALC262_TOSHIBA_RX1,
109         ALC262_TYAN,
110         ALC262_AUTO,
111         ALC262_MODEL_LAST /* last tag */
112 };
113
114 /* ALC268 models */
115 enum {
116         ALC267_QUANTA_IL1,
117         ALC268_3ST,
118         ALC268_TOSHIBA,
119         ALC268_ACER,
120         ALC268_ACER_DMIC,
121         ALC268_ACER_ASPIRE_ONE,
122         ALC268_DELL,
123         ALC268_ZEPTO,
124 #ifdef CONFIG_SND_DEBUG
125         ALC268_TEST,
126 #endif
127         ALC268_AUTO,
128         ALC268_MODEL_LAST /* last tag */
129 };
130
131 /* ALC269 models */
132 enum {
133         ALC269_BASIC,
134         ALC269_QUANTA_FL1,
135         ALC269_AMIC,
136         ALC269_DMIC,
137         ALC269VB_AMIC,
138         ALC269VB_DMIC,
139         ALC269_FUJITSU,
140         ALC269_LIFEBOOK,
141         ALC271_ACER,
142         ALC269_AUTO,
143         ALC269_MODEL_LAST /* last tag */
144 };
145
146 /* ALC861 models */
147 enum {
148         ALC861_3ST,
149         ALC660_3ST,
150         ALC861_3ST_DIG,
151         ALC861_6ST_DIG,
152         ALC861_UNIWILL_M31,
153         ALC861_TOSHIBA,
154         ALC861_ASUS,
155         ALC861_ASUS_LAPTOP,
156         ALC861_AUTO,
157         ALC861_MODEL_LAST,
158 };
159
160 /* ALC861-VD models */
161 enum {
162         ALC660VD_3ST,
163         ALC660VD_3ST_DIG,
164         ALC660VD_ASUS_V1S,
165         ALC861VD_3ST,
166         ALC861VD_3ST_DIG,
167         ALC861VD_6ST_DIG,
168         ALC861VD_LENOVO,
169         ALC861VD_DALLAS,
170         ALC861VD_HP,
171         ALC861VD_AUTO,
172         ALC861VD_MODEL_LAST,
173 };
174
175 /* ALC662 models */
176 enum {
177         ALC662_3ST_2ch_DIG,
178         ALC662_3ST_6ch_DIG,
179         ALC662_3ST_6ch,
180         ALC662_5ST_DIG,
181         ALC662_LENOVO_101E,
182         ALC662_ASUS_EEEPC_P701,
183         ALC662_ASUS_EEEPC_EP20,
184         ALC663_ASUS_M51VA,
185         ALC663_ASUS_G71V,
186         ALC663_ASUS_H13,
187         ALC663_ASUS_G50V,
188         ALC662_ECS,
189         ALC663_ASUS_MODE1,
190         ALC662_ASUS_MODE2,
191         ALC663_ASUS_MODE3,
192         ALC663_ASUS_MODE4,
193         ALC663_ASUS_MODE5,
194         ALC663_ASUS_MODE6,
195         ALC663_ASUS_MODE7,
196         ALC663_ASUS_MODE8,
197         ALC272_DELL,
198         ALC272_DELL_ZM1,
199         ALC272_SAMSUNG_NC10,
200         ALC662_AUTO,
201         ALC662_MODEL_LAST,
202 };
203
204 /* ALC882 models */
205 enum {
206         ALC882_3ST_DIG,
207         ALC882_6ST_DIG,
208         ALC882_ARIMA,
209         ALC882_W2JC,
210         ALC882_TARGA,
211         ALC882_ASUS_A7J,
212         ALC882_ASUS_A7M,
213         ALC885_MACPRO,
214         ALC885_MBA21,
215         ALC885_MBP3,
216         ALC885_MB5,
217         ALC885_MACMINI3,
218         ALC885_IMAC24,
219         ALC885_IMAC91,
220         ALC883_3ST_2ch_DIG,
221         ALC883_3ST_6ch_DIG,
222         ALC883_3ST_6ch,
223         ALC883_6ST_DIG,
224         ALC883_TARGA_DIG,
225         ALC883_TARGA_2ch_DIG,
226         ALC883_TARGA_8ch_DIG,
227         ALC883_ACER,
228         ALC883_ACER_ASPIRE,
229         ALC888_ACER_ASPIRE_4930G,
230         ALC888_ACER_ASPIRE_6530G,
231         ALC888_ACER_ASPIRE_8930G,
232         ALC888_ACER_ASPIRE_7730G,
233         ALC883_MEDION,
234         ALC883_MEDION_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         unsigned int  fixup:1; /* Means that this sku is set by driver, not read from hw */
298 };
299
300 struct alc_fixup;
301
302 struct alc_spec {
303         /* codec parameterization */
304         struct snd_kcontrol_new *mixers[5];     /* mixer arrays */
305         unsigned int num_mixers;
306         struct snd_kcontrol_new *cap_mixer;     /* capture mixer */
307         unsigned int beep_amp;  /* beep amp value, set via set_beep_amp() */
308
309         const struct hda_verb *init_verbs[10];  /* initialization verbs
310                                                  * don't forget NULL
311                                                  * termination!
312                                                  */
313         unsigned int num_init_verbs;
314
315         char stream_name_analog[32];    /* analog PCM stream */
316         struct hda_pcm_stream *stream_analog_playback;
317         struct hda_pcm_stream *stream_analog_capture;
318         struct hda_pcm_stream *stream_analog_alt_playback;
319         struct hda_pcm_stream *stream_analog_alt_capture;
320
321         char stream_name_digital[32];   /* digital PCM stream */
322         struct hda_pcm_stream *stream_digital_playback;
323         struct hda_pcm_stream *stream_digital_capture;
324
325         /* playback */
326         struct hda_multi_out multiout;  /* playback set-up
327                                          * max_channels, dacs must be set
328                                          * dig_out_nid and hp_nid are optional
329                                          */
330         hda_nid_t alt_dac_nid;
331         hda_nid_t slave_dig_outs[3];    /* optional - for auto-parsing */
332         int dig_out_type;
333
334         /* capture */
335         unsigned int num_adc_nids;
336         hda_nid_t *adc_nids;
337         hda_nid_t *capsrc_nids;
338         hda_nid_t dig_in_nid;           /* digital-in NID; optional */
339
340         /* capture setup for dynamic dual-adc switch */
341         unsigned int cur_adc_idx;
342         hda_nid_t cur_adc;
343         unsigned int cur_adc_stream_tag;
344         unsigned int cur_adc_format;
345
346         /* capture source */
347         unsigned int num_mux_defs;
348         const struct hda_input_mux *input_mux;
349         unsigned int cur_mux[3];
350         struct alc_mic_route ext_mic;
351         struct alc_mic_route int_mic;
352
353         /* channel model */
354         const struct hda_channel_mode *channel_mode;
355         int num_channel_mode;
356         int need_dac_fix;
357         int const_channel_count;
358         int ext_channel_count;
359
360         /* PCM information */
361         struct hda_pcm pcm_rec[3];      /* used in alc_build_pcms() */
362
363         /* dynamic controls, init_verbs and input_mux */
364         struct auto_pin_cfg autocfg;
365         struct alc_customize_define cdefine;
366         struct snd_array kctls;
367         struct hda_input_mux private_imux[3];
368         hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
369         hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
370         hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
371
372         /* hooks */
373         void (*init_hook)(struct hda_codec *codec);
374         void (*unsol_event)(struct hda_codec *codec, unsigned int res);
375 #ifdef CONFIG_SND_HDA_POWER_SAVE
376         void (*power_hook)(struct hda_codec *codec);
377 #endif
378
379         /* for pin sensing */
380         unsigned int sense_updated: 1;
381         unsigned int jack_present: 1;
382         unsigned int master_sw: 1;
383         unsigned int auto_mic:1;
384
385         /* other flags */
386         unsigned int no_analog :1; /* digital I/O only */
387         unsigned int dual_adc_switch:1; /* switch ADCs (for ALC275) */
388         unsigned int single_input_src:1;
389         int init_amp;
390         int codec_variant;      /* flag for other variants */
391
392         /* for virtual master */
393         hda_nid_t vmaster_nid;
394 #ifdef CONFIG_SND_HDA_POWER_SAVE
395         struct hda_loopback_check loopback;
396 #endif
397
398         /* for PLL fix */
399         hda_nid_t pll_nid;
400         unsigned int pll_coef_idx, pll_coef_bit;
401
402         /* fix-up list */
403         int fixup_id;
404         const struct alc_fixup *fixup_list;
405         const char *fixup_name;
406 };
407
408 /*
409  * configuration template - to be copied to the spec instance
410  */
411 struct alc_config_preset {
412         struct snd_kcontrol_new *mixers[5]; /* should be identical size
413                                              * with spec
414                                              */
415         struct snd_kcontrol_new *cap_mixer; /* capture mixer */
416         const struct hda_verb *init_verbs[5];
417         unsigned int num_dacs;
418         hda_nid_t *dac_nids;
419         hda_nid_t dig_out_nid;          /* optional */
420         hda_nid_t hp_nid;               /* optional */
421         hda_nid_t *slave_dig_outs;
422         unsigned int num_adc_nids;
423         hda_nid_t *adc_nids;
424         hda_nid_t *capsrc_nids;
425         hda_nid_t dig_in_nid;
426         unsigned int num_channel_mode;
427         const struct hda_channel_mode *channel_mode;
428         int need_dac_fix;
429         int const_channel_count;
430         unsigned int num_mux_defs;
431         const struct hda_input_mux *input_mux;
432         void (*unsol_event)(struct hda_codec *, unsigned int);
433         void (*setup)(struct hda_codec *);
434         void (*init_hook)(struct hda_codec *);
435 #ifdef CONFIG_SND_HDA_POWER_SAVE
436         struct hda_amp_list *loopbacks;
437         void (*power_hook)(struct hda_codec *codec);
438 #endif
439 };
440
441
442 /*
443  * input MUX handling
444  */
445 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
446                              struct snd_ctl_elem_info *uinfo)
447 {
448         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
449         struct alc_spec *spec = codec->spec;
450         unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
451         if (mux_idx >= spec->num_mux_defs)
452                 mux_idx = 0;
453         if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
454                 mux_idx = 0;
455         return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
456 }
457
458 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
459                             struct snd_ctl_elem_value *ucontrol)
460 {
461         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
462         struct alc_spec *spec = codec->spec;
463         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
464
465         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
466         return 0;
467 }
468
469 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
470                             struct snd_ctl_elem_value *ucontrol)
471 {
472         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
473         struct alc_spec *spec = codec->spec;
474         const struct hda_input_mux *imux;
475         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
476         unsigned int mux_idx;
477         hda_nid_t nid = spec->capsrc_nids ?
478                 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
479         unsigned int type;
480
481         mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
482         imux = &spec->input_mux[mux_idx];
483         if (!imux->num_items && mux_idx > 0)
484                 imux = &spec->input_mux[0];
485
486         type = get_wcaps_type(get_wcaps(codec, nid));
487         if (type == AC_WID_AUD_MIX) {
488                 /* Matrix-mixer style (e.g. ALC882) */
489                 unsigned int *cur_val = &spec->cur_mux[adc_idx];
490                 unsigned int i, idx;
491
492                 idx = ucontrol->value.enumerated.item[0];
493                 if (idx >= imux->num_items)
494                         idx = imux->num_items - 1;
495                 if (*cur_val == idx)
496                         return 0;
497                 for (i = 0; i < imux->num_items; i++) {
498                         unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
499                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
500                                                  imux->items[i].index,
501                                                  HDA_AMP_MUTE, v);
502                 }
503                 *cur_val = idx;
504                 return 1;
505         } else {
506                 /* MUX style (e.g. ALC880) */
507                 return snd_hda_input_mux_put(codec, imux, ucontrol, nid,
508                                              &spec->cur_mux[adc_idx]);
509         }
510 }
511
512 /*
513  * channel mode setting
514  */
515 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
516                             struct snd_ctl_elem_info *uinfo)
517 {
518         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
519         struct alc_spec *spec = codec->spec;
520         return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
521                                     spec->num_channel_mode);
522 }
523
524 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
525                            struct snd_ctl_elem_value *ucontrol)
526 {
527         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
528         struct alc_spec *spec = codec->spec;
529         return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
530                                    spec->num_channel_mode,
531                                    spec->ext_channel_count);
532 }
533
534 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
535                            struct snd_ctl_elem_value *ucontrol)
536 {
537         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
538         struct alc_spec *spec = codec->spec;
539         int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
540                                       spec->num_channel_mode,
541                                       &spec->ext_channel_count);
542         if (err >= 0 && !spec->const_channel_count) {
543                 spec->multiout.max_channels = spec->ext_channel_count;
544                 if (spec->need_dac_fix)
545                         spec->multiout.num_dacs = spec->multiout.max_channels / 2;
546         }
547         return err;
548 }
549
550 /*
551  * Control the mode of pin widget settings via the mixer.  "pc" is used
552  * instead of "%" to avoid consequences of accidentally treating the % as
553  * being part of a format specifier.  Maximum allowed length of a value is
554  * 63 characters plus NULL terminator.
555  *
556  * Note: some retasking pin complexes seem to ignore requests for input
557  * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
558  * are requested.  Therefore order this list so that this behaviour will not
559  * cause problems when mixer clients move through the enum sequentially.
560  * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
561  * March 2006.
562  */
563 static char *alc_pin_mode_names[] = {
564         "Mic 50pc bias", "Mic 80pc bias",
565         "Line in", "Line out", "Headphone out",
566 };
567 static unsigned char alc_pin_mode_values[] = {
568         PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
569 };
570 /* The control can present all 5 options, or it can limit the options based
571  * in the pin being assumed to be exclusively an input or an output pin.  In
572  * addition, "input" pins may or may not process the mic bias option
573  * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
574  * accept requests for bias as of chip versions up to March 2006) and/or
575  * wiring in the computer.
576  */
577 #define ALC_PIN_DIR_IN              0x00
578 #define ALC_PIN_DIR_OUT             0x01
579 #define ALC_PIN_DIR_INOUT           0x02
580 #define ALC_PIN_DIR_IN_NOMICBIAS    0x03
581 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
582
583 /* Info about the pin modes supported by the different pin direction modes.
584  * For each direction the minimum and maximum values are given.
585  */
586 static signed char alc_pin_mode_dir_info[5][2] = {
587         { 0, 2 },    /* ALC_PIN_DIR_IN */
588         { 3, 4 },    /* ALC_PIN_DIR_OUT */
589         { 0, 4 },    /* ALC_PIN_DIR_INOUT */
590         { 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
591         { 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
592 };
593 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
594 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
595 #define alc_pin_mode_n_items(_dir) \
596         (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
597
598 static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
599                              struct snd_ctl_elem_info *uinfo)
600 {
601         unsigned int item_num = uinfo->value.enumerated.item;
602         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
603
604         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
605         uinfo->count = 1;
606         uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
607
608         if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
609                 item_num = alc_pin_mode_min(dir);
610         strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
611         return 0;
612 }
613
614 static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
615                             struct snd_ctl_elem_value *ucontrol)
616 {
617         unsigned int i;
618         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
619         hda_nid_t nid = kcontrol->private_value & 0xffff;
620         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
621         long *valp = ucontrol->value.integer.value;
622         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
623                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
624                                                  0x00);
625
626         /* Find enumerated value for current pinctl setting */
627         i = alc_pin_mode_min(dir);
628         while (i <= alc_pin_mode_max(dir) && alc_pin_mode_values[i] != pinctl)
629                 i++;
630         *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
631         return 0;
632 }
633
634 static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
635                             struct snd_ctl_elem_value *ucontrol)
636 {
637         signed int change;
638         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
639         hda_nid_t nid = kcontrol->private_value & 0xffff;
640         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
641         long val = *ucontrol->value.integer.value;
642         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
643                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
644                                                  0x00);
645
646         if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
647                 val = alc_pin_mode_min(dir);
648
649         change = pinctl != alc_pin_mode_values[val];
650         if (change) {
651                 /* Set pin mode to that requested */
652                 snd_hda_codec_write_cache(codec, nid, 0,
653                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
654                                           alc_pin_mode_values[val]);
655
656                 /* Also enable the retasking pin's input/output as required
657                  * for the requested pin mode.  Enum values of 2 or less are
658                  * input modes.
659                  *
660                  * Dynamically switching the input/output buffers probably
661                  * reduces noise slightly (particularly on input) so we'll
662                  * do it.  However, having both input and output buffers
663                  * enabled simultaneously doesn't seem to be problematic if
664                  * this turns out to be necessary in the future.
665                  */
666                 if (val <= 2) {
667                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
668                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
669                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
670                                                  HDA_AMP_MUTE, 0);
671                 } else {
672                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
673                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
674                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
675                                                  HDA_AMP_MUTE, 0);
676                 }
677         }
678         return change;
679 }
680
681 #define ALC_PIN_MODE(xname, nid, dir) \
682         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
683           .subdevice = HDA_SUBDEV_NID_FLAG | nid, \
684           .info = alc_pin_mode_info, \
685           .get = alc_pin_mode_get, \
686           .put = alc_pin_mode_put, \
687           .private_value = nid | (dir<<16) }
688
689 /* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
690  * together using a mask with more than one bit set.  This control is
691  * currently used only by the ALC260 test model.  At this stage they are not
692  * needed for any "production" models.
693  */
694 #ifdef CONFIG_SND_DEBUG
695 #define alc_gpio_data_info      snd_ctl_boolean_mono_info
696
697 static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
698                              struct snd_ctl_elem_value *ucontrol)
699 {
700         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
701         hda_nid_t nid = kcontrol->private_value & 0xffff;
702         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
703         long *valp = ucontrol->value.integer.value;
704         unsigned int val = snd_hda_codec_read(codec, nid, 0,
705                                               AC_VERB_GET_GPIO_DATA, 0x00);
706
707         *valp = (val & mask) != 0;
708         return 0;
709 }
710 static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
711                              struct snd_ctl_elem_value *ucontrol)
712 {
713         signed int change;
714         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
715         hda_nid_t nid = kcontrol->private_value & 0xffff;
716         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
717         long val = *ucontrol->value.integer.value;
718         unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
719                                                     AC_VERB_GET_GPIO_DATA,
720                                                     0x00);
721
722         /* Set/unset the masked GPIO bit(s) as needed */
723         change = (val == 0 ? 0 : mask) != (gpio_data & mask);
724         if (val == 0)
725                 gpio_data &= ~mask;
726         else
727                 gpio_data |= mask;
728         snd_hda_codec_write_cache(codec, nid, 0,
729                                   AC_VERB_SET_GPIO_DATA, gpio_data);
730
731         return change;
732 }
733 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
734         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
735           .subdevice = HDA_SUBDEV_NID_FLAG | nid, \
736           .info = alc_gpio_data_info, \
737           .get = alc_gpio_data_get, \
738           .put = alc_gpio_data_put, \
739           .private_value = nid | (mask<<16) }
740 #endif   /* CONFIG_SND_DEBUG */
741
742 /* A switch control to allow the enabling of the digital IO pins on the
743  * ALC260.  This is incredibly simplistic; the intention of this control is
744  * to provide something in the test model allowing digital outputs to be
745  * identified if present.  If models are found which can utilise these
746  * outputs a more complete mixer control can be devised for those models if
747  * necessary.
748  */
749 #ifdef CONFIG_SND_DEBUG
750 #define alc_spdif_ctrl_info     snd_ctl_boolean_mono_info
751
752 static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
753                               struct snd_ctl_elem_value *ucontrol)
754 {
755         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
756         hda_nid_t nid = kcontrol->private_value & 0xffff;
757         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
758         long *valp = ucontrol->value.integer.value;
759         unsigned int val = snd_hda_codec_read(codec, nid, 0,
760                                               AC_VERB_GET_DIGI_CONVERT_1, 0x00);
761
762         *valp = (val & mask) != 0;
763         return 0;
764 }
765 static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
766                               struct snd_ctl_elem_value *ucontrol)
767 {
768         signed int change;
769         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
770         hda_nid_t nid = kcontrol->private_value & 0xffff;
771         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
772         long val = *ucontrol->value.integer.value;
773         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
774                                                     AC_VERB_GET_DIGI_CONVERT_1,
775                                                     0x00);
776
777         /* Set/unset the masked control bit(s) as needed */
778         change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
779         if (val==0)
780                 ctrl_data &= ~mask;
781         else
782                 ctrl_data |= mask;
783         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
784                                   ctrl_data);
785
786         return change;
787 }
788 #define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
789         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
790           .subdevice = HDA_SUBDEV_NID_FLAG | nid, \
791           .info = alc_spdif_ctrl_info, \
792           .get = alc_spdif_ctrl_get, \
793           .put = alc_spdif_ctrl_put, \
794           .private_value = nid | (mask<<16) }
795 #endif   /* CONFIG_SND_DEBUG */
796
797 /* A switch control to allow the enabling EAPD digital outputs on the ALC26x.
798  * Again, this is only used in the ALC26x test models to help identify when
799  * the EAPD line must be asserted for features to work.
800  */
801 #ifdef CONFIG_SND_DEBUG
802 #define alc_eapd_ctrl_info      snd_ctl_boolean_mono_info
803
804 static int alc_eapd_ctrl_get(struct snd_kcontrol *kcontrol,
805                               struct snd_ctl_elem_value *ucontrol)
806 {
807         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
808         hda_nid_t nid = kcontrol->private_value & 0xffff;
809         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
810         long *valp = ucontrol->value.integer.value;
811         unsigned int val = snd_hda_codec_read(codec, nid, 0,
812                                               AC_VERB_GET_EAPD_BTLENABLE, 0x00);
813
814         *valp = (val & mask) != 0;
815         return 0;
816 }
817
818 static int alc_eapd_ctrl_put(struct snd_kcontrol *kcontrol,
819                               struct snd_ctl_elem_value *ucontrol)
820 {
821         int change;
822         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
823         hda_nid_t nid = kcontrol->private_value & 0xffff;
824         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
825         long val = *ucontrol->value.integer.value;
826         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
827                                                     AC_VERB_GET_EAPD_BTLENABLE,
828                                                     0x00);
829
830         /* Set/unset the masked control bit(s) as needed */
831         change = (!val ? 0 : mask) != (ctrl_data & mask);
832         if (!val)
833                 ctrl_data &= ~mask;
834         else
835                 ctrl_data |= mask;
836         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
837                                   ctrl_data);
838
839         return change;
840 }
841
842 #define ALC_EAPD_CTRL_SWITCH(xname, nid, mask) \
843         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
844           .subdevice = HDA_SUBDEV_NID_FLAG | nid, \
845           .info = alc_eapd_ctrl_info, \
846           .get = alc_eapd_ctrl_get, \
847           .put = alc_eapd_ctrl_put, \
848           .private_value = nid | (mask<<16) }
849 #endif   /* CONFIG_SND_DEBUG */
850
851 /*
852  * set up the input pin config (depending on the given auto-pin type)
853  */
854 static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
855                               int auto_pin_type)
856 {
857         unsigned int val = PIN_IN;
858
859         if (auto_pin_type == AUTO_PIN_MIC) {
860                 unsigned int pincap;
861                 unsigned int oldval;
862                 oldval = snd_hda_codec_read(codec, nid, 0,
863                                             AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
864                 pincap = snd_hda_query_pin_caps(codec, nid);
865                 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
866                 /* if the default pin setup is vref50, we give it priority */
867                 if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50)
868                         val = PIN_VREF80;
869                 else if (pincap & AC_PINCAP_VREF_50)
870                         val = PIN_VREF50;
871                 else if (pincap & AC_PINCAP_VREF_100)
872                         val = PIN_VREF100;
873                 else if (pincap & AC_PINCAP_VREF_GRD)
874                         val = PIN_VREFGRD;
875         }
876         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
877 }
878
879 static void alc_fixup_autocfg_pin_nums(struct hda_codec *codec)
880 {
881         struct alc_spec *spec = codec->spec;
882         struct auto_pin_cfg *cfg = &spec->autocfg;
883
884         if (!cfg->line_outs) {
885                 while (cfg->line_outs < AUTO_CFG_MAX_OUTS &&
886                        cfg->line_out_pins[cfg->line_outs])
887                         cfg->line_outs++;
888         }
889         if (!cfg->speaker_outs) {
890                 while (cfg->speaker_outs < AUTO_CFG_MAX_OUTS &&
891                        cfg->speaker_pins[cfg->speaker_outs])
892                         cfg->speaker_outs++;
893         }
894         if (!cfg->hp_outs) {
895                 while (cfg->hp_outs < AUTO_CFG_MAX_OUTS &&
896                        cfg->hp_pins[cfg->hp_outs])
897                         cfg->hp_outs++;
898         }
899 }
900
901 /*
902  */
903 static void add_mixer(struct alc_spec *spec, struct snd_kcontrol_new *mix)
904 {
905         if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
906                 return;
907         spec->mixers[spec->num_mixers++] = mix;
908 }
909
910 static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
911 {
912         if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
913                 return;
914         spec->init_verbs[spec->num_init_verbs++] = verb;
915 }
916
917 /*
918  * set up from the preset table
919  */
920 static void setup_preset(struct hda_codec *codec,
921                          const struct alc_config_preset *preset)
922 {
923         struct alc_spec *spec = codec->spec;
924         int i;
925
926         for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
927                 add_mixer(spec, preset->mixers[i]);
928         spec->cap_mixer = preset->cap_mixer;
929         for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
930              i++)
931                 add_verb(spec, preset->init_verbs[i]);
932
933         spec->channel_mode = preset->channel_mode;
934         spec->num_channel_mode = preset->num_channel_mode;
935         spec->need_dac_fix = preset->need_dac_fix;
936         spec->const_channel_count = preset->const_channel_count;
937
938         if (preset->const_channel_count)
939                 spec->multiout.max_channels = preset->const_channel_count;
940         else
941                 spec->multiout.max_channels = spec->channel_mode[0].channels;
942         spec->ext_channel_count = spec->channel_mode[0].channels;
943
944         spec->multiout.num_dacs = preset->num_dacs;
945         spec->multiout.dac_nids = preset->dac_nids;
946         spec->multiout.dig_out_nid = preset->dig_out_nid;
947         spec->multiout.slave_dig_outs = preset->slave_dig_outs;
948         spec->multiout.hp_nid = preset->hp_nid;
949
950         spec->num_mux_defs = preset->num_mux_defs;
951         if (!spec->num_mux_defs)
952                 spec->num_mux_defs = 1;
953         spec->input_mux = preset->input_mux;
954
955         spec->num_adc_nids = preset->num_adc_nids;
956         spec->adc_nids = preset->adc_nids;
957         spec->capsrc_nids = preset->capsrc_nids;
958         spec->dig_in_nid = preset->dig_in_nid;
959
960         spec->unsol_event = preset->unsol_event;
961         spec->init_hook = preset->init_hook;
962 #ifdef CONFIG_SND_HDA_POWER_SAVE
963         spec->power_hook = preset->power_hook;
964         spec->loopback.amplist = preset->loopbacks;
965 #endif
966
967         if (preset->setup)
968                 preset->setup(codec);
969
970         alc_fixup_autocfg_pin_nums(codec);
971 }
972
973 /* Enable GPIO mask and set output */
974 static struct hda_verb alc_gpio1_init_verbs[] = {
975         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
976         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
977         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
978         { }
979 };
980
981 static struct hda_verb alc_gpio2_init_verbs[] = {
982         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
983         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
984         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
985         { }
986 };
987
988 static struct hda_verb alc_gpio3_init_verbs[] = {
989         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
990         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
991         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
992         { }
993 };
994
995 /*
996  * Fix hardware PLL issue
997  * On some codecs, the analog PLL gating control must be off while
998  * the default value is 1.
999  */
1000 static void alc_fix_pll(struct hda_codec *codec)
1001 {
1002         struct alc_spec *spec = codec->spec;
1003         unsigned int val;
1004
1005         if (!spec->pll_nid)
1006                 return;
1007         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
1008                             spec->pll_coef_idx);
1009         val = snd_hda_codec_read(codec, spec->pll_nid, 0,
1010                                  AC_VERB_GET_PROC_COEF, 0);
1011         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
1012                             spec->pll_coef_idx);
1013         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
1014                             val & ~(1 << spec->pll_coef_bit));
1015 }
1016
1017 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
1018                              unsigned int coef_idx, unsigned int coef_bit)
1019 {
1020         struct alc_spec *spec = codec->spec;
1021         spec->pll_nid = nid;
1022         spec->pll_coef_idx = coef_idx;
1023         spec->pll_coef_bit = coef_bit;
1024         alc_fix_pll(codec);
1025 }
1026
1027 static int alc_init_jacks(struct hda_codec *codec)
1028 {
1029 #ifdef CONFIG_SND_HDA_INPUT_JACK
1030         struct alc_spec *spec = codec->spec;
1031         int err;
1032         unsigned int hp_nid = spec->autocfg.hp_pins[0];
1033         unsigned int mic_nid = spec->ext_mic.pin;
1034
1035         if (hp_nid) {
1036                 err = snd_hda_input_jack_add(codec, hp_nid,
1037                                              SND_JACK_HEADPHONE, NULL);
1038                 if (err < 0)
1039                         return err;
1040                 snd_hda_input_jack_report(codec, hp_nid);
1041         }
1042
1043         if (mic_nid) {
1044                 err = snd_hda_input_jack_add(codec, mic_nid,
1045                                              SND_JACK_MICROPHONE, NULL);
1046                 if (err < 0)
1047                         return err;
1048                 snd_hda_input_jack_report(codec, mic_nid);
1049         }
1050 #endif /* CONFIG_SND_HDA_INPUT_JACK */
1051         return 0;
1052 }
1053
1054 static void alc_automute_speaker(struct hda_codec *codec, int pinctl)
1055 {
1056         struct alc_spec *spec = codec->spec;
1057         unsigned int mute;
1058         hda_nid_t nid;
1059         int i;
1060
1061         spec->jack_present = 0;
1062         for (i = 0; i < ARRAY_SIZE(spec->autocfg.hp_pins); i++) {
1063                 nid = spec->autocfg.hp_pins[i];
1064                 if (!nid)
1065                         break;
1066                 snd_hda_input_jack_report(codec, nid);
1067                 spec->jack_present |= snd_hda_jack_detect(codec, nid);
1068         }
1069
1070         mute = spec->jack_present ? HDA_AMP_MUTE : 0;
1071         /* Toggle internal speakers muting */
1072         for (i = 0; i < ARRAY_SIZE(spec->autocfg.speaker_pins); i++) {
1073                 nid = spec->autocfg.speaker_pins[i];
1074                 if (!nid)
1075                         break;
1076                 if (pinctl) {
1077                         snd_hda_codec_write(codec, nid, 0,
1078                                     AC_VERB_SET_PIN_WIDGET_CONTROL,
1079                                     spec->jack_present ? 0 : PIN_OUT);
1080                 } else {
1081                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
1082                                          HDA_AMP_MUTE, mute);
1083                 }
1084         }
1085 }
1086
1087 static void alc_automute_pin(struct hda_codec *codec)
1088 {
1089         alc_automute_speaker(codec, 1);
1090 }
1091
1092 static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
1093                                 hda_nid_t nid)
1094 {
1095         hda_nid_t conn[HDA_MAX_NUM_INPUTS];
1096         int i, nums;
1097
1098         nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
1099         for (i = 0; i < nums; i++)
1100                 if (conn[i] == nid)
1101                         return i;
1102         return -1;
1103 }
1104
1105 /* switch the current ADC according to the jack state */
1106 static void alc_dual_mic_adc_auto_switch(struct hda_codec *codec)
1107 {
1108         struct alc_spec *spec = codec->spec;
1109         unsigned int present;
1110         hda_nid_t new_adc;
1111
1112         present = snd_hda_jack_detect(codec, spec->ext_mic.pin);
1113         if (present)
1114                 spec->cur_adc_idx = 1;
1115         else
1116                 spec->cur_adc_idx = 0;
1117         new_adc = spec->adc_nids[spec->cur_adc_idx];
1118         if (spec->cur_adc && spec->cur_adc != new_adc) {
1119                 /* stream is running, let's swap the current ADC */
1120                 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
1121                 spec->cur_adc = new_adc;
1122                 snd_hda_codec_setup_stream(codec, new_adc,
1123                                            spec->cur_adc_stream_tag, 0,
1124                                            spec->cur_adc_format);
1125         }
1126 }
1127
1128 static void alc_mic_automute(struct hda_codec *codec)
1129 {
1130         struct alc_spec *spec = codec->spec;
1131         struct alc_mic_route *dead, *alive;
1132         unsigned int present, type;
1133         hda_nid_t cap_nid;
1134
1135         if (!spec->auto_mic)
1136                 return;
1137         if (!spec->int_mic.pin || !spec->ext_mic.pin)
1138                 return;
1139         if (snd_BUG_ON(!spec->adc_nids))
1140                 return;
1141
1142         if (spec->dual_adc_switch) {
1143                 alc_dual_mic_adc_auto_switch(codec);
1144                 return;
1145         }
1146
1147         cap_nid = spec->capsrc_nids ? spec->capsrc_nids[0] : spec->adc_nids[0];
1148
1149         present = snd_hda_jack_detect(codec, spec->ext_mic.pin);
1150         if (present) {
1151                 alive = &spec->ext_mic;
1152                 dead = &spec->int_mic;
1153         } else {
1154                 alive = &spec->int_mic;
1155                 dead = &spec->ext_mic;
1156         }
1157
1158         type = get_wcaps_type(get_wcaps(codec, cap_nid));
1159         if (type == AC_WID_AUD_MIX) {
1160                 /* Matrix-mixer style (e.g. ALC882) */
1161                 snd_hda_codec_amp_stereo(codec, cap_nid, HDA_INPUT,
1162                                          alive->mux_idx,
1163                                          HDA_AMP_MUTE, 0);
1164                 snd_hda_codec_amp_stereo(codec, cap_nid, HDA_INPUT,
1165                                          dead->mux_idx,
1166                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
1167         } else {
1168                 /* MUX style (e.g. ALC880) */
1169                 snd_hda_codec_write_cache(codec, cap_nid, 0,
1170                                           AC_VERB_SET_CONNECT_SEL,
1171                                           alive->mux_idx);
1172         }
1173         snd_hda_input_jack_report(codec, spec->ext_mic.pin);
1174
1175         /* FIXME: analog mixer */
1176 }
1177
1178 /* unsolicited event for HP jack sensing */
1179 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
1180 {
1181         if (codec->vendor_id == 0x10ec0880)
1182                 res >>= 28;
1183         else
1184                 res >>= 26;
1185         switch (res) {
1186         case ALC880_HP_EVENT:
1187                 alc_automute_pin(codec);
1188                 break;
1189         case ALC880_MIC_EVENT:
1190                 alc_mic_automute(codec);
1191                 break;
1192         }
1193 }
1194
1195 static void alc_inithook(struct hda_codec *codec)
1196 {
1197         alc_automute_pin(codec);
1198         alc_mic_automute(codec);
1199 }
1200
1201 /* additional initialization for ALC888 variants */
1202 static void alc888_coef_init(struct hda_codec *codec)
1203 {
1204         unsigned int tmp;
1205
1206         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
1207         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
1208         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
1209         if ((tmp & 0xf0) == 0x20)
1210                 /* alc888S-VC */
1211                 snd_hda_codec_read(codec, 0x20, 0,
1212                                    AC_VERB_SET_PROC_COEF, 0x830);
1213          else
1214                  /* alc888-VB */
1215                  snd_hda_codec_read(codec, 0x20, 0,
1216                                     AC_VERB_SET_PROC_COEF, 0x3030);
1217 }
1218
1219 static void alc889_coef_init(struct hda_codec *codec)
1220 {
1221         unsigned int tmp;
1222
1223         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
1224         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
1225         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
1226         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
1227 }
1228
1229 /* turn on/off EAPD control (only if available) */
1230 static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
1231 {
1232         if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
1233                 return;
1234         if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
1235                 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
1236                                     on ? 2 : 0);
1237 }
1238
1239 static void alc_auto_init_amp(struct hda_codec *codec, int type)
1240 {
1241         unsigned int tmp;
1242
1243         switch (type) {
1244         case ALC_INIT_GPIO1:
1245                 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
1246                 break;
1247         case ALC_INIT_GPIO2:
1248                 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
1249                 break;
1250         case ALC_INIT_GPIO3:
1251                 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
1252                 break;
1253         case ALC_INIT_DEFAULT:
1254                 switch (codec->vendor_id) {
1255                 case 0x10ec0260:
1256                         set_eapd(codec, 0x0f, 1);
1257                         set_eapd(codec, 0x10, 1);
1258                         break;
1259                 case 0x10ec0262:
1260                 case 0x10ec0267:
1261                 case 0x10ec0268:
1262                 case 0x10ec0269:
1263                 case 0x10ec0270:
1264                 case 0x10ec0272:
1265                 case 0x10ec0660:
1266                 case 0x10ec0662:
1267                 case 0x10ec0663:
1268                 case 0x10ec0665:
1269                 case 0x10ec0862:
1270                 case 0x10ec0889:
1271                         set_eapd(codec, 0x14, 1);
1272                         set_eapd(codec, 0x15, 1);
1273                         break;
1274                 }
1275                 switch (codec->vendor_id) {
1276                 case 0x10ec0260:
1277                         snd_hda_codec_write(codec, 0x1a, 0,
1278                                             AC_VERB_SET_COEF_INDEX, 7);
1279                         tmp = snd_hda_codec_read(codec, 0x1a, 0,
1280                                                  AC_VERB_GET_PROC_COEF, 0);
1281                         snd_hda_codec_write(codec, 0x1a, 0,
1282                                             AC_VERB_SET_COEF_INDEX, 7);
1283                         snd_hda_codec_write(codec, 0x1a, 0,
1284                                             AC_VERB_SET_PROC_COEF,
1285                                             tmp | 0x2010);
1286                         break;
1287                 case 0x10ec0262:
1288                 case 0x10ec0880:
1289                 case 0x10ec0882:
1290                 case 0x10ec0883:
1291                 case 0x10ec0885:
1292                 case 0x10ec0887:
1293                 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
1294                         alc889_coef_init(codec);
1295                         break;
1296                 case 0x10ec0888:
1297                         alc888_coef_init(codec);
1298                         break;
1299 #if 0 /* XXX: This may cause the silent output on speaker on some machines */
1300                 case 0x10ec0267:
1301                 case 0x10ec0268:
1302                         snd_hda_codec_write(codec, 0x20, 0,
1303                                             AC_VERB_SET_COEF_INDEX, 7);
1304                         tmp = snd_hda_codec_read(codec, 0x20, 0,
1305                                                  AC_VERB_GET_PROC_COEF, 0);
1306                         snd_hda_codec_write(codec, 0x20, 0,
1307                                             AC_VERB_SET_COEF_INDEX, 7);
1308                         snd_hda_codec_write(codec, 0x20, 0,
1309                                             AC_VERB_SET_PROC_COEF,
1310                                             tmp | 0x3000);
1311                         break;
1312 #endif /* XXX */
1313                 }
1314                 break;
1315         }
1316 }
1317
1318 static void alc_init_auto_hp(struct hda_codec *codec)
1319 {
1320         struct alc_spec *spec = codec->spec;
1321         struct auto_pin_cfg *cfg = &spec->autocfg;
1322         int i;
1323
1324         if (!cfg->hp_pins[0]) {
1325                 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
1326                         return;
1327         }
1328
1329         if (!cfg->speaker_pins[0]) {
1330                 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
1331                         return;
1332                 memcpy(cfg->speaker_pins, cfg->line_out_pins,
1333                        sizeof(cfg->speaker_pins));
1334                 cfg->speaker_outs = cfg->line_outs;
1335         }
1336
1337         if (!cfg->hp_pins[0]) {
1338                 memcpy(cfg->hp_pins, cfg->line_out_pins,
1339                        sizeof(cfg->hp_pins));
1340                 cfg->hp_outs = cfg->line_outs;
1341         }
1342
1343         for (i = 0; i < cfg->hp_outs; i++) {
1344                 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
1345                             cfg->hp_pins[i]);
1346                 snd_hda_codec_write_cache(codec, cfg->hp_pins[i], 0,
1347                                   AC_VERB_SET_UNSOLICITED_ENABLE,
1348                                   AC_USRSP_EN | ALC880_HP_EVENT);
1349         }
1350         spec->unsol_event = alc_sku_unsol_event;
1351 }
1352
1353 static void alc_init_auto_mic(struct hda_codec *codec)
1354 {
1355         struct alc_spec *spec = codec->spec;
1356         struct auto_pin_cfg *cfg = &spec->autocfg;
1357         hda_nid_t fixed, ext;
1358         int i;
1359
1360         /* there must be only two mic inputs exclusively */
1361         for (i = 0; i < cfg->num_inputs; i++)
1362                 if (cfg->inputs[i].type >= AUTO_PIN_LINE_IN)
1363                         return;
1364
1365         fixed = ext = 0;
1366         for (i = 0; i < cfg->num_inputs; i++) {
1367                 hda_nid_t nid = cfg->inputs[i].pin;
1368                 unsigned int defcfg;
1369                 defcfg = snd_hda_codec_get_pincfg(codec, nid);
1370                 switch (snd_hda_get_input_pin_attr(defcfg)) {
1371                 case INPUT_PIN_ATTR_INT:
1372                         if (fixed)
1373                                 return; /* already occupied */
1374                         fixed = nid;
1375                         break;
1376                 case INPUT_PIN_ATTR_UNUSED:
1377                         return; /* invalid entry */
1378                 default:
1379                         if (ext)
1380                                 return; /* already occupied */
1381                         ext = nid;
1382                         break;
1383                 }
1384         }
1385         if (!ext || !fixed)
1386                 return;
1387         if (!(get_wcaps(codec, ext) & AC_WCAP_UNSOL_CAP))
1388                 return; /* no unsol support */
1389         snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x\n",
1390                     ext, fixed);
1391         spec->ext_mic.pin = ext;
1392         spec->int_mic.pin = fixed;
1393         spec->ext_mic.mux_idx = MUX_IDX_UNDEF; /* set later */
1394         spec->int_mic.mux_idx = MUX_IDX_UNDEF; /* set later */
1395         spec->auto_mic = 1;
1396         snd_hda_codec_write_cache(codec, spec->ext_mic.pin, 0,
1397                                   AC_VERB_SET_UNSOLICITED_ENABLE,
1398                                   AC_USRSP_EN | ALC880_MIC_EVENT);
1399         spec->unsol_event = alc_sku_unsol_event;
1400 }
1401
1402 /* Could be any non-zero and even value. When used as fixup, tells
1403  * the driver to ignore any present sku defines.
1404  */
1405 #define ALC_FIXUP_SKU_IGNORE (2)
1406
1407 static int alc_auto_parse_customize_define(struct hda_codec *codec)
1408 {
1409         unsigned int ass, tmp, i;
1410         unsigned nid = 0;
1411         struct alc_spec *spec = codec->spec;
1412
1413         spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1414
1415         if (spec->cdefine.fixup) {
1416                 ass = spec->cdefine.sku_cfg;
1417                 if (ass == ALC_FIXUP_SKU_IGNORE)
1418                         return -1;
1419                 goto do_sku;
1420         }
1421
1422         ass = codec->subsystem_id & 0xffff;
1423         if (ass != codec->bus->pci->subsystem_device && (ass & 1))
1424                 goto do_sku;
1425
1426         nid = 0x1d;
1427         if (codec->vendor_id == 0x10ec0260)
1428                 nid = 0x17;
1429         ass = snd_hda_codec_get_pincfg(codec, nid);
1430
1431         if (!(ass & 1)) {
1432                 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1433                        codec->chip_name, ass);
1434                 return -1;
1435         }
1436
1437         /* check sum */
1438         tmp = 0;
1439         for (i = 1; i < 16; i++) {
1440                 if ((ass >> i) & 1)
1441                         tmp++;
1442         }
1443         if (((ass >> 16) & 0xf) != tmp)
1444                 return -1;
1445
1446         spec->cdefine.port_connectivity = ass >> 30;
1447         spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1448         spec->cdefine.check_sum = (ass >> 16) & 0xf;
1449         spec->cdefine.customization = ass >> 8;
1450 do_sku:
1451         spec->cdefine.sku_cfg = ass;
1452         spec->cdefine.external_amp = (ass & 0x38) >> 3;
1453         spec->cdefine.platform_type = (ass & 0x4) >> 2;
1454         spec->cdefine.swap = (ass & 0x2) >> 1;
1455         spec->cdefine.override = ass & 0x1;
1456
1457         snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1458                    nid, spec->cdefine.sku_cfg);
1459         snd_printd("SKU: port_connectivity=0x%x\n",
1460                    spec->cdefine.port_connectivity);
1461         snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1462         snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1463         snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1464         snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1465         snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1466         snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1467         snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1468
1469         return 0;
1470 }
1471
1472 /* check subsystem ID and set up device-specific initialization;
1473  * return 1 if initialized, 0 if invalid SSID
1474  */
1475 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1476  *      31 ~ 16 :       Manufacture ID
1477  *      15 ~ 8  :       SKU ID
1478  *      7  ~ 0  :       Assembly ID
1479  *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1480  */
1481 static int alc_subsystem_id(struct hda_codec *codec,
1482                             hda_nid_t porta, hda_nid_t porte,
1483                             hda_nid_t portd, hda_nid_t porti)
1484 {
1485         unsigned int ass, tmp, i;
1486         unsigned nid;
1487         struct alc_spec *spec = codec->spec;
1488
1489         if (spec->cdefine.fixup) {
1490                 ass = spec->cdefine.sku_cfg;
1491                 if (ass == ALC_FIXUP_SKU_IGNORE)
1492                         return 0;
1493                 goto do_sku;
1494         }
1495
1496         ass = codec->subsystem_id & 0xffff;
1497         if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1498                 goto do_sku;
1499
1500         /* invalid SSID, check the special NID pin defcfg instead */
1501         /*
1502          * 31~30        : port connectivity
1503          * 29~21        : reserve
1504          * 20           : PCBEEP input
1505          * 19~16        : Check sum (15:1)
1506          * 15~1         : Custom
1507          * 0            : override
1508         */
1509         nid = 0x1d;
1510         if (codec->vendor_id == 0x10ec0260)
1511                 nid = 0x17;
1512         ass = snd_hda_codec_get_pincfg(codec, nid);
1513         snd_printd("realtek: No valid SSID, "
1514                    "checking pincfg 0x%08x for NID 0x%x\n",
1515                    ass, nid);
1516         if (!(ass & 1))
1517                 return 0;
1518         if ((ass >> 30) != 1)   /* no physical connection */
1519                 return 0;
1520
1521         /* check sum */
1522         tmp = 0;
1523         for (i = 1; i < 16; i++) {
1524                 if ((ass >> i) & 1)
1525                         tmp++;
1526         }
1527         if (((ass >> 16) & 0xf) != tmp)
1528                 return 0;
1529 do_sku:
1530         snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1531                    ass & 0xffff, codec->vendor_id);
1532         /*
1533          * 0 : override
1534          * 1 :  Swap Jack
1535          * 2 : 0 --> Desktop, 1 --> Laptop
1536          * 3~5 : External Amplifier control
1537          * 7~6 : Reserved
1538         */
1539         tmp = (ass & 0x38) >> 3;        /* external Amp control */
1540         switch (tmp) {
1541         case 1:
1542                 spec->init_amp = ALC_INIT_GPIO1;
1543                 break;
1544         case 3:
1545                 spec->init_amp = ALC_INIT_GPIO2;
1546                 break;
1547         case 7:
1548                 spec->init_amp = ALC_INIT_GPIO3;
1549                 break;
1550         case 5:
1551         default:
1552                 spec->init_amp = ALC_INIT_DEFAULT;
1553                 break;
1554         }
1555
1556         /* is laptop or Desktop and enable the function "Mute internal speaker
1557          * when the external headphone out jack is plugged"
1558          */
1559         if (!(ass & 0x8000))
1560                 return 1;
1561         /*
1562          * 10~8 : Jack location
1563          * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1564          * 14~13: Resvered
1565          * 15   : 1 --> enable the function "Mute internal speaker
1566          *              when the external headphone out jack is plugged"
1567          */
1568         if (!spec->autocfg.hp_pins[0]) {
1569                 hda_nid_t nid;
1570                 tmp = (ass >> 11) & 0x3;        /* HP to chassis */
1571                 if (tmp == 0)
1572                         nid = porta;
1573                 else if (tmp == 1)
1574                         nid = porte;
1575                 else if (tmp == 2)
1576                         nid = portd;
1577                 else if (tmp == 3)
1578                         nid = porti;
1579                 else
1580                         return 1;
1581                 for (i = 0; i < spec->autocfg.line_outs; i++)
1582                         if (spec->autocfg.line_out_pins[i] == nid)
1583                                 return 1;
1584                 spec->autocfg.hp_pins[0] = nid;
1585         }
1586
1587         alc_init_auto_hp(codec);
1588         alc_init_auto_mic(codec);
1589         return 1;
1590 }
1591
1592 static void alc_ssid_check(struct hda_codec *codec,
1593                            hda_nid_t porta, hda_nid_t porte,
1594                            hda_nid_t portd, hda_nid_t porti)
1595 {
1596         if (!alc_subsystem_id(codec, porta, porte, portd, porti)) {
1597                 struct alc_spec *spec = codec->spec;
1598                 snd_printd("realtek: "
1599                            "Enable default setup for auto mode as fallback\n");
1600                 spec->init_amp = ALC_INIT_DEFAULT;
1601                 alc_init_auto_hp(codec);
1602                 alc_init_auto_mic(codec);
1603         }
1604 }
1605
1606 /*
1607  * Fix-up pin default configurations and add default verbs
1608  */
1609
1610 struct alc_pincfg {
1611         hda_nid_t nid;
1612         u32 val;
1613 };
1614
1615 struct alc_model_fixup {
1616         const int id;
1617         const char *name;
1618 };
1619
1620 struct alc_fixup {
1621         int type;
1622         bool chained;
1623         int chain_id;
1624         union {
1625                 unsigned int sku;
1626                 const struct alc_pincfg *pins;
1627                 const struct hda_verb *verbs;
1628                 void (*func)(struct hda_codec *codec,
1629                              const struct alc_fixup *fix,
1630                              int action);
1631         } v;
1632 };
1633
1634 enum {
1635         ALC_FIXUP_INVALID,
1636         ALC_FIXUP_SKU,
1637         ALC_FIXUP_PINS,
1638         ALC_FIXUP_VERBS,
1639         ALC_FIXUP_FUNC,
1640 };
1641
1642 enum {
1643         ALC_FIXUP_ACT_PRE_PROBE,
1644         ALC_FIXUP_ACT_PROBE,
1645         ALC_FIXUP_ACT_INIT,
1646 };
1647
1648 static void alc_apply_fixup(struct hda_codec *codec, int action)
1649 {
1650         struct alc_spec *spec = codec->spec;
1651         int id = spec->fixup_id;
1652 #ifdef CONFIG_SND_DEBUG_VERBOSE
1653         const char *modelname = spec->fixup_name;
1654 #endif
1655         int depth = 0;
1656
1657         if (!spec->fixup_list)
1658                 return;
1659
1660         while (id >= 0) {
1661                 const struct alc_fixup *fix = spec->fixup_list + id;
1662                 const struct alc_pincfg *cfg;
1663
1664                 switch (fix->type) {
1665                 case ALC_FIXUP_SKU:
1666                         if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku)
1667                                 break;;
1668                         snd_printdd(KERN_INFO "hda_codec: %s: "
1669                                     "Apply sku override for %s\n",
1670                                     codec->chip_name, modelname);
1671                         spec->cdefine.sku_cfg = fix->v.sku;
1672                         spec->cdefine.fixup = 1;
1673                         break;
1674                 case ALC_FIXUP_PINS:
1675                         cfg = fix->v.pins;
1676                         if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg)
1677                                 break;
1678                         snd_printdd(KERN_INFO "hda_codec: %s: "
1679                                     "Apply pincfg for %s\n",
1680                                     codec->chip_name, modelname);
1681                         for (; cfg->nid; cfg++)
1682                                 snd_hda_codec_set_pincfg(codec, cfg->nid,
1683                                                          cfg->val);
1684                         break;
1685                 case ALC_FIXUP_VERBS:
1686                         if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs)
1687                                 break;
1688                         snd_printdd(KERN_INFO "hda_codec: %s: "
1689                                     "Apply fix-verbs for %s\n",
1690                                     codec->chip_name, modelname);
1691                         add_verb(codec->spec, fix->v.verbs);
1692                         break;
1693                 case ALC_FIXUP_FUNC:
1694                         if (!fix->v.func)
1695                                 break;
1696                         snd_printdd(KERN_INFO "hda_codec: %s: "
1697                                     "Apply fix-func for %s\n",
1698                                     codec->chip_name, modelname);
1699                         fix->v.func(codec, fix, action);
1700                         break;
1701                 default:
1702                         snd_printk(KERN_ERR "hda_codec: %s: "
1703                                    "Invalid fixup type %d\n",
1704                                    codec->chip_name, fix->type);
1705                         break;
1706                 }
1707                 if (!fix[id].chained)
1708                         break;
1709                 if (++depth > 10)
1710                         break;
1711                 id = fix[id].chain_id;
1712         }
1713 }
1714
1715 static void alc_pick_fixup(struct hda_codec *codec,
1716                            const struct alc_model_fixup *models,
1717                            const struct snd_pci_quirk *quirk,
1718                            const struct alc_fixup *fixlist)
1719 {
1720         struct alc_spec *spec = codec->spec;
1721         int id = -1;
1722         const char *name = NULL;
1723
1724         if (codec->modelname && models) {
1725                 while (models->name) {
1726                         if (!strcmp(codec->modelname, models->name)) {
1727                                 id = models->id;
1728                                 name = models->name;
1729                                 break;
1730                         }
1731                         models++;
1732                 }
1733         }
1734         if (id < 0) {
1735                 quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1736                 if (quirk) {
1737                         id = quirk->value;
1738 #ifdef CONFIG_SND_DEBUG_VERBOSE
1739                         name = quirk->name;
1740 #endif
1741                 }
1742         }
1743
1744         spec->fixup_id = id;
1745         if (id >= 0) {
1746                 spec->fixup_list = fixlist;
1747                 spec->fixup_name = name;
1748         }
1749 }
1750
1751 static int alc_read_coef_idx(struct hda_codec *codec,
1752                         unsigned int coef_idx)
1753 {
1754         unsigned int val;
1755         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1756                                 coef_idx);
1757         val = snd_hda_codec_read(codec, 0x20, 0,
1758                                 AC_VERB_GET_PROC_COEF, 0);
1759         return val;
1760 }
1761
1762 static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1763                                                         unsigned int coef_val)
1764 {
1765         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1766                             coef_idx);
1767         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1768                             coef_val);
1769 }
1770
1771 /* set right pin controls for digital I/O */
1772 static void alc_auto_init_digital(struct hda_codec *codec)
1773 {
1774         struct alc_spec *spec = codec->spec;
1775         int i;
1776         hda_nid_t pin;
1777
1778         for (i = 0; i < spec->autocfg.dig_outs; i++) {
1779                 pin = spec->autocfg.dig_out_pins[i];
1780                 if (pin) {
1781                         snd_hda_codec_write(codec, pin, 0,
1782                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
1783                                             PIN_OUT);
1784                 }
1785         }
1786         pin = spec->autocfg.dig_in_pin;
1787         if (pin)
1788                 snd_hda_codec_write(codec, pin, 0,
1789                                     AC_VERB_SET_PIN_WIDGET_CONTROL,
1790                                     PIN_IN);
1791 }
1792
1793 /* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1794 static void alc_auto_parse_digital(struct hda_codec *codec)
1795 {
1796         struct alc_spec *spec = codec->spec;
1797         int i, err;
1798         hda_nid_t dig_nid;
1799
1800         /* support multiple SPDIFs; the secondary is set up as a slave */
1801         for (i = 0; i < spec->autocfg.dig_outs; i++) {
1802                 err = snd_hda_get_connections(codec,
1803                                               spec->autocfg.dig_out_pins[i],
1804                                               &dig_nid, 1);
1805                 if (err < 0)
1806                         continue;
1807                 if (!i) {
1808                         spec->multiout.dig_out_nid = dig_nid;
1809                         spec->dig_out_type = spec->autocfg.dig_out_type[0];
1810                 } else {
1811                         spec->multiout.slave_dig_outs = spec->slave_dig_outs;
1812                         if (i >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
1813                                 break;
1814                         spec->slave_dig_outs[i - 1] = dig_nid;
1815                 }
1816         }
1817
1818         if (spec->autocfg.dig_in_pin) {
1819                 dig_nid = codec->start_nid;
1820                 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1821                         unsigned int wcaps = get_wcaps(codec, dig_nid);
1822                         if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1823                                 continue;
1824                         if (!(wcaps & AC_WCAP_DIGITAL))
1825                                 continue;
1826                         if (!(wcaps & AC_WCAP_CONN_LIST))
1827                                 continue;
1828                         err = get_connection_index(codec, dig_nid,
1829                                                    spec->autocfg.dig_in_pin);
1830                         if (err >= 0) {
1831                                 spec->dig_in_nid = dig_nid;
1832                                 break;
1833                         }
1834                 }
1835         }
1836 }
1837
1838 /*
1839  * ALC888
1840  */
1841
1842 /*
1843  * 2ch mode
1844  */
1845 static struct hda_verb alc888_4ST_ch2_intel_init[] = {
1846 /* Mic-in jack as mic in */
1847         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1848         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1849 /* Line-in jack as Line in */
1850         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1851         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1852 /* Line-Out as Front */
1853         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1854         { } /* end */
1855 };
1856
1857 /*
1858  * 4ch mode
1859  */
1860 static struct hda_verb alc888_4ST_ch4_intel_init[] = {
1861 /* Mic-in jack as mic in */
1862         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1863         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1864 /* Line-in jack as Surround */
1865         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1866         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1867 /* Line-Out as Front */
1868         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1869         { } /* end */
1870 };
1871
1872 /*
1873  * 6ch mode
1874  */
1875 static struct hda_verb alc888_4ST_ch6_intel_init[] = {
1876 /* Mic-in jack as CLFE */
1877         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1878         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1879 /* Line-in jack as Surround */
1880         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1881         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1882 /* Line-Out as CLFE (workaround because Mic-in is not loud enough) */
1883         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1884         { } /* end */
1885 };
1886
1887 /*
1888  * 8ch mode
1889  */
1890 static struct hda_verb alc888_4ST_ch8_intel_init[] = {
1891 /* Mic-in jack as CLFE */
1892         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1893         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1894 /* Line-in jack as Surround */
1895         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1896         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1897 /* Line-Out as Side */
1898         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1899         { } /* end */
1900 };
1901
1902 static struct hda_channel_mode alc888_4ST_8ch_intel_modes[4] = {
1903         { 2, alc888_4ST_ch2_intel_init },
1904         { 4, alc888_4ST_ch4_intel_init },
1905         { 6, alc888_4ST_ch6_intel_init },
1906         { 8, alc888_4ST_ch8_intel_init },
1907 };
1908
1909 /*
1910  * ALC888 Fujitsu Siemens Amillo xa3530
1911  */
1912
1913 static struct hda_verb alc888_fujitsu_xa3530_verbs[] = {
1914 /* Front Mic: set to PIN_IN (empty by default) */
1915         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1916 /* Connect Internal HP to Front */
1917         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1918         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1919         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1920 /* Connect Bass HP to Front */
1921         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1922         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1923         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1924 /* Connect Line-Out side jack (SPDIF) to Side */
1925         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1926         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1927         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1928 /* Connect Mic jack to CLFE */
1929         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1930         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1931         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},
1932 /* Connect Line-in jack to Surround */
1933         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1934         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1935         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
1936 /* Connect HP out jack to Front */
1937         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1938         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1939         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1940 /* Enable unsolicited event for HP jack and Line-out jack */
1941         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1942         {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1943         {}
1944 };
1945
1946 static void alc_automute_amp(struct hda_codec *codec)
1947 {
1948         alc_automute_speaker(codec, 0);
1949 }
1950
1951 static void alc_automute_amp_unsol_event(struct hda_codec *codec,
1952                                          unsigned int res)
1953 {
1954         if (codec->vendor_id == 0x10ec0880)
1955                 res >>= 28;
1956         else
1957                 res >>= 26;
1958         if (res == ALC880_HP_EVENT)
1959                 alc_automute_amp(codec);
1960 }
1961
1962 static void alc889_automute_setup(struct hda_codec *codec)
1963 {
1964         struct alc_spec *spec = codec->spec;
1965
1966         spec->autocfg.hp_pins[0] = 0x15;
1967         spec->autocfg.speaker_pins[0] = 0x14;
1968         spec->autocfg.speaker_pins[1] = 0x16;
1969         spec->autocfg.speaker_pins[2] = 0x17;
1970         spec->autocfg.speaker_pins[3] = 0x19;
1971         spec->autocfg.speaker_pins[4] = 0x1a;
1972 }
1973
1974 static void alc889_intel_init_hook(struct hda_codec *codec)
1975 {
1976         alc889_coef_init(codec);
1977         alc_automute_amp(codec);
1978 }
1979
1980 static void alc888_fujitsu_xa3530_setup(struct hda_codec *codec)
1981 {
1982         struct alc_spec *spec = codec->spec;
1983
1984         spec->autocfg.hp_pins[0] = 0x17; /* line-out */
1985         spec->autocfg.hp_pins[1] = 0x1b; /* hp */
1986         spec->autocfg.speaker_pins[0] = 0x14; /* speaker */
1987         spec->autocfg.speaker_pins[1] = 0x15; /* bass */
1988 }
1989
1990 /*
1991  * ALC888 Acer Aspire 4930G model
1992  */
1993
1994 static struct hda_verb alc888_acer_aspire_4930g_verbs[] = {
1995 /* Front Mic: set to PIN_IN (empty by default) */
1996         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1997 /* Unselect Front Mic by default in input mixer 3 */
1998         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1999 /* Enable unsolicited event for HP jack */
2000         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
2001 /* Connect Internal HP to front */
2002         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2003         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2004         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
2005 /* Connect HP out to front */
2006         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2007         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2008         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
2009         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
2010         { }
2011 };
2012
2013 /*
2014  * ALC888 Acer Aspire 6530G model
2015  */
2016
2017 static struct hda_verb alc888_acer_aspire_6530g_verbs[] = {
2018 /* Route to built-in subwoofer as well as speakers */
2019         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2020         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2021         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2022         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2023 /* Bias voltage on for external mic port */
2024         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN | PIN_VREF80},
2025 /* Front Mic: set to PIN_IN (empty by default) */
2026         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2027 /* Unselect Front Mic by default in input mixer 3 */
2028         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
2029 /* Enable unsolicited event for HP jack */
2030         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
2031 /* Enable speaker output */
2032         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2033         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2034         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
2035 /* Enable headphone output */
2036         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | PIN_HP},
2037         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2038         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
2039         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
2040         { }
2041 };
2042
2043 /*
2044  *ALC888 Acer Aspire 7730G model
2045  */
2046
2047 static struct hda_verb alc888_acer_aspire_7730G_verbs[] = {
2048 /* Bias voltage on for external mic port */
2049         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN | PIN_VREF80},
2050 /* Front Mic: set to PIN_IN (empty by default) */
2051         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2052 /* Unselect Front Mic by default in input mixer 3 */
2053         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
2054 /* Enable unsolicited event for HP jack */
2055         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
2056 /* Enable speaker output */
2057         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2058         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2059         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
2060 /* Enable headphone output */
2061         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | PIN_HP},
2062         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2063         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
2064         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
2065 /*Enable internal subwoofer */
2066         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2067         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2068         {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
2069         {0x17, AC_VERB_SET_EAPD_BTLENABLE, 2},
2070         { }
2071 };
2072
2073 /*
2074  * ALC889 Acer Aspire 8930G model
2075  */
2076
2077 static struct hda_verb alc889_acer_aspire_8930g_verbs[] = {
2078 /* Front Mic: set to PIN_IN (empty by default) */
2079         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2080 /* Unselect Front Mic by default in input mixer 3 */
2081         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
2082 /* Enable unsolicited event for HP jack */
2083         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
2084 /* Connect Internal Front to Front */
2085         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2086         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2087         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
2088 /* Connect Internal Rear to Rear */
2089         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2090         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2091         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},
2092 /* Connect Internal CLFE to CLFE */
2093         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2094         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2095         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
2096 /* Connect HP out to Front */
2097         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | PIN_HP},
2098         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2099         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
2100 /* Enable all DACs */
2101 /*  DAC DISABLE/MUTE 1? */
2102 /*  setting bits 1-5 disables DAC nids 0x02-0x06 apparently. Init=0x38 */
2103         {0x20, AC_VERB_SET_COEF_INDEX, 0x03},
2104         {0x20, AC_VERB_SET_PROC_COEF, 0x0000},
2105 /*  DAC DISABLE/MUTE 2? */
2106 /*  some bit here disables the other DACs. Init=0x4900 */
2107         {0x20, AC_VERB_SET_COEF_INDEX, 0x08},
2108         {0x20, AC_VERB_SET_PROC_COEF, 0x0000},
2109 /* DMIC fix
2110  * This laptop has a stereo digital microphone. The mics are only 1cm apart
2111  * which makes the stereo useless. However, either the mic or the ALC889
2112  * makes the signal become a difference/sum signal instead of standard
2113  * stereo, which is annoying. So instead we flip this bit which makes the
2114  * codec replicate the sum signal to both channels, turning it into a
2115  * normal mono mic.
2116  */
2117 /*  DMIC_CONTROL? Init value = 0x0001 */
2118         {0x20, AC_VERB_SET_COEF_INDEX, 0x0b},
2119         {0x20, AC_VERB_SET_PROC_COEF, 0x0003},
2120         { }
2121 };
2122
2123 static struct hda_input_mux alc888_2_capture_sources[2] = {
2124         /* Front mic only available on one ADC */
2125         {
2126                 .num_items = 4,
2127                 .items = {
2128                         { "Mic", 0x0 },
2129                         { "Line", 0x2 },
2130                         { "CD", 0x4 },
2131                         { "Front Mic", 0xb },
2132                 },
2133         },
2134         {
2135                 .num_items = 3,
2136                 .items = {
2137                         { "Mic", 0x0 },
2138                         { "Line", 0x2 },
2139                         { "CD", 0x4 },
2140                 },
2141         }
2142 };
2143
2144 static struct hda_input_mux alc888_acer_aspire_6530_sources[2] = {
2145         /* Interal mic only available on one ADC */
2146         {
2147                 .num_items = 5,
2148                 .items = {
2149                         { "Mic", 0x0 },
2150                         { "Line In", 0x2 },
2151                         { "CD", 0x4 },
2152                         { "Input Mix", 0xa },
2153                         { "Internal Mic", 0xb },
2154                 },
2155         },
2156         {
2157                 .num_items = 4,
2158                 .items = {
2159                         { "Mic", 0x0 },
2160                         { "Line In", 0x2 },
2161                         { "CD", 0x4 },
2162                         { "Input Mix", 0xa },
2163                 },
2164         }
2165 };
2166
2167 static struct hda_input_mux alc889_capture_sources[3] = {
2168         /* Digital mic only available on first "ADC" */
2169         {
2170                 .num_items = 5,
2171                 .items = {
2172                         { "Mic", 0x0 },
2173                         { "Line", 0x2 },
2174                         { "CD", 0x4 },
2175                         { "Front Mic", 0xb },
2176                         { "Input Mix", 0xa },
2177                 },
2178         },
2179         {
2180                 .num_items = 4,
2181                 .items = {
2182                         { "Mic", 0x0 },
2183                         { "Line", 0x2 },
2184                         { "CD", 0x4 },
2185                         { "Input Mix", 0xa },
2186                 },
2187         },
2188         {
2189                 .num_items = 4,
2190                 .items = {
2191                         { "Mic", 0x0 },
2192                         { "Line", 0x2 },
2193                         { "CD", 0x4 },
2194                         { "Input Mix", 0xa },
2195                 },
2196         }
2197 };
2198
2199 static struct snd_kcontrol_new alc888_base_mixer[] = {
2200         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2201         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2202         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2203         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2204         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
2205                 HDA_OUTPUT),
2206         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2207         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2208         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2209         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2210         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
2211         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2212         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2213         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2214         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2215         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2216         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
2217         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2218         { } /* end */
2219 };
2220
2221 static struct snd_kcontrol_new alc888_acer_aspire_4930g_mixer[] = {
2222         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2223         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2224         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2225         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2226         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
2227                 HDA_OUTPUT),
2228         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2229         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2230         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2231         HDA_CODEC_VOLUME_MONO("Internal LFE Playback Volume", 0x0f, 1, 0x0, HDA_OUTPUT),
2232         HDA_BIND_MUTE_MONO("Internal LFE Playback Switch", 0x0f, 1, 2, HDA_INPUT),
2233         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2234         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2235         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2236         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2237         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2238         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
2239         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2240         { } /* end */
2241 };
2242
2243 static struct snd_kcontrol_new alc889_acer_aspire_8930g_mixer[] = {
2244         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2245         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2246         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2247         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2248         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
2249                 HDA_OUTPUT),
2250         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2251         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2252         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2253         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2254         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2255         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2256         HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
2257         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2258         { } /* end */
2259 };
2260
2261
2262 static void alc888_acer_aspire_4930g_setup(struct hda_codec *codec)
2263 {
2264         struct alc_spec *spec = codec->spec;
2265
2266         spec->autocfg.hp_pins[0] = 0x15;
2267         spec->autocfg.speaker_pins[0] = 0x14;
2268         spec->autocfg.speaker_pins[1] = 0x16;
2269         spec->autocfg.speaker_pins[2] = 0x17;
2270 }
2271
2272 static void alc888_acer_aspire_6530g_setup(struct hda_codec *codec)
2273 {
2274         struct alc_spec *spec = codec->spec;
2275
2276         spec->autocfg.hp_pins[0] = 0x15;
2277         spec->autocfg.speaker_pins[0] = 0x14;
2278         spec->autocfg.speaker_pins[1] = 0x16;
2279         spec->autocfg.speaker_pins[2] = 0x17;
2280 }
2281
2282 static void alc888_acer_aspire_7730g_setup(struct hda_codec *codec)
2283 {
2284         struct alc_spec *spec = codec->spec;
2285
2286         spec->autocfg.hp_pins[0] = 0x15;
2287         spec->autocfg.speaker_pins[0] = 0x14;
2288         spec->autocfg.speaker_pins[1] = 0x16;
2289         spec->autocfg.speaker_pins[2] = 0x17;
2290 }
2291
2292 static void alc889_acer_aspire_8930g_setup(struct hda_codec *codec)
2293 {
2294         struct alc_spec *spec = codec->spec;
2295
2296         spec->autocfg.hp_pins[0] = 0x15;
2297         spec->autocfg.speaker_pins[0] = 0x14;
2298         spec->autocfg.speaker_pins[1] = 0x16;
2299         spec->autocfg.speaker_pins[2] = 0x1b;
2300 }
2301
2302 /*
2303  * ALC880 3-stack model
2304  *
2305  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
2306  * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
2307  *                 F-Mic = 0x1b, HP = 0x19
2308  */
2309
2310 static hda_nid_t alc880_dac_nids[4] = {
2311         /* front, rear, clfe, rear_surr */
2312         0x02, 0x05, 0x04, 0x03
2313 };
2314
2315 static hda_nid_t alc880_adc_nids[3] = {
2316         /* ADC0-2 */
2317         0x07, 0x08, 0x09,
2318 };
2319
2320 /* The datasheet says the node 0x07 is connected from inputs,
2321  * but it shows zero connection in the real implementation on some devices.
2322  * Note: this is a 915GAV bug, fixed on 915GLV
2323  */
2324 static hda_nid_t alc880_adc_nids_alt[2] = {
2325         /* ADC1-2 */
2326         0x08, 0x09,
2327 };
2328
2329 #define ALC880_DIGOUT_NID       0x06
2330 #define ALC880_DIGIN_NID        0x0a
2331
2332 static struct hda_input_mux alc880_capture_source = {
2333         .num_items = 4,
2334         .items = {
2335                 { "Mic", 0x0 },
2336                 { "Front Mic", 0x3 },
2337                 { "Line", 0x2 },
2338                 { "CD", 0x4 },
2339         },
2340 };
2341
2342 /* channel source setting (2/6 channel selection for 3-stack) */
2343 /* 2ch mode */
2344 static struct hda_verb alc880_threestack_ch2_init[] = {
2345         /* set line-in to input, mute it */
2346         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2347         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2348         /* set mic-in to input vref 80%, mute it */
2349         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2350         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2351         { } /* end */
2352 };
2353
2354 /* 6ch mode */
2355 static struct hda_verb alc880_threestack_ch6_init[] = {
2356         /* set line-in to output, unmute it */
2357         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2358         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2359         /* set mic-in to output, unmute it */
2360         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2361         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2362         { } /* end */
2363 };
2364
2365 static struct hda_channel_mode alc880_threestack_modes[2] = {
2366         { 2, alc880_threestack_ch2_init },
2367         { 6, alc880_threestack_ch6_init },
2368 };
2369
2370 static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
2371         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2372         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2373         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2374         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
2375         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2376         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2377         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2378         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2379         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2380         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2381         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2382         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2383         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2384         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2385         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
2386         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
2387         HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
2388         {
2389                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2390                 .name = "Channel Mode",
2391                 .info = alc_ch_mode_info,
2392                 .get = alc_ch_mode_get,
2393                 .put = alc_ch_mode_put,
2394         },
2395         { } /* end */
2396 };
2397
2398 /* capture mixer elements */
2399 static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
2400                             struct snd_ctl_elem_info *uinfo)
2401 {
2402         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2403         struct alc_spec *spec = codec->spec;
2404         int err;
2405
2406         mutex_lock(&codec->control_mutex);
2407         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
2408                                                       HDA_INPUT);
2409         err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
2410         mutex_unlock(&codec->control_mutex);
2411         return err;
2412 }
2413
2414 static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
2415                            unsigned int size, unsigned int __user *tlv)
2416 {
2417         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2418         struct alc_spec *spec = codec->spec;
2419         int err;
2420
2421         mutex_lock(&codec->control_mutex);
2422         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
2423                                                       HDA_INPUT);
2424         err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
2425         mutex_unlock(&codec->control_mutex);
2426         return err;
2427 }
2428
2429 typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
2430                              struct snd_ctl_elem_value *ucontrol);
2431
2432 static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
2433                                  struct snd_ctl_elem_value *ucontrol,
2434                                  getput_call_t func)
2435 {
2436         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2437         struct alc_spec *spec = codec->spec;
2438         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
2439         int err;
2440
2441         mutex_lock(&codec->control_mutex);
2442         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[adc_idx],
2443                                                       3, 0, HDA_INPUT);
2444         err = func(kcontrol, ucontrol);
2445         mutex_unlock(&codec->control_mutex);
2446         return err;
2447 }
2448
2449 static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
2450                            struct snd_ctl_elem_value *ucontrol)
2451 {
2452         return alc_cap_getput_caller(kcontrol, ucontrol,
2453                                      snd_hda_mixer_amp_volume_get);
2454 }
2455
2456 static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
2457                            struct snd_ctl_elem_value *ucontrol)
2458 {
2459         return alc_cap_getput_caller(kcontrol, ucontrol,
2460                                      snd_hda_mixer_amp_volume_put);
2461 }
2462
2463 /* capture mixer elements */
2464 #define alc_cap_sw_info         snd_ctl_boolean_stereo_info
2465
2466 static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
2467                           struct snd_ctl_elem_value *ucontrol)
2468 {
2469         return alc_cap_getput_caller(kcontrol, ucontrol,
2470                                      snd_hda_mixer_amp_switch_get);
2471 }
2472
2473 static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
2474                           struct snd_ctl_elem_value *ucontrol)
2475 {
2476         return alc_cap_getput_caller(kcontrol, ucontrol,
2477                                      snd_hda_mixer_amp_switch_put);
2478 }
2479
2480 #define _DEFINE_CAPMIX(num) \
2481         { \
2482                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2483                 .name = "Capture Switch", \
2484                 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
2485                 .count = num, \
2486                 .info = alc_cap_sw_info, \
2487                 .get = alc_cap_sw_get, \
2488                 .put = alc_cap_sw_put, \
2489         }, \
2490         { \
2491                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2492                 .name = "Capture Volume", \
2493                 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
2494                            SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
2495                            SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
2496                 .count = num, \
2497                 .info = alc_cap_vol_info, \
2498                 .get = alc_cap_vol_get, \
2499                 .put = alc_cap_vol_put, \
2500                 .tlv = { .c = alc_cap_vol_tlv }, \
2501         }
2502
2503 #define _DEFINE_CAPSRC(num) \
2504         { \
2505                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2506                 /* .name = "Capture Source", */ \
2507                 .name = "Input Source", \
2508                 .count = num, \
2509                 .info = alc_mux_enum_info, \
2510                 .get = alc_mux_enum_get, \
2511                 .put = alc_mux_enum_put, \
2512         }
2513
2514 #define DEFINE_CAPMIX(num) \
2515 static struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
2516         _DEFINE_CAPMIX(num),                                  \
2517         _DEFINE_CAPSRC(num),                                  \
2518         { } /* end */                                         \
2519 }
2520
2521 #define DEFINE_CAPMIX_NOSRC(num) \
2522 static struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
2523         _DEFINE_CAPMIX(num),                                        \
2524         { } /* end */                                               \
2525 }
2526
2527 /* up to three ADCs */
2528 DEFINE_CAPMIX(1);
2529 DEFINE_CAPMIX(2);
2530 DEFINE_CAPMIX(3);
2531 DEFINE_CAPMIX_NOSRC(1);
2532 DEFINE_CAPMIX_NOSRC(2);
2533 DEFINE_CAPMIX_NOSRC(3);
2534
2535 /*
2536  * ALC880 5-stack model
2537  *
2538  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
2539  *      Side = 0x02 (0xd)
2540  * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
2541  *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
2542  */
2543
2544 /* additional mixers to alc880_three_stack_mixer */
2545 static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
2546         HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2547         HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
2548         { } /* end */
2549 };
2550
2551 /* channel source setting (6/8 channel selection for 5-stack) */
2552 /* 6ch mode */
2553 static struct hda_verb alc880_fivestack_ch6_init[] = {
2554         /* set line-in to input, mute it */
2555         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2556         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2557         { } /* end */
2558 };
2559
2560 /* 8ch mode */
2561 static struct hda_verb alc880_fivestack_ch8_init[] = {
2562         /* set line-in to output, unmute it */
2563         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2564         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2565         { } /* end */
2566 };
2567
2568 static struct hda_channel_mode alc880_fivestack_modes[2] = {
2569         { 6, alc880_fivestack_ch6_init },
2570         { 8, alc880_fivestack_ch8_init },
2571 };
2572
2573
2574 /*
2575  * ALC880 6-stack model
2576  *
2577  * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
2578  *      Side = 0x05 (0x0f)
2579  * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
2580  *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
2581  */
2582
2583 static hda_nid_t alc880_6st_dac_nids[4] = {
2584         /* front, rear, clfe, rear_surr */
2585         0x02, 0x03, 0x04, 0x05
2586 };
2587
2588 static struct hda_input_mux alc880_6stack_capture_source = {
2589         .num_items = 4,
2590         .items = {
2591                 { "Mic", 0x0 },
2592                 { "Front Mic", 0x1 },
2593                 { "Line", 0x2 },
2594                 { "CD", 0x4 },
2595         },
2596 };
2597
2598 /* fixed 8-channels */
2599 static struct hda_channel_mode alc880_sixstack_modes[1] = {
2600         { 8, NULL },
2601 };
2602
2603 static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
2604         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2605         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2606         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2607         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2608         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2609         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2610         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2611         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2612         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2613         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
2614         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2615         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2616         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2617         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2618         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2619         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2620         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2621         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2622         {
2623                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2624                 .name = "Channel Mode",
2625                 .info = alc_ch_mode_info,
2626                 .get = alc_ch_mode_get,
2627                 .put = alc_ch_mode_put,
2628         },
2629         { } /* end */
2630 };
2631
2632
2633 /*
2634  * ALC880 W810 model
2635  *
2636  * W810 has rear IO for:
2637  * Front (DAC 02)
2638  * Surround (DAC 03)
2639  * Center/LFE (DAC 04)
2640  * Digital out (06)
2641  *
2642  * The system also has a pair of internal speakers, and a headphone jack.
2643  * These are both connected to Line2 on the codec, hence to DAC 02.
2644  *
2645  * There is a variable resistor to control the speaker or headphone
2646  * volume. This is a hardware-only device without a software API.
2647  *
2648  * Plugging headphones in will disable the internal speakers. This is
2649  * implemented in hardware, not via the driver using jack sense. In
2650  * a similar fashion, plugging into the rear socket marked "front" will
2651  * disable both the speakers and headphones.
2652  *
2653  * For input, there's a microphone jack, and an "audio in" jack.
2654  * These may not do anything useful with this driver yet, because I
2655  * haven't setup any initialization verbs for these yet...
2656  */
2657
2658 static hda_nid_t alc880_w810_dac_nids[3] = {
2659         /* front, rear/surround, clfe */
2660         0x02, 0x03, 0x04
2661 };
2662
2663 /* fixed 6 channels */
2664 static struct hda_channel_mode alc880_w810_modes[1] = {
2665         { 6, NULL }
2666 };
2667
2668 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
2669 static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
2670         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2671         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2672         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2673         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2674         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2675         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2676         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2677         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2678         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
2679         { } /* end */
2680 };
2681
2682
2683 /*
2684  * Z710V model
2685  *
2686  * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
2687  * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
2688  *                 Line = 0x1a
2689  */
2690
2691 static hda_nid_t alc880_z71v_dac_nids[1] = {
2692         0x02
2693 };
2694 #define ALC880_Z71V_HP_DAC      0x03
2695
2696 /* fixed 2 channels */
2697 static struct hda_channel_mode alc880_2_jack_modes[1] = {
2698         { 2, NULL }
2699 };
2700
2701 static struct snd_kcontrol_new alc880_z71v_mixer[] = {
2702         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2703         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2704         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2705         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
2706         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2707         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2708         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2709         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2710         { } /* end */
2711 };
2712
2713
2714 /*
2715  * ALC880 F1734 model
2716  *
2717  * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
2718  * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
2719  */
2720
2721 static hda_nid_t alc880_f1734_dac_nids[1] = {
2722         0x03
2723 };
2724 #define ALC880_F1734_HP_DAC     0x02
2725
2726 static struct snd_kcontrol_new alc880_f1734_mixer[] = {
2727         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2728         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2729         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2730         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2731         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2732         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2733         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2734         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2735         { } /* end */
2736 };
2737
2738 static struct hda_input_mux alc880_f1734_capture_source = {
2739         .num_items = 2,
2740         .items = {
2741                 { "Mic", 0x1 },
2742                 { "CD", 0x4 },
2743         },
2744 };
2745
2746
2747 /*
2748  * ALC880 ASUS model
2749  *
2750  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
2751  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
2752  *  Mic = 0x18, Line = 0x1a
2753  */
2754
2755 #define alc880_asus_dac_nids    alc880_w810_dac_nids    /* identical with w810 */
2756 #define alc880_asus_modes       alc880_threestack_modes /* 2/6 channel mode */
2757
2758 static struct snd_kcontrol_new alc880_asus_mixer[] = {
2759         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2760         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2761         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2762         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2763         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2764         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2765         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2766         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2767         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2768         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2769         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2770         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2771         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2772         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2773         {
2774                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2775                 .name = "Channel Mode",
2776                 .info = alc_ch_mode_info,
2777                 .get = alc_ch_mode_get,
2778                 .put = alc_ch_mode_put,
2779         },
2780         { } /* end */
2781 };
2782
2783 /*
2784  * ALC880 ASUS W1V model
2785  *
2786  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
2787  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
2788  *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
2789  */
2790
2791 /* additional mixers to alc880_asus_mixer */
2792 static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
2793         HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
2794         HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
2795         { } /* end */
2796 };
2797
2798 /* TCL S700 */
2799 static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
2800         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2801         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
2802         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
2803         HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
2804         HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
2805         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
2806         HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
2807         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
2808         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
2809         { } /* end */
2810 };
2811
2812 /* Uniwill */
2813 static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
2814         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2815         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2816         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2817         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2818         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2819         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2820         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2821         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2822         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2823         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2824         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2825         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2826         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2827         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2828         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2829         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2830         {
2831                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2832                 .name = "Channel Mode",
2833                 .info = alc_ch_mode_info,
2834                 .get = alc_ch_mode_get,
2835                 .put = alc_ch_mode_put,
2836         },
2837         { } /* end */
2838 };
2839
2840 static struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
2841         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2842         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2843         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2844         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2845         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2846         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2847         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2848         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2849         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2850         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2851         { } /* end */
2852 };
2853
2854 static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
2855         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2856         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2857         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2858         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2859         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2860         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2861         { } /* end */
2862 };
2863
2864 /*
2865  * virtual master controls
2866  */
2867
2868 /*
2869  * slave controls for virtual master
2870  */
2871 static const char * const alc_slave_vols[] = {
2872         "Front Playback Volume",
2873         "Surround Playback Volume",
2874         "Center Playback Volume",
2875         "LFE Playback Volume",
2876         "Side Playback Volume",
2877         "Headphone Playback Volume",
2878         "Speaker Playback Volume",
2879         "Mono Playback Volume",
2880         "Line-Out Playback Volume",
2881         "PCM Playback Volume",
2882         NULL,
2883 };
2884
2885 static const char * const alc_slave_sws[] = {
2886         "Front Playback Switch",
2887         "Surround Playback Switch",
2888         "Center Playback Switch",
2889         "LFE Playback Switch",
2890         "Side Playback Switch",
2891         "Headphone Playback Switch",
2892         "Speaker Playback Switch",
2893         "Mono Playback Switch",
2894         "IEC958 Playback Switch",
2895         "Line-Out Playback Switch",
2896         "PCM Playback Switch",
2897         NULL,
2898 };
2899
2900 /*
2901  * build control elements
2902  */
2903
2904 #define NID_MAPPING             (-1)
2905
2906 #define SUBDEV_SPEAKER_         (0 << 6)
2907 #define SUBDEV_HP_              (1 << 6)
2908 #define SUBDEV_LINE_            (2 << 6)
2909 #define SUBDEV_SPEAKER(x)       (SUBDEV_SPEAKER_ | ((x) & 0x3f))
2910 #define SUBDEV_HP(x)            (SUBDEV_HP_ | ((x) & 0x3f))
2911 #define SUBDEV_LINE(x)          (SUBDEV_LINE_ | ((x) & 0x3f))
2912
2913 static void alc_free_kctls(struct hda_codec *codec);
2914
2915 #ifdef CONFIG_SND_HDA_INPUT_BEEP
2916 /* additional beep mixers; the actual parameters are overwritten at build */
2917 static struct snd_kcontrol_new alc_beep_mixer[] = {
2918         HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
2919         HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
2920         { } /* end */
2921 };
2922 #endif
2923
2924 static int alc_build_controls(struct hda_codec *codec)
2925 {
2926         struct alc_spec *spec = codec->spec;
2927         struct snd_kcontrol *kctl = NULL;
2928         struct snd_kcontrol_new *knew;
2929         int i, j, err;
2930         unsigned int u;
2931         hda_nid_t nid;
2932
2933         for (i = 0; i < spec->num_mixers; i++) {
2934                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
2935                 if (err < 0)
2936                         return err;
2937         }
2938         if (spec->cap_mixer) {
2939                 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
2940                 if (err < 0)
2941                         return err;
2942         }
2943         if (spec->multiout.dig_out_nid) {
2944                 err = snd_hda_create_spdif_out_ctls(codec,
2945                                                     spec->multiout.dig_out_nid);
2946                 if (err < 0)
2947                         return err;
2948                 if (!spec->no_analog) {
2949                         err = snd_hda_create_spdif_share_sw(codec,
2950                                                             &spec->multiout);
2951                         if (err < 0)
2952                                 return err;
2953                         spec->multiout.share_spdif = 1;
2954                 }
2955         }
2956         if (spec->dig_in_nid) {
2957                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
2958                 if (err < 0)
2959                         return err;
2960         }
2961
2962 #ifdef CONFIG_SND_HDA_INPUT_BEEP
2963         /* create beep controls if needed */
2964         if (spec->beep_amp) {
2965                 struct snd_kcontrol_new *knew;
2966                 for (knew = alc_beep_mixer; knew->name; knew++) {
2967                         struct snd_kcontrol *kctl;
2968                         kctl = snd_ctl_new1(knew, codec);
2969                         if (!kctl)
2970                                 return -ENOMEM;
2971                         kctl->private_value = spec->beep_amp;
2972                         err = snd_hda_ctl_add(codec, 0, kctl);
2973                         if (err < 0)
2974                                 return err;
2975                 }
2976         }
2977 #endif
2978
2979         /* if we have no master control, let's create it */
2980         if (!spec->no_analog &&
2981             !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
2982                 unsigned int vmaster_tlv[4];
2983                 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
2984                                         HDA_OUTPUT, vmaster_tlv);
2985                 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
2986                                           vmaster_tlv, alc_slave_vols);
2987                 if (err < 0)
2988                         return err;
2989         }
2990         if (!spec->no_analog &&
2991             !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
2992                 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
2993                                           NULL, alc_slave_sws);
2994                 if (err < 0)
2995                         return err;
2996         }
2997
2998         /* assign Capture Source enums to NID */
2999         if (spec->capsrc_nids || spec->adc_nids) {
3000                 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
3001                 if (!kctl)
3002                         kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
3003                 for (i = 0; kctl && i < kctl->count; i++) {
3004                         hda_nid_t *nids = spec->capsrc_nids;
3005                         if (!nids)
3006                                 nids = spec->adc_nids;
3007                         err = snd_hda_add_nid(codec, kctl, i, nids[i]);
3008                         if (err < 0)
3009                                 return err;
3010                 }
3011         }
3012         if (spec->cap_mixer) {
3013                 const char *kname = kctl ? kctl->id.name : NULL;
3014                 for (knew = spec->cap_mixer; knew->name; knew++) {
3015                         if (kname && strcmp(knew->name, kname) == 0)
3016                                 continue;
3017                         kctl = snd_hda_find_mixer_ctl(codec, knew->name);
3018                         for (i = 0; kctl && i < kctl->count; i++) {
3019                                 err = snd_hda_add_nid(codec, kctl, i,
3020                                                       spec->adc_nids[i]);
3021                                 if (err < 0)
3022                                         return err;
3023                         }
3024                 }
3025         }
3026
3027         /* other nid->control mapping */
3028         for (i = 0; i < spec->num_mixers; i++) {
3029                 for (knew = spec->mixers[i]; knew->name; knew++) {
3030                         if (knew->iface != NID_MAPPING)
3031                                 continue;
3032                         kctl = snd_hda_find_mixer_ctl(codec, knew->name);
3033                         if (kctl == NULL)
3034                                 continue;
3035                         u = knew->subdevice;
3036                         for (j = 0; j < 4; j++, u >>= 8) {
3037                                 nid = u & 0x3f;
3038                                 if (nid == 0)
3039                                         continue;
3040                                 switch (u & 0xc0) {
3041                                 case SUBDEV_SPEAKER_:
3042                                         nid = spec->autocfg.speaker_pins[nid];
3043                                         break;
3044                                 case SUBDEV_LINE_:
3045                                         nid = spec->autocfg.line_out_pins[nid];
3046                                         break;
3047                                 case SUBDEV_HP_:
3048                                         nid = spec->autocfg.hp_pins[nid];
3049                                         break;
3050                                 default:
3051                                         continue;
3052                                 }
3053                                 err = snd_hda_add_nid(codec, kctl, 0, nid);
3054                                 if (err < 0)
3055                                         return err;
3056                         }
3057                         u = knew->private_value;
3058                         for (j = 0; j < 4; j++, u >>= 8) {
3059                                 nid = u & 0xff;
3060                                 if (nid == 0)
3061                                         continue;
3062                                 err = snd_hda_add_nid(codec, kctl, 0, nid);
3063                                 if (err < 0)
3064                                         return err;
3065                         }
3066                 }
3067         }
3068
3069         alc_free_kctls(codec); /* no longer needed */
3070
3071         return 0;
3072 }
3073
3074
3075 /*
3076  * initialize the codec volumes, etc
3077  */
3078
3079 /*
3080  * generic initialization of ADC, input mixers and output mixers
3081  */
3082 static struct hda_verb alc880_volume_init_verbs[] = {
3083         /*
3084          * Unmute ADC0-2 and set the default input to mic-in
3085          */
3086         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
3087         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3088         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
3089         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3090         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
3091         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3092
3093         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
3094          * mixer widget
3095          * Note: PASD motherboards uses the Line In 2 as the input for front
3096          * panel mic (mic 2)
3097          */
3098         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
3099         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3100         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3101         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3102         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3103         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3104         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
3105         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
3106
3107         /*
3108          * Set up output mixers (0x0c - 0x0f)
3109          */
3110         /* set vol=0 to output mixers */
3111         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3112         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3113         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3114         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3115         /* set up input amps for analog loopback */
3116         /* Amp Indices: DAC = 0, mixer = 1 */
3117         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3118         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3119         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3120         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3121         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3122         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3123         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3124         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3125
3126         { }
3127 };
3128
3129 /*
3130  * 3-stack pin configuration:
3131  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
3132  */
3133 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
3134         /*
3135          * preset connection lists of input pins
3136          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
3137          */
3138         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
3139         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3140         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
3141
3142         /*
3143          * Set pin mode and muting
3144          */
3145         /* set front pin widgets 0x14 for output */
3146         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3147         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3148         /* Mic1 (rear panel) pin widget for input and vref at 80% */
3149         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3150         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3151         /* Mic2 (as headphone out) for HP output */
3152         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3153         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3154         /* Line In pin widget for input */
3155         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3156         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3157         /* Line2 (as front mic) pin widget for input and vref at 80% */
3158         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3159         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3160         /* CD pin widget for input */
3161         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3162
3163         { }
3164 };
3165
3166 /*
3167  * 5-stack pin configuration:
3168  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
3169  * line-in/side = 0x1a, f-mic = 0x1b
3170  */
3171 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
3172         /*
3173          * preset connection lists of input pins
3174          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
3175          */
3176         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3177         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
3178
3179         /*
3180          * Set pin mode and muting
3181          */
3182         /* set pin widgets 0x14-0x17 for output */
3183         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3184         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3185         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3186         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3187         /* unmute pins for output (no gain on this amp) */
3188         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3189         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3190         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3191         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3192
3193         /* Mic1 (rear panel) pin widget for input and vref at 80% */
3194         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3195         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3196         /* Mic2 (as headphone out) for HP output */
3197         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3198         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3199         /* Line In pin widget for input */
3200         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3201         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3202         /* Line2 (as front mic) pin widget for input and vref at 80% */
3203         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3204         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3205         /* CD pin widget for input */
3206         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3207
3208         { }
3209 };
3210
3211 /*
3212  * W810 pin configuration:
3213  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
3214  */
3215 static struct hda_verb alc880_pin_w810_init_verbs[] = {
3216         /* hphone/speaker input selector: front DAC */
3217         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
3218
3219         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3220         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3221         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3222         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3223         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3224         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3225
3226         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3227         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3228
3229         { }
3230 };
3231
3232 /*
3233  * Z71V pin configuration:
3234  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
3235  */
3236 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
3237         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3238         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3239         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3240         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3241
3242         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3243         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3244         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3245         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3246
3247         { }
3248 };
3249
3250 /*
3251  * 6-stack pin configuration:
3252  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
3253  * f-mic = 0x19, line = 0x1a, HP = 0x1b
3254  */
3255 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
3256         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3257
3258         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3259         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3260         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3261         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3262         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3263         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3264         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3265         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3266
3267         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3268         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3269         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3270         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3271         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3272         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3273         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3274         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3275         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3276
3277         { }
3278 };
3279
3280 /*
3281  * Uniwill pin configuration:
3282  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
3283  * line = 0x1a
3284  */
3285 static struct hda_verb alc880_uniwill_init_verbs[] = {
3286         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3287
3288         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3289         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3290         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3291         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3292         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3293         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3294         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3295         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3296         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3297         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3298         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3299         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3300         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3301         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3302
3303         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3304         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3305         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3306         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3307         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3308         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3309         /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
3310         /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
3311         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3312
3313         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3314         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
3315
3316         { }
3317 };
3318
3319 /*
3320 * Uniwill P53
3321 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19,
3322  */
3323 static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
3324         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3325
3326         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3327         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3328         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3329         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3330         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3331         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3332         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3333         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3334         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3335         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3336         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
3337         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
3338
3339         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3340         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3341         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3342         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3343         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3344         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3345
3346         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3347         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
3348
3349         { }
3350 };
3351
3352 static struct hda_verb alc880_beep_init_verbs[] = {
3353         { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
3354         { }
3355 };
3356
3357 /* auto-toggle front mic */
3358 static void alc88x_simple_mic_automute(struct hda_codec *codec)
3359 {
3360         unsigned int present;
3361         unsigned char bits;
3362
3363         present = snd_hda_jack_detect(codec, 0x18);
3364         bits = present ? HDA_AMP_MUTE : 0;
3365         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
3366 }
3367
3368 static void alc880_uniwill_setup(struct hda_codec *codec)
3369 {
3370         struct alc_spec *spec = codec->spec;
3371
3372         spec->autocfg.hp_pins[0] = 0x14;
3373         spec->autocfg.speaker_pins[0] = 0x15;
3374         spec->autocfg.speaker_pins[0] = 0x16;
3375 }
3376
3377 static void alc880_uniwill_init_hook(struct hda_codec *codec)
3378 {
3379         alc_automute_amp(codec);
3380         alc88x_simple_mic_automute(codec);
3381 }
3382
3383 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
3384                                        unsigned int res)
3385 {
3386         /* Looks like the unsol event is incompatible with the standard
3387          * definition.  4bit tag is placed at 28 bit!
3388          */
3389         switch (res >> 28) {
3390         case ALC880_MIC_EVENT:
3391                 alc88x_simple_mic_automute(codec);
3392                 break;
3393         default:
3394                 alc_automute_amp_unsol_event(codec, res);
3395                 break;
3396         }
3397 }
3398
3399 static void alc880_uniwill_p53_setup(struct hda_codec *codec)
3400 {
3401         struct alc_spec *spec = codec->spec;
3402
3403         spec->autocfg.hp_pins[0] = 0x14;
3404         spec->autocfg.speaker_pins[0] = 0x15;
3405 }
3406
3407 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
3408 {
3409         unsigned int present;
3410
3411         present = snd_hda_codec_read(codec, 0x21, 0,
3412                                      AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
3413         present &= HDA_AMP_VOLMASK;
3414         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
3415                                  HDA_AMP_VOLMASK, present);
3416         snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
3417                                  HDA_AMP_VOLMASK, present);
3418 }
3419
3420 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
3421                                            unsigned int res)
3422 {
3423         /* Looks like the unsol event is incompatible with the standard
3424          * definition.  4bit tag is placed at 28 bit!
3425          */
3426         if ((res >> 28) == ALC880_DCVOL_EVENT)
3427                 alc880_uniwill_p53_dcvol_automute(codec);
3428         else
3429                 alc_automute_amp_unsol_event(codec, res);
3430 }
3431
3432 /*
3433  * F1734 pin configuration:
3434  * HP = 0x14, speaker-out = 0x15, mic = 0x18
3435  */
3436 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
3437         {0x07, AC_VERB_SET_CONNECT_SEL, 0x01},
3438         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
3439         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
3440         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
3441         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
3442
3443         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3444         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3445         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3446         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3447
3448         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3449         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3450         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
3451         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3452         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3453         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3454         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3455         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3456         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3457
3458         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
3459         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_DCVOL_EVENT},
3460
3461         { }
3462 };
3463
3464 /*
3465  * ASUS pin configuration:
3466  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
3467  */
3468 static struct hda_verb alc880_pin_asus_init_verbs[] = {
3469         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
3470         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
3471         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
3472         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
3473
3474         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3475         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3476         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3477         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3478         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3479         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3480         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3481         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3482
3483         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3484         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3485         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3486         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3487         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3488         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3489         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3490         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3491         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3492
3493         { }
3494 };
3495
3496 /* Enable GPIO mask and set output */
3497 #define alc880_gpio1_init_verbs alc_gpio1_init_verbs
3498 #define alc880_gpio2_init_verbs alc_gpio2_init_verbs
3499 #define alc880_gpio3_init_verbs alc_gpio3_init_verbs
3500
3501 /* Clevo m520g init */
3502 static struct hda_verb alc880_pin_clevo_init_verbs[] = {
3503         /* headphone output */
3504         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
3505         /* line-out */
3506         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3507         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3508         /* Line-in */
3509         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3510         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3511         /* CD */
3512         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3513         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3514         /* Mic1 (rear panel) */
3515         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3516         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3517         /* Mic2 (front panel) */
3518         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3519         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3520         /* headphone */
3521         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3522         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3523         /* change to EAPD mode */
3524         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
3525         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
3526
3527         { }
3528 };
3529
3530 static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
3531         /* change to EAPD mode */
3532         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
3533         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
3534
3535         /* Headphone output */
3536         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3537         /* Front output*/
3538         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3539         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
3540
3541         /* Line In pin widget for input */
3542         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3543         /* CD pin widget for input */
3544         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3545         /* Mic1 (rear panel) pin widget for input and vref at 80% */
3546         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3547
3548         /* change to EAPD mode */
3549         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
3550         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
3551
3552         { }
3553 };
3554
3555 /*
3556  * LG m1 express dual
3557  *
3558  * Pin assignment:
3559  *   Rear Line-In/Out (blue): 0x14
3560  *   Build-in Mic-In: 0x15
3561  *   Speaker-out: 0x17
3562  *   HP-Out (green): 0x1b
3563  *   Mic-In/Out (red): 0x19
3564  *   SPDIF-Out: 0x1e
3565  */
3566
3567 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
3568 static hda_nid_t alc880_lg_dac_nids[3] = {
3569         0x05, 0x02, 0x03
3570 };
3571
3572 /* seems analog CD is not working */
3573 static struct hda_input_mux alc880_lg_capture_source = {
3574         .num_items = 3,
3575         .items = {
3576                 { "Mic", 0x1 },
3577                 { "Line", 0x5 },
3578                 { "Internal Mic", 0x6 },
3579         },
3580 };
3581
3582 /* 2,4,6 channel modes */
3583 static struct hda_verb alc880_lg_ch2_init[] = {
3584         /* set line-in and mic-in to input */
3585         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
3586         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
3587         { }
3588 };
3589
3590 static struct hda_verb alc880_lg_ch4_init[] = {
3591         /* set line-in to out and mic-in to input */
3592         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
3593         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
3594         { }
3595 };
3596
3597 static struct hda_verb alc880_lg_ch6_init[] = {
3598         /* set line-in and mic-in to output */
3599         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
3600         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
3601         { }
3602 };
3603
3604 static struct hda_channel_mode alc880_lg_ch_modes[3] = {
3605         { 2, alc880_lg_ch2_init },
3606         { 4, alc880_lg_ch4_init },
3607         { 6, alc880_lg_ch6_init },
3608 };
3609
3610 static struct snd_kcontrol_new alc880_lg_mixer[] = {
3611         HDA_CODEC_VOLUME("Front Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3612         HDA_BIND_MUTE("Front Playback Switch", 0x0f, 2, HDA_INPUT),
3613         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3614         HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
3615         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
3616         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
3617         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
3618         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
3619         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
3620         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
3621         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
3622         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
3623         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
3624         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
3625         {
3626                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3627                 .name = "Channel Mode",
3628                 .info = alc_ch_mode_info,
3629                 .get = alc_ch_mode_get,
3630                 .put = alc_ch_mode_put,
3631         },
3632         { } /* end */
3633 };
3634
3635 static struct hda_verb alc880_lg_init_verbs[] = {
3636         /* set capture source to mic-in */
3637         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3638         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3639         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3640         /* mute all amp mixer inputs */
3641         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
3642         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
3643         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
3644         /* line-in to input */
3645         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3646         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3647         /* built-in mic */
3648         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3649         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3650         /* speaker-out */
3651         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3652         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3653         /* mic-in to input */
3654         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
3655         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3656         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3657         /* HP-out */
3658         {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
3659         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3660         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3661         /* jack sense */
3662         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3663         { }
3664 };
3665
3666 /* toggle speaker-output according to the hp-jack state */
3667 static void alc880_lg_setup(struct hda_codec *codec)
3668 {
3669         struct alc_spec *spec = codec->spec;
3670
3671         spec->autocfg.hp_pins[0] = 0x1b;
3672         spec->autocfg.speaker_pins[0] = 0x17;
3673 }
3674
3675 /*
3676  * LG LW20
3677  *
3678  * Pin assignment:
3679  *   Speaker-out: 0x14
3680  *   Mic-In: 0x18
3681  *   Built-in Mic-In: 0x19
3682  *   Line-In: 0x1b
3683  *   HP-Out: 0x1a
3684  *   SPDIF-Out: 0x1e
3685  */
3686
3687 static struct hda_input_mux alc880_lg_lw_capture_source = {
3688         .num_items = 3,
3689         .items = {
3690                 { "Mic", 0x0 },
3691                 { "Internal Mic", 0x1 },
3692                 { "Line In", 0x2 },
3693         },
3694 };
3695
3696 #define alc880_lg_lw_modes alc880_threestack_modes
3697
3698 static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
3699         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3700         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
3701         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3702         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
3703         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
3704         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
3705         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
3706         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
3707         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
3708         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
3709         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
3710         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
3711         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
3712         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
3713         {
3714                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3715                 .name = "Channel Mode",
3716                 .info = alc_ch_mode_info,
3717                 .get = alc_ch_mode_get,
3718                 .put = alc_ch_mode_put,
3719         },
3720         { } /* end */
3721 };
3722
3723 static struct hda_verb alc880_lg_lw_init_verbs[] = {
3724         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3725         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
3726         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
3727
3728         /* set capture source to mic-in */
3729         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3730         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3731         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3732         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
3733         /* speaker-out */
3734         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3735         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3736         /* HP-out */
3737         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3738         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3739         /* mic-in to input */
3740         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3741         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3742         /* built-in mic */
3743         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3744         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3745         /* jack sense */
3746         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3747         { }
3748 };
3749
3750 /* toggle speaker-output according to the hp-jack state */
3751 static void alc880_lg_lw_setup(struct hda_codec *codec)
3752 {
3753         struct alc_spec *spec = codec->spec;
3754
3755         spec->autocfg.hp_pins[0] = 0x1b;
3756         spec->autocfg.speaker_pins[0] = 0x14;
3757 }
3758
3759 static struct snd_kcontrol_new alc880_medion_rim_mixer[] = {
3760         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3761         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
3762         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
3763         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
3764         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
3765         HDA_CODEC_MUTE("Internal Playback Switch", 0x0b, 0x1, HDA_INPUT),
3766         { } /* end */
3767 };
3768
3769 static struct hda_input_mux alc880_medion_rim_capture_source = {
3770         .num_items = 2,
3771         .items = {
3772                 { "Mic", 0x0 },
3773                 { "Internal Mic", 0x1 },
3774         },
3775 };
3776
3777 static struct hda_verb alc880_medion_rim_init_verbs[] = {
3778         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3779
3780         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3781         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3782
3783         /* Mic1 (rear panel) pin widget for input and vref at 80% */
3784         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3785         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3786         /* Mic2 (as headphone out) for HP output */
3787         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3788         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3789         /* Internal Speaker */
3790         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3791         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3792
3793         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
3794         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
3795
3796         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3797         { }
3798 };
3799
3800 /* toggle speaker-output according to the hp-jack state */
3801 static void alc880_medion_rim_automute(struct hda_codec *codec)
3802 {
3803         struct alc_spec *spec = codec->spec;
3804         alc_automute_amp(codec);
3805         /* toggle EAPD */
3806         if (spec->jack_present)
3807                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0);
3808         else
3809                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 2);
3810 }
3811
3812 static void alc880_medion_rim_unsol_event(struct hda_codec *codec,
3813                                           unsigned int res)
3814 {
3815         /* Looks like the unsol event is incompatible with the standard
3816          * definition.  4bit tag is placed at 28 bit!
3817          */
3818         if ((res >> 28) == ALC880_HP_EVENT)
3819                 alc880_medion_rim_automute(codec);
3820 }
3821
3822 static void alc880_medion_rim_setup(struct hda_codec *codec)
3823 {
3824         struct alc_spec *spec = codec->spec;
3825
3826         spec->autocfg.hp_pins[0] = 0x14;
3827         spec->autocfg.speaker_pins[0] = 0x1b;
3828 }
3829
3830 #ifdef CONFIG_SND_HDA_POWER_SAVE
3831 static struct hda_amp_list alc880_loopbacks[] = {
3832         { 0x0b, HDA_INPUT, 0 },
3833         { 0x0b, HDA_INPUT, 1 },
3834         { 0x0b, HDA_INPUT, 2 },
3835         { 0x0b, HDA_INPUT, 3 },
3836         { 0x0b, HDA_INPUT, 4 },
3837         { } /* end */
3838 };
3839
3840 static struct hda_amp_list alc880_lg_loopbacks[] = {
3841         { 0x0b, HDA_INPUT, 1 },
3842         { 0x0b, HDA_INPUT, 6 },
3843         { 0x0b, HDA_INPUT, 7 },
3844         { } /* end */
3845 };
3846 #endif
3847
3848 /*
3849  * Common callbacks
3850  */
3851
3852 static void alc_init_special_input_src(struct hda_codec *codec);
3853
3854 static int alc_init(struct hda_codec *codec)
3855 {
3856         struct alc_spec *spec = codec->spec;
3857         unsigned int i;
3858
3859         alc_fix_pll(codec);
3860         alc_auto_init_amp(codec, spec->init_amp);
3861
3862         for (i = 0; i < spec->num_init_verbs; i++)
3863                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
3864         alc_init_special_input_src(codec);
3865
3866         if (spec->init_hook)
3867                 spec->init_hook(codec);
3868
3869         alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
3870
3871         hda_call_check_power_status(codec, 0x01);
3872         return 0;
3873 }
3874
3875 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
3876 {
3877         struct alc_spec *spec = codec->spec;
3878
3879         if (spec->unsol_event)
3880                 spec->unsol_event(codec, res);
3881 }
3882
3883 #ifdef CONFIG_SND_HDA_POWER_SAVE
3884 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
3885 {
3886         struct alc_spec *spec = codec->spec;
3887         return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
3888 }
3889 #endif
3890
3891 /*
3892  * Analog playback callbacks
3893  */
3894 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
3895                                     struct hda_codec *codec,
3896                                     struct snd_pcm_substream *substream)
3897 {
3898         struct alc_spec *spec = codec->spec;
3899         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
3900                                              hinfo);
3901 }
3902
3903 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3904                                        struct hda_codec *codec,
3905                                        unsigned int stream_tag,
3906                                        unsigned int format,
3907                                        struct snd_pcm_substream *substream)
3908 {
3909         struct alc_spec *spec = codec->spec;
3910         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
3911                                                 stream_tag, format, substream);
3912 }
3913
3914 static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
3915                                        struct hda_codec *codec,
3916                                        struct snd_pcm_substream *substream)
3917 {
3918         struct alc_spec *spec = codec->spec;
3919         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
3920 }
3921
3922 /*
3923  * Digital out
3924  */
3925 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
3926                                         struct hda_codec *codec,
3927                                         struct snd_pcm_substream *substream)
3928 {
3929         struct alc_spec *spec = codec->spec;
3930         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
3931 }
3932
3933 static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3934                                            struct hda_codec *codec,
3935                                            unsigned int stream_tag,
3936                                            unsigned int format,
3937                                            struct snd_pcm_substream *substream)
3938 {
3939         struct alc_spec *spec = codec->spec;
3940         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
3941                                              stream_tag, format, substream);
3942 }
3943
3944 static int alc880_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
3945                                            struct hda_codec *codec,
3946                                            struct snd_pcm_substream *substream)
3947 {
3948         struct alc_spec *spec = codec->spec;
3949         return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
3950 }
3951
3952 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
3953                                          struct hda_codec *codec,
3954                                          struct snd_pcm_substream *substream)
3955 {
3956         struct alc_spec *spec = codec->spec;
3957         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
3958 }
3959
3960 /*
3961  * Analog capture
3962  */
3963 static int alc880_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3964                                       struct hda_codec *codec,
3965                                       unsigned int stream_tag,
3966                                       unsigned int format,
3967                                       struct snd_pcm_substream *substream)
3968 {
3969         struct alc_spec *spec = codec->spec;
3970
3971         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
3972                                    stream_tag, 0, format);
3973         return 0;
3974 }
3975
3976 static int alc880_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3977                                       struct hda_codec *codec,
3978                                       struct snd_pcm_substream *substream)
3979 {
3980         struct alc_spec *spec = codec->spec;
3981
3982         snd_hda_codec_cleanup_stream(codec,
3983                                      spec->adc_nids[substream->number + 1]);
3984         return 0;
3985 }
3986
3987 /* analog capture with dynamic dual-adc changes */
3988 static int dualmic_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3989                                        struct hda_codec *codec,
3990                                        unsigned int stream_tag,
3991                                        unsigned int format,
3992                                        struct snd_pcm_substream *substream)
3993 {
3994         struct alc_spec *spec = codec->spec;
3995         spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
3996         spec->cur_adc_stream_tag = stream_tag;
3997         spec->cur_adc_format = format;
3998         snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
3999         return 0;
4000 }
4001
4002 static int dualmic_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
4003                                        struct hda_codec *codec,
4004                                        struct snd_pcm_substream *substream)
4005 {
4006         struct alc_spec *spec = codec->spec;
4007         snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
4008         spec->cur_adc = 0;
4009         return 0;
4010 }
4011
4012 static struct hda_pcm_stream dualmic_pcm_analog_capture = {
4013         .substreams = 1,
4014         .channels_min = 2,
4015         .channels_max = 2,
4016         .nid = 0, /* fill later */
4017         .ops = {
4018                 .prepare = dualmic_capture_pcm_prepare,
4019                 .cleanup = dualmic_capture_pcm_cleanup
4020         },
4021 };
4022
4023 /*
4024  */
4025 static struct hda_pcm_stream alc880_pcm_analog_playback = {
4026         .substreams = 1,
4027         .channels_min = 2,
4028         .channels_max = 8,
4029         /* NID is set in alc_build_pcms */
4030         .ops = {
4031                 .open = alc880_playback_pcm_open,
4032                 .prepare = alc880_playback_pcm_prepare,
4033                 .cleanup = alc880_playback_pcm_cleanup
4034         },
4035 };
4036
4037 static struct hda_pcm_stream alc880_pcm_analog_capture = {
4038         .substreams = 1,
4039         .channels_min = 2,
4040         .channels_max = 2,
4041         /* NID is set in alc_build_pcms */
4042 };
4043
4044 static struct hda_pcm_stream alc880_pcm_analog_alt_playback = {
4045         .substreams = 1,
4046         .channels_min = 2,
4047         .channels_max = 2,
4048         /* NID is set in alc_build_pcms */
4049 };
4050
4051 static struct hda_pcm_stream alc880_pcm_analog_alt_capture = {
4052         .substreams = 2, /* can be overridden */
4053         .channels_min = 2,
4054         .channels_max = 2,
4055         /* NID is set in alc_build_pcms */
4056         .ops = {
4057                 .prepare = alc880_alt_capture_pcm_prepare,
4058                 .cleanup = alc880_alt_capture_pcm_cleanup
4059         },
4060 };
4061
4062 static struct hda_pcm_stream alc880_pcm_digital_playback = {
4063         .substreams = 1,
4064         .channels_min = 2,
4065         .channels_max = 2,
4066         /* NID is set in alc_build_pcms */
4067         .ops = {
4068                 .open = alc880_dig_playback_pcm_open,
4069                 .close = alc880_dig_playback_pcm_close,
4070                 .prepare = alc880_dig_playback_pcm_prepare,
4071                 .cleanup = alc880_dig_playback_pcm_cleanup
4072         },
4073 };
4074
4075 static struct hda_pcm_stream alc880_pcm_digital_capture = {
4076         .substreams = 1,
4077         .channels_min = 2,
4078         .channels_max = 2,
4079         /* NID is set in alc_build_pcms */
4080 };
4081
4082 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
4083 static struct hda_pcm_stream alc_pcm_null_stream = {
4084         .substreams = 0,
4085         .channels_min = 0,
4086         .channels_max = 0,
4087 };
4088
4089 static int alc_build_pcms(struct hda_codec *codec)
4090 {
4091         struct alc_spec *spec = codec->spec;
4092         struct hda_pcm *info = spec->pcm_rec;
4093         int i;
4094
4095         codec->num_pcms = 1;
4096         codec->pcm_info = info;
4097
4098         if (spec->no_analog)
4099                 goto skip_analog;
4100
4101         snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
4102                  "%s Analog", codec->chip_name);
4103         info->name = spec->stream_name_analog;
4104
4105         if (spec->stream_analog_playback) {
4106                 if (snd_BUG_ON(!spec->multiout.dac_nids))
4107                         return -EINVAL;
4108                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
4109                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
4110         }
4111         if (spec->stream_analog_capture) {
4112                 if (snd_BUG_ON(!spec->adc_nids))
4113                         return -EINVAL;
4114                 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
4115                 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
4116         }
4117
4118         if (spec->channel_mode) {
4119                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
4120                 for (i = 0; i < spec->num_channel_mode; i++) {
4121                         if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
4122                                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
4123                         }
4124                 }
4125         }
4126
4127  skip_analog:
4128         /* SPDIF for stream index #1 */
4129         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
4130                 snprintf(spec->stream_name_digital,
4131                          sizeof(spec->stream_name_digital),
4132                          "%s Digital", codec->chip_name);
4133                 codec->num_pcms = 2;
4134                 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
4135                 info = spec->pcm_rec + 1;
4136                 info->name = spec->stream_name_digital;
4137                 if (spec->dig_out_type)
4138                         info->pcm_type = spec->dig_out_type;
4139                 else
4140                         info->pcm_type = HDA_PCM_TYPE_SPDIF;
4141                 if (spec->multiout.dig_out_nid &&
4142                     spec->stream_digital_playback) {
4143                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
4144                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
4145                 }
4146                 if (spec->dig_in_nid &&
4147                     spec->stream_digital_capture) {
4148                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
4149                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
4150                 }
4151                 /* FIXME: do we need this for all Realtek codec models? */
4152                 codec->spdif_status_reset = 1;
4153         }
4154
4155         if (spec->no_analog)
4156                 return 0;
4157
4158         /* If the use of more than one ADC is requested for the current
4159          * model, configure a second analog capture-only PCM.
4160          */
4161         /* Additional Analaog capture for index #2 */
4162         if ((spec->alt_dac_nid && spec->stream_analog_alt_playback) ||
4163             (spec->num_adc_nids > 1 && spec->stream_analog_alt_capture)) {
4164                 codec->num_pcms = 3;
4165                 info = spec->pcm_rec + 2;
4166                 info->name = spec->stream_name_analog;
4167                 if (spec->alt_dac_nid) {
4168                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
4169                                 *spec->stream_analog_alt_playback;
4170                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
4171                                 spec->alt_dac_nid;
4172                 } else {
4173                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
4174                                 alc_pcm_null_stream;
4175                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
4176                 }
4177                 if (spec->num_adc_nids > 1) {
4178                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
4179                                 *spec->stream_analog_alt_capture;
4180                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
4181                                 spec->adc_nids[1];
4182                         info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
4183                                 spec->num_adc_nids - 1;
4184                 } else {
4185                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
4186                                 alc_pcm_null_stream;
4187                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
4188                 }
4189         }
4190
4191         return 0;
4192 }
4193
4194 static inline void alc_shutup(struct hda_codec *codec)
4195 {
4196         snd_hda_shutup_pins(codec);
4197 }
4198
4199 static void alc_free_kctls(struct hda_codec *codec)
4200 {
4201         struct alc_spec *spec = codec->spec;
4202
4203         if (spec->kctls.list) {
4204                 struct snd_kcontrol_new *kctl = spec->kctls.list;
4205                 int i;
4206                 for (i = 0; i < spec->kctls.used; i++)
4207                         kfree(kctl[i].name);
4208         }
4209         snd_array_free(&spec->kctls);
4210 }
4211
4212 static void alc_free(struct hda_codec *codec)
4213 {
4214         struct alc_spec *spec = codec->spec;
4215
4216         if (!spec)
4217                 return;
4218
4219         alc_shutup(codec);
4220         snd_hda_input_jack_free(codec);
4221         alc_free_kctls(codec);
4222         kfree(spec);
4223         snd_hda_detach_beep_device(codec);
4224 }
4225
4226 #ifdef CONFIG_SND_HDA_POWER_SAVE
4227 static void alc_power_eapd(struct hda_codec *codec)
4228 {
4229         /* We currently only handle front, HP */
4230         switch (codec->vendor_id) {
4231         case 0x10ec0260:
4232                 set_eapd(codec, 0x0f, 0);
4233                 set_eapd(codec, 0x10, 0);
4234                 break;
4235         case 0x10ec0262:
4236         case 0x10ec0267:
4237         case 0x10ec0268:
4238         case 0x10ec0269:
4239         case 0x10ec0270:
4240         case 0x10ec0272:
4241         case 0x10ec0660:
4242         case 0x10ec0662:
4243         case 0x10ec0663:
4244         case 0x10ec0665:
4245         case 0x10ec0862:
4246         case 0x10ec0889:
4247                 set_eapd(codec, 0x14, 0);
4248                 set_eapd(codec, 0x15, 0);
4249                 break;
4250         }
4251 }
4252
4253 static int alc_suspend(struct hda_codec *codec, pm_message_t state)
4254 {
4255         struct alc_spec *spec = codec->spec;
4256         alc_shutup(codec);
4257         if (spec && spec->power_hook)
4258                 spec->power_hook(codec);
4259         return 0;
4260 }
4261 #endif
4262
4263 #ifdef SND_HDA_NEEDS_RESUME
4264 static int alc_resume(struct hda_codec *codec)
4265 {
4266         codec->patch_ops.init(codec);
4267         snd_hda_codec_resume_amp(codec);
4268         snd_hda_codec_resume_cache(codec);
4269         hda_call_check_power_status(codec, 0x01);
4270         return 0;
4271 }
4272 #endif
4273
4274 /*
4275  */
4276 static struct hda_codec_ops alc_patch_ops = {
4277         .build_controls = alc_build_controls,
4278         .build_pcms = alc_build_pcms,
4279         .init = alc_init,
4280         .free = alc_free,
4281         .unsol_event = alc_unsol_event,
4282 #ifdef SND_HDA_NEEDS_RESUME
4283         .resume = alc_resume,
4284 #endif
4285 #ifdef CONFIG_SND_HDA_POWER_SAVE
4286         .suspend = alc_suspend,
4287         .check_power_status = alc_check_power_status,
4288 #endif
4289         .reboot_notify = alc_shutup,
4290 };
4291
4292 /* replace the codec chip_name with the given string */
4293 static int alc_codec_rename(struct hda_codec *codec, const char *name)
4294 {
4295         kfree(codec->chip_name);
4296         codec->chip_name = kstrdup(name, GFP_KERNEL);
4297         if (!codec->chip_name) {
4298                 alc_free(codec);
4299                 return -ENOMEM;
4300         }
4301         return 0;
4302 }
4303
4304 /*
4305  * Test configuration for debugging
4306  *
4307  * Almost all inputs/outputs are enabled.  I/O pins can be configured via
4308  * enum controls.
4309  */
4310 #ifdef CONFIG_SND_DEBUG
4311 static hda_nid_t alc880_test_dac_nids[4] = {
4312         0x02, 0x03, 0x04, 0x05
4313 };
4314
4315 static struct hda_input_mux alc880_test_capture_source = {
4316         .num_items = 7,
4317         .items = {
4318                 { "In-1", 0x0 },
4319                 { "In-2", 0x1 },
4320                 { "In-3", 0x2 },
4321                 { "In-4", 0x3 },
4322                 { "CD", 0x4 },
4323                 { "Front", 0x5 },
4324                 { "Surround", 0x6 },
4325         },
4326 };
4327
4328 static struct hda_channel_mode alc880_test_modes[4] = {
4329         { 2, NULL },
4330         { 4, NULL },
4331         { 6, NULL },
4332         { 8, NULL },
4333 };
4334
4335 static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
4336                                  struct snd_ctl_elem_info *uinfo)
4337 {
4338         static char *texts[] = {
4339                 "N/A", "Line Out", "HP Out",
4340                 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
4341         };
4342         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
4343         uinfo->count = 1;
4344         uinfo->value.enumerated.items = 8;
4345         if (uinfo->value.enumerated.item >= 8)
4346                 uinfo->value.enumerated.item = 7;
4347         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
4348         return 0;
4349 }
4350
4351 static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
4352                                 struct snd_ctl_elem_value *ucontrol)
4353 {
4354         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4355         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
4356         unsigned int pin_ctl, item = 0;
4357
4358         pin_ctl = snd_hda_codec_read(codec, nid, 0,
4359                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4360         if (pin_ctl & AC_PINCTL_OUT_EN) {
4361                 if (pin_ctl & AC_PINCTL_HP_EN)
4362                         item = 2;
4363                 else
4364                         item = 1;
4365         } else if (pin_ctl & AC_PINCTL_IN_EN) {
4366                 switch (pin_ctl & AC_PINCTL_VREFEN) {
4367                 case AC_PINCTL_VREF_HIZ: item = 3; break;
4368                 case AC_PINCTL_VREF_50:  item = 4; break;
4369                 case AC_PINCTL_VREF_GRD: item = 5; break;
4370                 case AC_PINCTL_VREF_80:  item = 6; break;
4371                 case AC_PINCTL_VREF_100: item = 7; break;
4372                 }
4373         }
4374         ucontrol->value.enumerated.item[0] = item;
4375         return 0;
4376 }
4377
4378 static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
4379                                 struct snd_ctl_elem_value *ucontrol)
4380 {
4381         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4382         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
4383         static unsigned int ctls[] = {
4384                 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
4385                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
4386                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
4387                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
4388                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
4389                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
4390         };
4391         unsigned int old_ctl, new_ctl;
4392
4393         old_ctl = snd_hda_codec_read(codec, nid, 0,
4394                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4395         new_ctl = ctls[ucontrol->value.enumerated.item[0]];
4396         if (old_ctl != new_ctl) {
4397                 int val;
4398                 snd_hda_codec_write_cache(codec, nid, 0,
4399                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
4400                                           new_ctl);
4401                 val = ucontrol->value.enumerated.item[0] >= 3 ?
4402                         HDA_AMP_MUTE : 0;
4403                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
4404                                          HDA_AMP_MUTE, val);
4405                 return 1;
4406         }
4407         return 0;
4408 }
4409
4410 static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
4411                                  struct snd_ctl_elem_info *uinfo)
4412 {
4413         static char *texts[] = {
4414                 "Front", "Surround", "CLFE", "Side"
4415         };
4416         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
4417         uinfo->count = 1;
4418         uinfo->value.enumerated.items = 4;
4419         if (uinfo->value.enumerated.item >= 4)
4420                 uinfo->value.enumerated.item = 3;
4421         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
4422         return 0;
4423 }
4424
4425 static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
4426                                 struct snd_ctl_elem_value *ucontrol)
4427 {
4428         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4429         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
4430         unsigned int sel;
4431
4432         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
4433         ucontrol->value.enumerated.item[0] = sel & 3;
4434         return 0;
4435 }
4436
4437 static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
4438                                 struct snd_ctl_elem_value *ucontrol)
4439 {
4440         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4441         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
4442         unsigned int sel;
4443
4444         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
4445         if (ucontrol->value.enumerated.item[0] != sel) {
4446                 sel = ucontrol->value.enumerated.item[0] & 3;
4447                 snd_hda_codec_write_cache(codec, nid, 0,
4448                                           AC_VERB_SET_CONNECT_SEL, sel);
4449                 return 1;
4450         }
4451         return 0;
4452 }
4453
4454 #define PIN_CTL_TEST(xname,nid) {                       \
4455                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
4456                         .name = xname,                 \
4457                         .subdevice = HDA_SUBDEV_NID_FLAG | nid, \
4458                         .info = alc_test_pin_ctl_info, \
4459                         .get = alc_test_pin_ctl_get,   \
4460                         .put = alc_test_pin_ctl_put,   \
4461                         .private_value = nid           \
4462                         }
4463
4464 #define PIN_SRC_TEST(xname,nid) {                       \
4465                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
4466                         .name = xname,                 \
4467                         .subdevice = HDA_SUBDEV_NID_FLAG | nid, \
4468                         .info = alc_test_pin_src_info, \
4469                         .get = alc_test_pin_src_get,   \
4470                         .put = alc_test_pin_src_put,   \
4471                         .private_value = nid           \
4472                         }
4473
4474 static struct snd_kcontrol_new alc880_test_mixer[] = {
4475         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
4476         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
4477         HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
4478         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
4479         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
4480         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
4481         HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
4482         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
4483         PIN_CTL_TEST("Front Pin Mode", 0x14),
4484         PIN_CTL_TEST("Surround Pin Mode", 0x15),
4485         PIN_CTL_TEST("CLFE Pin Mode", 0x16),
4486         PIN_CTL_TEST("Side Pin Mode", 0x17),
4487         PIN_CTL_TEST("In-1 Pin Mode", 0x18),
4488         PIN_CTL_TEST("In-2 Pin Mode", 0x19),
4489         PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
4490         PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
4491         PIN_SRC_TEST("In-1 Pin Source", 0x18),
4492         PIN_SRC_TEST("In-2 Pin Source", 0x19),
4493         PIN_SRC_TEST("In-3 Pin Source", 0x1a),
4494         PIN_SRC_TEST("In-4 Pin Source", 0x1b),
4495         HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
4496         HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
4497         HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
4498         HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
4499         HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
4500         HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
4501         HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
4502         HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
4503         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
4504         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
4505         {
4506                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4507                 .name = "Channel Mode",
4508                 .info = alc_ch_mode_info,
4509                 .get = alc_ch_mode_get,
4510                 .put = alc_ch_mode_put,
4511         },
4512         { } /* end */
4513 };
4514
4515 static struct hda_verb alc880_test_init_verbs[] = {
4516         /* Unmute inputs of 0x0c - 0x0f */
4517         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4518         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4519         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4520         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4521         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4522         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4523         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4524         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4525         /* Vol output for 0x0c-0x0f */
4526         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4527         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4528         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4529         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4530         /* Set output pins 0x14-0x17 */
4531         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4532         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4533         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4534         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4535         /* Unmute output pins 0x14-0x17 */
4536         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4537         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4538         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4539         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4540         /* Set input pins 0x18-0x1c */
4541         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4542         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4543         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4544         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4545         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4546         /* Mute input pins 0x18-0x1b */
4547         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4548         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4549         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4550         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4551         /* ADC set up */
4552         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4553         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
4554         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4555         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
4556         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4557         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
4558         /* Analog input/passthru */
4559         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4560         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4561         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4562         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4563         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4564         { }
4565 };
4566 #endif
4567
4568 /*
4569  */
4570
4571 static const char * const alc880_models[ALC880_MODEL_LAST] = {
4572         [ALC880_3ST]            = "3stack",
4573         [ALC880_TCL_S700]       = "tcl",
4574         [ALC880_3ST_DIG]        = "3stack-digout",
4575         [ALC880_CLEVO]          = "clevo",
4576         [ALC880_5ST]            = "5stack",
4577         [ALC880_5ST_DIG]        = "5stack-digout",
4578         [ALC880_W810]           = "w810",
4579         [ALC880_Z71V]           = "z71v",
4580         [ALC880_6ST]            = "6stack",
4581         [ALC880_6ST_DIG]        = "6stack-digout",
4582         [ALC880_ASUS]           = "asus",
4583         [ALC880_ASUS_W1V]       = "asus-w1v",
4584         [ALC880_ASUS_DIG]       = "asus-dig",
4585         [ALC880_ASUS_DIG2]      = "asus-dig2",
4586         [ALC880_UNIWILL_DIG]    = "uniwill",
4587         [ALC880_UNIWILL_P53]    = "uniwill-p53",
4588         [ALC880_FUJITSU]        = "fujitsu",
4589         [ALC880_F1734]          = "F1734",
4590         [ALC880_LG]             = "lg",
4591         [ALC880_LG_LW]          = "lg-lw",
4592         [ALC880_MEDION_RIM]     = "medion",
4593 #ifdef CONFIG_SND_DEBUG
4594         [ALC880_TEST]           = "test",
4595 #endif
4596         [ALC880_AUTO]           = "auto",
4597 };
4598
4599 static struct snd_pci_quirk alc880_cfg_tbl[] = {
4600         SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
4601         SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
4602         SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
4603         SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
4604         SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
4605         SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
4606         SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
4607         SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
4608         SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
4609         SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
4610         SND_PCI_QUIRK(0x103c, 0x2a09, "HP", ALC880_5ST),
4611         SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
4612         SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
4613         SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
4614         SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
4615         SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
4616         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
4617         SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
4618         /* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
4619         SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
4620         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
4621         SND_PCI_QUIRK(0x1043, 0x814e, "ASUS P5GD1 w/SPDIF", ALC880_6ST_DIG),
4622         SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
4623         SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
4624         SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
4625         SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_ASUS), /* default ASUS */
4626         SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
4627         SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
4628         SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
4629         SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
4630         SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
4631         SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
4632         SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
4633         SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
4634         SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
4635         SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
4636         SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
4637         SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
4638         SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
4639         SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
4640         SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_F1734),
4641         SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
4642         SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
4643         SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
4644         SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_MEDION_RIM),
4645         SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
4646         SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
4647         SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
4648         SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FUJITSU),
4649         SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_F1734),
4650         SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
4651         SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
4652         SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
4653         SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_LG),
4654         SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
4655         SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
4656         SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
4657         SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG), /* broken BIOS */
4658         SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
4659         SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
4660         SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
4661         SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
4662         SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
4663         SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
4664         SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
4665         SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
4666         SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
4667         SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
4668         SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
4669         /* default Intel */
4670         SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_3ST),
4671         SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
4672         SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
4673         {}
4674 };
4675
4676 /*
4677  * ALC880 codec presets
4678  */
4679 static struct alc_config_preset alc880_presets[] = {
4680         [ALC880_3ST] = {
4681                 .mixers = { alc880_three_stack_mixer },
4682                 .init_verbs = { alc880_volume_init_verbs,
4683                                 alc880_pin_3stack_init_verbs },
4684                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4685                 .dac_nids = alc880_dac_nids,
4686                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
4687                 .channel_mode = alc880_threestack_modes,
4688                 .need_dac_fix = 1,
4689                 .input_mux = &alc880_capture_source,
4690         },
4691         [ALC880_3ST_DIG] = {
4692                 .mixers = { alc880_three_stack_mixer },
4693                 .init_verbs = { alc880_volume_init_verbs,
4694                                 alc880_pin_3stack_init_verbs },
4695                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4696                 .dac_nids = alc880_dac_nids,
4697                 .dig_out_nid = ALC880_DIGOUT_NID,
4698                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
4699                 .channel_mode = alc880_threestack_modes,
4700                 .need_dac_fix = 1,
4701                 .input_mux = &alc880_capture_source,
4702         },
4703         [ALC880_TCL_S700] = {
4704                 .mixers = { alc880_tcl_s700_mixer },
4705                 .init_verbs = { alc880_volume_init_verbs,
4706                                 alc880_pin_tcl_S700_init_verbs,
4707                                 alc880_gpio2_init_verbs },
4708                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4709                 .dac_nids = alc880_dac_nids,
4710                 .adc_nids = alc880_adc_nids_alt, /* FIXME: correct? */
4711                 .num_adc_nids = 1, /* single ADC */
4712                 .hp_nid = 0x03,
4713                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4714                 .channel_mode = alc880_2_jack_modes,
4715                 .input_mux = &alc880_capture_source,
4716         },
4717         [ALC880_5ST] = {
4718                 .mixers = { alc880_three_stack_mixer,
4719                             alc880_five_stack_mixer},
4720                 .init_verbs = { alc880_volume_init_verbs,
4721                                 alc880_pin_5stack_init_verbs },
4722                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4723                 .dac_nids = alc880_dac_nids,
4724                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
4725                 .channel_mode = alc880_fivestack_modes,
4726                 .input_mux = &alc880_capture_source,
4727         },
4728         [ALC880_5ST_DIG] = {
4729                 .mixers = { alc880_three_stack_mixer,
4730                             alc880_five_stack_mixer },
4731                 .init_verbs = { alc880_volume_init_verbs,
4732                                 alc880_pin_5stack_init_verbs },
4733                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4734                 .dac_nids = alc880_dac_nids,
4735                 .dig_out_nid = ALC880_DIGOUT_NID,
4736                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
4737                 .channel_mode = alc880_fivestack_modes,
4738                 .input_mux = &alc880_capture_source,
4739         },
4740         [ALC880_6ST] = {
4741                 .mixers = { alc880_six_stack_mixer },
4742                 .init_verbs = { alc880_volume_init_verbs,
4743                                 alc880_pin_6stack_init_verbs },
4744                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
4745                 .dac_nids = alc880_6st_dac_nids,
4746                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
4747                 .channel_mode = alc880_sixstack_modes,
4748                 .input_mux = &alc880_6stack_capture_source,
4749         },
4750         [ALC880_6ST_DIG] = {
4751                 .mixers = { alc880_six_stack_mixer },
4752                 .init_verbs = { alc880_volume_init_verbs,
4753                                 alc880_pin_6stack_init_verbs },
4754                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
4755                 .dac_nids = alc880_6st_dac_nids,
4756                 .dig_out_nid = ALC880_DIGOUT_NID,
4757                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
4758                 .channel_mode = alc880_sixstack_modes,
4759                 .input_mux = &alc880_6stack_capture_source,
4760         },
4761         [ALC880_W810] = {
4762                 .mixers = { alc880_w810_base_mixer },
4763                 .init_verbs = { alc880_volume_init_verbs,
4764                                 alc880_pin_w810_init_verbs,
4765                                 alc880_gpio2_init_verbs },
4766                 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
4767                 .dac_nids = alc880_w810_dac_nids,
4768                 .dig_out_nid = ALC880_DIGOUT_NID,
4769                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
4770                 .channel_mode = alc880_w810_modes,
4771                 .input_mux = &alc880_capture_source,
4772         },
4773         [ALC880_Z71V] = {
4774                 .mixers = { alc880_z71v_mixer },
4775                 .init_verbs = { alc880_volume_init_verbs,
4776                                 alc880_pin_z71v_init_verbs },
4777                 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
4778                 .dac_nids = alc880_z71v_dac_nids,
4779                 .dig_out_nid = ALC880_DIGOUT_NID,
4780                 .hp_nid = 0x03,
4781                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4782                 .channel_mode = alc880_2_jack_modes,
4783                 .input_mux = &alc880_capture_source,
4784         },
4785         [ALC880_F1734] = {
4786                 .mixers = { alc880_f1734_mixer },
4787                 .init_verbs = { alc880_volume_init_verbs,
4788                                 alc880_pin_f1734_init_verbs },
4789                 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
4790                 .dac_nids = alc880_f1734_dac_nids,
4791                 .hp_nid = 0x02,
4792                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4793                 .channel_mode = alc880_2_jack_modes,
4794                 .input_mux = &alc880_f1734_capture_source,
4795                 .unsol_event = alc880_uniwill_p53_unsol_event,
4796                 .setup = alc880_uniwill_p53_setup,
4797                 .init_hook = alc_automute_amp,
4798         },
4799         [ALC880_ASUS] = {
4800                 .mixers = { alc880_asus_mixer },
4801                 .init_verbs = { alc880_volume_init_verbs,
4802                                 alc880_pin_asus_init_verbs,
4803                                 alc880_gpio1_init_verbs },
4804                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4805                 .dac_nids = alc880_asus_dac_nids,
4806                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4807                 .channel_mode = alc880_asus_modes,
4808                 .need_dac_fix = 1,
4809                 .input_mux = &alc880_capture_source,
4810         },
4811         [ALC880_ASUS_DIG] = {
4812                 .mixers = { alc880_asus_mixer },
4813                 .init_verbs = { alc880_volume_init_verbs,
4814                                 alc880_pin_asus_init_verbs,
4815                                 alc880_gpio1_init_verbs },
4816                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4817                 .dac_nids = alc880_asus_dac_nids,
4818                 .dig_out_nid = ALC880_DIGOUT_NID,
4819                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4820                 .channel_mode = alc880_asus_modes,
4821                 .need_dac_fix = 1,
4822                 .input_mux = &alc880_capture_source,
4823         },
4824         [ALC880_ASUS_DIG2] = {
4825                 .mixers = { alc880_asus_mixer },
4826                 .init_verbs = { alc880_volume_init_verbs,
4827                                 alc880_pin_asus_init_verbs,
4828                                 alc880_gpio2_init_verbs }, /* use GPIO2 */
4829                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4830                 .dac_nids = alc880_asus_dac_nids,
4831                 .dig_out_nid = ALC880_DIGOUT_NID,
4832                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4833                 .channel_mode = alc880_asus_modes,
4834                 .need_dac_fix = 1,
4835                 .input_mux = &alc880_capture_source,
4836         },
4837         [ALC880_ASUS_W1V] = {
4838                 .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
4839                 .init_verbs = { alc880_volume_init_verbs,
4840                                 alc880_pin_asus_init_verbs,
4841                                 alc880_gpio1_init_verbs },
4842                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4843                 .dac_nids = alc880_asus_dac_nids,
4844                 .dig_out_nid = ALC880_DIGOUT_NID,
4845                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4846                 .channel_mode = alc880_asus_modes,
4847                 .need_dac_fix = 1,
4848                 .input_mux = &alc880_capture_source,
4849         },
4850         [ALC880_UNIWILL_DIG] = {
4851                 .mixers = { alc880_asus_mixer },
4852                 .init_verbs = { alc880_volume_init_verbs,
4853                                 alc880_pin_asus_init_verbs },
4854                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4855                 .dac_nids = alc880_asus_dac_nids,
4856                 .dig_out_nid = ALC880_DIGOUT_NID,
4857                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4858                 .channel_mode = alc880_asus_modes,
4859                 .need_dac_fix = 1,
4860                 .input_mux = &alc880_capture_source,
4861         },
4862         [ALC880_UNIWILL] = {
4863                 .mixers = { alc880_uniwill_mixer },
4864                 .init_verbs = { alc880_volume_init_verbs,
4865                                 alc880_uniwill_init_verbs },
4866                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4867                 .dac_nids = alc880_asus_dac_nids,
4868                 .dig_out_nid = ALC880_DIGOUT_NID,
4869                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
4870                 .channel_mode = alc880_threestack_modes,
4871                 .need_dac_fix = 1,
4872                 .input_mux = &alc880_capture_source,
4873                 .unsol_event = alc880_uniwill_unsol_event,
4874                 .setup = alc880_uniwill_setup,
4875                 .init_hook = alc880_uniwill_init_hook,
4876         },
4877         [ALC880_UNIWILL_P53] = {
4878                 .mixers = { alc880_uniwill_p53_mixer },
4879                 .init_verbs = { alc880_volume_init_verbs,
4880                                 alc880_uniwill_p53_init_verbs },
4881                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4882                 .dac_nids = alc880_asus_dac_nids,
4883                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
4884                 .channel_mode = alc880_threestack_modes,
4885                 .input_mux = &alc880_capture_source,
4886                 .unsol_event = alc880_uniwill_p53_unsol_event,
4887                 .setup = alc880_uniwill_p53_setup,
4888                 .init_hook = alc_automute_amp,
4889         },
4890         [ALC880_FUJITSU] = {
4891                 .mixers = { alc880_fujitsu_mixer },
4892                 .init_verbs = { alc880_volume_init_verbs,
4893                                 alc880_uniwill_p53_init_verbs,
4894                                 alc880_beep_init_verbs },
4895                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4896                 .dac_nids = alc880_dac_nids,
4897                 .dig_out_nid = ALC880_DIGOUT_NID,
4898                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4899                 .channel_mode = alc880_2_jack_modes,
4900                 .input_mux = &alc880_capture_source,
4901                 .unsol_event = alc880_uniwill_p53_unsol_event,
4902                 .setup = alc880_uniwill_p53_setup,
4903                 .init_hook = alc_automute_amp,
4904         },
4905         [ALC880_CLEVO] = {
4906                 .mixers = { alc880_three_stack_mixer },
4907                 .init_verbs = { alc880_volume_init_verbs,
4908                                 alc880_pin_clevo_init_verbs },
4909                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4910                 .dac_nids = alc880_dac_nids,
4911                 .hp_nid = 0x03,
4912                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
4913                 .channel_mode = alc880_threestack_modes,
4914                 .need_dac_fix = 1,
4915                 .input_mux = &alc880_capture_source,
4916         },
4917         [ALC880_LG] = {
4918                 .mixers = { alc880_lg_mixer },
4919                 .init_verbs = { alc880_volume_init_verbs,
4920                                 alc880_lg_init_verbs },
4921                 .num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
4922                 .dac_nids = alc880_lg_dac_nids,
4923                 .dig_out_nid = ALC880_DIGOUT_NID,
4924                 .num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
4925                 .channel_mode = alc880_lg_ch_modes,
4926                 .need_dac_fix = 1,
4927                 .input_mux = &alc880_lg_capture_source,
4928                 .unsol_event = alc_automute_amp_unsol_event,
4929                 .setup = alc880_lg_setup,
4930                 .init_hook = alc_automute_amp,
4931 #ifdef CONFIG_SND_HDA_POWER_SAVE
4932                 .loopbacks = alc880_lg_loopbacks,
4933 #endif
4934         },
4935         [ALC880_LG_LW] = {
4936                 .mixers = { alc880_lg_lw_mixer },
4937                 .init_verbs = { alc880_volume_init_verbs,
4938                                 alc880_lg_lw_init_verbs },
4939                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4940                 .dac_nids = alc880_dac_nids,
4941                 .dig_out_nid = ALC880_DIGOUT_NID,
4942                 .num_channel_mode = ARRAY_SIZE(alc880_lg_lw_modes),
4943                 .channel_mode = alc880_lg_lw_modes,
4944                 .input_mux = &alc880_lg_lw_capture_source,
4945                 .unsol_event = alc_automute_amp_unsol_event,
4946                 .setup = alc880_lg_lw_setup,
4947                 .init_hook = alc_automute_amp,
4948         },
4949         [ALC880_MEDION_RIM] = {
4950                 .mixers = { alc880_medion_rim_mixer },
4951                 .init_verbs = { alc880_volume_init_verbs,
4952                                 alc880_medion_rim_init_verbs,
4953                                 alc_gpio2_init_verbs },
4954                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4955                 .dac_nids = alc880_dac_nids,
4956                 .dig_out_nid = ALC880_DIGOUT_NID,
4957                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4958                 .channel_mode = alc880_2_jack_modes,
4959                 .input_mux = &alc880_medion_rim_capture_source,
4960                 .unsol_event = alc880_medion_rim_unsol_event,
4961                 .setup = alc880_medion_rim_setup,
4962                 .init_hook = alc880_medion_rim_automute,
4963         },
4964 #ifdef CONFIG_SND_DEBUG
4965         [ALC880_TEST] = {
4966                 .mixers = { alc880_test_mixer },
4967                 .init_verbs = { alc880_test_init_verbs },
4968                 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
4969                 .dac_nids = alc880_test_dac_nids,
4970                 .dig_out_nid = ALC880_DIGOUT_NID,
4971                 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
4972                 .channel_mode = alc880_test_modes,
4973                 .input_mux = &alc880_test_capture_source,
4974         },
4975 #endif
4976 };
4977
4978 /*
4979  * Automatic parse of I/O pins from the BIOS configuration
4980  */
4981
4982 enum {
4983         ALC_CTL_WIDGET_VOL,
4984         ALC_CTL_WIDGET_MUTE,
4985         ALC_CTL_BIND_MUTE,
4986 };
4987 static struct snd_kcontrol_new alc880_control_templates[] = {
4988         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
4989         HDA_CODEC_MUTE(NULL, 0, 0, 0),
4990         HDA_BIND_MUTE(NULL, 0, 0, 0),
4991 };
4992
4993 /* add dynamic controls */
4994 static int add_control(struct alc_spec *spec, int type, const char *name,
4995                        int cidx, unsigned long val)
4996 {
4997         struct snd_kcontrol_new *knew;
4998
4999         snd_array_init(&spec->kctls, sizeof(*knew), 32);
5000         knew = snd_array_new(&spec->kctls);
5001         if (!knew)
5002                 return -ENOMEM;
5003         *knew = alc880_control_templates[type];
5004         knew->name = kstrdup(name, GFP_KERNEL);
5005         if (!knew->name)
5006                 return -ENOMEM;
5007         knew->index = cidx;
5008         if (get_amp_nid_(val))
5009                 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
5010         knew->private_value = val;
5011         return 0;
5012 }
5013
5014 static int add_control_with_pfx(struct alc_spec *spec, int type,
5015                                 const char *pfx, const char *dir,
5016                                 const char *sfx, int cidx, unsigned long val)
5017 {
5018         char name[32];
5019         snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
5020         return add_control(spec, type, name, cidx, val);
5021 }
5022
5023 #define add_pb_vol_ctrl(spec, type, pfx, val)                   \
5024         add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
5025 #define add_pb_sw_ctrl(spec, type, pfx, val)                    \
5026         add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
5027 #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val)                   \
5028         add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
5029 #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val)                    \
5030         add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
5031
5032 #define alc880_is_fixed_pin(nid)        ((nid) >= 0x14 && (nid) <= 0x17)
5033 #define alc880_fixed_pin_idx(nid)       ((nid) - 0x14)
5034 #define alc880_is_multi_pin(nid)        ((nid) >= 0x18)
5035 #define alc880_multi_pin_idx(nid)       ((nid) - 0x18)
5036 #define alc880_idx_to_dac(nid)          ((nid) + 0x02)
5037 #define alc880_dac_to_idx(nid)          ((nid) - 0x02)
5038 #define alc880_idx_to_mixer(nid)        ((nid) + 0x0c)
5039 #define alc880_idx_to_selector(nid)     ((nid) + 0x10)
5040 #define ALC880_PIN_CD_NID               0x1c
5041
5042 /* fill in the dac_nids table from the parsed pin configuration */
5043 static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
5044                                      const struct auto_pin_cfg *cfg)
5045 {
5046         hda_nid_t nid;
5047         int assigned[4];
5048         int i, j;
5049
5050         memset(assigned, 0, sizeof(assigned));
5051         spec->multiout.dac_nids = spec->private_dac_nids;
5052
5053         /* check the pins hardwired to audio widget */
5054         for (i = 0; i < cfg->line_outs; i++) {
5055                 nid = cfg->line_out_pins[i];
5056                 if (alc880_is_fixed_pin(nid)) {
5057                         int idx = alc880_fixed_pin_idx(nid);
5058                         spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
5059                         assigned[idx] = 1;
5060                 }
5061         }
5062         /* left pins can be connect to any audio widget */
5063         for (i = 0; i < cfg->line_outs; i++) {
5064                 nid = cfg->line_out_pins[i];
5065                 if (alc880_is_fixed_pin(nid))
5066                         continue;
5067                 /* search for an empty channel */
5068                 for (j = 0; j < cfg->line_outs; j++) {
5069                         if (!assigned[j]) {
5070                                 spec->multiout.dac_nids[i] =
5071                                         alc880_idx_to_dac(j);
5072                                 assigned[j] = 1;
5073                                 break;
5074                         }
5075                 }
5076         }
5077         spec->multiout.num_dacs = cfg->line_outs;
5078         return 0;
5079 }
5080
5081 static const char *alc_get_line_out_pfx(const struct auto_pin_cfg *cfg,
5082                                         bool can_be_master)
5083 {
5084         if (!cfg->hp_outs && !cfg->speaker_outs && can_be_master)
5085                 return "Master";
5086
5087         switch (cfg->line_out_type) {
5088         case AUTO_PIN_SPEAKER_OUT:
5089                 if (cfg->line_outs == 1)
5090                         return "Speaker";
5091                 break;
5092         case AUTO_PIN_HP_OUT:
5093                 return "Headphone";
5094         default:
5095                 if (cfg->line_outs == 1)
5096                         return "PCM";
5097                 break;
5098         }
5099         return NULL;
5100 }
5101
5102 /* add playback controls from the parsed DAC table */
5103 static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
5104                                              const struct auto_pin_cfg *cfg)
5105 {
5106         static const char * const chname[4] = {
5107                 "Front", "Surround", NULL /*CLFE*/, "Side"
5108         };
5109         const char *pfx = alc_get_line_out_pfx(cfg, false);
5110         hda_nid_t nid;
5111         int i, err;
5112
5113         for (i = 0; i < cfg->line_outs; i++) {
5114                 if (!spec->multiout.dac_nids[i])
5115                         continue;
5116                 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
5117                 if (!pfx && i == 2) {
5118                         /* Center/LFE */
5119                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
5120                                               "Center",
5121                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
5122                                                               HDA_OUTPUT));
5123                         if (err < 0)
5124                                 return err;
5125                         err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
5126                                               "LFE",
5127                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
5128                                                               HDA_OUTPUT));
5129                         if (err < 0)
5130                                 return err;
5131                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
5132                                              "Center",
5133                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
5134                                                               HDA_INPUT));
5135                         if (err < 0)
5136                                 return err;
5137                         err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
5138                                              "LFE",
5139                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
5140                                                               HDA_INPUT));
5141                         if (err < 0)
5142                                 return err;
5143                 } else {
5144                         const char *name = pfx;
5145                         int index = i;
5146                         if (!name) {
5147                                 name = chname[i];
5148                                 index = 0;
5149                         }
5150                         err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL,
5151                                                 name, index,
5152                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
5153                                                               HDA_OUTPUT));
5154                         if (err < 0)
5155                                 return err;
5156                         err = __add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE,
5157                                                name, index,
5158                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
5159                                                               HDA_INPUT));
5160                         if (err < 0)
5161                                 return err;
5162                 }
5163         }
5164         return 0;
5165 }
5166
5167 /* add playback controls for speaker and HP outputs */
5168 static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
5169                                         const char *pfx)
5170 {
5171         hda_nid_t nid;
5172         int err;
5173
5174         if (!pin)
5175                 return 0;
5176
5177         if (alc880_is_fixed_pin(pin)) {
5178                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
5179                 /* specify the DAC as the extra output */
5180                 if (!spec->multiout.hp_nid)
5181                         spec->multiout.hp_nid = nid;
5182                 else
5183                         spec->multiout.extra_out_nid[0] = nid;
5184                 /* control HP volume/switch on the output mixer amp */
5185                 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
5186                 err = add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, pfx,
5187                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
5188                 if (err < 0)
5189                         return err;
5190                 err = add_pb_sw_ctrl(spec, ALC_CTL_BIND_MUTE, pfx,
5191                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
5192                 if (err < 0)
5193                         return err;
5194         } else if (alc880_is_multi_pin(pin)) {
5195                 /* set manual connection */
5196                 /* we have only a switch on HP-out PIN */
5197                 err = add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
5198                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
5199                 if (err < 0)
5200                         return err;
5201         }
5202         return 0;
5203 }
5204
5205 /* create input playback/capture controls for the given pin */
5206 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
5207                             const char *ctlname, int ctlidx,
5208                             int idx, hda_nid_t mix_nid)
5209 {
5210         int err;
5211
5212         err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
5213                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
5214         if (err < 0)
5215                 return err;
5216         err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
5217                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
5218         if (err < 0)
5219                 return err;
5220         return 0;
5221 }
5222
5223 static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
5224 {
5225         unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
5226         return (pincap & AC_PINCAP_IN) != 0;
5227 }
5228
5229 /* create playback/capture controls for input pins */
5230 static int alc_auto_create_input_ctls(struct hda_codec *codec,
5231                                       const struct auto_pin_cfg *cfg,
5232                                       hda_nid_t mixer,
5233                                       hda_nid_t cap1, hda_nid_t cap2)
5234 {
5235         struct alc_spec *spec = codec->spec;
5236         struct hda_input_mux *imux = &spec->private_imux[0];
5237         int i, err, idx, type_idx = 0;
5238         const char *prev_label = NULL;
5239
5240         for (i = 0; i < cfg->num_inputs; i++) {
5241                 hda_nid_t pin;
5242                 const char *label;
5243
5244                 pin = cfg->inputs[i].pin;
5245                 if (!alc_is_input_pin(codec, pin))
5246                         continue;
5247
5248                 label = hda_get_autocfg_input_label(codec, cfg, i);
5249                 if (prev_label && !strcmp(label, prev_label))
5250                         type_idx++;
5251                 else
5252                         type_idx = 0;
5253                 prev_label = label;
5254
5255                 if (mixer) {
5256                         idx = get_connection_index(codec, mixer, pin);
5257                         if (idx >= 0) {
5258                                 err = new_analog_input(spec, pin,
5259                                                        label, type_idx,
5260                                                        idx, mixer);
5261                                 if (err < 0)
5262                                         return err;
5263                         }
5264                 }
5265
5266                 if (!cap1)
5267                         continue;
5268                 idx = get_connection_index(codec, cap1, pin);
5269                 if (idx < 0 && cap2)
5270                         idx = get_connection_index(codec, cap2, pin);
5271                 if (idx >= 0)
5272                         snd_hda_add_imux_item(imux, label, idx, NULL);
5273         }
5274         return 0;
5275 }
5276
5277 static int alc880_auto_create_input_ctls(struct hda_codec *codec,
5278                                                 const struct auto_pin_cfg *cfg)
5279 {
5280         return alc_auto_create_input_ctls(codec, cfg, 0x0b, 0x08, 0x09);
5281 }
5282
5283 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
5284                                unsigned int pin_type)
5285 {
5286         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5287                             pin_type);
5288         /* unmute pin */
5289         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
5290                             AMP_OUT_UNMUTE);
5291 }
5292
5293 static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
5294                                               hda_nid_t nid, int pin_type,
5295                                               int dac_idx)
5296 {
5297         alc_set_pin_output(codec, nid, pin_type);
5298         /* need the manual connection? */
5299         if (alc880_is_multi_pin(nid)) {
5300                 struct alc_spec *spec = codec->spec;
5301                 int idx = alc880_multi_pin_idx(nid);
5302                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
5303                                     AC_VERB_SET_CONNECT_SEL,
5304                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
5305         }
5306 }
5307
5308 static int get_pin_type(int line_out_type)
5309 {
5310         if (line_out_type == AUTO_PIN_HP_OUT)
5311                 return PIN_HP;
5312         else
5313                 return PIN_OUT;
5314 }
5315
5316 static void alc880_auto_init_multi_out(struct hda_codec *codec)
5317 {
5318         struct alc_spec *spec = codec->spec;
5319         int i;
5320
5321         for (i = 0; i < spec->autocfg.line_outs; i++) {
5322                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
5323                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
5324                 alc880_auto_set_output_and_unmute(codec, nid, pin_type, i);
5325         }
5326 }
5327
5328 static void alc880_auto_init_extra_out(struct hda_codec *codec)
5329 {
5330         struct alc_spec *spec = codec->spec;
5331         hda_nid_t pin;
5332
5333         pin = spec->autocfg.speaker_pins[0];
5334         if (pin) /* connect to front */
5335                 alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
5336         pin = spec->autocfg.hp_pins[0];
5337         if (pin) /* connect to front */
5338                 alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
5339 }
5340
5341 static void alc880_auto_init_analog_input(struct hda_codec *codec)
5342 {
5343         struct alc_spec *spec = codec->spec;
5344         struct auto_pin_cfg *cfg = &spec->autocfg;
5345         int i;
5346
5347         for (i = 0; i < cfg->num_inputs; i++) {
5348                 hda_nid_t nid = cfg->inputs[i].pin;
5349                 if (alc_is_input_pin(codec, nid)) {
5350                         alc_set_input_pin(codec, nid, cfg->inputs[i].type);
5351                         if (nid != ALC880_PIN_CD_NID &&
5352                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
5353                                 snd_hda_codec_write(codec, nid, 0,
5354                                                     AC_VERB_SET_AMP_GAIN_MUTE,
5355                                                     AMP_OUT_MUTE);
5356                 }
5357         }
5358 }
5359
5360 static void alc880_auto_init_input_src(struct hda_codec *codec)
5361 {
5362         struct alc_spec *spec = codec->spec;
5363         int c;
5364
5365         for (c = 0; c < spec->num_adc_nids; c++) {
5366                 unsigned int mux_idx;
5367                 const struct hda_input_mux *imux;
5368                 mux_idx = c >= spec->num_mux_defs ? 0 : c;
5369                 imux = &spec->input_mux[mux_idx];
5370                 if (!imux->num_items && mux_idx > 0)
5371                         imux = &spec->input_mux[0];
5372                 if (imux)
5373                         snd_hda_codec_write(codec, spec->adc_nids[c], 0,
5374                                             AC_VERB_SET_CONNECT_SEL,
5375                                             imux->items[0].index);
5376         }
5377 }
5378
5379 /* parse the BIOS configuration and set up the alc_spec */
5380 /* return 1 if successful, 0 if the proper config is not found,
5381  * or a negative error code
5382  */
5383 static int alc880_parse_auto_config(struct hda_codec *codec)
5384 {
5385         struct alc_spec *spec = codec->spec;
5386         int err;
5387         static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
5388
5389         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
5390                                            alc880_ignore);
5391         if (err < 0)
5392                 return err;
5393         if (!spec->autocfg.line_outs)
5394                 return 0; /* can't find valid BIOS pin config */
5395
5396         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
5397         if (err < 0)
5398                 return err;
5399         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
5400         if (err < 0)
5401                 return err;
5402         err = alc880_auto_create_extra_out(spec,
5403                                            spec->autocfg.speaker_pins[0],
5404                                            "Speaker");
5405         if (err < 0)
5406                 return err;
5407         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
5408                                            "Headphone");
5409         if (err < 0)
5410                 return err;
5411         err = alc880_auto_create_input_ctls(codec, &spec->autocfg);
5412         if (err < 0)
5413                 return err;
5414
5415         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
5416
5417         alc_auto_parse_digital(codec);
5418
5419         if (spec->kctls.list)
5420                 add_mixer(spec, spec->kctls.list);
5421
5422         add_verb(spec, alc880_volume_init_verbs);
5423
5424         spec->num_mux_defs = 1;
5425         spec->input_mux = &spec->private_imux[0];
5426
5427         alc_ssid_check(codec, 0x15, 0x1b, 0x14, 0);
5428
5429         return 1;
5430 }
5431
5432 /* additional initialization for auto-configuration model */
5433 static void alc880_auto_init(struct hda_codec *codec)
5434 {
5435         struct alc_spec *spec = codec->spec;
5436         alc880_auto_init_multi_out(codec);
5437         alc880_auto_init_extra_out(codec);
5438         alc880_auto_init_analog_input(codec);
5439         alc880_auto_init_input_src(codec);
5440         alc_auto_init_digital(codec);
5441         if (spec->unsol_event)
5442                 alc_inithook(codec);
5443 }
5444
5445 /* check the ADC/MUX contains all input pins; some ADC/MUX contains only
5446  * one of two digital mic pins, e.g. on ALC272
5447  */
5448 static void fixup_automic_adc(struct hda_codec *codec)
5449 {
5450         struct alc_spec *spec = codec->spec;
5451         int i;
5452
5453         for (i = 0; i < spec->num_adc_nids; i++) {
5454                 hda_nid_t cap = spec->capsrc_nids ?
5455                         spec->capsrc_nids[i] : spec->adc_nids[i];
5456                 int iidx, eidx;
5457
5458                 iidx = get_connection_index(codec, cap, spec->int_mic.pin);
5459                 if (iidx < 0)
5460                         continue;
5461                 eidx = get_connection_index(codec, cap, spec->ext_mic.pin);
5462                 if (eidx < 0)
5463                         continue;
5464                 spec->int_mic.mux_idx = iidx;
5465                 spec->ext_mic.mux_idx = eidx;
5466                 if (spec->capsrc_nids)
5467                         spec->capsrc_nids += i;
5468                 spec->adc_nids += i;
5469                 spec->num_adc_nids = 1;
5470                 return;
5471         }
5472         snd_printd(KERN_INFO "hda_codec: %s: "
5473                    "No ADC/MUX containing both 0x%x and 0x%x pins\n",
5474                    codec->chip_name, spec->int_mic.pin, spec->ext_mic.pin);
5475         spec->auto_mic = 0; /* disable auto-mic to be sure */
5476 }
5477
5478 /* select or unmute the given capsrc route */
5479 static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
5480                                     int idx)
5481 {
5482         if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
5483                 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
5484                                          HDA_AMP_MUTE, 0);
5485         } else {
5486                 snd_hda_codec_write_cache(codec, cap, 0,
5487                                           AC_VERB_SET_CONNECT_SEL, idx);
5488         }
5489 }
5490
5491 /* set the default connection to that pin */
5492 static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
5493 {
5494         struct alc_spec *spec = codec->spec;
5495         int i;
5496
5497         for (i = 0; i < spec->num_adc_nids; i++) {
5498                 hda_nid_t cap = spec->capsrc_nids ?
5499                         spec->capsrc_nids[i] : spec->adc_nids[i];
5500                 int idx;
5501
5502                 idx = get_connection_index(codec, cap, pin);
5503                 if (idx < 0)
5504                         continue;
5505                 select_or_unmute_capsrc(codec, cap, idx);
5506                 return i; /* return the found index */
5507         }
5508         return -1; /* not found */
5509 }
5510
5511 /* choose the ADC/MUX containing the input pin and initialize the setup */
5512 static void fixup_single_adc(struct hda_codec *codec)
5513 {
5514         struct alc_spec *spec = codec->spec;
5515         struct auto_pin_cfg *cfg = &spec->autocfg;
5516         int i;
5517
5518         /* search for the input pin; there must be only one */
5519         if (cfg->num_inputs != 1)
5520                 return;
5521         i = init_capsrc_for_pin(codec, cfg->inputs[0].pin);
5522         if (i >= 0) {
5523                 /* use only this ADC */
5524                 if (spec->capsrc_nids)
5525                         spec->capsrc_nids += i;
5526                 spec->adc_nids += i;
5527                 spec->num_adc_nids = 1;
5528                 spec->single_input_src = 1;
5529         }
5530 }
5531
5532 /* initialize dual adcs */
5533 static void fixup_dual_adc_switch(struct hda_codec *codec)
5534 {
5535         struct alc_spec *spec = codec->spec;
5536         init_capsrc_for_pin(codec, spec->ext_mic.pin);
5537         init_capsrc_for_pin(codec, spec->int_mic.pin);
5538 }
5539
5540 /* initialize some special cases for input sources */
5541 static void alc_init_special_input_src(struct hda_codec *codec)
5542 {
5543         struct alc_spec *spec = codec->spec;
5544         if (spec->dual_adc_switch)
5545                 fixup_dual_adc_switch(codec);
5546         else if (spec->single_input_src)
5547                 init_capsrc_for_pin(codec, spec->autocfg.inputs[0].pin);
5548 }
5549
5550 static void set_capture_mixer(struct hda_codec *codec)
5551 {
5552         struct alc_spec *spec = codec->spec;
5553         static struct snd_kcontrol_new *caps[2][3] = {
5554                 { alc_capture_mixer_nosrc1,
5555                   alc_capture_mixer_nosrc2,
5556                   alc_capture_mixer_nosrc3 },
5557                 { alc_capture_mixer1,
5558                   alc_capture_mixer2,
5559                   alc_capture_mixer3 },
5560         };
5561         if (spec->num_adc_nids > 0 && spec->num_adc_nids <= 3) {
5562                 int mux = 0;
5563                 int num_adcs = spec->num_adc_nids;
5564                 if (spec->dual_adc_switch)
5565                         num_adcs = 1;
5566                 else if (spec->auto_mic)
5567                         fixup_automic_adc(codec);
5568                 else if (spec->input_mux) {
5569                         if (spec->input_mux->num_items > 1)
5570                                 mux = 1;
5571                         else if (spec->input_mux->num_items == 1)
5572                                 fixup_single_adc(codec);
5573                 }
5574                 spec->cap_mixer = caps[mux][num_adcs - 1];
5575         }
5576 }
5577
5578 /* fill adc_nids (and capsrc_nids) containing all active input pins */
5579 static void fillup_priv_adc_nids(struct hda_codec *codec, hda_nid_t *nids,
5580                                  int num_nids)
5581 {
5582         struct alc_spec *spec = codec->spec;
5583         struct auto_pin_cfg *cfg = &spec->autocfg;
5584         int n;
5585         hda_nid_t fallback_adc = 0, fallback_cap = 0;
5586
5587         for (n = 0; n < num_nids; n++) {
5588                 hda_nid_t adc, cap;
5589                 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
5590                 int nconns, i, j;
5591
5592                 adc = nids[n];
5593                 if (get_wcaps_type(get_wcaps(codec, adc)) != AC_WID_AUD_IN)
5594                         continue;
5595                 cap = adc;
5596                 nconns = snd_hda_get_connections(codec, cap, conn,
5597                                                  ARRAY_SIZE(conn));
5598                 if (nconns == 1) {
5599                         cap = conn[0];
5600                         nconns = snd_hda_get_connections(codec, cap, conn,
5601                                                          ARRAY_SIZE(conn));
5602                 }
5603                 if (nconns <= 0)
5604                         continue;
5605                 if (!fallback_adc) {
5606                         fallback_adc = adc;
5607                         fallback_cap = cap;
5608                 }
5609                 for (i = 0; i < cfg->num_inputs; i++) {
5610                         hda_nid_t nid = cfg->inputs[i].pin;
5611                         for (j = 0; j < nconns; j++) {
5612                                 if (conn[j] == nid)
5613                                         break;
5614                         }
5615                         if (j >= nconns)
5616                                 break;
5617                 }
5618                 if (i >= cfg->num_inputs) {
5619                         int num_adcs = spec->num_adc_nids;
5620                         spec->private_adc_nids[num_adcs] = adc;
5621                         spec->private_capsrc_nids[num_adcs] = cap;
5622                         spec->num_adc_nids++;
5623                         spec->adc_nids = spec->private_adc_nids;
5624                         if (adc != cap)
5625                                 spec->capsrc_nids = spec->private_capsrc_nids;
5626                 }
5627         }
5628         if (!spec->num_adc_nids) {
5629                 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
5630                        " using fallback 0x%x\n",
5631                        codec->chip_name, fallback_adc);
5632                 spec->private_adc_nids[0] = fallback_adc;
5633                 spec->adc_nids = spec->private_adc_nids;
5634                 if (fallback_adc != fallback_cap) {
5635                         spec->private_capsrc_nids[0] = fallback_cap;
5636                         spec->capsrc_nids = spec->private_adc_nids;
5637                 }
5638         }
5639 }
5640
5641 #ifdef CONFIG_SND_HDA_INPUT_BEEP
5642 #define set_beep_amp(spec, nid, idx, dir) \
5643         ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
5644
5645 static struct snd_pci_quirk beep_white_list[] = {
5646         SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
5647         SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
5648         SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
5649         {}
5650 };
5651
5652 static inline int has_cdefine_beep(struct hda_codec *codec)
5653 {
5654         struct alc_spec *spec = codec->spec;
5655         const struct snd_pci_quirk *q;
5656         q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
5657         if (q)
5658                 return q->value;
5659         return spec->cdefine.enable_pcbeep;
5660 }
5661 #else
5662 #define set_beep_amp(spec, nid, idx, dir) /* NOP */
5663 #define has_cdefine_beep(codec)         0
5664 #endif
5665
5666 /*
5667  * OK, here we have finally the patch for ALC880
5668  */
5669
5670 static int patch_alc880(struct hda_codec *codec)
5671 {
5672         struct alc_spec *spec;
5673         int board_config;
5674         int err;
5675
5676         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5677         if (spec == NULL)
5678                 return -ENOMEM;
5679
5680         codec->spec = spec;
5681
5682         board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
5683                                                   alc880_models,
5684                                                   alc880_cfg_tbl);
5685         if (board_config < 0) {
5686                 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5687                        codec->chip_name);
5688                 board_config = ALC880_AUTO;
5689         }
5690
5691         if (board_config == ALC880_AUTO) {
5692                 /* automatic parse from the BIOS config */
5693                 err = alc880_parse_auto_config(codec);
5694                 if (err < 0) {
5695                         alc_free(codec);
5696                         return err;
5697                 } else if (!err) {
5698                         printk(KERN_INFO
5699                                "hda_codec: Cannot set up configuration "
5700                                "from BIOS.  Using 3-stack mode...\n");
5701                         board_config = ALC880_3ST;
5702                 }
5703         }
5704
5705         err = snd_hda_attach_beep_device(codec, 0x1);
5706         if (err < 0) {
5707                 alc_free(codec);
5708                 return err;
5709         }
5710
5711         if (board_config != ALC880_AUTO)
5712                 setup_preset(codec, &alc880_presets[board_config]);
5713
5714         spec->stream_analog_playback = &alc880_pcm_analog_playback;
5715         spec->stream_analog_capture = &alc880_pcm_analog_capture;
5716         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
5717
5718         spec->stream_digital_playback = &alc880_pcm_digital_playback;
5719         spec->stream_digital_capture = &alc880_pcm_digital_capture;
5720
5721         if (!spec->adc_nids && spec->input_mux) {
5722                 /* check whether NID 0x07 is valid */
5723                 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
5724                 /* get type */
5725                 wcap = get_wcaps_type(wcap);
5726                 if (wcap != AC_WID_AUD_IN) {
5727                         spec->adc_nids = alc880_adc_nids_alt;
5728                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
5729                 } else {
5730                         spec->adc_nids = alc880_adc_nids;
5731                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
5732                 }
5733         }
5734         set_capture_mixer(codec);
5735         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5736
5737         spec->vmaster_nid = 0x0c;
5738
5739         codec->patch_ops = alc_patch_ops;
5740         if (board_config == ALC880_AUTO)
5741                 spec->init_hook = alc880_auto_init;
5742 #ifdef CONFIG_SND_HDA_POWER_SAVE
5743         if (!spec->loopback.amplist)
5744                 spec->loopback.amplist = alc880_loopbacks;
5745 #endif
5746
5747         return 0;
5748 }
5749
5750
5751 /*
5752  * ALC260 support
5753  */
5754
5755 static hda_nid_t alc260_dac_nids[1] = {
5756         /* front */
5757         0x02,
5758 };
5759
5760 static hda_nid_t alc260_adc_nids[1] = {
5761         /* ADC0 */
5762         0x04,
5763 };
5764
5765 static hda_nid_t alc260_adc_nids_alt[1] = {
5766         /* ADC1 */
5767         0x05,
5768 };
5769
5770 /* NIDs used when simultaneous access to both ADCs makes sense.  Note that
5771  * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
5772  */
5773 static hda_nid_t alc260_dual_adc_nids[2] = {
5774         /* ADC0, ADC1 */
5775         0x04, 0x05
5776 };
5777
5778 #define ALC260_DIGOUT_NID       0x03
5779 #define ALC260_DIGIN_NID        0x06
5780
5781 static struct hda_input_mux alc260_capture_source = {
5782         .num_items = 4,
5783         .items = {
5784                 { "Mic", 0x0 },
5785                 { "Front Mic", 0x1 },
5786                 { "Line", 0x2 },
5787                 { "CD", 0x4 },
5788         },
5789 };
5790
5791 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
5792  * headphone jack and the internal CD lines since these are the only pins at
5793  * which audio can appear.  For flexibility, also allow the option of
5794  * recording the mixer output on the second ADC (ADC0 doesn't have a
5795  * connection to the mixer output).
5796  */
5797 static struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
5798         {
5799                 .num_items = 3,
5800                 .items = {
5801                         { "Mic/Line", 0x0 },
5802                         { "CD", 0x4 },
5803                         { "Headphone", 0x2 },
5804                 },
5805         },
5806         {
5807                 .num_items = 4,
5808                 .items = {
5809                         { "Mic/Line", 0x0 },
5810                         { "CD", 0x4 },
5811                         { "Headphone", 0x2 },
5812                         { "Mixer", 0x5 },
5813                 },
5814         },
5815
5816 };
5817
5818 /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
5819  * the Fujitsu S702x, but jacks are marked differently.
5820  */
5821 static struct hda_input_mux alc260_acer_capture_sources[2] = {
5822         {
5823                 .num_items = 4,
5824                 .items = {
5825                         { "Mic", 0x0 },
5826                         { "Line", 0x2 },
5827                         { "CD", 0x4 },
5828                         { "Headphone", 0x5 },
5829                 },
5830         },
5831         {
5832                 .num_items = 5,
5833                 .items = {
5834                         { "Mic", 0x0 },
5835                         { "Line", 0x2 },
5836                         { "CD", 0x4 },
5837                         { "Headphone", 0x6 },
5838                         { "Mixer", 0x5 },
5839                 },
5840         },
5841 };
5842
5843 /* Maxdata Favorit 100XS */
5844 static struct hda_input_mux alc260_favorit100_capture_sources[2] = {
5845         {
5846                 .num_items = 2,
5847                 .items = {
5848                         { "Line/Mic", 0x0 },
5849                         { "CD", 0x4 },
5850                 },
5851         },
5852         {
5853                 .num_items = 3,
5854                 .items = {
5855                         { "Line/Mic", 0x0 },
5856                         { "CD", 0x4 },
5857                         { "Mixer", 0x5 },
5858                 },
5859         },
5860 };
5861
5862 /*
5863  * This is just place-holder, so there's something for alc_build_pcms to look
5864  * at when it calculates the maximum number of channels. ALC260 has no mixer
5865  * element which allows changing the channel mode, so the verb list is
5866  * never used.
5867  */
5868 static struct hda_channel_mode alc260_modes[1] = {
5869         { 2, NULL },
5870 };
5871
5872
5873 /* Mixer combinations
5874  *
5875  * basic: base_output + input + pc_beep + capture
5876  * HP: base_output + input + capture_alt
5877  * HP_3013: hp_3013 + input + capture
5878  * fujitsu: fujitsu + capture
5879  * acer: acer + capture
5880  */
5881
5882 static struct snd_kcontrol_new alc260_base_output_mixer[] = {
5883         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5884         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
5885         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5886         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
5887         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
5888         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
5889         { } /* end */
5890 };
5891
5892 static struct snd_kcontrol_new alc260_input_mixer[] = {
5893         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5894         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5895         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
5896         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
5897         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
5898         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
5899         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
5900         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
5901         { } /* end */
5902 };
5903
5904 /* update HP, line and mono out pins according to the master switch */
5905 static void alc260_hp_master_update(struct hda_codec *codec,
5906                                     hda_nid_t hp, hda_nid_t line,
5907                                     hda_nid_t mono)
5908 {
5909         struct alc_spec *spec = codec->spec;
5910         unsigned int val = spec->master_sw ? PIN_HP : 0;
5911         /* change HP and line-out pins */
5912         snd_hda_codec_write(codec, hp, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5913                             val);
5914         snd_hda_codec_write(codec, line, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5915                             val);
5916         /* mono (speaker) depending on the HP jack sense */
5917         val = (val && !spec->jack_present) ? PIN_OUT : 0;
5918         snd_hda_codec_write(codec, mono, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5919                             val);
5920 }
5921
5922 static int alc260_hp_master_sw_get(struct snd_kcontrol *kcontrol,
5923                                    struct snd_ctl_elem_value *ucontrol)
5924 {
5925         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5926         struct alc_spec *spec = codec->spec;
5927         *ucontrol->value.integer.value = spec->master_sw;
5928         return 0;
5929 }
5930
5931 static int alc260_hp_master_sw_put(struct snd_kcontrol *kcontrol,
5932                                    struct snd_ctl_elem_value *ucontrol)
5933 {
5934         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5935         struct alc_spec *spec = codec->spec;
5936         int val = !!*ucontrol->value.integer.value;
5937         hda_nid_t hp, line, mono;
5938
5939         if (val == spec->master_sw)
5940                 return 0;
5941         spec->master_sw = val;
5942         hp = (kcontrol->private_value >> 16) & 0xff;
5943         line = (kcontrol->private_value >> 8) & 0xff;
5944         mono = kcontrol->private_value & 0xff;
5945         alc260_hp_master_update(codec, hp, line, mono);
5946         return 1;
5947 }
5948
5949 static struct snd_kcontrol_new alc260_hp_output_mixer[] = {
5950         {
5951                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5952                 .name = "Master Playback Switch",
5953                 .subdevice = HDA_SUBDEV_NID_FLAG | 0x11,
5954                 .info = snd_ctl_boolean_mono_info,
5955                 .get = alc260_hp_master_sw_get,
5956                 .put = alc260_hp_master_sw_put,
5957                 .private_value = (0x0f << 16) | (0x10 << 8) | 0x11
5958         },
5959     &