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