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