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