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