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