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