ALSA: hda - make alc882_auto_init_input_src aware of selectors
[safe/jmp/linux-2.6] / 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
34 #define ALC880_FRONT_EVENT              0x01
35 #define ALC880_DCVOL_EVENT              0x02
36 #define ALC880_HP_EVENT                 0x04
37 #define ALC880_MIC_EVENT                0x08
38
39 /* ALC880 board config type */
40 enum {
41         ALC880_3ST,
42         ALC880_3ST_DIG,
43         ALC880_5ST,
44         ALC880_5ST_DIG,
45         ALC880_W810,
46         ALC880_Z71V,
47         ALC880_6ST,
48         ALC880_6ST_DIG,
49         ALC880_F1734,
50         ALC880_ASUS,
51         ALC880_ASUS_DIG,
52         ALC880_ASUS_W1V,
53         ALC880_ASUS_DIG2,
54         ALC880_FUJITSU,
55         ALC880_UNIWILL_DIG,
56         ALC880_UNIWILL,
57         ALC880_UNIWILL_P53,
58         ALC880_CLEVO,
59         ALC880_TCL_S700,
60         ALC880_LG,
61         ALC880_LG_LW,
62         ALC880_MEDION_RIM,
63 #ifdef CONFIG_SND_DEBUG
64         ALC880_TEST,
65 #endif
66         ALC880_AUTO,
67         ALC880_MODEL_LAST /* last tag */
68 };
69
70 /* ALC260 models */
71 enum {
72         ALC260_BASIC,
73         ALC260_HP,
74         ALC260_HP_DC7600,
75         ALC260_HP_3013,
76         ALC260_FUJITSU_S702X,
77         ALC260_ACER,
78         ALC260_WILL,
79         ALC260_REPLACER_672V,
80 #ifdef CONFIG_SND_DEBUG
81         ALC260_TEST,
82 #endif
83         ALC260_AUTO,
84         ALC260_MODEL_LAST /* last tag */
85 };
86
87 /* ALC262 models */
88 enum {
89         ALC262_BASIC,
90         ALC262_HIPPO,
91         ALC262_HIPPO_1,
92         ALC262_FUJITSU,
93         ALC262_HP_BPC,
94         ALC262_HP_BPC_D7000_WL,
95         ALC262_HP_BPC_D7000_WF,
96         ALC262_HP_TC_T5735,
97         ALC262_HP_RP5700,
98         ALC262_BENQ_ED8,
99         ALC262_SONY_ASSAMD,
100         ALC262_BENQ_T31,
101         ALC262_ULTRA,
102         ALC262_LENOVO_3000,
103         ALC262_NEC,
104         ALC262_TOSHIBA_S06,
105         ALC262_TOSHIBA_RX1,
106         ALC262_AUTO,
107         ALC262_MODEL_LAST /* last tag */
108 };
109
110 /* ALC268 models */
111 enum {
112         ALC267_QUANTA_IL1,
113         ALC268_3ST,
114         ALC268_TOSHIBA,
115         ALC268_ACER,
116         ALC268_ACER_DMIC,
117         ALC268_ACER_ASPIRE_ONE,
118         ALC268_DELL,
119         ALC268_ZEPTO,
120 #ifdef CONFIG_SND_DEBUG
121         ALC268_TEST,
122 #endif
123         ALC268_AUTO,
124         ALC268_MODEL_LAST /* last tag */
125 };
126
127 /* ALC269 models */
128 enum {
129         ALC269_BASIC,
130         ALC269_QUANTA_FL1,
131         ALC269_ASUS_EEEPC_P703,
132         ALC269_ASUS_EEEPC_P901,
133         ALC269_FUJITSU,
134         ALC269_LIFEBOOK,
135         ALC269_AUTO,
136         ALC269_MODEL_LAST /* last tag */
137 };
138
139 /* ALC861 models */
140 enum {
141         ALC861_3ST,
142         ALC660_3ST,
143         ALC861_3ST_DIG,
144         ALC861_6ST_DIG,
145         ALC861_UNIWILL_M31,
146         ALC861_TOSHIBA,
147         ALC861_ASUS,
148         ALC861_ASUS_LAPTOP,
149         ALC861_AUTO,
150         ALC861_MODEL_LAST,
151 };
152
153 /* ALC861-VD models */
154 enum {
155         ALC660VD_3ST,
156         ALC660VD_3ST_DIG,
157         ALC660VD_ASUS_V1S,
158         ALC861VD_3ST,
159         ALC861VD_3ST_DIG,
160         ALC861VD_6ST_DIG,
161         ALC861VD_LENOVO,
162         ALC861VD_DALLAS,
163         ALC861VD_HP,
164         ALC861VD_AUTO,
165         ALC861VD_MODEL_LAST,
166 };
167
168 /* ALC662 models */
169 enum {
170         ALC662_3ST_2ch_DIG,
171         ALC662_3ST_6ch_DIG,
172         ALC662_3ST_6ch,
173         ALC662_5ST_DIG,
174         ALC662_LENOVO_101E,
175         ALC662_ASUS_EEEPC_P701,
176         ALC662_ASUS_EEEPC_EP20,
177         ALC663_ASUS_M51VA,
178         ALC663_ASUS_G71V,
179         ALC663_ASUS_H13,
180         ALC663_ASUS_G50V,
181         ALC662_ECS,
182         ALC663_ASUS_MODE1,
183         ALC662_ASUS_MODE2,
184         ALC663_ASUS_MODE3,
185         ALC663_ASUS_MODE4,
186         ALC663_ASUS_MODE5,
187         ALC663_ASUS_MODE6,
188         ALC662_AUTO,
189         ALC662_MODEL_LAST,
190 };
191
192 /* ALC882 models */
193 enum {
194         ALC882_3ST_DIG,
195         ALC882_6ST_DIG,
196         ALC882_ARIMA,
197         ALC882_W2JC,
198         ALC882_TARGA,
199         ALC882_ASUS_A7J,
200         ALC882_ASUS_A7M,
201         ALC885_MACPRO,
202         ALC885_MBP3,
203         ALC885_IMAC24,
204         ALC882_AUTO,
205         ALC882_MODEL_LAST,
206 };
207
208 /* ALC883 models */
209 enum {
210         ALC883_3ST_2ch_DIG,
211         ALC883_3ST_6ch_DIG,
212         ALC883_3ST_6ch,
213         ALC883_6ST_DIG,
214         ALC883_TARGA_DIG,
215         ALC883_TARGA_2ch_DIG,
216         ALC883_ACER,
217         ALC883_ACER_ASPIRE,
218         ALC888_ACER_ASPIRE_4930G,
219         ALC883_MEDION,
220         ALC883_MEDION_MD2,
221         ALC883_LAPTOP_EAPD,
222         ALC883_LENOVO_101E_2ch,
223         ALC883_LENOVO_NB0763,
224         ALC888_LENOVO_MS7195_DIG,
225         ALC888_LENOVO_SKY,
226         ALC883_HAIER_W66,
227         ALC888_3ST_HP,
228         ALC888_6ST_DELL,
229         ALC883_MITAC,
230         ALC883_CLEVO_M720,
231         ALC883_FUJITSU_PI2515,
232         ALC888_FUJITSU_XA3530,
233         ALC883_3ST_6ch_INTEL,
234         ALC888_ASUS_M90V,
235         ALC888_ASUS_EEE1601,
236         ALC1200_ASUS_P5Q,
237         ALC883_AUTO,
238         ALC883_MODEL_LAST,
239 };
240
241 /* styles of capture selection */
242 enum {
243         CAPT_MUX = 0,   /* only mux based */
244         CAPT_MIX,       /* only mixer based */
245         CAPT_1MUX_MIX,  /* first mux and other mixers */
246 };
247
248 /* for GPIO Poll */
249 #define GPIO_MASK       0x03
250
251 struct alc_spec {
252         /* codec parameterization */
253         struct snd_kcontrol_new *mixers[5];     /* mixer arrays */
254         unsigned int num_mixers;
255         struct snd_kcontrol_new *cap_mixer;     /* capture mixer */
256
257         const struct hda_verb *init_verbs[5];   /* initialization verbs
258                                                  * don't forget NULL
259                                                  * termination!
260                                                  */
261         unsigned int num_init_verbs;
262
263         char *stream_name_analog;       /* analog PCM stream */
264         struct hda_pcm_stream *stream_analog_playback;
265         struct hda_pcm_stream *stream_analog_capture;
266         struct hda_pcm_stream *stream_analog_alt_playback;
267         struct hda_pcm_stream *stream_analog_alt_capture;
268
269         char *stream_name_digital;      /* digital PCM stream */
270         struct hda_pcm_stream *stream_digital_playback;
271         struct hda_pcm_stream *stream_digital_capture;
272
273         /* playback */
274         struct hda_multi_out multiout;  /* playback set-up
275                                          * max_channels, dacs must be set
276                                          * dig_out_nid and hp_nid are optional
277                                          */
278         hda_nid_t alt_dac_nid;
279         int dig_out_type;
280
281         /* capture */
282         unsigned int num_adc_nids;
283         hda_nid_t *adc_nids;
284         hda_nid_t *capsrc_nids;
285         hda_nid_t dig_in_nid;           /* digital-in NID; optional */
286         int capture_style;              /* capture style (CAPT_*) */
287
288         /* capture source */
289         unsigned int num_mux_defs;
290         const struct hda_input_mux *input_mux;
291         unsigned int cur_mux[3];
292
293         /* channel model */
294         const struct hda_channel_mode *channel_mode;
295         int num_channel_mode;
296         int need_dac_fix;
297
298         /* PCM information */
299         struct hda_pcm pcm_rec[3];      /* used in alc_build_pcms() */
300
301         /* dynamic controls, init_verbs and input_mux */
302         struct auto_pin_cfg autocfg;
303         struct snd_array kctls;
304         struct hda_input_mux private_imux[3];
305         hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
306
307         /* hooks */
308         void (*init_hook)(struct hda_codec *codec);
309         void (*unsol_event)(struct hda_codec *codec, unsigned int res);
310
311         /* for pin sensing */
312         unsigned int sense_updated: 1;
313         unsigned int jack_present: 1;
314         unsigned int master_sw: 1;
315
316         /* other flags */
317         unsigned int no_analog :1; /* digital I/O only */
318
319         /* for virtual master */
320         hda_nid_t vmaster_nid;
321 #ifdef CONFIG_SND_HDA_POWER_SAVE
322         struct hda_loopback_check loopback;
323 #endif
324
325         /* for PLL fix */
326         hda_nid_t pll_nid;
327         unsigned int pll_coef_idx, pll_coef_bit;
328
329 #ifdef SND_HDA_NEEDS_RESUME
330 #define ALC_MAX_PINS    16
331         unsigned int num_pins;
332         hda_nid_t pin_nids[ALC_MAX_PINS];
333         unsigned int pin_cfgs[ALC_MAX_PINS];
334 #endif
335 };
336
337 /*
338  * configuration template - to be copied to the spec instance
339  */
340 struct alc_config_preset {
341         struct snd_kcontrol_new *mixers[5]; /* should be identical size
342                                              * with spec
343                                              */
344         struct snd_kcontrol_new *cap_mixer; /* capture mixer */
345         const struct hda_verb *init_verbs[5];
346         unsigned int num_dacs;
347         hda_nid_t *dac_nids;
348         hda_nid_t dig_out_nid;          /* optional */
349         hda_nid_t hp_nid;               /* optional */
350         unsigned int num_adc_nids;
351         hda_nid_t *adc_nids;
352         hda_nid_t *capsrc_nids;
353         hda_nid_t dig_in_nid;
354         unsigned int num_channel_mode;
355         const struct hda_channel_mode *channel_mode;
356         int need_dac_fix;
357         unsigned int num_mux_defs;
358         const struct hda_input_mux *input_mux;
359         void (*unsol_event)(struct hda_codec *, unsigned int);
360         void (*init_hook)(struct hda_codec *);
361 #ifdef CONFIG_SND_HDA_POWER_SAVE
362         struct hda_amp_list *loopbacks;
363 #endif
364 };
365
366
367 /*
368  * input MUX handling
369  */
370 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
371                              struct snd_ctl_elem_info *uinfo)
372 {
373         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
374         struct alc_spec *spec = codec->spec;
375         unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
376         if (mux_idx >= spec->num_mux_defs)
377                 mux_idx = 0;
378         return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
379 }
380
381 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
382                             struct snd_ctl_elem_value *ucontrol)
383 {
384         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
385         struct alc_spec *spec = codec->spec;
386         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
387
388         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
389         return 0;
390 }
391
392 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
393                             struct snd_ctl_elem_value *ucontrol)
394 {
395         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
396         struct alc_spec *spec = codec->spec;
397         const struct hda_input_mux *imux;
398         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
399         unsigned int mux_idx;
400         hda_nid_t nid = spec->capsrc_nids ?
401                 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
402
403         mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
404         imux = &spec->input_mux[mux_idx];
405
406         if (spec->capture_style &&
407             !(spec->capture_style == CAPT_1MUX_MIX && !adc_idx)) {
408                 /* Matrix-mixer style (e.g. ALC882) */
409                 unsigned int *cur_val = &spec->cur_mux[adc_idx];
410                 unsigned int i, idx;
411
412                 idx = ucontrol->value.enumerated.item[0];
413                 if (idx >= imux->num_items)
414                         idx = imux->num_items - 1;
415                 if (*cur_val == idx)
416                         return 0;
417                 for (i = 0; i < imux->num_items; i++) {
418                         unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
419                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
420                                                  imux->items[i].index,
421                                                  HDA_AMP_MUTE, v);
422                 }
423                 *cur_val = idx;
424                 return 1;
425         } else {
426                 /* MUX style (e.g. ALC880) */
427                 return snd_hda_input_mux_put(codec, imux, ucontrol, nid,
428                                              &spec->cur_mux[adc_idx]);
429         }
430 }
431
432 /*
433  * channel mode setting
434  */
435 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
436                             struct snd_ctl_elem_info *uinfo)
437 {
438         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
439         struct alc_spec *spec = codec->spec;
440         return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
441                                     spec->num_channel_mode);
442 }
443
444 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
445                            struct snd_ctl_elem_value *ucontrol)
446 {
447         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
448         struct alc_spec *spec = codec->spec;
449         return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
450                                    spec->num_channel_mode,
451                                    spec->multiout.max_channels);
452 }
453
454 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
455                            struct snd_ctl_elem_value *ucontrol)
456 {
457         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
458         struct alc_spec *spec = codec->spec;
459         int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
460                                       spec->num_channel_mode,
461                                       &spec->multiout.max_channels);
462         if (err >= 0 && spec->need_dac_fix)
463                 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
464         return err;
465 }
466
467 /*
468  * Control the mode of pin widget settings via the mixer.  "pc" is used
469  * instead of "%" to avoid consequences of accidently treating the % as
470  * being part of a format specifier.  Maximum allowed length of a value is
471  * 63 characters plus NULL terminator.
472  *
473  * Note: some retasking pin complexes seem to ignore requests for input
474  * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
475  * are requested.  Therefore order this list so that this behaviour will not
476  * cause problems when mixer clients move through the enum sequentially.
477  * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
478  * March 2006.
479  */
480 static char *alc_pin_mode_names[] = {
481         "Mic 50pc bias", "Mic 80pc bias",
482         "Line in", "Line out", "Headphone out",
483 };
484 static unsigned char alc_pin_mode_values[] = {
485         PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
486 };
487 /* The control can present all 5 options, or it can limit the options based
488  * in the pin being assumed to be exclusively an input or an output pin.  In
489  * addition, "input" pins may or may not process the mic bias option
490  * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
491  * accept requests for bias as of chip versions up to March 2006) and/or
492  * wiring in the computer.
493  */
494 #define ALC_PIN_DIR_IN              0x00
495 #define ALC_PIN_DIR_OUT             0x01
496 #define ALC_PIN_DIR_INOUT           0x02
497 #define ALC_PIN_DIR_IN_NOMICBIAS    0x03
498 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
499
500 /* Info about the pin modes supported by the different pin direction modes.
501  * For each direction the minimum and maximum values are given.
502  */
503 static signed char alc_pin_mode_dir_info[5][2] = {
504         { 0, 2 },    /* ALC_PIN_DIR_IN */
505         { 3, 4 },    /* ALC_PIN_DIR_OUT */
506         { 0, 4 },    /* ALC_PIN_DIR_INOUT */
507         { 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
508         { 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
509 };
510 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
511 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
512 #define alc_pin_mode_n_items(_dir) \
513         (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
514
515 static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
516                              struct snd_ctl_elem_info *uinfo)
517 {
518         unsigned int item_num = uinfo->value.enumerated.item;
519         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
520
521         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
522         uinfo->count = 1;
523         uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
524
525         if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
526                 item_num = alc_pin_mode_min(dir);
527         strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
528         return 0;
529 }
530
531 static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
532                             struct snd_ctl_elem_value *ucontrol)
533 {
534         unsigned int i;
535         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
536         hda_nid_t nid = kcontrol->private_value & 0xffff;
537         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
538         long *valp = ucontrol->value.integer.value;
539         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
540                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
541                                                  0x00);
542
543         /* Find enumerated value for current pinctl setting */
544         i = alc_pin_mode_min(dir);
545         while (alc_pin_mode_values[i] != pinctl && i <= alc_pin_mode_max(dir))
546                 i++;
547         *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
548         return 0;
549 }
550
551 static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
552                             struct snd_ctl_elem_value *ucontrol)
553 {
554         signed int change;
555         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
556         hda_nid_t nid = kcontrol->private_value & 0xffff;
557         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
558         long val = *ucontrol->value.integer.value;
559         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
560                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
561                                                  0x00);
562
563         if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
564                 val = alc_pin_mode_min(dir);
565
566         change = pinctl != alc_pin_mode_values[val];
567         if (change) {
568                 /* Set pin mode to that requested */
569                 snd_hda_codec_write_cache(codec, nid, 0,
570                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
571                                           alc_pin_mode_values[val]);
572
573                 /* Also enable the retasking pin's input/output as required
574                  * for the requested pin mode.  Enum values of 2 or less are
575                  * input modes.
576                  *
577                  * Dynamically switching the input/output buffers probably
578                  * reduces noise slightly (particularly on input) so we'll
579                  * do it.  However, having both input and output buffers
580                  * enabled simultaneously doesn't seem to be problematic if
581                  * this turns out to be necessary in the future.
582                  */
583                 if (val <= 2) {
584                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
585                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
586                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
587                                                  HDA_AMP_MUTE, 0);
588                 } else {
589                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
590                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
591                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
592                                                  HDA_AMP_MUTE, 0);
593                 }
594         }
595         return change;
596 }
597
598 #define ALC_PIN_MODE(xname, nid, dir) \
599         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
600           .info = alc_pin_mode_info, \
601           .get = alc_pin_mode_get, \
602           .put = alc_pin_mode_put, \
603           .private_value = nid | (dir<<16) }
604
605 /* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
606  * together using a mask with more than one bit set.  This control is
607  * currently used only by the ALC260 test model.  At this stage they are not
608  * needed for any "production" models.
609  */
610 #ifdef CONFIG_SND_DEBUG
611 #define alc_gpio_data_info      snd_ctl_boolean_mono_info
612
613 static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
614                              struct snd_ctl_elem_value *ucontrol)
615 {
616         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
617         hda_nid_t nid = kcontrol->private_value & 0xffff;
618         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
619         long *valp = ucontrol->value.integer.value;
620         unsigned int val = snd_hda_codec_read(codec, nid, 0,
621                                               AC_VERB_GET_GPIO_DATA, 0x00);
622
623         *valp = (val & mask) != 0;
624         return 0;
625 }
626 static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
627                              struct snd_ctl_elem_value *ucontrol)
628 {
629         signed int change;
630         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
631         hda_nid_t nid = kcontrol->private_value & 0xffff;
632         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
633         long val = *ucontrol->value.integer.value;
634         unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
635                                                     AC_VERB_GET_GPIO_DATA,
636                                                     0x00);
637
638         /* Set/unset the masked GPIO bit(s) as needed */
639         change = (val == 0 ? 0 : mask) != (gpio_data & mask);
640         if (val == 0)
641                 gpio_data &= ~mask;
642         else
643                 gpio_data |= mask;
644         snd_hda_codec_write_cache(codec, nid, 0,
645                                   AC_VERB_SET_GPIO_DATA, gpio_data);
646
647         return change;
648 }
649 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
650         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
651           .info = alc_gpio_data_info, \
652           .get = alc_gpio_data_get, \
653           .put = alc_gpio_data_put, \
654           .private_value = nid | (mask<<16) }
655 #endif   /* CONFIG_SND_DEBUG */
656
657 /* A switch control to allow the enabling of the digital IO pins on the
658  * ALC260.  This is incredibly simplistic; the intention of this control is
659  * to provide something in the test model allowing digital outputs to be
660  * identified if present.  If models are found which can utilise these
661  * outputs a more complete mixer control can be devised for those models if
662  * necessary.
663  */
664 #ifdef CONFIG_SND_DEBUG
665 #define alc_spdif_ctrl_info     snd_ctl_boolean_mono_info
666
667 static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
668                               struct snd_ctl_elem_value *ucontrol)
669 {
670         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
671         hda_nid_t nid = kcontrol->private_value & 0xffff;
672         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
673         long *valp = ucontrol->value.integer.value;
674         unsigned int val = snd_hda_codec_read(codec, nid, 0,
675                                               AC_VERB_GET_DIGI_CONVERT_1, 0x00);
676
677         *valp = (val & mask) != 0;
678         return 0;
679 }
680 static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
681                               struct snd_ctl_elem_value *ucontrol)
682 {
683         signed int change;
684         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
685         hda_nid_t nid = kcontrol->private_value & 0xffff;
686         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
687         long val = *ucontrol->value.integer.value;
688         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
689                                                     AC_VERB_GET_DIGI_CONVERT_1,
690                                                     0x00);
691
692         /* Set/unset the masked control bit(s) as needed */
693         change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
694         if (val==0)
695                 ctrl_data &= ~mask;
696         else
697                 ctrl_data |= mask;
698         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
699                                   ctrl_data);
700
701         return change;
702 }
703 #define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
704         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
705           .info = alc_spdif_ctrl_info, \
706           .get = alc_spdif_ctrl_get, \
707           .put = alc_spdif_ctrl_put, \
708           .private_value = nid | (mask<<16) }
709 #endif   /* CONFIG_SND_DEBUG */
710
711 /* A switch control to allow the enabling EAPD digital outputs on the ALC26x.
712  * Again, this is only used in the ALC26x test models to help identify when
713  * the EAPD line must be asserted for features to work.
714  */
715 #ifdef CONFIG_SND_DEBUG
716 #define alc_eapd_ctrl_info      snd_ctl_boolean_mono_info
717
718 static int alc_eapd_ctrl_get(struct snd_kcontrol *kcontrol,
719                               struct snd_ctl_elem_value *ucontrol)
720 {
721         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
722         hda_nid_t nid = kcontrol->private_value & 0xffff;
723         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
724         long *valp = ucontrol->value.integer.value;
725         unsigned int val = snd_hda_codec_read(codec, nid, 0,
726                                               AC_VERB_GET_EAPD_BTLENABLE, 0x00);
727
728         *valp = (val & mask) != 0;
729         return 0;
730 }
731
732 static int alc_eapd_ctrl_put(struct snd_kcontrol *kcontrol,
733                               struct snd_ctl_elem_value *ucontrol)
734 {
735         int change;
736         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
737         hda_nid_t nid = kcontrol->private_value & 0xffff;
738         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
739         long val = *ucontrol->value.integer.value;
740         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
741                                                     AC_VERB_GET_EAPD_BTLENABLE,
742                                                     0x00);
743
744         /* Set/unset the masked control bit(s) as needed */
745         change = (!val ? 0 : mask) != (ctrl_data & mask);
746         if (!val)
747                 ctrl_data &= ~mask;
748         else
749                 ctrl_data |= mask;
750         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
751                                   ctrl_data);
752
753         return change;
754 }
755
756 #define ALC_EAPD_CTRL_SWITCH(xname, nid, mask) \
757         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
758           .info = alc_eapd_ctrl_info, \
759           .get = alc_eapd_ctrl_get, \
760           .put = alc_eapd_ctrl_put, \
761           .private_value = nid | (mask<<16) }
762 #endif   /* CONFIG_SND_DEBUG */
763
764 /*
765  */
766 static void add_mixer(struct alc_spec *spec, struct snd_kcontrol_new *mix)
767 {
768         if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
769                 return;
770         spec->mixers[spec->num_mixers++] = mix;
771 }
772
773 static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
774 {
775         if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
776                 return;
777         spec->init_verbs[spec->num_init_verbs++] = verb;
778 }
779
780 #ifdef CONFIG_PROC_FS
781 /*
782  * hook for proc
783  */
784 static void print_realtek_coef(struct snd_info_buffer *buffer,
785                                struct hda_codec *codec, hda_nid_t nid)
786 {
787         int coeff;
788
789         if (nid != 0x20)
790                 return;
791         coeff = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PROC_COEF, 0);
792         snd_iprintf(buffer, "  Processing Coefficient: 0x%02x\n", coeff);
793         coeff = snd_hda_codec_read(codec, nid, 0,
794                                    AC_VERB_GET_COEF_INDEX, 0);
795         snd_iprintf(buffer, "  Coefficient Index: 0x%02x\n", coeff);
796 }
797 #else
798 #define print_realtek_coef      NULL
799 #endif
800
801 /*
802  * set up from the preset table
803  */
804 static void setup_preset(struct alc_spec *spec,
805                          const struct alc_config_preset *preset)
806 {
807         int i;
808
809         for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
810                 add_mixer(spec, preset->mixers[i]);
811         spec->cap_mixer = preset->cap_mixer;
812         for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
813              i++)
814                 add_verb(spec, preset->init_verbs[i]);
815
816         spec->channel_mode = preset->channel_mode;
817         spec->num_channel_mode = preset->num_channel_mode;
818         spec->need_dac_fix = preset->need_dac_fix;
819
820         spec->multiout.max_channels = spec->channel_mode[0].channels;
821
822         spec->multiout.num_dacs = preset->num_dacs;
823         spec->multiout.dac_nids = preset->dac_nids;
824         spec->multiout.dig_out_nid = preset->dig_out_nid;
825         spec->multiout.hp_nid = preset->hp_nid;
826
827         spec->num_mux_defs = preset->num_mux_defs;
828         if (!spec->num_mux_defs)
829                 spec->num_mux_defs = 1;
830         spec->input_mux = preset->input_mux;
831
832         spec->num_adc_nids = preset->num_adc_nids;
833         spec->adc_nids = preset->adc_nids;
834         spec->capsrc_nids = preset->capsrc_nids;
835         spec->dig_in_nid = preset->dig_in_nid;
836
837         spec->unsol_event = preset->unsol_event;
838         spec->init_hook = preset->init_hook;
839 #ifdef CONFIG_SND_HDA_POWER_SAVE
840         spec->loopback.amplist = preset->loopbacks;
841 #endif
842 }
843
844 /* Enable GPIO mask and set output */
845 static struct hda_verb alc_gpio1_init_verbs[] = {
846         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
847         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
848         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
849         { }
850 };
851
852 static struct hda_verb alc_gpio2_init_verbs[] = {
853         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
854         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
855         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
856         { }
857 };
858
859 static struct hda_verb alc_gpio3_init_verbs[] = {
860         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
861         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
862         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
863         { }
864 };
865
866 /*
867  * Fix hardware PLL issue
868  * On some codecs, the analog PLL gating control must be off while
869  * the default value is 1.
870  */
871 static void alc_fix_pll(struct hda_codec *codec)
872 {
873         struct alc_spec *spec = codec->spec;
874         unsigned int val;
875
876         if (!spec->pll_nid)
877                 return;
878         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
879                             spec->pll_coef_idx);
880         val = snd_hda_codec_read(codec, spec->pll_nid, 0,
881                                  AC_VERB_GET_PROC_COEF, 0);
882         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
883                             spec->pll_coef_idx);
884         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
885                             val & ~(1 << spec->pll_coef_bit));
886 }
887
888 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
889                              unsigned int coef_idx, unsigned int coef_bit)
890 {
891         struct alc_spec *spec = codec->spec;
892         spec->pll_nid = nid;
893         spec->pll_coef_idx = coef_idx;
894         spec->pll_coef_bit = coef_bit;
895         alc_fix_pll(codec);
896 }
897
898 static void alc_sku_automute(struct hda_codec *codec)
899 {
900         struct alc_spec *spec = codec->spec;
901         unsigned int present;
902         unsigned int hp_nid = spec->autocfg.hp_pins[0];
903         unsigned int sp_nid = spec->autocfg.speaker_pins[0];
904
905         /* need to execute and sync at first */
906         snd_hda_codec_read(codec, hp_nid, 0, AC_VERB_SET_PIN_SENSE, 0);
907         present = snd_hda_codec_read(codec, hp_nid, 0,
908                                      AC_VERB_GET_PIN_SENSE, 0);
909         spec->jack_present = (present & 0x80000000) != 0;
910         snd_hda_codec_write(codec, sp_nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
911                             spec->jack_present ? 0 : PIN_OUT);
912 }
913
914 #if 0 /* it's broken in some acses -- temporarily disabled */
915 static void alc_mic_automute(struct hda_codec *codec)
916 {
917         struct alc_spec *spec = codec->spec;
918         unsigned int present;
919         unsigned int mic_nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
920         unsigned int fmic_nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
921         unsigned int mix_nid = spec->capsrc_nids[0];
922         unsigned int capsrc_idx_mic, capsrc_idx_fmic;
923
924         capsrc_idx_mic = mic_nid - 0x18;
925         capsrc_idx_fmic = fmic_nid - 0x18;
926         present = snd_hda_codec_read(codec, mic_nid, 0,
927                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
928         snd_hda_codec_write(codec, mix_nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
929                     0x7000 | (capsrc_idx_mic << 8) | (present ? 0 : 0x80));
930         snd_hda_codec_write(codec, mix_nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
931                     0x7000 | (capsrc_idx_fmic << 8) | (present ? 0x80 : 0));
932         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, capsrc_idx_fmic,
933                          HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
934 }
935 #else
936 #define alc_mic_automute(codec) /* NOP */
937 #endif /* disabled */
938
939 /* unsolicited event for HP jack sensing */
940 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
941 {
942         if (codec->vendor_id == 0x10ec0880)
943                 res >>= 28;
944         else
945                 res >>= 26;
946         if (res == ALC880_HP_EVENT)
947                 alc_sku_automute(codec);
948
949         if (res == ALC880_MIC_EVENT)
950                 alc_mic_automute(codec);
951 }
952
953 static void alc_inithook(struct hda_codec *codec)
954 {
955         alc_sku_automute(codec);
956         alc_mic_automute(codec);
957 }
958
959 /* additional initialization for ALC888 variants */
960 static void alc888_coef_init(struct hda_codec *codec)
961 {
962         unsigned int tmp;
963
964         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
965         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
966         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
967         if ((tmp & 0xf0) == 2)
968                 /* alc888S-VC */
969                 snd_hda_codec_read(codec, 0x20, 0,
970                                    AC_VERB_SET_PROC_COEF, 0x830);
971          else
972                  /* alc888-VB */
973                  snd_hda_codec_read(codec, 0x20, 0,
974                                     AC_VERB_SET_PROC_COEF, 0x3030);
975 }
976
977 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
978  *      31 ~ 16 :       Manufacture ID
979  *      15 ~ 8  :       SKU ID
980  *      7  ~ 0  :       Assembly ID
981  *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
982  */
983 static void alc_subsystem_id(struct hda_codec *codec,
984                              unsigned int porta, unsigned int porte,
985                              unsigned int portd)
986 {
987         unsigned int ass, tmp, i;
988         unsigned nid;
989         struct alc_spec *spec = codec->spec;
990
991         ass = codec->subsystem_id & 0xffff;
992         if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
993                 goto do_sku;
994
995         /*
996          * 31~30        : port conetcivity
997          * 29~21        : reserve
998          * 20           : PCBEEP input
999          * 19~16        : Check sum (15:1)
1000          * 15~1         : Custom
1001          * 0            : override
1002         */
1003         nid = 0x1d;
1004         if (codec->vendor_id == 0x10ec0260)
1005                 nid = 0x17;
1006         ass = snd_hda_codec_read(codec, nid, 0,
1007                                  AC_VERB_GET_CONFIG_DEFAULT, 0);
1008         if (!(ass & 1) && !(ass & 0x100000))
1009                 return;
1010         if ((ass >> 30) != 1)   /* no physical connection */
1011                 return;
1012
1013         /* check sum */
1014         tmp = 0;
1015         for (i = 1; i < 16; i++) {
1016                 if ((ass >> i) & 1)
1017                         tmp++;
1018         }
1019         if (((ass >> 16) & 0xf) != tmp)
1020                 return;
1021 do_sku:
1022         /*
1023          * 0 : override
1024          * 1 :  Swap Jack
1025          * 2 : 0 --> Desktop, 1 --> Laptop
1026          * 3~5 : External Amplifier control
1027          * 7~6 : Reserved
1028         */
1029         tmp = (ass & 0x38) >> 3;        /* external Amp control */
1030         switch (tmp) {
1031         case 1:
1032                 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
1033                 break;
1034         case 3:
1035                 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
1036                 break;
1037         case 7:
1038                 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
1039                 break;
1040         case 5: /* set EAPD output high */
1041                 switch (codec->vendor_id) {
1042                 case 0x10ec0260:
1043                         snd_hda_codec_write(codec, 0x0f, 0,
1044                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1045                         snd_hda_codec_write(codec, 0x10, 0,
1046                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1047                         break;
1048                 case 0x10ec0262:
1049                 case 0x10ec0267:
1050                 case 0x10ec0268:
1051                 case 0x10ec0269:
1052                 case 0x10ec0660:
1053                 case 0x10ec0662:
1054                 case 0x10ec0663:
1055                 case 0x10ec0862:
1056                 case 0x10ec0889:
1057                         snd_hda_codec_write(codec, 0x14, 0,
1058                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1059                         snd_hda_codec_write(codec, 0x15, 0,
1060                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1061                         break;
1062                 }
1063                 switch (codec->vendor_id) {
1064                 case 0x10ec0260:
1065                         snd_hda_codec_write(codec, 0x1a, 0,
1066                                             AC_VERB_SET_COEF_INDEX, 7);
1067                         tmp = snd_hda_codec_read(codec, 0x1a, 0,
1068                                                  AC_VERB_GET_PROC_COEF, 0);
1069                         snd_hda_codec_write(codec, 0x1a, 0,
1070                                             AC_VERB_SET_COEF_INDEX, 7);
1071                         snd_hda_codec_write(codec, 0x1a, 0,
1072                                             AC_VERB_SET_PROC_COEF,
1073                                             tmp | 0x2010);
1074                         break;
1075                 case 0x10ec0262:
1076                 case 0x10ec0880:
1077                 case 0x10ec0882:
1078                 case 0x10ec0883:
1079                 case 0x10ec0885:
1080                 case 0x10ec0889:
1081                         snd_hda_codec_write(codec, 0x20, 0,
1082                                             AC_VERB_SET_COEF_INDEX, 7);
1083                         tmp = snd_hda_codec_read(codec, 0x20, 0,
1084                                                  AC_VERB_GET_PROC_COEF, 0);
1085                         snd_hda_codec_write(codec, 0x20, 0,
1086                                             AC_VERB_SET_COEF_INDEX, 7);
1087                         snd_hda_codec_write(codec, 0x20, 0,
1088                                             AC_VERB_SET_PROC_COEF,
1089                                             tmp | 0x2010);
1090                         break;
1091                 case 0x10ec0888:
1092                         /*alc888_coef_init(codec);*/ /* called in alc_init() */
1093                         break;
1094                 case 0x10ec0267:
1095                 case 0x10ec0268:
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 | 0x3000);
1105                         break;
1106                 }
1107         default:
1108                 break;
1109         }
1110
1111         /* is laptop or Desktop and enable the function "Mute internal speaker
1112          * when the external headphone out jack is plugged"
1113          */
1114         if (!(ass & 0x8000))
1115                 return;
1116         /*
1117          * 10~8 : Jack location
1118          * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1119          * 14~13: Resvered
1120          * 15   : 1 --> enable the function "Mute internal speaker
1121          *              when the external headphone out jack is plugged"
1122          */
1123         if (!spec->autocfg.speaker_pins[0]) {
1124                 if (spec->autocfg.line_out_pins[0])
1125                         spec->autocfg.speaker_pins[0] =
1126                                 spec->autocfg.line_out_pins[0];
1127                 else
1128                         return;
1129         }
1130
1131         if (!spec->autocfg.hp_pins[0]) {
1132                 tmp = (ass >> 11) & 0x3;        /* HP to chassis */
1133                 if (tmp == 0)
1134                         spec->autocfg.hp_pins[0] = porta;
1135                 else if (tmp == 1)
1136                         spec->autocfg.hp_pins[0] = porte;
1137                 else if (tmp == 2)
1138                         spec->autocfg.hp_pins[0] = portd;
1139                 else
1140                         return;
1141         }
1142         if (spec->autocfg.hp_pins[0])
1143                 snd_hda_codec_write(codec, spec->autocfg.hp_pins[0], 0,
1144                         AC_VERB_SET_UNSOLICITED_ENABLE,
1145                         AC_USRSP_EN | ALC880_HP_EVENT);
1146
1147 #if 0 /* it's broken in some acses -- temporarily disabled */
1148         if (spec->autocfg.input_pins[AUTO_PIN_MIC] &&
1149                 spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC])
1150                 snd_hda_codec_write(codec,
1151                         spec->autocfg.input_pins[AUTO_PIN_MIC], 0,
1152                         AC_VERB_SET_UNSOLICITED_ENABLE,
1153                         AC_USRSP_EN | ALC880_MIC_EVENT);
1154 #endif /* disabled */
1155
1156         spec->unsol_event = alc_sku_unsol_event;
1157 }
1158
1159 /*
1160  * Fix-up pin default configurations
1161  */
1162
1163 struct alc_pincfg {
1164         hda_nid_t nid;
1165         u32 val;
1166 };
1167
1168 static void alc_fix_pincfg(struct hda_codec *codec,
1169                            const struct snd_pci_quirk *quirk,
1170                            const struct alc_pincfg **pinfix)
1171 {
1172         const struct alc_pincfg *cfg;
1173
1174         quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1175         if (!quirk)
1176                 return;
1177
1178         cfg = pinfix[quirk->value];
1179         for (; cfg->nid; cfg++) {
1180                 int i;
1181                 u32 val = cfg->val;
1182                 for (i = 0; i < 4; i++) {
1183                         snd_hda_codec_write(codec, cfg->nid, 0,
1184                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_0 + i,
1185                                     val & 0xff);
1186                         val >>= 8;
1187                 }
1188         }
1189 }
1190
1191 /*
1192  * ALC888
1193  */
1194
1195 /*
1196  * 2ch mode
1197  */
1198 static struct hda_verb alc888_4ST_ch2_intel_init[] = {
1199 /* Mic-in jack as mic in */
1200         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1201         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1202 /* Line-in jack as Line in */
1203         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1204         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1205 /* Line-Out as Front */
1206         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1207         { } /* end */
1208 };
1209
1210 /*
1211  * 4ch mode
1212  */
1213 static struct hda_verb alc888_4ST_ch4_intel_init[] = {
1214 /* Mic-in jack as mic in */
1215         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1216         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1217 /* Line-in jack as Surround */
1218         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1219         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1220 /* Line-Out as Front */
1221         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1222         { } /* end */
1223 };
1224
1225 /*
1226  * 6ch mode
1227  */
1228 static struct hda_verb alc888_4ST_ch6_intel_init[] = {
1229 /* Mic-in jack as CLFE */
1230         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1231         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1232 /* Line-in jack as Surround */
1233         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1234         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1235 /* Line-Out as CLFE (workaround because Mic-in is not loud enough) */
1236         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1237         { } /* end */
1238 };
1239
1240 /*
1241  * 8ch mode
1242  */
1243 static struct hda_verb alc888_4ST_ch8_intel_init[] = {
1244 /* Mic-in jack as CLFE */
1245         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1246         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1247 /* Line-in jack as Surround */
1248         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1249         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1250 /* Line-Out as Side */
1251         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1252         { } /* end */
1253 };
1254
1255 static struct hda_channel_mode alc888_4ST_8ch_intel_modes[4] = {
1256         { 2, alc888_4ST_ch2_intel_init },
1257         { 4, alc888_4ST_ch4_intel_init },
1258         { 6, alc888_4ST_ch6_intel_init },
1259         { 8, alc888_4ST_ch8_intel_init },
1260 };
1261
1262 /*
1263  * ALC888 Fujitsu Siemens Amillo xa3530
1264  */
1265
1266 static struct hda_verb alc888_fujitsu_xa3530_verbs[] = {
1267 /* Front Mic: set to PIN_IN (empty by default) */
1268         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1269 /* Connect Internal HP to Front */
1270         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1271         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1272         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1273 /* Connect Bass HP to Front */
1274         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1275         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1276         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1277 /* Connect Line-Out side jack (SPDIF) to Side */
1278         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1279         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1280         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1281 /* Connect Mic jack to CLFE */
1282         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1283         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1284         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},
1285 /* Connect Line-in jack to Surround */
1286         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1287         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1288         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
1289 /* Connect HP out jack to Front */
1290         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1291         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1292         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1293 /* Enable unsolicited event for HP jack and Line-out jack */
1294         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1295         {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1296         {}
1297 };
1298
1299 static void alc888_fujitsu_xa3530_automute(struct hda_codec *codec)
1300 {
1301         unsigned int present;
1302         unsigned int bits;
1303         /* Line out presence */
1304         present = snd_hda_codec_read(codec, 0x17, 0,
1305                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1306         /* HP out presence */
1307         present = present || snd_hda_codec_read(codec, 0x1b, 0,
1308                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1309         bits = present ? HDA_AMP_MUTE : 0;
1310         /* Toggle internal speakers muting */
1311         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
1312                                  HDA_AMP_MUTE, bits);
1313         /* Toggle internal bass muting */
1314         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
1315                                  HDA_AMP_MUTE, bits);
1316 }
1317
1318 static void alc888_fujitsu_xa3530_unsol_event(struct hda_codec *codec,
1319                 unsigned int res)
1320 {
1321         if (res >> 26 == ALC880_HP_EVENT)
1322                 alc888_fujitsu_xa3530_automute(codec);
1323 }
1324
1325
1326 /*
1327  * ALC888 Acer Aspire 4930G model
1328  */
1329
1330 static struct hda_verb alc888_acer_aspire_4930g_verbs[] = {
1331 /* Front Mic: set to PIN_IN (empty by default) */
1332         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1333 /* Unselect Front Mic by default in input mixer 3 */
1334         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1335 /* Enable unsolicited event for HP jack */
1336         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1337 /* Connect Internal HP to front */
1338         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1339         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1340         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1341 /* Connect HP out to front */
1342         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1343         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1344         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1345         { }
1346 };
1347
1348 static struct hda_input_mux alc888_2_capture_sources[2] = {
1349         /* Front mic only available on one ADC */
1350         {
1351                 .num_items = 4,
1352                 .items = {
1353                         { "Mic", 0x0 },
1354                         { "Line", 0x2 },
1355                         { "CD", 0x4 },
1356                         { "Front Mic", 0xb },
1357                 },
1358         },
1359         {
1360                 .num_items = 3,
1361                 .items = {
1362                         { "Mic", 0x0 },
1363                         { "Line", 0x2 },
1364                         { "CD", 0x4 },
1365                 },
1366         }
1367 };
1368
1369 static struct snd_kcontrol_new alc888_base_mixer[] = {
1370         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1371         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1372         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1373         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1374         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
1375                 HDA_OUTPUT),
1376         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1377         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1378         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1379         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1380         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1381         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1382         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1383         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1384         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1385         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1386         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
1387         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1388         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1389         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1390         { } /* end */
1391 };
1392
1393 static void alc888_acer_aspire_4930g_automute(struct hda_codec *codec)
1394 {
1395         unsigned int present;
1396         unsigned int bits;
1397         present = snd_hda_codec_read(codec, 0x15, 0,
1398                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1399         bits = present ? HDA_AMP_MUTE : 0;
1400         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
1401                                  HDA_AMP_MUTE, bits);
1402 }
1403
1404 static void alc888_acer_aspire_4930g_unsol_event(struct hda_codec *codec,
1405                 unsigned int res)
1406 {
1407         if (res >> 26 == ALC880_HP_EVENT)
1408                 alc888_acer_aspire_4930g_automute(codec);
1409 }
1410
1411 /*
1412  * ALC880 3-stack model
1413  *
1414  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
1415  * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
1416  *                 F-Mic = 0x1b, HP = 0x19
1417  */
1418
1419 static hda_nid_t alc880_dac_nids[4] = {
1420         /* front, rear, clfe, rear_surr */
1421         0x02, 0x05, 0x04, 0x03
1422 };
1423
1424 static hda_nid_t alc880_adc_nids[3] = {
1425         /* ADC0-2 */
1426         0x07, 0x08, 0x09,
1427 };
1428
1429 /* The datasheet says the node 0x07 is connected from inputs,
1430  * but it shows zero connection in the real implementation on some devices.
1431  * Note: this is a 915GAV bug, fixed on 915GLV
1432  */
1433 static hda_nid_t alc880_adc_nids_alt[2] = {
1434         /* ADC1-2 */
1435         0x08, 0x09,
1436 };
1437
1438 #define ALC880_DIGOUT_NID       0x06
1439 #define ALC880_DIGIN_NID        0x0a
1440
1441 static struct hda_input_mux alc880_capture_source = {
1442         .num_items = 4,
1443         .items = {
1444                 { "Mic", 0x0 },
1445                 { "Front Mic", 0x3 },
1446                 { "Line", 0x2 },
1447                 { "CD", 0x4 },
1448         },
1449 };
1450
1451 /* channel source setting (2/6 channel selection for 3-stack) */
1452 /* 2ch mode */
1453 static struct hda_verb alc880_threestack_ch2_init[] = {
1454         /* set line-in to input, mute it */
1455         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1456         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1457         /* set mic-in to input vref 80%, mute it */
1458         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1459         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1460         { } /* end */
1461 };
1462
1463 /* 6ch mode */
1464 static struct hda_verb alc880_threestack_ch6_init[] = {
1465         /* set line-in to output, unmute it */
1466         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1467         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1468         /* set mic-in to output, unmute it */
1469         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1470         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1471         { } /* end */
1472 };
1473
1474 static struct hda_channel_mode alc880_threestack_modes[2] = {
1475         { 2, alc880_threestack_ch2_init },
1476         { 6, alc880_threestack_ch6_init },
1477 };
1478
1479 static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
1480         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1481         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1482         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1483         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
1484         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1485         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1486         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1487         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1488         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1489         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1490         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1491         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1492         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1493         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1494         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
1495         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
1496         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1497         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1498         HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
1499         {
1500                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1501                 .name = "Channel Mode",
1502                 .info = alc_ch_mode_info,
1503                 .get = alc_ch_mode_get,
1504                 .put = alc_ch_mode_put,
1505         },
1506         { } /* end */
1507 };
1508
1509 /* capture mixer elements */
1510 static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1511                             struct snd_ctl_elem_info *uinfo)
1512 {
1513         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1514         struct alc_spec *spec = codec->spec;
1515         int err;
1516
1517         mutex_lock(&codec->control_mutex);
1518         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1519                                                       HDA_INPUT);
1520         err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
1521         mutex_unlock(&codec->control_mutex);
1522         return err;
1523 }
1524
1525 static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1526                            unsigned int size, unsigned int __user *tlv)
1527 {
1528         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1529         struct alc_spec *spec = codec->spec;
1530         int err;
1531
1532         mutex_lock(&codec->control_mutex);
1533         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1534                                                       HDA_INPUT);
1535         err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
1536         mutex_unlock(&codec->control_mutex);
1537         return err;
1538 }
1539
1540 typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1541                              struct snd_ctl_elem_value *ucontrol);
1542
1543 static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1544                                  struct snd_ctl_elem_value *ucontrol,
1545                                  getput_call_t func)
1546 {
1547         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1548         struct alc_spec *spec = codec->spec;
1549         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1550         int err;
1551
1552         mutex_lock(&codec->control_mutex);
1553         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[adc_idx],
1554                                                       3, 0, HDA_INPUT);
1555         err = func(kcontrol, ucontrol);
1556         mutex_unlock(&codec->control_mutex);
1557         return err;
1558 }
1559
1560 static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1561                            struct snd_ctl_elem_value *ucontrol)
1562 {
1563         return alc_cap_getput_caller(kcontrol, ucontrol,
1564                                      snd_hda_mixer_amp_volume_get);
1565 }
1566
1567 static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1568                            struct snd_ctl_elem_value *ucontrol)
1569 {
1570         return alc_cap_getput_caller(kcontrol, ucontrol,
1571                                      snd_hda_mixer_amp_volume_put);
1572 }
1573
1574 /* capture mixer elements */
1575 #define alc_cap_sw_info         snd_ctl_boolean_stereo_info
1576
1577 static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1578                           struct snd_ctl_elem_value *ucontrol)
1579 {
1580         return alc_cap_getput_caller(kcontrol, ucontrol,
1581                                      snd_hda_mixer_amp_switch_get);
1582 }
1583
1584 static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1585                           struct snd_ctl_elem_value *ucontrol)
1586 {
1587         return alc_cap_getput_caller(kcontrol, ucontrol,
1588                                      snd_hda_mixer_amp_switch_put);
1589 }
1590
1591 #define DEFINE_CAPMIX(num) \
1592 static struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1593         { \
1594                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1595                 .name = "Capture Switch", \
1596                 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1597                 .count = num, \
1598                 .info = alc_cap_sw_info, \
1599                 .get = alc_cap_sw_get, \
1600                 .put = alc_cap_sw_put, \
1601         }, \
1602         { \
1603                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1604                 .name = "Capture Volume", \
1605                 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1606                            SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1607                            SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1608                 .count = num, \
1609                 .info = alc_cap_vol_info, \
1610                 .get = alc_cap_vol_get, \
1611                 .put = alc_cap_vol_put, \
1612                 .tlv = { .c = alc_cap_vol_tlv }, \
1613         }, \
1614         { \
1615                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1616                 /* .name = "Capture Source", */ \
1617                 .name = "Input Source", \
1618                 .count = num, \
1619                 .info = alc_mux_enum_info, \
1620                 .get = alc_mux_enum_get, \
1621                 .put = alc_mux_enum_put, \
1622         }, \
1623         { } /* end */ \
1624 }
1625
1626 /* up to three ADCs */
1627 DEFINE_CAPMIX(1);
1628 DEFINE_CAPMIX(2);
1629 DEFINE_CAPMIX(3);
1630
1631
1632 /*
1633  * ALC880 5-stack model
1634  *
1635  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
1636  *      Side = 0x02 (0xd)
1637  * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
1638  *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
1639  */
1640
1641 /* additional mixers to alc880_three_stack_mixer */
1642 static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
1643         HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1644         HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
1645         { } /* end */
1646 };
1647
1648 /* channel source setting (6/8 channel selection for 5-stack) */
1649 /* 6ch mode */
1650 static struct hda_verb alc880_fivestack_ch6_init[] = {
1651         /* set line-in to input, mute it */
1652         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1653         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1654         { } /* end */
1655 };
1656
1657 /* 8ch mode */
1658 static struct hda_verb alc880_fivestack_ch8_init[] = {
1659         /* set line-in to output, unmute it */
1660         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1661         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1662         { } /* end */
1663 };
1664
1665 static struct hda_channel_mode alc880_fivestack_modes[2] = {
1666         { 6, alc880_fivestack_ch6_init },
1667         { 8, alc880_fivestack_ch8_init },
1668 };
1669
1670
1671 /*
1672  * ALC880 6-stack model
1673  *
1674  * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
1675  *      Side = 0x05 (0x0f)
1676  * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
1677  *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
1678  */
1679
1680 static hda_nid_t alc880_6st_dac_nids[4] = {
1681         /* front, rear, clfe, rear_surr */
1682         0x02, 0x03, 0x04, 0x05
1683 };
1684
1685 static struct hda_input_mux alc880_6stack_capture_source = {
1686         .num_items = 4,
1687         .items = {
1688                 { "Mic", 0x0 },
1689                 { "Front Mic", 0x1 },
1690                 { "Line", 0x2 },
1691                 { "CD", 0x4 },
1692         },
1693 };
1694
1695 /* fixed 8-channels */
1696 static struct hda_channel_mode alc880_sixstack_modes[1] = {
1697         { 8, NULL },
1698 };
1699
1700 static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
1701         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1702         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1703         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1704         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1705         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1706         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1707         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1708         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1709         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1710         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1711         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1712         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1713         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1714         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1715         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1716         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1717         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1718         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1719         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1720         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1721         {
1722                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1723                 .name = "Channel Mode",
1724                 .info = alc_ch_mode_info,
1725                 .get = alc_ch_mode_get,
1726                 .put = alc_ch_mode_put,
1727         },
1728         { } /* end */
1729 };
1730
1731
1732 /*
1733  * ALC880 W810 model
1734  *
1735  * W810 has rear IO for:
1736  * Front (DAC 02)
1737  * Surround (DAC 03)
1738  * Center/LFE (DAC 04)
1739  * Digital out (06)
1740  *
1741  * The system also has a pair of internal speakers, and a headphone jack.
1742  * These are both connected to Line2 on the codec, hence to DAC 02.
1743  *
1744  * There is a variable resistor to control the speaker or headphone
1745  * volume. This is a hardware-only device without a software API.
1746  *
1747  * Plugging headphones in will disable the internal speakers. This is
1748  * implemented in hardware, not via the driver using jack sense. In
1749  * a similar fashion, plugging into the rear socket marked "front" will
1750  * disable both the speakers and headphones.
1751  *
1752  * For input, there's a microphone jack, and an "audio in" jack.
1753  * These may not do anything useful with this driver yet, because I
1754  * haven't setup any initialization verbs for these yet...
1755  */
1756
1757 static hda_nid_t alc880_w810_dac_nids[3] = {
1758         /* front, rear/surround, clfe */
1759         0x02, 0x03, 0x04
1760 };
1761
1762 /* fixed 6 channels */
1763 static struct hda_channel_mode alc880_w810_modes[1] = {
1764         { 6, NULL }
1765 };
1766
1767 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
1768 static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
1769         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1770         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1771         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1772         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1773         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1774         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1775         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1776         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1777         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1778         { } /* end */
1779 };
1780
1781
1782 /*
1783  * Z710V model
1784  *
1785  * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
1786  * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
1787  *                 Line = 0x1a
1788  */
1789
1790 static hda_nid_t alc880_z71v_dac_nids[1] = {
1791         0x02
1792 };
1793 #define ALC880_Z71V_HP_DAC      0x03
1794
1795 /* fixed 2 channels */
1796 static struct hda_channel_mode alc880_2_jack_modes[1] = {
1797         { 2, NULL }
1798 };
1799
1800 static struct snd_kcontrol_new alc880_z71v_mixer[] = {
1801         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1802         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1803         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1804         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
1805         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1806         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1807         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1808         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1809         { } /* end */
1810 };
1811
1812
1813 /*
1814  * ALC880 F1734 model
1815  *
1816  * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
1817  * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
1818  */
1819
1820 static hda_nid_t alc880_f1734_dac_nids[1] = {
1821         0x03
1822 };
1823 #define ALC880_F1734_HP_DAC     0x02
1824
1825 static struct snd_kcontrol_new alc880_f1734_mixer[] = {
1826         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1827         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1828         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1829         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1830         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1831         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1832         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1833         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1834         { } /* end */
1835 };
1836
1837 static struct hda_input_mux alc880_f1734_capture_source = {
1838         .num_items = 2,
1839         .items = {
1840                 { "Mic", 0x1 },
1841                 { "CD", 0x4 },
1842         },
1843 };
1844
1845
1846 /*
1847  * ALC880 ASUS model
1848  *
1849  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1850  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1851  *  Mic = 0x18, Line = 0x1a
1852  */
1853
1854 #define alc880_asus_dac_nids    alc880_w810_dac_nids    /* identical with w810 */
1855 #define alc880_asus_modes       alc880_threestack_modes /* 2/6 channel mode */
1856
1857 static struct snd_kcontrol_new alc880_asus_mixer[] = {
1858         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1859         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1860         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1861         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1862         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1863         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1864         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1865         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1866         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1867         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1868         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1869         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1870         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1871         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1872         {
1873                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1874                 .name = "Channel Mode",
1875                 .info = alc_ch_mode_info,
1876                 .get = alc_ch_mode_get,
1877                 .put = alc_ch_mode_put,
1878         },
1879         { } /* end */
1880 };
1881
1882 /*
1883  * ALC880 ASUS W1V model
1884  *
1885  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1886  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1887  *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
1888  */
1889
1890 /* additional mixers to alc880_asus_mixer */
1891 static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
1892         HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
1893         HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
1894         { } /* end */
1895 };
1896
1897 /* additional mixers to alc880_asus_mixer */
1898 static struct snd_kcontrol_new alc880_pcbeep_mixer[] = {
1899         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1900         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1901         { } /* end */
1902 };
1903
1904 /* TCL S700 */
1905 static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
1906         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1907         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1908         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1909         HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
1910         HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
1911         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
1912         HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
1913         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1914         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1915         { } /* end */
1916 };
1917
1918 /* Uniwill */
1919 static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
1920         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1921         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1922         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1923         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1924         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1925         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1926         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1927         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1928         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1929         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1930         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1931         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1932         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1933         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1934         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1935         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1936         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1937         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1938         {
1939                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1940                 .name = "Channel Mode",
1941                 .info = alc_ch_mode_info,
1942                 .get = alc_ch_mode_get,
1943                 .put = alc_ch_mode_put,
1944         },
1945         { } /* end */
1946 };
1947
1948 static struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
1949         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1950         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1951         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1952         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1953         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1954         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1955         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1956         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1957         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1958         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1959         { } /* end */
1960 };
1961
1962 static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
1963         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1964         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1965         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1966         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1967         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1968         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1969         { } /* end */
1970 };
1971
1972 /*
1973  * virtual master controls
1974  */
1975
1976 /*
1977  * slave controls for virtual master
1978  */
1979 static const char *alc_slave_vols[] = {
1980         "Front Playback Volume",
1981         "Surround Playback Volume",
1982         "Center Playback Volume",
1983         "LFE Playback Volume",
1984         "Side Playback Volume",
1985         "Headphone Playback Volume",
1986         "Speaker Playback Volume",
1987         "Mono Playback Volume",
1988         "Line-Out Playback Volume",
1989         "PCM Playback Volume",
1990         NULL,
1991 };
1992
1993 static const char *alc_slave_sws[] = {
1994         "Front Playback Switch",
1995         "Surround Playback Switch",
1996         "Center Playback Switch",
1997         "LFE Playback Switch",
1998         "Side Playback Switch",
1999         "Headphone Playback Switch",
2000         "Speaker Playback Switch",
2001         "Mono Playback Switch",
2002         "IEC958 Playback Switch",
2003         NULL,
2004 };
2005
2006 /*
2007  * build control elements
2008  */
2009
2010 static void alc_free_kctls(struct hda_codec *codec);
2011
2012 static int alc_build_controls(struct hda_codec *codec)
2013 {
2014         struct alc_spec *spec = codec->spec;
2015         int err;
2016         int i;
2017
2018         for (i = 0; i < spec->num_mixers; i++) {
2019                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
2020                 if (err < 0)
2021                         return err;
2022         }
2023         if (spec->cap_mixer) {
2024                 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
2025                 if (err < 0)
2026                         return err;
2027         }
2028         if (spec->multiout.dig_out_nid) {
2029                 err = snd_hda_create_spdif_out_ctls(codec,
2030                                                     spec->multiout.dig_out_nid);
2031                 if (err < 0)
2032                         return err;
2033                 if (!spec->no_analog) {
2034                         err = snd_hda_create_spdif_share_sw(codec,
2035                                                             &spec->multiout);
2036                         if (err < 0)
2037                                 return err;
2038                         spec->multiout.share_spdif = 1;
2039                 }
2040         }
2041         if (spec->dig_in_nid) {
2042                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
2043                 if (err < 0)
2044                         return err;
2045         }
2046
2047         /* if we have no master control, let's create it */
2048         if (!spec->no_analog &&
2049             !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
2050                 unsigned int vmaster_tlv[4];
2051                 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
2052                                         HDA_OUTPUT, vmaster_tlv);
2053                 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
2054                                           vmaster_tlv, alc_slave_vols);
2055                 if (err < 0)
2056                         return err;
2057         }
2058         if (!spec->no_analog &&
2059             !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
2060                 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
2061                                           NULL, alc_slave_sws);
2062                 if (err < 0)
2063                         return err;
2064         }
2065
2066         alc_free_kctls(codec); /* no longer needed */
2067         return 0;
2068 }
2069
2070
2071 /*
2072  * initialize the codec volumes, etc
2073  */
2074
2075 /*
2076  * generic initialization of ADC, input mixers and output mixers
2077  */
2078 static struct hda_verb alc880_volume_init_verbs[] = {
2079         /*
2080          * Unmute ADC0-2 and set the default input to mic-in
2081          */
2082         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
2083         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2084         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
2085         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2086         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
2087         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2088
2089         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2090          * mixer widget
2091          * Note: PASD motherboards uses the Line In 2 as the input for front
2092          * panel mic (mic 2)
2093          */
2094         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
2095         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2096         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2097         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2098         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2099         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2100         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2101         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2102
2103         /*
2104          * Set up output mixers (0x0c - 0x0f)
2105          */
2106         /* set vol=0 to output mixers */
2107         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2108         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2109         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2110         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2111         /* set up input amps for analog loopback */
2112         /* Amp Indices: DAC = 0, mixer = 1 */
2113         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2114         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2115         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2116         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2117         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2118         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2119         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2120         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2121
2122         { }
2123 };
2124
2125 /*
2126  * 3-stack pin configuration:
2127  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
2128  */
2129 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
2130         /*
2131          * preset connection lists of input pins
2132          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2133          */
2134         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2135         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2136         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2137
2138         /*
2139          * Set pin mode and muting
2140          */
2141         /* set front pin widgets 0x14 for output */
2142         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2143         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2144         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2145         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2146         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2147         /* Mic2 (as headphone out) for HP output */
2148         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2149         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2150         /* Line In pin widget for input */
2151         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2152         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2153         /* Line2 (as front mic) pin widget for input and vref at 80% */
2154         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2155         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2156         /* CD pin widget for input */
2157         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2158
2159         { }
2160 };
2161
2162 /*
2163  * 5-stack pin configuration:
2164  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
2165  * line-in/side = 0x1a, f-mic = 0x1b
2166  */
2167 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
2168         /*
2169          * preset connection lists of input pins
2170          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2171          */
2172         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2173         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
2174
2175         /*
2176          * Set pin mode and muting
2177          */
2178         /* set pin widgets 0x14-0x17 for output */
2179         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2180         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2181         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2182         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2183         /* unmute pins for output (no gain on this amp) */
2184         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2185         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2186         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2187         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2188
2189         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2190         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2191         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2192         /* Mic2 (as headphone out) for HP output */
2193         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2194         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2195         /* Line In pin widget for input */
2196         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2197         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2198         /* Line2 (as front mic) pin widget for input and vref at 80% */
2199         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2200         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2201         /* CD pin widget for input */
2202         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2203
2204         { }
2205 };
2206
2207 /*
2208  * W810 pin configuration:
2209  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
2210  */
2211 static struct hda_verb alc880_pin_w810_init_verbs[] = {
2212         /* hphone/speaker input selector: front DAC */
2213         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
2214
2215         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2216         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2217         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2218         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2219         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2220         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2221
2222         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2223         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2224
2225         { }
2226 };
2227
2228 /*
2229  * Z71V pin configuration:
2230  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
2231  */
2232 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
2233         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2234         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2235         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2236         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2237
2238         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2239         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2240         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2241         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2242
2243         { }
2244 };
2245
2246 /*
2247  * 6-stack pin configuration:
2248  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
2249  * f-mic = 0x19, line = 0x1a, HP = 0x1b
2250  */
2251 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
2252         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2253
2254         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2255         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2256         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2257         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2258         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2259         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2260         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2261         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2262
2263         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2264         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2265         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2266         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2267         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2268         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2269         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2270         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2271         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2272
2273         { }
2274 };
2275
2276 /*
2277  * Uniwill pin configuration:
2278  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
2279  * line = 0x1a
2280  */
2281 static struct hda_verb alc880_uniwill_init_verbs[] = {
2282         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2283
2284         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2285         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2286         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2287         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2288         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2289         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2290         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2291         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2292         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2293         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2294         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2295         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2296         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2297         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2298
2299         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2300         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2301         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2302         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2303         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2304         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2305         /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
2306         /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
2307         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2308
2309         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2310         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
2311
2312         { }
2313 };
2314
2315 /*
2316 * Uniwill P53
2317 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19,
2318  */
2319 static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
2320         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2321
2322         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2323         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2324         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2325         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2326         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2327         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2328         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2329         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2330         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2331         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2332         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2333         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2334
2335         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2336         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2337         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2338         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2339         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2340         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2341
2342         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2343         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
2344
2345         { }
2346 };
2347
2348 static struct hda_verb alc880_beep_init_verbs[] = {
2349         { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
2350         { }
2351 };
2352
2353 /* toggle speaker-output according to the hp-jack state */
2354 static void alc880_uniwill_hp_automute(struct hda_codec *codec)
2355 {
2356         unsigned int present;
2357         unsigned char bits;
2358
2359         present = snd_hda_codec_read(codec, 0x14, 0,
2360                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2361         bits = present ? HDA_AMP_MUTE : 0;
2362         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
2363                                  HDA_AMP_MUTE, bits);
2364         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
2365                                  HDA_AMP_MUTE, bits);
2366 }
2367
2368 /* auto-toggle front mic */
2369 static void alc880_uniwill_mic_automute(struct hda_codec *codec)
2370 {
2371         unsigned int present;
2372         unsigned char bits;
2373
2374         present = snd_hda_codec_read(codec, 0x18, 0,
2375                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2376         bits = present ? HDA_AMP_MUTE : 0;
2377         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
2378 }
2379
2380 static void alc880_uniwill_automute(struct hda_codec *codec)
2381 {
2382         alc880_uniwill_hp_automute(codec);
2383         alc880_uniwill_mic_automute(codec);
2384 }
2385
2386 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
2387                                        unsigned int res)
2388 {
2389         /* Looks like the unsol event is incompatible with the standard
2390          * definition.  4bit tag is placed at 28 bit!
2391          */
2392         switch (res >> 28) {
2393         case ALC880_HP_EVENT:
2394                 alc880_uniwill_hp_automute(codec);
2395                 break;
2396         case ALC880_MIC_EVENT:
2397                 alc880_uniwill_mic_automute(codec);
2398                 break;
2399         }
2400 }
2401
2402 static void alc880_uniwill_p53_hp_automute(struct hda_codec *codec)
2403 {
2404         unsigned int present;
2405         unsigned char bits;
2406
2407         present = snd_hda_codec_read(codec, 0x14, 0,
2408                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2409         bits = present ? HDA_AMP_MUTE : 0;
2410         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, HDA_AMP_MUTE, bits);
2411 }
2412
2413 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
2414 {
2415         unsigned int present;
2416
2417         present = snd_hda_codec_read(codec, 0x21, 0,
2418                                      AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
2419         present &= HDA_AMP_VOLMASK;
2420         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
2421                                  HDA_AMP_VOLMASK, present);
2422         snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
2423                                  HDA_AMP_VOLMASK, present);
2424 }
2425
2426 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
2427                                            unsigned int res)
2428 {
2429         /* Looks like the unsol event is incompatible with the standard
2430          * definition.  4bit tag is placed at 28 bit!
2431          */
2432         if ((res >> 28) == ALC880_HP_EVENT)
2433                 alc880_uniwill_p53_hp_automute(codec);
2434         if ((res >> 28) == ALC880_DCVOL_EVENT)
2435                 alc880_uniwill_p53_dcvol_automute(codec);
2436 }
2437
2438 /*
2439  * F1734 pin configuration:
2440  * HP = 0x14, speaker-out = 0x15, mic = 0x18
2441  */
2442 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
2443         {0x07, AC_VERB_SET_CONNECT_SEL, 0x01},
2444         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2445         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2446         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2447         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2448
2449         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2450         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2451         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2452         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2453
2454         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2455         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2456         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
2457         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2458         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2459         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2460         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2461         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2462         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2463
2464         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
2465         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_DCVOL_EVENT},
2466
2467         { }
2468 };
2469
2470 /*
2471  * ASUS pin configuration:
2472  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
2473  */
2474 static struct hda_verb alc880_pin_asus_init_verbs[] = {
2475         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2476         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2477         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2478         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2479
2480         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2481         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2482         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2483         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2484         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2485         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2486         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2487         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2488
2489         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2490         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2491         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2492         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2493         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2494         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2495         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2496         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2497         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2498
2499         { }
2500 };
2501
2502 /* Enable GPIO mask and set output */
2503 #define alc880_gpio1_init_verbs alc_gpio1_init_verbs
2504 #define alc880_gpio2_init_verbs alc_gpio2_init_verbs
2505
2506 /* Clevo m520g init */
2507 static struct hda_verb alc880_pin_clevo_init_verbs[] = {
2508         /* headphone output */
2509         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2510         /* line-out */
2511         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2512         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2513         /* Line-in */
2514         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2515         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2516         /* CD */
2517         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2518         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2519         /* Mic1 (rear panel) */
2520         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2521         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2522         /* Mic2 (front panel) */
2523         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2524         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2525         /* headphone */
2526         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2527         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2528         /* change to EAPD mode */
2529         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2530         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2531
2532         { }
2533 };
2534
2535 static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
2536         /* change to EAPD mode */
2537         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2538         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2539
2540         /* Headphone output */
2541         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2542         /* Front output*/
2543         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2544         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
2545
2546         /* Line In pin widget for input */
2547         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2548         /* CD pin widget for input */
2549         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2550         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2551         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2552
2553         /* change to EAPD mode */
2554         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2555         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
2556
2557         { }
2558 };
2559
2560 /*
2561  * LG m1 express dual
2562  *
2563  * Pin assignment:
2564  *   Rear Line-In/Out (blue): 0x14
2565  *   Build-in Mic-In: 0x15
2566  *   Speaker-out: 0x17
2567  *   HP-Out (green): 0x1b
2568  *   Mic-In/Out (red): 0x19
2569  *   SPDIF-Out: 0x1e
2570  */
2571
2572 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
2573 static hda_nid_t alc880_lg_dac_nids[3] = {
2574         0x05, 0x02, 0x03
2575 };
2576
2577 /* seems analog CD is not working */
2578 static struct hda_input_mux alc880_lg_capture_source = {
2579         .num_items = 3,
2580         .items = {
2581                 { "Mic", 0x1 },
2582                 { "Line", 0x5 },
2583                 { "Internal Mic", 0x6 },
2584         },
2585 };
2586
2587 /* 2,4,6 channel modes */
2588 static struct hda_verb alc880_lg_ch2_init[] = {
2589         /* set line-in and mic-in to input */
2590         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2591         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2592         { }
2593 };
2594
2595 static struct hda_verb alc880_lg_ch4_init[] = {
2596         /* set line-in to out and mic-in to input */
2597         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2598         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2599         { }
2600 };
2601
2602 static struct hda_verb alc880_lg_ch6_init[] = {
2603         /* set line-in and mic-in to output */
2604         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2605         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2606         { }
2607 };
2608
2609 static struct hda_channel_mode alc880_lg_ch_modes[3] = {
2610         { 2, alc880_lg_ch2_init },
2611         { 4, alc880_lg_ch4_init },
2612         { 6, alc880_lg_ch6_init },
2613 };
2614
2615 static struct snd_kcontrol_new alc880_lg_mixer[] = {
2616         HDA_CODEC_VOLUME("Front Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2617         HDA_BIND_MUTE("Front Playback Switch", 0x0f, 2, HDA_INPUT),
2618         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2619         HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
2620         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
2621         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
2622         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
2623         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
2624         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2625         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2626         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
2627         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
2628         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
2629         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
2630         {
2631                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2632                 .name = "Channel Mode",
2633                 .info = alc_ch_mode_info,
2634                 .get = alc_ch_mode_get,
2635                 .put = alc_ch_mode_put,
2636         },
2637         { } /* end */
2638 };
2639
2640 static struct hda_verb alc880_lg_init_verbs[] = {
2641         /* set capture source to mic-in */
2642         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2643         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2644         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2645         /* mute all amp mixer inputs */
2646         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
2647         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2648         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2649         /* line-in to input */
2650         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2651         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2652         /* built-in mic */
2653         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2654         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2655         /* speaker-out */
2656         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2657         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2658         /* mic-in to input */
2659         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2660         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2661         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2662         /* HP-out */
2663         {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
2664         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2665         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2666         /* jack sense */
2667         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2668         { }
2669 };
2670
2671 /* toggle speaker-output according to the hp-jack state */
2672 static void alc880_lg_automute(struct hda_codec *codec)
2673 {
2674         unsigned int present;
2675         unsigned char bits;
2676
2677         present = snd_hda_codec_read(codec, 0x1b, 0,
2678                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2679         bits = present ? HDA_AMP_MUTE : 0;
2680         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
2681                                  HDA_AMP_MUTE, bits);
2682 }
2683
2684 static void alc880_lg_unsol_event(struct hda_codec *codec, unsigned int res)
2685 {
2686         /* Looks like the unsol event is incompatible with the standard
2687          * definition.  4bit tag is placed at 28 bit!
2688          */
2689         if ((res >> 28) == 0x01)
2690                 alc880_lg_automute(codec);
2691 }
2692
2693 /*
2694  * LG LW20
2695  *
2696  * Pin assignment:
2697  *   Speaker-out: 0x14
2698  *   Mic-In: 0x18
2699  *   Built-in Mic-In: 0x19
2700  *   Line-In: 0x1b
2701  *   HP-Out: 0x1a
2702  *   SPDIF-Out: 0x1e
2703  */
2704
2705 static struct hda_input_mux alc880_lg_lw_capture_source = {
2706         .num_items = 3,
2707         .items = {
2708                 { "Mic", 0x0 },
2709                 { "Internal Mic", 0x1 },
2710                 { "Line In", 0x2 },
2711         },
2712 };
2713
2714 #define alc880_lg_lw_modes alc880_threestack_modes
2715
2716 static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
2717         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2718         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2719         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2720         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
2721         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2722         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2723         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2724         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2725         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2726         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2727         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2728         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2729         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
2730         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
2731         {
2732                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2733                 .name = "Channel Mode",
2734                 .info = alc_ch_mode_info,
2735                 .get = alc_ch_mode_get,
2736                 .put = alc_ch_mode_put,
2737         },
2738         { } /* end */
2739 };
2740
2741 static struct hda_verb alc880_lg_lw_init_verbs[] = {
2742         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2743         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2744         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2745
2746         /* set capture source to mic-in */
2747         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2748         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2749         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2750         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2751         /* speaker-out */
2752         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2753         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2754         /* HP-out */
2755         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2756         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2757         /* mic-in to input */
2758         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2759         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2760         /* built-in mic */
2761         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2762         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2763         /* jack sense */
2764         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2765         { }
2766 };
2767
2768 /* toggle speaker-output according to the hp-jack state */
2769 static void alc880_lg_lw_automute(struct hda_codec *codec)
2770 {
2771         unsigned int present;
2772         unsigned char bits;
2773
2774         present = snd_hda_codec_read(codec, 0x1b, 0,
2775                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2776         bits = present ? HDA_AMP_MUTE : 0;
2777         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
2778                                  HDA_AMP_MUTE, bits);
2779 }
2780
2781 static void alc880_lg_lw_unsol_event(struct hda_codec *codec, unsigned int res)
2782 {
2783         /* Looks like the unsol event is incompatible with the standard
2784          * definition.  4bit tag is placed at 28 bit!
2785          */
2786         if ((res >> 28) == 0x01)
2787                 alc880_lg_lw_automute(codec);
2788 }
2789
2790 static struct snd_kcontrol_new alc880_medion_rim_mixer[] = {
2791         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2792         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
2793         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2794         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2795         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2796         HDA_CODEC_MUTE("Internal Playback Switch", 0x0b, 0x1, HDA_INPUT),
2797         { } /* end */
2798 };
2799
2800 static struct hda_input_mux alc880_medion_rim_capture_source = {
2801         .num_items = 2,
2802         .items = {
2803                 { "Mic", 0x0 },
2804                 { "Internal Mic", 0x1 },
2805         },
2806 };
2807
2808 static struct hda_verb alc880_medion_rim_init_verbs[] = {
2809         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2810
2811         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2812         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2813
2814         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2815         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2816         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2817         /* Mic2 (as headphone out) for HP output */
2818         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2819         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2820         /* Internal Speaker */
2821         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2822         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2823
2824         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2825         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2826
2827         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2828         { }
2829 };
2830
2831 /* toggle speaker-output according to the hp-jack state */
2832 static void alc880_medion_rim_automute(struct hda_codec *codec)
2833 {
2834         unsigned int present;
2835         unsigned char bits;
2836
2837         present = snd_hda_codec_read(codec, 0x14, 0,
2838                                      AC_VERB_GET_PIN_SENSE, 0)
2839                 & AC_PINSENSE_PRESENCE;
2840         bits = present ? HDA_AMP_MUTE : 0;
2841         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
2842                                  HDA_AMP_MUTE, bits);
2843         if (present)
2844                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0);
2845         else
2846                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 2);
2847 }
2848
2849 static void alc880_medion_rim_unsol_event(struct hda_codec *codec,
2850                                           unsigned int res)
2851 {
2852         /* Looks like the unsol event is incompatible with the standard
2853          * definition.  4bit tag is placed at 28 bit!
2854          */
2855         if ((res >> 28) == ALC880_HP_EVENT)
2856                 alc880_medion_rim_automute(codec);
2857 }
2858
2859 #ifdef CONFIG_SND_HDA_POWER_SAVE
2860 static struct hda_amp_list alc880_loopbacks[] = {
2861         { 0x0b, HDA_INPUT, 0 },
2862         { 0x0b, HDA_INPUT, 1 },
2863         { 0x0b, HDA_INPUT, 2 },
2864         { 0x0b, HDA_INPUT, 3 },
2865         { 0x0b, HDA_INPUT, 4 },
2866         { } /* end */
2867 };
2868
2869 static struct hda_amp_list alc880_lg_loopbacks[] = {
2870         { 0x0b, HDA_INPUT, 1 },
2871         { 0x0b, HDA_INPUT, 6 },
2872         { 0x0b, HDA_INPUT, 7 },
2873         { } /* end */
2874 };
2875 #endif
2876
2877 /*
2878  * Common callbacks
2879  */
2880
2881 static int alc_init(struct hda_codec *codec)
2882 {
2883         struct alc_spec *spec = codec->spec;
2884         unsigned int i;
2885
2886         alc_fix_pll(codec);
2887         if (codec->vendor_id == 0x10ec0888)
2888                 alc888_coef_init(codec);
2889
2890         for (i = 0; i < spec->num_init_verbs; i++)
2891                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2892
2893         if (spec->init_hook)
2894                 spec->init_hook(codec);
2895
2896         return 0;
2897 }
2898
2899 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2900 {
2901         struct alc_spec *spec = codec->spec;
2902
2903         if (spec->unsol_event)
2904                 spec->unsol_event(codec, res);
2905 }
2906
2907 #ifdef CONFIG_SND_HDA_POWER_SAVE
2908 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2909 {
2910         struct alc_spec *spec = codec->spec;
2911         return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2912 }
2913 #endif
2914
2915 /*
2916  * Analog playback callbacks
2917  */
2918 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
2919                                     struct hda_codec *codec,
2920                                     struct snd_pcm_substream *substream)
2921 {
2922         struct alc_spec *spec = codec->spec;
2923         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2924                                              hinfo);
2925 }
2926
2927 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2928                                        struct hda_codec *codec,
2929                                        unsigned int stream_tag,
2930                                        unsigned int format,
2931                                        struct snd_pcm_substream *substream)
2932 {
2933         struct alc_spec *spec = codec->spec;
2934         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2935                                                 stream_tag, format, substream);
2936 }
2937
2938 static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2939                                        struct hda_codec *codec,
2940                                        struct snd_pcm_substream *substream)
2941 {
2942         struct alc_spec *spec = codec->spec;
2943         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2944 }
2945
2946 /*
2947  * Digital out
2948  */
2949 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2950                                         struct hda_codec *codec,
2951                                         struct snd_pcm_substream *substream)
2952 {
2953         struct alc_spec *spec = codec->spec;
2954         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2955 }
2956
2957 static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2958                                            struct hda_codec *codec,
2959                                            unsigned int stream_tag,
2960                                            unsigned int format,
2961                                            struct snd_pcm_substream *substream)
2962 {
2963         struct alc_spec *spec = codec->spec;
2964         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2965                                              stream_tag, format, substream);
2966 }
2967
2968 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2969                                          struct hda_codec *codec,
2970                                          struct snd_pcm_substream *substream)
2971 {
2972         struct alc_spec *spec = codec->spec;
2973         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2974 }
2975
2976 /*
2977  * Analog capture
2978  */
2979 static int alc880_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2980                                       struct hda_codec *codec,
2981                                       unsigned int stream_tag,
2982                                       unsigned int format,
2983                                       struct snd_pcm_substream *substream)
2984 {
2985         struct alc_spec *spec = codec->spec;
2986
2987         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
2988                                    stream_tag, 0, format);
2989         return 0;
2990 }
2991
2992 static int alc880_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2993                                       struct hda_codec *codec,
2994                                       struct snd_pcm_substream *substream)
2995 {
2996         struct alc_spec *spec = codec->spec;
2997
2998         snd_hda_codec_cleanup_stream(codec,
2999                                      spec->adc_nids[substream->number + 1]);
3000         return 0;
3001 }
3002
3003
3004 /*
3005  */
3006 static struct hda_pcm_stream alc880_pcm_analog_playback = {
3007         .substreams = 1,
3008         .channels_min = 2,
3009         .channels_max = 8,
3010         /* NID is set in alc_build_pcms */
3011         .ops = {
3012                 .open = alc880_playback_pcm_open,
3013                 .prepare = alc880_playback_pcm_prepare,
3014                 .cleanup = alc880_playback_pcm_cleanup
3015         },
3016 };
3017
3018 static struct hda_pcm_stream alc880_pcm_analog_capture = {
3019         .substreams = 1,
3020         .channels_min = 2,
3021         .channels_max = 2,
3022         /* NID is set in alc_build_pcms */
3023 };
3024
3025 static struct hda_pcm_stream alc880_pcm_analog_alt_playback = {
3026         .substreams = 1,
3027         .channels_min = 2,
3028         .channels_max = 2,
3029         /* NID is set in alc_build_pcms */
3030 };
3031
3032 static struct hda_pcm_stream alc880_pcm_analog_alt_capture = {
3033         .substreams = 2, /* can be overridden */
3034         .channels_min = 2,
3035         .channels_max = 2,
3036         /* NID is set in alc_build_pcms */
3037         .ops = {
3038                 .prepare = alc880_alt_capture_pcm_prepare,
3039                 .cleanup = alc880_alt_capture_pcm_cleanup
3040         },
3041 };
3042
3043 static struct hda_pcm_stream alc880_pcm_digital_playback = {
3044         .substreams = 1,
3045         .channels_min = 2,
3046         .channels_max = 2,
3047         /* NID is set in alc_build_pcms */
3048         .ops = {
3049                 .open = alc880_dig_playback_pcm_open,
3050                 .close = alc880_dig_playback_pcm_close,
3051                 .prepare = alc880_dig_playback_pcm_prepare
3052         },
3053 };
3054
3055 static struct hda_pcm_stream alc880_pcm_digital_capture = {
3056         .substreams = 1,
3057         .channels_min = 2,
3058         .channels_max = 2,
3059         /* NID is set in alc_build_pcms */
3060 };
3061
3062 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
3063 static struct hda_pcm_stream alc_pcm_null_stream = {
3064         .substreams = 0,
3065         .channels_min = 0,
3066         .channels_max = 0,
3067 };
3068
3069 static int alc_build_pcms(struct hda_codec *codec)
3070 {
3071         struct alc_spec *spec = codec->spec;
3072         struct hda_pcm *info = spec->pcm_rec;
3073         int i;
3074
3075         codec->num_pcms = 1;
3076         codec->pcm_info = info;
3077
3078         if (spec->no_analog)
3079                 goto skip_analog;
3080
3081         info->name = spec->stream_name_analog;
3082         if (spec->stream_analog_playback) {
3083                 if (snd_BUG_ON(!spec->multiout.dac_nids))
3084                         return -EINVAL;
3085                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
3086                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
3087         }
3088         if (spec->stream_analog_capture) {
3089                 if (snd_BUG_ON(!spec->adc_nids))
3090                         return -EINVAL;
3091                 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
3092                 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
3093         }
3094
3095         if (spec->channel_mode) {
3096                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
3097                 for (i = 0; i < spec->num_channel_mode; i++) {
3098                         if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
3099                                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
3100                         }
3101                 }
3102         }
3103
3104  skip_analog:
3105         /* SPDIF for stream index #1 */
3106         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
3107                 codec->num_pcms = 2;
3108                 info = spec->pcm_rec + 1;
3109                 info->name = spec->stream_name_digital;
3110                 if (spec->dig_out_type)
3111                         info->pcm_type = spec->dig_out_type;
3112                 else
3113                         info->pcm_type = HDA_PCM_TYPE_SPDIF;
3114                 if (spec->multiout.dig_out_nid &&
3115                     spec->stream_digital_playback) {
3116                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
3117                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
3118                 }
3119                 if (spec->dig_in_nid &&
3120                     spec->stream_digital_capture) {
3121                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
3122                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
3123                 }
3124                 /* FIXME: do we need this for all Realtek codec models? */
3125                 codec->spdif_status_reset = 1;
3126         }
3127
3128         if (spec->no_analog)
3129                 return 0;
3130
3131         /* If the use of more than one ADC is requested for the current
3132          * model, configure a second analog capture-only PCM.
3133          */
3134         /* Additional Analaog capture for index #2 */
3135         if ((spec->alt_dac_nid && spec->stream_analog_alt_playback) ||
3136             (spec->num_adc_nids > 1 && spec->stream_analog_alt_capture)) {
3137                 codec->num_pcms = 3;
3138                 info = spec->pcm_rec + 2;
3139                 info->name = spec->stream_name_analog;
3140                 if (spec->alt_dac_nid) {
3141                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
3142                                 *spec->stream_analog_alt_playback;
3143                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
3144                                 spec->alt_dac_nid;
3145                 } else {
3146                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
3147                                 alc_pcm_null_stream;
3148                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
3149                 }
3150                 if (spec->num_adc_nids > 1) {
3151                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
3152                                 *spec->stream_analog_alt_capture;
3153                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
3154                                 spec->adc_nids[1];
3155                         info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
3156                                 spec->num_adc_nids - 1;
3157                 } else {
3158                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
3159                                 alc_pcm_null_stream;
3160                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
3161                 }
3162         }
3163
3164         return 0;
3165 }
3166
3167 static void alc_free_kctls(struct hda_codec *codec)
3168 {
3169         struct alc_spec *spec = codec->spec;
3170
3171         if (spec->kctls.list) {
3172                 struct snd_kcontrol_new *kctl = spec->kctls.list;
3173                 int i;
3174                 for (i = 0; i < spec->kctls.used; i++)
3175                         kfree(kctl[i].name);
3176         }
3177         snd_array_free(&spec->kctls);
3178 }
3179
3180 static void alc_free(struct hda_codec *codec)
3181 {
3182         struct alc_spec *spec = codec->spec;
3183
3184         if (!spec)
3185                 return;
3186
3187         alc_free_kctls(codec);
3188         kfree(spec);
3189         codec->spec = NULL; /* to be sure */
3190 }
3191
3192 #ifdef SND_HDA_NEEDS_RESUME
3193 static void store_pin_configs(struct hda_codec *codec)
3194 {
3195         struct alc_spec *spec = codec->spec;
3196         hda_nid_t nid, end_nid;
3197
3198         end_nid = codec->start_nid + codec->num_nodes;
3199         for (nid = codec->start_nid; nid < end_nid; nid++) {
3200                 unsigned int wid_caps = get_wcaps(codec, nid);
3201                 unsigned int wid_type =
3202                         (wid_caps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
3203                 if (wid_type != AC_WID_PIN)
3204                         continue;
3205                 if (spec->num_pins >= ARRAY_SIZE(spec->pin_nids))
3206                         break;
3207                 spec->pin_nids[spec->num_pins] = nid;
3208                 spec->pin_cfgs[spec->num_pins] =
3209                         snd_hda_codec_read(codec, nid, 0,
3210                                            AC_VERB_GET_CONFIG_DEFAULT, 0);
3211                 spec->num_pins++;
3212         }
3213 }
3214
3215 static void resume_pin_configs(struct hda_codec *codec)
3216 {
3217         struct alc_spec *spec = codec->spec;
3218         int i;
3219
3220         for (i = 0; i < spec->num_pins; i++) {
3221                 hda_nid_t pin_nid = spec->pin_nids[i];
3222                 unsigned int pin_config = spec->pin_cfgs[i];
3223                 snd_hda_codec_write(codec, pin_nid, 0,
3224                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
3225                                     pin_config & 0x000000ff);
3226                 snd_hda_codec_write(codec, pin_nid, 0,
3227                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
3228                                     (pin_config & 0x0000ff00) >> 8);
3229                 snd_hda_codec_write(codec, pin_nid, 0,
3230                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
3231                                     (pin_config & 0x00ff0000) >> 16);
3232                 snd_hda_codec_write(codec, pin_nid, 0,
3233                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
3234                                     pin_config >> 24);
3235         }
3236 }
3237
3238 static int alc_resume(struct hda_codec *codec)
3239 {
3240         resume_pin_configs(codec);
3241         codec->patch_ops.init(codec);
3242         snd_hda_codec_resume_amp(codec);
3243         snd_hda_codec_resume_cache(codec);
3244         return 0;
3245 }
3246 #else
3247 #define store_pin_configs(codec)
3248 #endif
3249
3250 /*
3251  */
3252 static struct hda_codec_ops alc_patch_ops = {
3253         .build_controls = alc_build_controls,
3254         .build_pcms = alc_build_pcms,
3255         .init = alc_init,
3256         .free = alc_free,
3257         .unsol_event = alc_unsol_event,
3258 #ifdef SND_HDA_NEEDS_RESUME
3259         .resume = alc_resume,
3260 #endif
3261 #ifdef CONFIG_SND_HDA_POWER_SAVE
3262         .check_power_status = alc_check_power_status,
3263 #endif
3264 };
3265
3266
3267 /*
3268  * Test configuration for debugging
3269  *
3270  * Almost all inputs/outputs are enabled.  I/O pins can be configured via
3271  * enum controls.
3272  */
3273 #ifdef CONFIG_SND_DEBUG
3274 static hda_nid_t alc880_test_dac_nids[4] = {
3275         0x02, 0x03, 0x04, 0x05
3276 };
3277
3278 static struct hda_input_mux alc880_test_capture_source = {
3279         .num_items = 7,
3280         .items = {
3281                 { "In-1", 0x0 },
3282                 { "In-2", 0x1 },
3283                 { "In-3", 0x2 },
3284                 { "In-4", 0x3 },
3285                 { "CD", 0x4 },
3286                 { "Front", 0x5 },
3287                 { "Surround", 0x6 },
3288         },
3289 };
3290
3291 static struct hda_channel_mode alc880_test_modes[4] = {
3292         { 2, NULL },
3293         { 4, NULL },
3294         { 6, NULL },
3295         { 8, NULL },
3296 };
3297
3298 static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
3299                                  struct snd_ctl_elem_info *uinfo)
3300 {
3301         static char *texts[] = {
3302                 "N/A", "Line Out", "HP Out",
3303                 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
3304         };
3305         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3306         uinfo->count = 1;
3307         uinfo->value.enumerated.items = 8;
3308         if (uinfo->value.enumerated.item >= 8)
3309                 uinfo->value.enumerated.item = 7;
3310         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3311         return 0;
3312 }
3313
3314 static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
3315                                 struct snd_ctl_elem_value *ucontrol)
3316 {
3317         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3318         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3319         unsigned int pin_ctl, item = 0;
3320
3321         pin_ctl = snd_hda_codec_read(codec, nid, 0,
3322                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3323         if (pin_ctl & AC_PINCTL_OUT_EN) {
3324                 if (pin_ctl & AC_PINCTL_HP_EN)
3325                         item = 2;
3326                 else
3327                         item = 1;
3328         } else if (pin_ctl & AC_PINCTL_IN_EN) {
3329                 switch (pin_ctl & AC_PINCTL_VREFEN) {
3330                 case AC_PINCTL_VREF_HIZ: item = 3; break;
3331                 case AC_PINCTL_VREF_50:  item = 4; break;
3332                 case AC_PINCTL_VREF_GRD: item = 5; break;
3333                 case AC_PINCTL_VREF_80:  item = 6; break;
3334                 case AC_PINCTL_VREF_100: item = 7; break;
3335                 }
3336         }
3337         ucontrol->value.enumerated.item[0] = item;
3338         return 0;
3339 }
3340
3341 static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
3342                                 struct snd_ctl_elem_value *ucontrol)
3343 {
3344         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3345         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3346         static unsigned int ctls[] = {
3347                 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
3348                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
3349                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
3350                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
3351                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
3352                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
3353         };
3354         unsigned int old_ctl, new_ctl;
3355
3356         old_ctl = snd_hda_codec_read(codec, nid, 0,
3357                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3358         new_ctl = ctls[ucontrol->value.enumerated.item[0]];
3359         if (old_ctl != new_ctl) {
3360                 int val;
3361                 snd_hda_codec_write_cache(codec, nid, 0,
3362                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
3363                                           new_ctl);
3364                 val = ucontrol->value.enumerated.item[0] >= 3 ?
3365                         HDA_AMP_MUTE : 0;
3366                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3367                                          HDA_AMP_MUTE, val);
3368                 return 1;
3369         }
3370         return 0;
3371 }
3372
3373 static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
3374                                  struct snd_ctl_elem_info *uinfo)
3375 {
3376         static char *texts[] = {
3377                 "Front", "Surround", "CLFE", "Side"
3378         };
3379         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3380         uinfo->count = 1;
3381         uinfo->value.enumerated.items = 4;
3382         if (uinfo->value.enumerated.item >= 4)
3383                 uinfo->value.enumerated.item = 3;
3384         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3385         return 0;
3386 }
3387
3388 static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
3389                                 struct snd_ctl_elem_value *ucontrol)
3390 {
3391         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3392         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3393         unsigned int sel;
3394
3395         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
3396         ucontrol->value.enumerated.item[0] = sel & 3;
3397         return 0;
3398 }
3399
3400 static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
3401                                 struct snd_ctl_elem_value *ucontrol)
3402 {
3403         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3404         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3405         unsigned int sel;
3406
3407         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
3408         if (ucontrol->value.enumerated.item[0] != sel) {
3409                 sel = ucontrol->value.enumerated.item[0] & 3;
3410                 snd_hda_codec_write_cache(codec, nid, 0,
3411                                           AC_VERB_SET_CONNECT_SEL, sel);
3412                 return 1;
3413         }
3414         return 0;
3415 }
3416
3417 #define PIN_CTL_TEST(xname,nid) {                       \
3418                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3419                         .name = xname,                 \
3420                         .info = alc_test_pin_ctl_info, \
3421                         .get = alc_test_pin_ctl_get,   \
3422                         .put = alc_test_pin_ctl_put,   \
3423                         .private_value = nid           \
3424                         }
3425
3426 #define PIN_SRC_TEST(xname,nid) {                       \
3427                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3428                         .name = xname,                 \
3429                         .info = alc_test_pin_src_info, \
3430                         .get = alc_test_pin_src_get,   \
3431                         .put = alc_test_pin_src_put,   \
3432                         .private_value = nid           \
3433                         }
3434
3435 static struct snd_kcontrol_new alc880_test_mixer[] = {
3436         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3437         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
3438         HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
3439         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3440         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
3441         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
3442         HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
3443         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
3444         PIN_CTL_TEST("Front Pin Mode", 0x14),
3445         PIN_CTL_TEST("Surround Pin Mode", 0x15),
3446         PIN_CTL_TEST("CLFE Pin Mode", 0x16),
3447         PIN_CTL_TEST("Side Pin Mode", 0x17),
3448         PIN_CTL_TEST("In-1 Pin Mode", 0x18),
3449         PIN_CTL_TEST("In-2 Pin Mode", 0x19),
3450         PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
3451         PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
3452         PIN_SRC_TEST("In-1 Pin Source", 0x18),
3453         PIN_SRC_TEST("In-2 Pin Source", 0x19),
3454         PIN_SRC_TEST("In-3 Pin Source", 0x1a),
3455         PIN_SRC_TEST("In-4 Pin Source", 0x1b),
3456         HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
3457         HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
3458         HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
3459         HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
3460         HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
3461         HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
3462         HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
3463         HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
3464         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
3465         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
3466         {
3467                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3468                 .name = "Channel Mode",
3469                 .info = alc_ch_mode_info,
3470                 .get = alc_ch_mode_get,
3471                 .put = alc_ch_mode_put,
3472         },
3473         { } /* end */
3474 };
3475
3476 static struct hda_verb alc880_test_init_verbs[] = {
3477         /* Unmute inputs of 0x0c - 0x0f */
3478         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3479         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3480         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3481         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3482         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3483         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3484         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3485         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3486         /* Vol output for 0x0c-0x0f */
3487         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3488         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3489         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3490         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3491         /* Set output pins 0x14-0x17 */
3492         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3493         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3494         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3495         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3496         /* Unmute output pins 0x14-0x17 */
3497         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3498         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3499         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3500         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3501         /* Set input pins 0x18-0x1c */
3502         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3503         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3504         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3505         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3506         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3507         /* Mute input pins 0x18-0x1b */
3508         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3509         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3510         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3511         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3512         /* ADC set up */
3513         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3514         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
3515         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3516         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
3517         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3518         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
3519         /* Analog input/passthru */
3520         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3521         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3522         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3523         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3524         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3525         { }
3526 };
3527 #endif
3528
3529 /*
3530  */
3531
3532 static const char *alc880_models[ALC880_MODEL_LAST] = {
3533         [ALC880_3ST]            = "3stack",
3534         [ALC880_TCL_S700]       = "tcl",
3535         [ALC880_3ST_DIG]        = "3stack-digout",
3536         [ALC880_CLEVO]          = "clevo",
3537         [ALC880_5ST]            = "5stack",
3538         [ALC880_5ST_DIG]        = "5stack-digout",
3539         [ALC880_W810]           = "w810",
3540         [ALC880_Z71V]           = "z71v",
3541         [ALC880_6ST]            = "6stack",
3542         [ALC880_6ST_DIG]        = "6stack-digout",
3543         [ALC880_ASUS]           = "asus",
3544         [ALC880_ASUS_W1V]       = "asus-w1v",
3545         [ALC880_ASUS_DIG]       = "asus-dig",
3546         [ALC880_ASUS_DIG2]      = "asus-dig2",
3547         [ALC880_UNIWILL_DIG]    = "uniwill",
3548         [ALC880_UNIWILL_P53]    = "uniwill-p53",
3549         [ALC880_FUJITSU]        = "fujitsu",
3550         [ALC880_F1734]          = "F1734",
3551         [ALC880_LG]             = "lg",
3552         [ALC880_LG_LW]          = "lg-lw",
3553         [ALC880_MEDION_RIM]     = "medion",
3554 #ifdef CONFIG_SND_DEBUG
3555         [ALC880_TEST]           = "test",
3556 #endif
3557         [ALC880_AUTO]           = "auto",
3558 };
3559
3560 static struct snd_pci_quirk alc880_cfg_tbl[] = {
3561         SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
3562         SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
3563         SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
3564         SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
3565         SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
3566         SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
3567         SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
3568         SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
3569         SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
3570         SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
3571         SND_PCI_QUIRK(0x103c, 0x2a09, "HP", ALC880_5ST),
3572         SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
3573         SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
3574         SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
3575         SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
3576         SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
3577         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
3578         SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
3579         /* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
3580         SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
3581         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
3582         SND_PCI_QUIRK(0x1043, 0x814e, "ASUS P5GD1 w/SPDIF", ALC880_6ST_DIG),
3583         SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
3584         SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
3585         SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
3586         SND_PCI_QUIRK(0x1043, 0, "ASUS", ALC880_ASUS), /* default ASUS */
3587         SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
3588         SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
3589         SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
3590         SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
3591         SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
3592         SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
3593         SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
3594         SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
3595         SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
3596         SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
3597         SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
3598         SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
3599         SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
3600         SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
3601         SND_PCI_QUIRK(0x1584, 0x9054, "Uniwlll", ALC880_F1734),
3602         SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
3603         SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
3604         SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
3605         SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_MEDION_RIM),
3606         SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
3607         SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
3608         SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
3609         SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FUJITSU),
3610         SND_PCI_QUIRK(0x1734, 0x10ac, "FSC", ALC880_UNIWILL),
3611         SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
3612         SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
3613         SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
3614         SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
3615         SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
3616         SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
3617         SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG), /* broken BIOS */
3618         SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
3619         SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
3620         SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
3621         SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
3622         SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
3623         SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
3624         SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
3625         SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
3626         SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
3627         SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
3628         SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
3629         SND_PCI_QUIRK(0x8086, 0, "Intel mobo", ALC880_3ST), /* default Intel */
3630         SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
3631         SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
3632         {}
3633 };
3634
3635 /*
3636  * ALC880 codec presets
3637  */
3638 static struct alc_config_preset alc880_presets[] = {
3639         [ALC880_3ST] = {
3640                 .mixers = { alc880_three_stack_mixer },
3641                 .init_verbs = { alc880_volume_init_verbs,
3642                                 alc880_pin_3stack_init_verbs },
3643                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3644                 .dac_nids = alc880_dac_nids,
3645                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3646                 .channel_mode = alc880_threestack_modes,
3647                 .need_dac_fix = 1,
3648                 .input_mux = &alc880_capture_source,
3649         },
3650         [ALC880_3ST_DIG] = {
3651                 .mixers = { alc880_three_stack_mixer },
3652                 .init_verbs = { alc880_volume_init_verbs,
3653                                 alc880_pin_3stack_init_verbs },
3654                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3655                 .dac_nids = alc880_dac_nids,
3656                 .dig_out_nid = ALC880_DIGOUT_NID,
3657                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3658                 .channel_mode = alc880_threestack_modes,
3659                 .need_dac_fix = 1,
3660                 .input_mux = &alc880_capture_source,
3661         },
3662         [ALC880_TCL_S700] = {
3663                 .mixers = { alc880_tcl_s700_mixer },
3664                 .init_verbs = { alc880_volume_init_verbs,
3665                                 alc880_pin_tcl_S700_init_verbs,
3666                                 alc880_gpio2_init_verbs },
3667                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3668                 .dac_nids = alc880_dac_nids,
3669                 .adc_nids = alc880_adc_nids_alt, /* FIXME: correct? */
3670                 .num_adc_nids = 1, /* single ADC */
3671                 .hp_nid = 0x03,
3672                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3673                 .channel_mode = alc880_2_jack_modes,
3674                 .input_mux = &alc880_capture_source,
3675         },
3676         [ALC880_5ST] = {
3677                 .mixers = { alc880_three_stack_mixer,
3678                             alc880_five_stack_mixer},
3679                 .init_verbs = { alc880_volume_init_verbs,
3680                                 alc880_pin_5stack_init_verbs },
3681                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3682                 .dac_nids = alc880_dac_nids,
3683                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3684                 .channel_mode = alc880_fivestack_modes,
3685                 .input_mux = &alc880_capture_source,
3686         },
3687         [ALC880_5ST_DIG] = {
3688                 .mixers = { alc880_three_stack_mixer,
3689                             alc880_five_stack_mixer },
3690                 .init_verbs = { alc880_volume_init_verbs,
3691                                 alc880_pin_5stack_init_verbs },
3692                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3693                 .dac_nids = alc880_dac_nids,
3694                 .dig_out_nid = ALC880_DIGOUT_NID,
3695                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3696                 .channel_mode = alc880_fivestack_modes,
3697                 .input_mux = &alc880_capture_source,
3698         },
3699         [ALC880_6ST] = {
3700                 .mixers = { alc880_six_stack_mixer },
3701                 .init_verbs = { alc880_volume_init_verbs,
3702                                 alc880_pin_6stack_init_verbs },
3703                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3704                 .dac_nids = alc880_6st_dac_nids,
3705                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3706                 .channel_mode = alc880_sixstack_modes,
3707                 .input_mux = &alc880_6stack_capture_source,
3708         },
3709         [ALC880_6ST_DIG] = {
3710                 .mixers = { alc880_six_stack_mixer },
3711                 .init_verbs = { alc880_volume_init_verbs,
3712                                 alc880_pin_6stack_init_verbs },
3713                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3714                 .dac_nids = alc880_6st_dac_nids,
3715                 .dig_out_nid = ALC880_DIGOUT_NID,
3716                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3717                 .channel_mode = alc880_sixstack_modes,
3718                 .input_mux = &alc880_6stack_capture_source,
3719         },
3720         [ALC880_W810] = {
3721                 .mixers = { alc880_w810_base_mixer },
3722                 .init_verbs = { alc880_volume_init_verbs,
3723                                 alc880_pin_w810_init_verbs,
3724                                 alc880_gpio2_init_verbs },
3725                 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
3726                 .dac_nids = alc880_w810_dac_nids,
3727                 .dig_out_nid = ALC880_DIGOUT_NID,
3728                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3729                 .channel_mode = alc880_w810_modes,
3730                 .input_mux = &alc880_capture_source,
3731         },
3732         [ALC880_Z71V] = {
3733                 .mixers = { alc880_z71v_mixer },
3734                 .init_verbs = { alc880_volume_init_verbs,
3735                                 alc880_pin_z71v_init_verbs },
3736                 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
3737                 .dac_nids = alc880_z71v_dac_nids,
3738                 .dig_out_nid = ALC880_DIGOUT_NID,
3739                 .hp_nid = 0x03,
3740                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3741                 .channel_mode = alc880_2_jack_modes,
3742                 .input_mux = &alc880_capture_source,
3743         },
3744         [ALC880_F1734] = {
3745                 .mixers = { alc880_f1734_mixer },
3746                 .init_verbs = { alc880_volume_init_verbs,
3747                                 alc880_pin_f1734_init_verbs },
3748                 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
3749                 .dac_nids = alc880_f1734_dac_nids,
3750                 .hp_nid = 0x02,
3751                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3752                 .channel_mode = alc880_2_jack_modes,
3753                 .input_mux = &alc880_f1734_capture_source,
3754                 .unsol_event = alc880_uniwill_p53_unsol_event,
3755                 .init_hook = alc880_uniwill_p53_hp_automute,
3756         },
3757         [ALC880_ASUS] = {
3758                 .mixers = { alc880_asus_mixer },
3759                 .init_verbs = { alc880_volume_init_verbs,
3760                                 alc880_pin_asus_init_verbs,
3761                                 alc880_gpio1_init_verbs },
3762                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3763                 .dac_nids = alc880_asus_dac_nids,
3764                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3765                 .channel_mode = alc880_asus_modes,
3766                 .need_dac_fix = 1,
3767                 .input_mux = &alc880_capture_source,
3768         },
3769         [ALC880_ASUS_DIG] = {
3770                 .mixers = { alc880_asus_mixer },
3771                 .init_verbs = { alc880_volume_init_verbs,
3772                                 alc880_pin_asus_init_verbs,
3773                                 alc880_gpio1_init_verbs },
3774                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3775                 .dac_nids = alc880_asus_dac_nids,
3776                 .dig_out_nid = ALC880_DIGOUT_NID,
3777                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3778                 .channel_mode = alc880_asus_modes,
3779                 .need_dac_fix = 1,
3780                 .input_mux = &alc880_capture_source,
3781         },
3782         [ALC880_ASUS_DIG2] = {
3783                 .mixers = { alc880_asus_mixer },
3784                 .init_verbs = { alc880_volume_init_verbs,
3785                                 alc880_pin_asus_init_verbs,
3786                                 alc880_gpio2_init_verbs }, /* use GPIO2 */
3787                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3788                 .dac_nids = alc880_asus_dac_nids,
3789                 .dig_out_nid = ALC880_DIGOUT_NID,
3790                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3791                 .channel_mode = alc880_asus_modes,
3792                 .need_dac_fix = 1,
3793                 .input_mux = &alc880_capture_source,
3794         },
3795         [ALC880_ASUS_W1V] = {
3796                 .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
3797                 .init_verbs = { alc880_volume_init_verbs,
3798                                 alc880_pin_asus_init_verbs,
3799                                 alc880_gpio1_init_verbs },
3800                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3801                 .dac_nids = alc880_asus_dac_nids,
3802                 .dig_out_nid = ALC880_DIGOUT_NID,
3803                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3804                 .channel_mode = alc880_asus_modes,
3805                 .need_dac_fix = 1,
3806                 .input_mux = &alc880_capture_source,
3807         },
3808         [ALC880_UNIWILL_DIG] = {
3809                 .mixers = { alc880_asus_mixer, alc880_pcbeep_mixer },
3810                 .init_verbs = { alc880_volume_init_verbs,
3811                                 alc880_pin_asus_init_verbs },
3812                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3813                 .dac_nids = alc880_asus_dac_nids,
3814                 .dig_out_nid = ALC880_DIGOUT_NID,
3815                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3816                 .channel_mode = alc880_asus_modes,
3817                 .need_dac_fix = 1,
3818                 .input_mux = &alc880_capture_source,
3819         },
3820         [ALC880_UNIWILL] = {
3821                 .mixers = { alc880_uniwill_mixer },
3822                 .init_verbs = { alc880_volume_init_verbs,
3823                                 alc880_uniwill_init_verbs },
3824                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3825                 .dac_nids = alc880_asus_dac_nids,
3826                 .dig_out_nid = ALC880_DIGOUT_NID,
3827                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3828                 .channel_mode = alc880_threestack_modes,
3829                 .need_dac_fix = 1,
3830                 .input_mux = &alc880_capture_source,
3831                 .unsol_event = alc880_uniwill_unsol_event,
3832                 .init_hook = alc880_uniwill_automute,
3833         },
3834         [ALC880_UNIWILL_P53] = {
3835                 .mixers = { alc880_uniwill_p53_mixer },
3836                 .init_verbs = { alc880_volume_init_verbs,
3837                                 alc880_uniwill_p53_init_verbs },
3838                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3839                 .dac_nids = alc880_asus_dac_nids,
3840                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3841                 .channel_mode = alc880_threestack_modes,
3842                 .input_mux = &alc880_capture_source,
3843                 .unsol_event = alc880_uniwill_p53_unsol_event,
3844                 .init_hook = alc880_uniwill_p53_hp_automute,
3845         },
3846         [ALC880_FUJITSU] = {
3847                 .mixers = { alc880_fujitsu_mixer,
3848                             alc880_pcbeep_mixer, },
3849                 .init_verbs = { alc880_volume_init_verbs,
3850                                 alc880_uniwill_p53_init_verbs,
3851                                 alc880_beep_init_verbs },
3852                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3853                 .dac_nids = alc880_dac_nids,
3854                 .dig_out_nid = ALC880_DIGOUT_NID,
3855                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3856                 .channel_mode = alc880_2_jack_modes,
3857                 .input_mux = &alc880_capture_source,
3858                 .unsol_event = alc880_uniwill_p53_unsol_event,
3859                 .init_hook = alc880_uniwill_p53_hp_automute,
3860         },
3861         [ALC880_CLEVO] = {
3862                 .mixers = { alc880_three_stack_mixer },
3863                 .init_verbs = { alc880_volume_init_verbs,
3864                                 alc880_pin_clevo_init_verbs },
3865                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3866                 .dac_nids = alc880_dac_nids,
3867                 .hp_nid = 0x03,
3868                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3869                 .channel_mode = alc880_threestack_modes,
3870                 .need_dac_fix = 1,
3871                 .input_mux = &alc880_capture_source,
3872         },
3873         [ALC880_LG] = {
3874                 .mixers = { alc880_lg_mixer },
3875                 .init_verbs = { alc880_volume_init_verbs,
3876                                 alc880_lg_init_verbs },
3877                 .num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
3878                 .dac_nids = alc880_lg_dac_nids,
3879                 .dig_out_nid = ALC880_DIGOUT_NID,
3880                 .num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
3881                 .channel_mode = alc880_lg_ch_modes,
3882                 .need_dac_fix = 1,
3883                 .input_mux = &alc880_lg_capture_source,
3884                 .unsol_event = alc880_lg_unsol_event,
3885                 .init_hook = alc880_lg_automute,
3886 #ifdef CONFIG_SND_HDA_POWER_SAVE
3887                 .loopbacks = alc880_lg_loopbacks,
3888 #endif
3889         },
3890         [ALC880_LG_LW] = {
3891                 .mixers = { alc880_lg_lw_mixer },
3892                 .init_verbs = { alc880_volume_init_verbs,
3893                                 alc880_lg_lw_init_verbs },
3894                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3895                 .dac_nids = alc880_dac_nids,
3896                 .dig_out_nid = ALC880_DIGOUT_NID,
3897                 .num_channel_mode = ARRAY_SIZE(alc880_lg_lw_modes),
3898                 .channel_mode = alc880_lg_lw_modes,
3899                 .input_mux = &alc880_lg_lw_capture_source,
3900                 .unsol_event = alc880_lg_lw_unsol_event,
3901                 .init_hook = alc880_lg_lw_automute,
3902         },
3903         [ALC880_MEDION_RIM] = {
3904                 .mixers = { alc880_medion_rim_mixer },
3905                 .init_verbs = { alc880_volume_init_verbs,
3906                                 alc880_medion_rim_init_verbs,
3907                                 alc_gpio2_init_verbs },
3908                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3909                 .dac_nids = alc880_dac_nids,
3910                 .dig_out_nid = ALC880_DIGOUT_NID,
3911                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3912                 .channel_mode = alc880_2_jack_modes,
3913                 .input_mux = &alc880_medion_rim_capture_source,
3914                 .unsol_event = alc880_medion_rim_unsol_event,
3915                 .init_hook = alc880_medion_rim_automute,
3916         },
3917 #ifdef CONFIG_SND_DEBUG
3918         [ALC880_TEST] = {
3919                 .mixers = { alc880_test_mixer },
3920                 .init_verbs = { alc880_test_init_verbs },
3921                 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
3922                 .dac_nids = alc880_test_dac_nids,
3923                 .dig_out_nid = ALC880_DIGOUT_NID,
3924                 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
3925                 .channel_mode = alc880_test_modes,
3926                 .input_mux = &alc880_test_capture_source,
3927         },
3928 #endif
3929 };
3930
3931 /*
3932  * Automatic parse of I/O pins from the BIOS configuration
3933  */
3934
3935 enum {
3936         ALC_CTL_WIDGET_VOL,
3937         ALC_CTL_WIDGET_MUTE,
3938         ALC_CTL_BIND_MUTE,
3939 };
3940 static struct snd_kcontrol_new alc880_control_templates[] = {
3941         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
3942         HDA_CODEC_MUTE(NULL, 0, 0, 0),
3943         HDA_BIND_MUTE(NULL, 0, 0, 0),
3944 };
3945
3946 /* add dynamic controls */
3947 static int add_control(struct alc_spec *spec, int type, const char *name,
3948                        unsigned long val)
3949 {
3950         struct snd_kcontrol_new *knew;
3951
3952         snd_array_init(&spec->kctls, sizeof(*knew), 32);
3953         knew = snd_array_new(&spec->kctls);
3954         if (!knew)
3955                 return -ENOMEM;
3956         *knew = alc880_control_templates[type];
3957         knew->name = kstrdup(name, GFP_KERNEL);
3958         if (!knew->name)
3959                 return -ENOMEM;
3960         knew->private_value = val;
3961         return 0;
3962 }
3963
3964 #define alc880_is_fixed_pin(nid)        ((nid) >= 0x14 && (nid) <= 0x17)
3965 #define alc880_fixed_pin_idx(nid)       ((nid) - 0x14)
3966 #define alc880_is_multi_pin(nid)        ((nid) >= 0x18)
3967 #define alc880_multi_pin_idx(nid)       ((nid) - 0x18)
3968 #define alc880_is_input_pin(nid)        ((nid) >= 0x18)
3969 #define alc880_input_pin_idx(nid)       ((nid) - 0x18)
3970 #define alc880_idx_to_dac(nid)          ((nid) + 0x02)
3971 #define alc880_dac_to_idx(nid)          ((nid) - 0x02)
3972 #define alc880_idx_to_mixer(nid)        ((nid) + 0x0c)
3973 #define alc880_idx_to_selector(nid)     ((nid) + 0x10)
3974 #define ALC880_PIN_CD_NID               0x1c
3975
3976 /* fill in the dac_nids table from the parsed pin configuration */
3977 static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
3978                                      const struct auto_pin_cfg *cfg)
3979 {
3980         hda_nid_t nid;
3981         int assigned[4];
3982         int i, j;
3983
3984         memset(assigned, 0, sizeof(assigned));
3985         spec->multiout.dac_nids = spec->private_dac_nids;
3986
3987         /* check the pins hardwired to audio widget */
3988         for (i = 0; i < cfg->line_outs; i++) {
3989                 nid = cfg->line_out_pins[i];
3990                 if (alc880_is_fixed_pin(nid)) {
3991                         int idx = alc880_fixed_pin_idx(nid);
3992                         spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
3993                         assigned[idx] = 1;
3994                 }
3995         }
3996         /* left pins can be connect to any audio widget */
3997         for (i = 0; i < cfg->line_outs; i++) {
3998                 nid = cfg->line_out_pins[i];
3999                 if (alc880_is_fixed_pin(nid))
4000                         continue;
4001                 /* search for an empty channel */
4002                 for (j = 0; j < cfg->line_outs; j++) {
4003                         if (!assigned[j]) {
4004                                 spec->multiout.dac_nids[i] =
4005                                         alc880_idx_to_dac(j);
4006                                 assigned[j] = 1;
4007                                 break;
4008                         }
4009                 }
4010         }
4011         spec->multiout.num_dacs = cfg->line_outs;
4012         return 0;
4013 }
4014
4015 /* add playback controls from the parsed DAC table */
4016 static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
4017                                              const struct auto_pin_cfg *cfg)
4018 {
4019         char name[32];
4020         static const char *chname[4] = {
4021                 "Front", "Surround", NULL /*CLFE*/, "Side"
4022         };
4023         hda_nid_t nid;
4024         int i, err;
4025
4026         for (i = 0; i < cfg->line_outs; i++) {
4027                 if (!spec->multiout.dac_nids[i])
4028                         continue;
4029                 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
4030                 if (i == 2) {
4031                         /* Center/LFE */
4032                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
4033                                           "Center Playback Volume",
4034                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
4035                                                               HDA_OUTPUT));
4036                         if (err < 0)
4037                                 return err;
4038                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
4039                                           "LFE Playback Volume",
4040                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
4041                                                               HDA_OUTPUT));
4042                         if (err < 0)
4043                                 return err;
4044                         err = add_control(spec, ALC_CTL_BIND_MUTE,
4045                                           "Center Playback Switch",
4046                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
4047                                                               HDA_INPUT));
4048                         if (err < 0)
4049                                 return err;
4050                         err = add_control(spec, ALC_CTL_BIND_MUTE,
4051                                           "LFE Playback Switch",
4052                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
4053                                                               HDA_INPUT));
4054                         if (err < 0)
4055                                 return err;
4056                 } else {
4057                         sprintf(name, "%s Playback Volume", chname[i]);
4058                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4059                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
4060                                                               HDA_OUTPUT));
4061                         if (err < 0)
4062                                 return err;
4063                         sprintf(name, "%s Playback Switch", chname[i]);
4064                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
4065                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
4066                                                               HDA_INPUT));
4067                         if (err < 0)
4068                                 return err;
4069                 }
4070         }
4071         return 0;
4072 }
4073
4074 /* add playback controls for speaker and HP outputs */
4075 static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
4076                                         const char *pfx)
4077 {
4078         hda_nid_t nid;
4079         int err;
4080         char name[32];
4081
4082         if (!pin)
4083                 return 0;
4084
4085         if (alc880_is_fixed_pin(pin)) {
4086                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
4087                 /* specify the DAC as the extra output */
4088                 if (!spec->multiout.hp_nid)
4089                         spec->multiout.hp_nid = nid;
4090                 else
4091                         spec->multiout.extra_out_nid[0] = nid;
4092                 /* control HP volume/switch on the output mixer amp */
4093                 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
4094                 sprintf(name, "%s Playback Volume", pfx);
4095                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4096                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
4097                 if (err < 0)
4098                         return err;
4099                 sprintf(name, "%s Playback Switch", pfx);
4100                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
4101                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
4102                 if (err < 0)
4103                         return err;
4104         } else if (alc880_is_multi_pin(pin)) {
4105                 /* set manual connection */
4106                 /* we have only a switch on HP-out PIN */
4107                 sprintf(name, "%s Playback Switch", pfx);
4108                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
4109                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4110                 if (err < 0)
4111                         return err;
4112         }
4113         return 0;
4114 }
4115
4116 /* create input playback/capture controls for the given pin */
4117 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
4118                             const char *ctlname,
4119                             int idx, hda_nid_t mix_nid)
4120 {
4121         char name[32];
4122         int err;
4123
4124         sprintf(name, "%s Playback Volume", ctlname);
4125         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4126                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
4127         if (err < 0)
4128                 return err;
4129         sprintf(name, "%s Playback Switch", ctlname);
4130         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
4131                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
4132         if (err < 0)
4133                 return err;
4134         return 0;
4135 }
4136
4137 /* create playback/capture controls for input pins */
4138 static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec,
4139                                                 const struct auto_pin_cfg *cfg)
4140 {
4141         struct hda_input_mux *imux = &spec->private_imux[0];
4142         int i, err, idx;
4143
4144         for (i = 0; i < AUTO_PIN_LAST; i++) {
4145                 if (alc880_is_input_pin(cfg->input_pins[i])) {
4146                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
4147                         err = new_analog_input(spec, cfg->input_pins[i],
4148                                                auto_pin_cfg_labels[i],
4149                                                idx, 0x0b);
4150                         if (err < 0)
4151                                 return err;
4152                         imux->items[imux->num_items].label =
4153                                 auto_pin_cfg_labels[i];
4154                         imux->items[imux->num_items].index =
4155                                 alc880_input_pin_idx(cfg->input_pins[i]);
4156                         imux->num_items++;
4157                 }
4158         }
4159         return 0;
4160 }
4161
4162 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
4163                                unsigned int pin_type)
4164 {
4165         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4166                             pin_type);
4167         /* unmute pin */
4168         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4169                             AMP_OUT_UNMUTE);
4170 }
4171
4172 static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
4173                                               hda_nid_t nid, int pin_type,
4174                                               int dac_idx)
4175 {
4176         alc_set_pin_output(codec, nid, pin_type);
4177         /* need the manual connection? */
4178         if (alc880_is_multi_pin(nid)) {
4179                 struct alc_spec *spec = codec->spec;
4180                 int idx = alc880_multi_pin_idx(nid);
4181                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
4182                                     AC_VERB_SET_CONNECT_SEL,
4183                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
4184         }
4185 }
4186
4187 static int get_pin_type(int line_out_type)
4188 {
4189         if (line_out_type == AUTO_PIN_HP_OUT)
4190                 return PIN_HP;
4191         else
4192                 return PIN_OUT;
4193 }
4194
4195 static void alc880_auto_init_multi_out(struct hda_codec *codec)
4196 {
4197         struct alc_spec *spec = codec->spec;
4198         int i;
4199
4200         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
4201         for (i = 0; i < spec->autocfg.line_outs; i++) {
4202                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
4203                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
4204                 alc880_auto_set_output_and_unmute(codec, nid, pin_type, i);
4205         }
4206 }
4207
4208 static void alc880_auto_init_extra_out(struct hda_codec *codec)
4209 {
4210         struct alc_spec *spec = codec->spec;
4211         hda_nid_t pin;
4212
4213         pin = spec->autocfg.speaker_pins[0];
4214         if (pin) /* connect to front */
4215                 alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
4216         pin = spec->autocfg.hp_pins[0];
4217         if (pin) /* connect to front */
4218                 alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
4219 }
4220
4221 static void alc880_auto_init_analog_input(struct hda_codec *codec)
4222 {
4223         struct alc_spec *spec = codec->spec;
4224         int i;
4225
4226         for (i = 0; i < AUTO_PIN_LAST; i++) {
4227                 hda_nid_t nid = spec->autocfg.input_pins[i];
4228                 if (alc880_is_input_pin(nid)) {
4229                         snd_hda_codec_write(codec, nid, 0,
4230                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
4231                                             i <= AUTO_PIN_FRONT_MIC ?
4232                                             PIN_VREF80 : PIN_IN);
4233                         if (nid != ALC880_PIN_CD_NID)
4234                                 snd_hda_codec_write(codec, nid, 0,
4235                                                     AC_VERB_SET_AMP_GAIN_MUTE,
4236                                                     AMP_OUT_MUTE);
4237                 }
4238         }
4239 }
4240
4241 /* parse the BIOS configuration and set up the alc_spec */
4242 /* return 1 if successful, 0 if the proper config is not found,
4243  * or a negative error code
4244  */
4245 static int alc880_parse_auto_config(struct hda_codec *codec)
4246 {
4247         struct alc_spec *spec = codec->spec;
4248         int err;
4249         static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4250
4251         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
4252                                            alc880_ignore);
4253         if (err < 0)
4254                 return err;
4255         if (!spec->autocfg.line_outs)
4256                 return 0; /* can't find valid BIOS pin config */
4257
4258         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
4259         if (err < 0)
4260                 return err;
4261         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
4262         if (err < 0)
4263                 return err;
4264         err = alc880_auto_create_extra_out(spec,
4265                                            spec->autocfg.speaker_pins[0],
4266                                            "Speaker");
4267         if (err < 0)
4268                 return err;
4269         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
4270                                            "Headphone");
4271         if (err < 0)
4272                 return err;
4273         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
4274         if (err < 0)
4275                 return err;
4276
4277         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4278
4279         if (spec->autocfg.dig_out_pin)
4280                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
4281         if (spec->autocfg.dig_in_pin)
4282                 spec->dig_in_nid = ALC880_DIGIN_NID;
4283
4284         if (spec->kctls.list)
4285                 add_mixer(spec, spec->kctls.list);
4286
4287         add_verb(spec, alc880_volume_init_verbs);
4288
4289         spec->num_mux_defs = 1;
4290         spec->input_mux = &spec->private_imux[0];
4291
4292         store_pin_configs(codec);
4293         return 1;
4294 }
4295
4296 /* additional initialization for auto-configuration model */
4297 static void alc880_auto_init(struct hda_codec *codec)
4298 {
4299         struct alc_spec *spec = codec->spec;
4300         alc880_auto_init_multi_out(codec);
4301         alc880_auto_init_extra_out(codec);
4302         alc880_auto_init_analog_input(codec);
4303         if (spec->unsol_event)
4304                 alc_inithook(codec);
4305 }
4306
4307 /*
4308  * OK, here we have finally the patch for ALC880
4309  */
4310
4311 static void set_capture_mixer(struct alc_spec *spec)
4312 {
4313         static struct snd_kcontrol_new *caps[3] = {
4314                 alc_capture_mixer1,
4315                 alc_capture_mixer2,
4316                 alc_capture_mixer3,
4317         };
4318         if (spec->num_adc_nids > 0 && spec->num_adc_nids <= 3)
4319                 spec->cap_mixer = caps[spec->num_adc_nids - 1];
4320 }
4321
4322 static int patch_alc880(struct hda_codec *codec)
4323 {
4324         struct alc_spec *spec;
4325         int board_config;
4326         int err;
4327
4328         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4329         if (spec == NULL)
4330                 return -ENOMEM;
4331
4332         codec->spec = spec;
4333
4334         board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
4335                                                   alc880_models,
4336                                                   alc880_cfg_tbl);
4337         if (board_config < 0) {
4338                 printk(KERN_INFO "hda_codec: Unknown model for ALC880, "
4339                        "trying auto-probe from BIOS...\n");
4340                 board_config = ALC880_AUTO;
4341         }
4342
4343         if (board_config == ALC880_AUTO) {
4344                 /* automatic parse from the BIOS config */
4345                 err = alc880_parse_auto_config(codec);
4346                 if (err < 0) {
4347                         alc_free(codec);
4348                         return err;
4349                 } else if (!err) {
4350                         printk(KERN_INFO
4351                                "hda_codec: Cannot set up configuration "
4352                                "from BIOS.  Using 3-stack mode...\n");
4353                         board_config = ALC880_3ST;
4354                 }
4355         }
4356
4357         if (board_config != ALC880_AUTO)
4358                 setup_preset(spec, &alc880_presets[board_config]);
4359
4360         spec->stream_name_analog = "ALC880 Analog";
4361         spec->stream_analog_playback = &alc880_pcm_analog_playback;
4362         spec->stream_analog_capture = &alc880_pcm_analog_capture;
4363         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
4364
4365         spec->stream_name_digital = "ALC880 Digital";
4366         spec->stream_digital_playback = &alc880_pcm_digital_playback;
4367         spec->stream_digital_capture = &alc880_pcm_digital_capture;
4368
4369         if (!spec->adc_nids && spec->input_mux) {
4370                 /* check whether NID 0x07 is valid */
4371                 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
4372                 /* get type */
4373                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
4374                 if (wcap != AC_WID_AUD_IN) {
4375                         spec->adc_nids = alc880_adc_nids_alt;
4376                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
4377                 } else {
4378                         spec->adc_nids = alc880_adc_nids;
4379                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
4380                 }
4381         }
4382         set_capture_mixer(spec);
4383
4384         spec->vmaster_nid = 0x0c;
4385
4386         codec->patch_ops = alc_patch_ops;
4387         if (board_config == ALC880_AUTO)
4388                 spec->init_hook = alc880_auto_init;
4389 #ifdef CONFIG_SND_HDA_POWER_SAVE
4390         if (!spec->loopback.amplist)
4391                 spec->loopback.amplist = alc880_loopbacks;
4392 #endif
4393         codec->proc_widget_hook = print_realtek_coef;
4394
4395         return 0;
4396 }
4397
4398
4399 /*
4400  * ALC260 support
4401  */
4402
4403 static hda_nid_t alc260_dac_nids[1] = {
4404         /* front */
4405         0x02,
4406 };
4407
4408 static hda_nid_t alc260_adc_nids[1] = {
4409         /* ADC0 */
4410         0x04,
4411 };
4412
4413 static hda_nid_t alc260_adc_nids_alt[1] = {
4414         /* ADC1 */
4415         0x05,
4416 };
4417
4418 /* NIDs used when simultaneous access to both ADCs makes sense.  Note that
4419  * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
4420  */
4421 static hda_nid_t alc260_dual_adc_nids[2] = {
4422         /* ADC0, ADC1 */
4423         0x04, 0x05
4424 };
4425
4426 #define ALC260_DIGOUT_NID       0x03
4427 #define ALC260_DIGIN_NID        0x06
4428
4429 static struct hda_input_mux alc260_capture_source = {
4430         .num_items = 4,
4431         .items = {
4432                 { "Mic", 0x0 },
4433                 { "Front Mic", 0x1 },
4434                 { "Line", 0x2 },
4435                 { "CD", 0x4 },
4436         },
4437 };
4438
4439 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
4440  * headphone jack and the internal CD lines since these are the only pins at
4441  * which audio can appear.  For flexibility, also allow the option of
4442  * recording the mixer output on the second ADC (ADC0 doesn't have a
4443  * connection to the mixer output).
4444  */
4445 static struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
4446         {
4447                 .num_items = 3,
4448                 .items = {
4449                         { "Mic/Line", 0x0 },
4450                         { "CD", 0x4 },
4451                         { "Headphone", 0x2 },
4452                 },
4453         },
4454         {
4455                 .num_items = 4,
4456                 .items = {
4457                         { "Mic/Line", 0x0 },
4458                         { "CD", 0x4 },
4459                         { "Headphone", 0x2 },
4460                         { "Mixer", 0x5 },
4461                 },
4462         },
4463
4464 };
4465
4466 /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
4467  * the Fujitsu S702x, but jacks are marked differently.
4468  */
4469 static struct hda_input_mux alc260_acer_capture_sources[2] = {
4470         {
4471                 .num_items = 4,
4472                 .items = {
4473                         { "Mic", 0x0 },
4474                         { "Line", 0x2 },
4475                         { "CD", 0x4 },
4476                         { "Headphone", 0x5 },
4477                 },
4478         },
4479         {
4480                 .num_items = 5,
4481                 .items = {
4482                         { "Mic", 0x0 },
4483                         { "Line", 0x2 },
4484                         { "CD", 0x4 },
4485                         { "Headphone", 0x6 },
4486                         { "Mixer", 0x5 },
4487                 },
4488         },
4489 };
4490 /*
4491  * This is just place-holder, so there's something for alc_build_pcms to look
4492  * at when it calculates the maximum number of channels. ALC260 has no mixer
4493  * element which allows changing the channel mode, so the verb list is
4494  * never used.
4495  */
4496 static struct hda_channel_mode alc260_modes[1] = {
4497         { 2, NULL },
4498 };
4499
4500
4501 /* Mixer combinations
4502  *
4503  * basic: base_output + input + pc_beep + capture
4504  * HP: base_output + input + capture_alt
4505  * HP_3013: hp_3013 + input + capture
4506  * fujitsu: fujitsu + capture
4507  * acer: acer + capture
4508  */
4509
4510 static struct snd_kcontrol_new alc260_base_output_mixer[] = {
4511         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4512         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
4513         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4514         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
4515         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4516         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4517         { } /* end */
4518 };
4519
4520 static struct snd_kcontrol_new alc260_input_mixer[] = {
4521         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4522         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4523         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4524         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4525         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4526         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4527         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
4528         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
4529         { } /* end */
4530 };
4531
4532 static struct snd_kcontrol_new alc260_pc_beep_mixer[] = {
4533         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x07, 0x05, HDA_INPUT),
4534         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x07, 0x05, HDA_INPUT),
4535         { } /* end */
4536 };
4537
4538 /* update HP, line and mono out pins according to the master switch */
4539 static void alc260_hp_master_update(struct hda_codec *codec,
4540                                     hda_nid_t hp, hda_nid_t line,
4541                                     hda_nid_t mono)
4542 {
4543         struct alc_spec *spec = codec->spec;
4544         unsigned int val = spec->master_sw ? PIN_HP : 0;
4545         /* change HP and line-out pins */
4546         snd_hda_codec_write(codec, hp, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4547                             val);
4548         snd_hda_codec_write(codec, line, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4549                             val);
4550         /* mono (speaker) depending on the HP jack sense */
4551         val = (val && !spec->jack_present) ? PIN_OUT : 0;
4552         snd_hda_codec_write(codec, mono, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4553                             val);
4554 }
4555
4556 static int alc260_hp_master_sw_get(struct snd_kcontrol *kcontrol,
4557                                    struct snd_ctl_elem_value *ucontrol)
4558 {
4559         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4560         struct alc_spec *spec = codec->spec;
4561         *ucontrol->value.integer.value = spec->master_sw;
4562         return 0;
4563 }
4564
4565 static int alc260_hp_master_sw_put(struct snd_kcontrol *kcontrol,
4566                                    struct snd_ctl_elem_value *ucontrol)
4567 {
4568         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4569         struct alc_spec *spec = codec->spec;
4570         int val = !!*ucontrol->value.integer.value;
4571         hda_nid_t hp, line, mono;
4572
4573         if (val == spec->master_sw)
4574                 return 0;
4575         spec->master_sw = val;
4576         hp = (kcontrol->private_value >> 16) & 0xff;
4577         line = (kcontrol->private_value >> 8) & 0xff;
4578         mono = kcontrol->private_value & 0xff;
4579         alc260_hp_master_update(codec, hp, line, mono);
4580         return 1;
4581 }
4582
4583 static struct snd_kcontrol_new alc260_hp_output_mixer[] = {
4584         {
4585                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4586                 .name = "Master Playback Switch",
4587                 .info = snd_ctl_boolean_mono_info,
4588                 .get = alc260_hp_master_sw_get,
4589                 .put = alc260_hp_master_sw_put,
4590                 .private_value = (0x0f << 16) | (0x10 << 8) | 0x11
4591         },
4592         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4593         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
4594         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4595         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
4596         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4597                               HDA_OUTPUT),
4598         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4599         { } /* end */
4600 };
4601
4602 static struct hda_verb alc260_hp_unsol_verbs[] = {
4603         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4604         {},
4605 };
4606
4607 static void alc260_hp_automute(struct hda_codec *codec)
4608 {
4609         struct alc_spec *spec = codec->spec;
4610         unsigned int present;
4611
4612         present = snd_hda_codec_read(codec, 0x10, 0,
4613                                      AC_VERB_GET_PIN_SENSE, 0);
4614         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4615         alc260_hp_master_update(codec, 0x0f, 0x10, 0x11);
4616 }
4617
4618 static void alc260_hp_unsol_event(struct hda_codec *codec, unsigned int res)
4619 {
4620         if ((res >> 26) == ALC880_HP_EVENT)
4621                 alc260_hp_automute(codec);
4622 }
4623
4624 static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
4625         {
4626                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4627                 .name = "Master Playback Switch",
4628                 .info = snd_ctl_boolean_mono_info,
4629                 .get = alc260_hp_master_sw_get,
4630                 .put = alc260_hp_master_sw_put,
4631                 .private_value = (0x15 << 16) | (0x10 << 8) | 0x11
4632         },
4633         HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4634         HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
4635         HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
4636         HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
4637         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4638         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
4639         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4640         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
4641         { } /* end */
4642 };
4643
4644 static struct hda_bind_ctls alc260_dc7600_bind_master_vol = {
4645         .ops = &snd_hda_bind_vol,
4646         .values = {
4647                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_OUTPUT),
4648                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
4649                 HDA_COMPOSE_AMP_VAL(0x0a, 3, 0, HDA_OUTPUT),
4650                 0
4651         },
4652 };
4653
4654 static struct hda_bind_ctls alc260_dc7600_bind_switch = {
4655         .ops = &snd_hda_bind_sw,
4656         .values = {
4657                 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
4658                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
4659                 0
4660         },
4661 };
4662
4663 static struct snd_kcontrol_new alc260_hp_dc7600_mixer[] = {
4664         HDA_BIND_VOL("Master Playback Volume", &alc260_dc7600_bind_master_vol),
4665         HDA_BIND_SW("LineOut Playback Switch", &alc260_dc7600_bind_switch),
4666         HDA_CODEC_MUTE("Speaker Playback Switch", 0x0f, 0x0, HDA_OUTPUT),
4667         HDA_CODEC_MUTE("Headphone Playback Switch", 0x10, 0x0, HDA_OUTPUT),
4668         { } /* end */
4669 };
4670
4671 static struct hda_verb alc260_hp_3013_unsol_verbs[] = {
4672         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4673         {},
4674 };
4675
4676 static void alc260_hp_3013_automute(struct hda_codec *codec)
4677 {
4678         struct alc_spec *spec = codec->spec;
4679         unsigned int present;
4680
4681         present = snd_hda_codec_read(codec, 0x15, 0,
4682                                      AC_VERB_GET_PIN_SENSE, 0);
4683         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4684         alc260_hp_master_update(codec, 0x15, 0x10, 0x11);
4685 }
4686
4687 static void alc260_hp_3013_unsol_event(struct hda_codec *codec,
4688                                        unsigned int res)
4689 {
4690         if ((res >> 26) == ALC880_HP_EVENT)
4691                 alc260_hp_3013_automute(codec);
4692 }
4693
4694 static void alc260_hp_3012_automute(struct hda_codec *codec)
4695 {
4696         unsigned int present, bits;
4697
4698         present = snd_hda_codec_read(codec, 0x10, 0,
4699                         AC_VERB_GET_PIN_SENSE, 0) & AC_PINSENSE_PRESENCE;
4700
4701         bits = present ? 0 : PIN_OUT;
4702         snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4703                             bits);
4704         snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4705                             bits);
4706         snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4707                             bits);
4708 }
4709
4710 static void alc260_hp_3012_unsol_event(struct hda_codec *codec,
4711                                        unsigned int res)
4712 {
4713         if ((res >> 26) == ALC880_HP_EVENT)
4714                 alc260_hp_3012_automute(codec);
4715 }
4716
4717 /* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12,
4718  * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
4719  */
4720 static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
4721         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4722         HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
4723         ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4724         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4725         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4726         HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
4727         HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
4728         ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
4729         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4730         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4731         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4732         HDA_BIND_MUTE("Speaker Playback Switch", 0x09, 2, HDA_INPUT),
4733         { } /* end */
4734 };
4735
4736 /* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks.  Note that current
4737  * versions of the ALC260 don't act on requests to enable mic bias from NID
4738  * 0x0f (used to drive the headphone jack in these laptops).  The ALC260
4739  * datasheet doesn't mention this restriction.  At this stage it's not clear
4740  * whether this behaviour is intentional or is a hardware bug in chip
4741  * revisions available in early 2006.  Therefore for now allow the
4742  * "Headphone Jack Mode" control to span all choices, but if it turns out
4743  * that the lack of mic bias for this NID is intentional we could change the
4744  * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
4745  *
4746  * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
4747  * don't appear to make the mic bias available from the "line" jack, even
4748  * though the NID used for this jack (0x14) can supply it.  The theory is
4749  * that perhaps Acer have included blocking capacitors between the ALC260
4750  * and the output jack.  If this turns out to be the case for all such
4751  * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
4752  * to ALC_PIN_DIR_INOUT_NOMICBIAS.
4753  *
4754  * The C20x Tablet series have a mono internal speaker which is controlled
4755  * via the chip's Mono sum widget and pin complex, so include the necessary
4756  * controls for such models.  On models without a "mono speaker" the control
4757  * won't do anything.
4758  */
4759 static struct snd_kcontrol_new alc260_acer_mixer[] = {
4760         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4761         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
4762         ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
4763         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4764                               HDA_OUTPUT),
4765         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2,
4766                            HDA_INPUT),
4767         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4768         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4769         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4770         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4771         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4772         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4773         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4774         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4775         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4776         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4777         { } /* end */
4778 };
4779
4780 /* Packard bell V7900  ALC260 pin usage: HP = 0x0f, Mic jack = 0x12,
4781  * Line In jack = 0x14, CD audio =  0x16, pc beep = 0x17.
4782  */
4783 static struct snd_kcontrol_new alc260_will_mixer[] = {
4784         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4785         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
4786         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4787         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4788         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4789         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4790         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4791         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4792         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4793         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4794         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4795         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4796         { } /* end */
4797 };
4798
4799 /* Replacer 672V ALC260 pin usage: Mic jack = 0x12,
4800  * Line In jack = 0x14, ATAPI Mic = 0x13, speaker = 0x0f.
4801  */
4802 static struct snd_kcontrol_new alc260_replacer_672v_mixer[] = {
4803         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4804         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
4805         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4806         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4807         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4808         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x07, 0x1, HDA_INPUT),
4809         HDA_CODEC_MUTE("ATATI Mic Playback Switch", 0x07, 0x1, HDA_INPUT),
4810         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4811         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4812         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4813         { } /* end */
4814 };
4815
4816 /*
4817  * initialization verbs
4818  */
4819 static struct hda_verb alc260_init_verbs[] = {
4820         /* Line In pin widget for input */
4821         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4822         /* CD pin widget for input */
4823         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4824         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4825         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4826         /* Mic2 (front panel) pin widget for input and vref at 80% */
4827         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4828         /* LINE-2 is used for line-out in rear */
4829         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4830         /* select line-out */
4831         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
4832         /* LINE-OUT pin */
4833         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4834         /* enable HP */
4835         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4836         /* enable Mono */
4837         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4838         /* mute capture amp left and right */
4839         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4840         /* set connection select to line in (default select for this ADC) */
4841         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4842         /* mute capture amp left and right */
4843         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4844         /* set connection select to line in (default select for this ADC) */
4845         {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
4846         /* set vol=0 Line-Out mixer amp left and right */
4847         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4848         /* unmute pin widget amp left and right (no gain on this amp) */
4849         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4850         /* set vol=0 HP mixer amp left and right */
4851         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4852         /* unmute pin widget amp left and right (no gain on this amp) */
4853         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4854         /* set vol=0 Mono mixer amp left and right */
4855         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4856         /* unmute pin widget amp left and right (no gain on this amp) */
4857         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4858         /* unmute LINE-2 out pin */
4859         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4860         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4861          * Line In 2 = 0x03
4862          */
4863         /* mute analog inputs */
4864         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4865         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4866         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4867         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4868         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4869         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4870         /* mute Front out path */
4871         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4872         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4873         /* mute Headphone out path */
4874         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4875         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4876         /* mute Mono out path */
4877         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4878         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4879         { }
4880 };
4881
4882 #if 0 /* should be identical with alc260_init_verbs? */
4883 static struct hda_verb alc260_hp_init_verbs[] = {
4884         /* Headphone and output */
4885         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4886         /* mono output */
4887         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4888         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4889         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4890         /* Mic2 (front panel) pin widget for input and vref at 80% */
4891         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4892         /* Line In pin widget for input */
4893         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4894         /* Line-2 pin widget for output */
4895         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4896         /* CD pin widget for input */
4897         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4898         /* unmute amp left and right */
4899         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4900         /* set connection select to line in (default select for this ADC) */
4901         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4902         /* unmute Line-Out mixer amp left and right (volume = 0) */
4903         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4904         /* mute pin widget amp left and right (no gain on this amp) */
4905         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4906         /* unmute HP mixer amp left and right (volume = 0) */
4907         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4908         /* mute pin widget amp left and right (no gain on this amp) */
4909         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4910         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4911          * Line In 2 = 0x03
4912          */
4913         /* mute analog inputs */
4914         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4915         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4916         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4917         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4918         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4919         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4920         /* Unmute Front out path */
4921         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4922         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4923         /* Unmute Headphone out path */
4924         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4925         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4926         /* Unmute Mono out path */
4927         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4928         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4929         { }
4930 };
4931 #endif
4932
4933 static struct hda_verb alc260_hp_3013_init_verbs[] = {
4934         /* Line out and output */
4935         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4936         /* mono output */
4937         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4938         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4939         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4940         /* Mic2 (front panel) pin widget for input and vref at 80% */
4941         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4942         /* Line In pin widget for input */
4943         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4944         /* Headphone pin widget for output */
4945         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4946         /* CD pin widget for input */
4947         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4948         /* unmute amp left and right */
4949         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4950         /* set connection select to line in (default select for this ADC) */
4951         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4952         /* unmute Line-Out mixer amp left and right (volume = 0) */
4953         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4954         /* mute pin widget amp left and right (no gain on this amp) */
4955         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4956         /* unmute HP mixer amp left and right (volume = 0) */
4957         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4958         /* mute pin widget amp left and right (no gain on this amp) */
4959         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4960         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4961          * Line In 2 = 0x03
4962          */
4963         /* mute analog inputs */
4964         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4965         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4966         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4967         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4968         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4969         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4970         /* Unmute Front out path */
4971         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4972         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4973         /* Unmute Headphone out path */
4974         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4975         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4976         /* Unmute Mono out path */
4977         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4978         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4979         { }
4980 };
4981
4982 /* Initialisation sequence for ALC260 as configured in Fujitsu S702x
4983  * laptops.  ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
4984  * audio = 0x16, internal speaker = 0x10.
4985  */
4986 static struct hda_verb alc260_fujitsu_init_verbs[] = {
4987         /* Disable all GPIOs */
4988         {0x01, AC_VERB_SET_GPIO_MASK, 0},
4989         /* Internal speaker is connected to headphone pin */
4990         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4991         /* Headphone/Line-out jack connects to Line1 pin; make it an output */
4992         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4993         /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
4994         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4995         /* Ensure all other unused pins are disabled and muted. */
4996         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4997         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4998         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4999         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5000         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5001         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5002         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5003         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5004
5005         /* Disable digital (SPDIF) pins */
5006         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5007         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5008
5009         /* Ensure Line1 pin widget takes its input from the OUT1 sum bus
5010          * when acting as an output.
5011          */
5012         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5013
5014         /* Start with output sum widgets muted and their output gains at min */
5015         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5016         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5017         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5018         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5019         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5020         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5021         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5022         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5023         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5024
5025         /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
5026         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5027         /* Unmute Line1 pin widget output buffer since it starts as an output.
5028          * If the pin mode is changed by the user the pin mode control will
5029          * take care of enabling the pin's input/output buffers as needed.
5030          * Therefore there's no need to enable the input buffer at this
5031          * stage.
5032          */
5033         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5034         /* Unmute input buffer of pin widget used for Line-in (no equiv
5035          * mixer ctrl)
5036          */
5037         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5038
5039         /* Mute capture amp left and right */
5040         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5041         /* Set ADC connection select to match default mixer setting - line
5042          * in (on mic1 pin)
5043          */
5044         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5045
5046         /* Do the same for the second ADC: mute capture input amp and
5047          * set ADC connection to line in (on mic1 pin)
5048          */
5049         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5050         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5051
5052         /* Mute all inputs to mixer widget (even unconnected ones) */
5053         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5054         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5055         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5056         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5057         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5058         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5059         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5060         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5061
5062         { }
5063 };
5064
5065 /* Initialisation sequence for ALC260 as configured in Acer TravelMate and
5066  * similar laptops (adapted from Fujitsu init verbs).
5067  */
5068 static struct hda_verb alc260_acer_init_verbs[] = {
5069         /* On TravelMate laptops, GPIO 0 enables the internal speaker and
5070          * the headphone jack.  Turn this on and rely on the standard mute
5071          * methods whenever the user wants to turn these outputs off.
5072          */
5073         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5074         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5075         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5076         /* Internal speaker/Headphone jack is connected to Line-out pin */
5077         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5078         /* Internal microphone/Mic jack is connected to Mic1 pin */
5079         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
5080         /* Line In jack is connected to Line1 pin */
5081         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5082         /* Some Acers (eg: C20x Tablets) use Mono pin for internal speaker */
5083         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5084         /* Ensure all other unused pins are disabled and muted. */
5085         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5086         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5087         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5088         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5089         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5090         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5091         /* Disable digital (SPDIF) pins */
5092         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5093         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5094
5095         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
5096          * bus when acting as outputs.
5097          */
5098         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5099         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5100
5101         /* Start with output sum widgets muted and their output gains at min */
5102         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5103         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5104         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5105         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5106         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5107         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5108         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5109         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5110         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5111
5112         /* Unmute Line-out pin widget amp left and right
5113          * (no equiv mixer ctrl)
5114          */
5115         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5116         /* Unmute mono pin widget amp output (no equiv mixer ctrl) */
5117         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5118         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
5119          * inputs. If the pin mode is changed by the user the pin mode control
5120          * will take care of enabling the pin's input/output buffers as needed.
5121          * Therefore there's no need to enable the input buffer at this
5122          * stage.
5123          */
5124         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5125         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5126
5127         /* Mute capture amp left and right */
5128         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5129         /* Set ADC connection select to match default mixer setting - mic
5130          * (on mic1 pin)
5131          */
5132         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5133
5134         /* Do similar with the second ADC: mute capture input amp and
5135          * set ADC connection to mic to match ALSA's default state.
5136          */
5137         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5138         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5139
5140         /* Mute all inputs to mixer widget (even unconnected ones) */
5141         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5142         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5143         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5144         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5145         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5146         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5147         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5148         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5149
5150         { }
5151 };
5152
5153 static struct hda_verb alc260_will_verbs[] = {
5154         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5155         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x00},
5156         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
5157         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
5158         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
5159         {0x1a, AC_VERB_SET_PROC_COEF, 0x3040},
5160         {}
5161 };
5162
5163 static struct hda_verb alc260_replacer_672v_verbs[] = {
5164         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
5165         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
5166         {0x1a, AC_VERB_SET_PROC_COEF, 0x3050},
5167
5168         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5169         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5170         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5171
5172         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5173         {}
5174 };
5175
5176 /* toggle speaker-output according to the hp-jack state */
5177 static void alc260_replacer_672v_automute(struct hda_codec *codec)
5178 {
5179         unsigned int present;
5180
5181         /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
5182         present = snd_hda_codec_read(codec, 0x0f, 0,
5183                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5184         if (present) {
5185                 snd_hda_codec_write_cache(codec, 0x01, 0,
5186                                           AC_VERB_SET_GPIO_DATA, 1);
5187                 snd_hda_codec_write_cache(codec, 0x0f, 0,
5188                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
5189                                           PIN_HP);
5190         } else {
5191                 snd_hda_codec_write_cache(codec, 0x01, 0,
5192                                           AC_VERB_SET_GPIO_DATA, 0);
5193                 snd_hda_codec_write_cache(codec, 0x0f, 0,
5194                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
5195                                           PIN_OUT);
5196         }
5197 }
5198
5199 static void alc260_replacer_672v_unsol_event(struct hda_codec *codec,
5200                                        unsigned int res)
5201 {
5202         if ((res >> 26) == ALC880_HP_EVENT)
5203                 alc260_replacer_672v_automute(codec);
5204 }
5205
5206 static struct hda_verb alc260_hp_dc7600_verbs[] = {
5207         {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
5208         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
5209         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5210         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5211         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5212         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5213         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5214         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5215         {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5216         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5217         {}
5218 };
5219
5220 /* Test configuration for debugging, modelled after the ALC880 test
5221  * configuration.
5222  */
5223 #ifdef CONFIG_SND_DEBUG
5224 static hda_nid_t alc260_test_dac_nids[1] = {
5225         0x02,
5226 };
5227 static hda_nid_t alc260_test_adc_nids[2] = {
5228         0x04, 0x05,
5229 };
5230 /* For testing the ALC260, each input MUX needs its own definition since
5231  * the signal assignments are different.  This assumes that the first ADC
5232  * is NID 0x04.
5233  */
5234 static struct hda_input_mux alc260_test_capture_sources[2] = {
5235         {
5236                 .num_items = 7,
5237                 .items = {
5238                         { "MIC1 pin", 0x0 },
5239                         { "MIC2 pin", 0x1 },
5240                         { "LINE1 pin", 0x2 },
5241                         { "LINE2 pin", 0x3 },
5242                         { "CD pin", 0x4 },
5243                         { "LINE-OUT pin", 0x5 },
5244                         { "HP-OUT pin", 0x6 },
5245                 },
5246         },
5247         {
5248                 .num_items = 8,
5249                 .items = {
5250                         { "MIC1 pin", 0x0 },
5251                         { "MIC2 pin", 0x1 },
5252                         { "LINE1 pin", 0x2 },
5253                         { "LINE2 pin", 0x3 },
5254                         { "CD pin", 0x4 },
5255                         { "Mixer", 0x5 },
5256                         { "LINE-OUT pin", 0x6 },
5257                         { "HP-OUT pin", 0x7 },
5258                 },
5259         },
5260 };
5261 static struct snd_kcontrol_new alc260_test_mixer[] = {
5262         /* Output driver widgets */
5263         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
5264         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
5265         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5266         HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
5267         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5268         HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),
5269
5270         /* Modes for retasking pin widgets
5271          * Note: the ALC260 doesn't seem to act on requests to enable mic
5272          * bias from NIDs 0x0f and 0x10.  The ALC260 datasheet doesn't
5273          * mention this restriction.  At this stage it's not clear whether
5274          * this behaviour is intentional or is a hardware bug in chip
5275          * revisions available at least up until early 2006.  Therefore for
5276          * now allow the "HP-OUT" and "LINE-OUT" Mode controls to span all
5277          * choices, but if it turns out that the lack of mic bias for these
5278          * NIDs is intentional we could change their modes from
5279          * ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
5280          */
5281         ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
5282         ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
5283         ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
5284         ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
5285         ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
5286         ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),
5287
5288         /* Loopback mixer controls */
5289         HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
5290         HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
5291         HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
5292         HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
5293         HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
5294         HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
5295         HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
5296         HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
5297         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5298         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5299         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
5300         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
5301         HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
5302         HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
5303         HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
5304         HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
5305
5306         /* Controls for GPIO pins, assuming they are configured as outputs */
5307         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
5308         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
5309         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
5310         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
5311
5312         /* Switches to allow the digital IO pins to be enabled.  The datasheet
5313          * is ambigious as to which NID is which; testing on laptops which
5314          * make this output available should provide clarification.
5315          */
5316         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
5317         ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),
5318
5319         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
5320          * this output to turn on an external amplifier.
5321          */
5322         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
5323         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
5324
5325         { } /* end */
5326 };
5327 static struct hda_verb alc260_test_init_verbs[] = {
5328         /* Enable all GPIOs as outputs with an initial value of 0 */
5329         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
5330         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5331         {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
5332
5333         /* Enable retasking pins as output, initially without power amp */
5334         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5335         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5336         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5337         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5338         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5339         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5340
5341         /* Disable digital (SPDIF) pins initially, but users can enable
5342          * them via a mixer switch.  In the case of SPDIF-out, this initverb
5343          * payload also sets the generation to 0, output to be in "consumer"
5344          * PCM format, copyright asserted, no pre-emphasis and no validity
5345          * control.
5346          */
5347         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5348         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5349
5350         /* Ensure mic1, mic2, line1 and line2 pin widgets take input from the
5351          * OUT1 sum bus when acting as an output.
5352          */
5353         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5354         {0x0c, AC_VERB_SET_CONNECT_SEL, 0},
5355         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5356         {0x0e, AC_VERB_SET_CONNECT_SEL, 0},
5357
5358         /* Start with output sum widgets muted and their output gains at min */
5359         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5360         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5361         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5362         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5363         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5364         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5365         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5366         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5367         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5368
5369         /* Unmute retasking pin widget output buffers since the default
5370          * state appears to be output.  As the pin mode is changed by the
5371          * user the pin mode control will take care of enabling the pin's
5372          * input/output buffers as needed.
5373          */
5374         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5375         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5376         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5377         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5378         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5379         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5380         /* Also unmute the mono-out pin widget */
5381         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5382
5383         /* Mute capture amp left and right */
5384         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5385         /* Set ADC connection select to match default mixer setting (mic1
5386          * pin)
5387          */
5388         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5389
5390         /* Do the same for the second ADC: mute capture input amp and
5391          * set ADC connection to mic1 pin
5392          */
5393         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5394         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5395
5396         /* Mute all inputs to mixer widget (even unconnected ones) */
5397         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5398         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5399         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5400         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5401         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5402         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5403         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5404         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5405
5406         { }
5407 };
5408 #endif
5409
5410 #define alc260_pcm_analog_playback      alc880_pcm_analog_alt_playback
5411 #define alc260_pcm_analog_capture       alc880_pcm_analog_capture
5412
5413 #define alc260_pcm_digital_playback     alc880_pcm_digital_playback
5414 #define alc260_pcm_digital_capture      alc880_pcm_digital_capture
5415
5416 /*
5417  * for BIOS auto-configuration
5418  */
5419
5420 static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
5421                                         const char *pfx, int *vol_bits)
5422 {
5423         hda_nid_t nid_vol;
5424         unsigned long vol_val, sw_val;
5425         char name[32];
5426         int err;
5427
5428         if (nid >= 0x0f && nid < 0x11) {
5429                 nid_vol = nid - 0x7;
5430                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
5431                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
5432         } else if (nid == 0x11) {
5433                 nid_vol = nid - 0x7;
5434                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT);
5435                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
5436         } else if (nid >= 0x12 && nid <= 0x15) {
5437                 nid_vol = 0x08;
5438                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
5439                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
5440         } else
5441                 return 0; /* N/A */
5442
5443         if (!(*vol_bits & (1 << nid_vol))) {
5444                 /* first control for the volume widget */
5445                 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
5446                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name, vol_val);
5447                 if (err < 0)
5448                         return err;
5449                 *vol_bits |= (1 << nid_vol);
5450         }
5451         snprintf(name, sizeof(name), "%s Playback Switch", pfx);
5452         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, sw_val);
5453         if (err < 0)
5454                 return err;
5455         return 1;
5456 }
5457
5458 /* add playback controls from the parsed DAC table */
5459 static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
5460                                              const struct auto_pin_cfg *cfg)
5461 {
5462         hda_nid_t nid;
5463         int err;
5464         int vols = 0;
5465
5466         spec->multiout.num_dacs = 1;
5467         spec->multiout.dac_nids = spec->private_dac_nids;
5468         spec->multiout.dac_nids[0] = 0x02;
5469
5470         nid = cfg->line_out_pins[0];
5471         if (nid) {
5472                 err = alc260_add_playback_controls(spec, nid, "Front", &vols);
5473                 if (err < 0)
5474                         return err;
5475         }
5476
5477         nid = cfg->speaker_pins[0];
5478         if (nid) {
5479                 err = alc260_add_playback_controls(spec, nid, "Speaker", &vols);
5480                 if (err < 0)
5481                         return err;
5482         }
5483
5484         nid = cfg->hp_pins[0];
5485         if (nid) {
5486                 err = alc260_add_playback_controls(spec, nid, "Headphone",
5487                                                    &vols);
5488                 if (err < 0)
5489                         return err;
5490         }
5491         return 0;
5492 }
5493
5494 /* create playback/capture controls for input pins */
5495 static int alc260_auto_create_analog_input_ctls(struct alc_spec *spec,
5496                                                 const struct auto_pin_cfg *cfg)
5497 {
5498         struct hda_input_mux *imux = &spec->private_imux[0];
5499         int i, err, idx;
5500
5501         for (i = 0; i < AUTO_PIN_LAST; i++) {
5502                 if (cfg->input_pins[i] >= 0x12) {
5503                         idx = cfg->input_pins[i] - 0x12;
5504                         err = new_analog_input(spec, cfg->input_pins[i],
5505                                                auto_pin_cfg_labels[i], idx,
5506                                                0x07);
5507                         if (err < 0)
5508                                 return err;
5509                         imux->items[imux->num_items].label =
5510                                 auto_pin_cfg_labels[i];
5511                         imux->items[imux->num_items].index = idx;
5512                         imux->num_items++;
5513                 }
5514                 if (cfg->input_pins[i] >= 0x0f && cfg->input_pins[i] <= 0x10){
5515                         idx = cfg->input_pins[i] - 0x09;
5516                         err = new_analog_input(spec, cfg->input_pins[i],
5517                                                auto_pin_cfg_labels[i], idx,
5518                                                0x07);
5519                         if (err < 0)
5520                                 return err;
5521                         imux->items[imux->num_items].label =
5522                                 auto_pin_cfg_labels[i];
5523                         imux->items[imux->num_items].index = idx;
5524                         imux->num_items++;
5525                 }
5526         }
5527         return 0;
5528 }
5529
5530 static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
5531                                               hda_nid_t nid, int pin_type,
5532                                               int sel_idx)
5533 {
5534         alc_set_pin_output(codec, nid, pin_type);
5535         /* need the manual connection? */
5536         if (nid >= 0x12) {
5537                 int idx = nid - 0x12;
5538                 snd_hda_codec_write(codec, idx + 0x0b, 0,
5539                                     AC_VERB_SET_CONNECT_SEL, sel_idx);
5540         }
5541 }
5542
5543 static void alc260_auto_init_multi_out(struct hda_codec *codec)
5544 {
5545         struct alc_spec *spec = codec->spec;
5546         hda_nid_t nid;
5547
5548         alc_subsystem_id(codec, 0x10, 0x15, 0x0f);
5549         nid = spec->autocfg.line_out_pins[0];
5550         if (nid) {
5551                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
5552                 alc260_auto_set_output_and_unmute(codec, nid, pin_type, 0);
5553         }
5554
5555         nid = spec->autocfg.speaker_pins[0];
5556         if (nid)
5557                 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
5558
5559         nid = spec->autocfg.hp_pins[0];
5560         if (nid)
5561                 alc260_auto_set_output_and_unmute(codec, nid, PIN_HP, 0);
5562 }
5563
5564 #define ALC260_PIN_CD_NID               0x16
5565 static void alc260_auto_init_analog_input(struct hda_codec *codec)
5566 {
5567         struct alc_spec *spec = codec->spec;
5568         int i;
5569
5570         for (i = 0; i < AUTO_PIN_LAST; i++) {
5571                 hda_nid_t nid = spec->autocfg.input_pins[i];
5572                 if (nid >= 0x12) {
5573                         snd_hda_codec_write(codec, nid, 0,
5574                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
5575                                             i <= AUTO_PIN_FRONT_MIC ?
5576                                             PIN_VREF80 : PIN_IN);
5577                         if (nid != ALC260_PIN_CD_NID)
5578                                 snd_hda_codec_write(codec, nid, 0,
5579                                                     AC_VERB_SET_AMP_GAIN_MUTE,
5580                                                     AMP_OUT_MUTE);
5581                 }
5582         }
5583 }
5584
5585 /*
5586  * generic initialization of ADC, input mixers and output mixers
5587  */
5588 static struct hda_verb alc260_volume_init_verbs[] = {
5589         /*
5590          * Unmute ADC0-1 and set the default input to mic-in
5591          */
5592         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5593         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5594         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5595         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5596
5597         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5598          * mixer widget
5599          * Note: PASD motherboards uses the Line In 2 as the input for
5600          * front panel mic (mic 2)
5601          */
5602         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
5603         /* mute analog inputs */
5604         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5605         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5606         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5607         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5608         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5609
5610         /*
5611          * Set up output mixers (0x08 - 0x0a)
5612          */
5613         /* set vol=0 to output mixers */
5614         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5615         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5616         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5617         /* set up input amps for analog loopback */
5618         /* Amp Indices: DAC = 0, mixer = 1 */
5619         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5620         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5621         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5622         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5623         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5624         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5625
5626         { }
5627 };
5628
5629 static int alc260_parse_auto_config(struct hda_codec *codec)
5630 {
5631         struct alc_spec *spec = codec->spec;
5632         int err;
5633         static hda_nid_t alc260_ignore[] = { 0x17, 0 };
5634
5635         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
5636                                            alc260_ignore);
5637         if (err < 0)
5638                 return err;
5639         err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg);
5640         if (err < 0)
5641                 return err;
5642         if (!spec->kctls.list)
5643                 return 0; /* can't find valid BIOS pin config */
5644         err = alc260_auto_create_analog_input_ctls(spec, &spec->autocfg);
5645         if (err < 0)
5646                 return err;
5647
5648         spec->multiout.max_channels = 2;
5649
5650         if (spec->autocfg.dig_out_pin)
5651                 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
5652         if (spec->kctls.list)
5653                 add_mixer(spec, spec->kctls.list);
5654
5655         add_verb(spec, alc260_volume_init_verbs);
5656
5657         spec->num_mux_defs = 1;
5658         spec->input_mux = &spec->private_imux[0];
5659
5660         store_pin_configs(codec);
5661         return 1;
5662 }
5663
5664 /* additional initialization for auto-configuration model */
5665 static void alc260_auto_init(struct hda_codec *codec)
5666 {
5667         struct alc_spec *spec = codec->spec;
5668         alc260_auto_init_multi_out(codec);
5669         alc260_auto_init_analog_input(codec);
5670         if (spec->unsol_event)
5671                 alc_inithook(codec);
5672 }
5673
5674 #ifdef CONFIG_SND_HDA_POWER_SAVE
5675 static struct hda_amp_list alc260_loopbacks[] = {
5676         { 0x07, HDA_INPUT, 0 },
5677         { 0x07, HDA_INPUT, 1 },
5678         { 0x07, HDA_INPUT, 2 },
5679         { 0x07, HDA_INPUT, 3 },
5680         { 0x07, HDA_INPUT, 4 },
5681         { } /* end */
5682 };
5683 #endif
5684
5685 /*
5686  * ALC260 configurations
5687  */
5688 static const char *alc260_models[ALC260_MODEL_LAST] = {
5689         [ALC260_BASIC]          = "basic",
5690         [ALC260_HP]             = "hp",
5691         [ALC260_HP_3013]        = "hp-3013",
5692         [ALC260_HP_DC7600]      = "hp-dc7600",
5693         [ALC260_FUJITSU_S702X]  = "fujitsu",
5694         [ALC260_ACER]           = "acer",
5695         [ALC260_WILL]           = "will",
5696         [ALC260_REPLACER_672V]  = "replacer",
5697 #ifdef CONFIG_SND_DEBUG
5698         [ALC260_TEST]           = "test",
5699 #endif
5700         [ALC260_AUTO]           = "auto",
5701 };
5702
5703 static struct snd_pci_quirk alc260_cfg_tbl[] = {
5704         SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER),
5705         SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
5706         SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
5707         SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_HP_3013),
5708         SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
5709         SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP_3013),
5710         SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_DC7600),
5711         SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
5712         SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
5713         SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP),
5714         SND_PCI_QUIRK(0x103c, 0x3016, "HP", ALC260_HP),
5715         SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_BASIC),
5716         SND_PCI_QUIRK(0x104d, 0x81cc, "Sony VAIO", ALC260_BASIC),
5717         SND_PCI_QUIRK(0x104d, 0x81cd, "Sony VAIO", ALC260_BASIC),
5718         SND_PCI_QUIRK(0x10cf, 0x1326, "Fujitsu S702X", ALC260_FUJITSU_S702X),
5719         SND_PCI_QUIRK(0x152d, 0x0729, "CTL U553W", ALC260_BASIC),
5720         SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_REPLACER_672V),
5721         SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_WILL),
5722         {}
5723 };
5724
5725 static struct alc_config_preset alc260_presets[] = {
5726         [ALC260_BASIC] = {
5727                 .mixers = { alc260_base_output_mixer,
5728                             alc260_input_mixer,
5729                             alc260_pc_beep_mixer },
5730                 .init_verbs = { alc260_init_verbs },
5731                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5732                 .dac_nids = alc260_dac_nids,
5733                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5734                 .adc_nids = alc260_adc_nids,
5735                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5736                 .channel_mode = alc260_modes,
5737                 .input_mux = &alc260_capture_source,
5738         },
5739         [ALC260_HP] = {
5740                 .mixers = { alc260_hp_output_mixer,
5741                             alc260_input_mixer },
5742                 .init_verbs = { alc260_init_verbs,
5743                                 alc260_hp_unsol_verbs },
5744                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5745                 .dac_nids = alc260_dac_nids,
5746                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
5747                 .adc_nids = alc260_adc_nids_alt,
5748                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5749                 .channel_mode = alc260_modes,
5750                 .input_mux = &alc260_capture_source,
5751                 .unsol_event = alc260_hp_unsol_event,
5752                 .init_hook = alc260_hp_automute,
5753         },
5754         [ALC260_HP_DC7600] = {
5755                 .mixers = { alc260_hp_dc7600_mixer,
5756                             alc260_input_mixer },
5757                 .init_verbs = { alc260_init_verbs,
5758                                 alc260_hp_dc7600_verbs },
5759                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5760                 .dac_nids = alc260_dac_nids,
5761                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
5762                 .adc_nids = alc260_adc_nids_alt,
5763                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5764                 .channel_mode = alc260_modes,
5765                 .input_mux = &alc260_capture_source,
5766                 .unsol_event = alc260_hp_3012_unsol_event,
5767                 .init_hook = alc260_hp_3012_automute,
5768         },
5769         [ALC260_HP_3013] = {
5770                 .mixers = { alc260_hp_3013_mixer,
5771                             alc260_input_mixer },
5772                 .init_verbs = { alc260_hp_3013_init_verbs,
5773                                 alc260_hp_3013_unsol_verbs },
5774                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5775                 .dac_nids = alc260_dac_nids,
5776                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
5777                 .adc_nids = alc260_adc_nids_alt,
5778                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5779                 .channel_mode = alc260_modes,
5780                 .input_mux = &alc260_capture_source,
5781                 .unsol_event = alc260_hp_3013_unsol_event,
5782                 .init_hook = alc260_hp_3013_automute,
5783         },
5784         [ALC260_FUJITSU_S702X] = {
5785                 .mixers = { alc260_fujitsu_mixer },
5786                 .init_verbs = { alc260_fujitsu_init_verbs },
5787                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5788                 .dac_nids = alc260_dac_nids,
5789                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5790                 .adc_nids = alc260_dual_adc_nids,
5791                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5792                 .channel_mode = alc260_modes,
5793                 .num_mux_defs = ARRAY_SIZE(alc260_fujitsu_capture_sources),
5794                 .input_mux = alc260_fujitsu_capture_sources,
5795         },
5796         [ALC260_ACER] = {
5797                 .mixers = { alc260_acer_mixer },
5798                 .init_verbs = { alc260_acer_init_verbs },
5799                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5800                 .dac_nids = alc260_dac_nids,
5801                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5802                 .adc_nids = alc260_dual_adc_nids,
5803                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5804                 .channel_mode = alc260_modes,
5805                 .num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources),
5806                 .input_mux = alc260_acer_capture_sources,
5807         },
5808         [ALC260_WILL] = {
5809                 .mixers = { alc260_will_mixer },
5810                 .init_verbs = { alc260_init_verbs, alc260_will_verbs },
5811                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5812                 .dac_nids = alc260_dac_nids,
5813                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5814                 .adc_nids = alc260_adc_nids,
5815                 .dig_out_nid = ALC260_DIGOUT_NID,
5816                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5817                 .channel_mode = alc260_modes,
5818                 .input_mux = &alc260_capture_source,
5819         },
5820         [ALC260_REPLACER_672V] = {
5821                 .mixers = { alc260_replacer_672v_mixer },
5822                 .init_verbs = { alc260_init_verbs, alc260_replacer_672v_verbs },
5823                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5824                 .dac_nids = alc260_dac_nids,
5825                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5826                 .adc_nids = alc260_adc_nids,
5827                 .dig_out_nid = ALC260_DIGOUT_NID,
5828                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5829                 .channel_mode = alc260_modes,
5830                 .input_mux = &alc260_capture_source,
5831                 .unsol_event = alc260_replacer_672v_unsol_event,
5832                 .init_hook = alc260_replacer_672v_automute,
5833         },
5834 #ifdef CONFIG_SND_DEBUG
5835         [ALC260_TEST] = {
5836                 .mixers = { alc260_test_mixer },
5837                 .init_verbs = { alc260_test_init_verbs },
5838                 .num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
5839                 .dac_nids = alc260_test_dac_nids,
5840                 .num_adc_nids = ARRAY_SIZE(alc260_test_adc_nids),
5841                 .adc_nids = alc260_test_adc_nids,
5842                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5843                 .channel_mode = alc260_modes,
5844                 .num_mux_defs = ARRAY_SIZE(alc260_test_capture_sources),
5845                 .input_mux = alc260_test_capture_sources,
5846         },
5847 #endif
5848 };
5849
5850 static int patch_alc260(struct hda_codec *codec)
5851 {
5852         struct alc_spec *spec;
5853         int err, board_config;
5854
5855         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5856         if (spec == NULL)
5857                 return -ENOMEM;
5858
5859         codec->spec = spec;
5860
5861         board_config = snd_hda_check_board_config(codec, ALC260_MODEL_LAST,
5862                                                   alc260_models,
5863                                                   alc260_cfg_tbl);
5864         if (board_config < 0) {
5865                 snd_printd(KERN_INFO "hda_codec: Unknown model for ALC260, "
5866                            "trying auto-probe from BIOS...\n");
5867                 board_config = ALC260_AUTO;
5868         }
5869
5870         if (board_config == ALC260_AUTO) {
5871                 /* automatic parse from the BIOS config */
5872                 err = alc260_parse_auto_config(codec);
5873                 if (err < 0) {
5874                         alc_free(codec);
5875                         return err;
5876                 } else if (!err) {
5877                         printk(KERN_INFO
5878                                "hda_codec: Cannot set up configuration "
5879                                "from BIOS.  Using base mode...\n");
5880                         board_config = ALC260_BASIC;
5881                 }
5882         }
5883
5884         if (board_config != ALC260_AUTO)
5885                 setup_preset(spec, &alc260_presets[board_config]);
5886
5887         spec->stream_name_analog = "ALC260 Analog";
5888         spec->stream_analog_playback = &alc260_pcm_analog_playback;
5889         spec->stream_analog_capture = &alc260_pcm_analog_capture;
5890
5891         spec->stream_name_digital = "ALC260 Digital";
5892         spec->stream_digital_playback = &alc260_pcm_digital_playback;
5893         spec->stream_digital_capture = &alc260_pcm_digital_capture;
5894
5895         if (!spec->adc_nids && spec->input_mux) {
5896                 /* check whether NID 0x04 is valid */
5897                 unsigned int wcap = get_wcaps(codec, 0x04);
5898                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
5899                 /* get type */
5900                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
5901                         spec->adc_nids = alc260_adc_nids_alt;
5902                         spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
5903                 } else {
5904                         spec->adc_nids = alc260_adc_nids;
5905                         spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
5906                 }
5907         }
5908         set_capture_mixer(spec);
5909
5910         spec->vmaster_nid = 0x08;
5911
5912         codec->patch_ops = alc_patch_ops;
5913         if (board_config == ALC260_AUTO)
5914                 spec->init_hook = alc260_auto_init;
5915 #ifdef CONFIG_SND_HDA_POWER_SAVE
5916         if (!spec->loopback.amplist)
5917                 spec->loopback.amplist = alc260_loopbacks;
5918 #endif
5919         codec->proc_widget_hook = print_realtek_coef;
5920
5921         return 0;
5922 }
5923
5924
5925 /*
5926  * ALC882 support
5927  *
5928  * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5929  * configuration.  Each pin widget can choose any input DACs and a mixer.
5930  * Each ADC is connected from a mixer of all inputs.  This makes possible
5931  * 6-channel independent captures.
5932  *
5933  * In addition, an independent DAC for the multi-playback (not used in this
5934  * driver yet).
5935  */
5936 #define ALC882_DIGOUT_NID       0x06
5937 #define ALC882_DIGIN_NID        0x0a
5938
5939 static struct hda_channel_mode alc882_ch_modes[1] = {
5940         { 8, NULL }
5941 };
5942
5943 static hda_nid_t alc882_dac_nids[4] = {
5944         /* front, rear, clfe, rear_surr */
5945         0x02, 0x03, 0x04, 0x05
5946 };
5947
5948 /* identical with ALC880 */
5949 #define alc882_adc_nids         alc880_adc_nids
5950 #define alc882_adc_nids_alt     alc880_adc_nids_alt
5951
5952 static hda_nid_t alc882_capsrc_nids[3] = { 0x24, 0x23, 0x22 };
5953 static hda_nid_t alc882_capsrc_nids_alt[2] = { 0x23, 0x22 };
5954
5955 /* input MUX */
5956 /* FIXME: should be a matrix-type input source selection */
5957
5958 static struct hda_input_mux alc882_capture_source = {
5959         .num_items = 4,
5960         .items = {
5961                 { "Mic", 0x0 },
5962                 { "Front Mic", 0x1 },
5963                 { "Line", 0x2 },
5964                 { "CD", 0x4 },
5965         },
5966 };
5967 /*
5968  * 2ch mode
5969  */
5970 static struct hda_verb alc882_3ST_ch2_init[] = {
5971         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
5972         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5973         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
5974         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5975         { } /* end */
5976 };
5977
5978 /*
5979  * 6ch mode
5980  */
5981 static struct hda_verb alc882_3ST_ch6_init[] = {
5982         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5983         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5984         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
5985         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5986         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5987         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
5988         { } /* end */
5989 };
5990
5991 static struct hda_channel_mode alc882_3ST_6ch_modes[2] = {
5992         { 2, alc882_3ST_ch2_init },
5993         { 6, alc882_3ST_ch6_init },
5994 };
5995
5996 /*
5997  * 6ch mode
5998  */
5999 static struct hda_verb alc882_sixstack_ch6_init[] = {
6000         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
6001         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6002         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6003         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6004         { } /* end */
6005 };
6006
6007 /*
6008  * 8ch mode
6009  */
6010 static struct hda_verb alc882_sixstack_ch8_init[] = {
6011         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6012         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6013         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6014         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6015         { } /* end */
6016 };
6017
6018 static struct hda_channel_mode alc882_sixstack_modes[2] = {
6019         { 6, alc882_sixstack_ch6_init },
6020         { 8, alc882_sixstack_ch8_init },
6021 };
6022
6023 /*
6024  * macbook pro ALC885 can switch LineIn to LineOut without loosing Mic
6025  */
6026
6027 /*
6028  * 2ch mode
6029  */
6030 static struct hda_verb alc885_mbp_ch2_init[] = {
6031         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6032         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6033         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6034         { } /* end */
6035 };
6036
6037 /*
6038  * 6ch mode
6039  */
6040 static struct hda_verb alc885_mbp_ch6_init[] = {
6041         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6042         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6043         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6044         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6045         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6046         { } /* end */
6047 };
6048
6049 static struct hda_channel_mode alc885_mbp_6ch_modes[2] = {
6050         { 2, alc885_mbp_ch2_init },
6051         { 6, alc885_mbp_ch6_init },
6052 };
6053
6054
6055 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
6056  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
6057  */
6058 static struct snd_kcontrol_new alc882_base_mixer[] = {
6059         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6060         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6061         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6062         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6063         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6064         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6065         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6066         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6067         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
6068         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
6069         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6070         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6071         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6072         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6073         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6074         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6075         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6076         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6077         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6078         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6079         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6080         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6081         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6082         { } /* end */
6083 };
6084
6085 static struct snd_kcontrol_new alc885_mbp3_mixer[] = {
6086         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
6087         HDA_BIND_MUTE   ("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
6088         HDA_CODEC_MUTE  ("Speaker Playback Switch", 0x14, 0x00, HDA_OUTPUT),
6089         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
6090         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6091         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6092         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
6093         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
6094         HDA_CODEC_VOLUME("Line Boost", 0x1a, 0x00, HDA_INPUT),
6095         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
6096         { } /* end */
6097 };
6098 static struct snd_kcontrol_new alc882_w2jc_mixer[] = {
6099         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6100         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6101         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6102         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6103         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6104         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6105         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6106         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6107         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6108         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6109         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6110         { } /* end */
6111 };
6112
6113 static struct snd_kcontrol_new alc882_targa_mixer[] = {
6114         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6115         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6116         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6117         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6118         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6119         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6120         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6121         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6122         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6123         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6124         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6125         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6126         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6127         { } /* end */
6128 };
6129
6130 /* Pin assignment: Front=0x14, HP = 0x15, Front = 0x16, ???
6131  *                 Front Mic=0x18, Line In = 0x1a, Line In = 0x1b, CD = 0x1c
6132  */
6133 static struct snd_kcontrol_new alc882_asus_a7j_mixer[] = {
6134         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6135         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6136         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6137         HDA_CODEC_MUTE("Mobile Front Playback Switch", 0x16, 0x0, HDA_OUTPUT),
6138         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6139         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6140         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6141         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6142         HDA_CODEC_VOLUME("Mobile Line Playback Volume", 0x0b, 0x03, HDA_INPUT),
6143         HDA_CODEC_MUTE("Mobile Line Playback Switch", 0x0b, 0x03, HDA_INPUT),
6144         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6145         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6146         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6147         { } /* end */
6148 };
6149
6150 static struct snd_kcontrol_new alc882_asus_a7m_mixer[] = {
6151         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6152         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6153         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6154         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6155         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6156         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6157         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6158         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6159         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6160         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6161         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6162         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6163         { } /* end */
6164 };
6165
6166 static struct snd_kcontrol_new alc882_chmode_mixer[] = {
6167         {
6168                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6169                 .name = "Channel Mode",
6170                 .info = alc_ch_mode_info,
6171                 .get = alc_ch_mode_get,
6172                 .put = alc_ch_mode_put,
6173         },
6174         { } /* end */
6175 };
6176
6177 static struct hda_verb alc882_init_verbs[] = {
6178         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6179         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6180         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6181         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6182         /* Rear mixer */
6183         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6184         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6185         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6186         /* CLFE mixer */
6187         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6188         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6189         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6190         /* Side mixer */
6191         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6192         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6193         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6194
6195         /* Front Pin: output 0 (0x0c) */
6196         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6197         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6198         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6199         /* Rear Pin: output 1 (0x0d) */
6200         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6201         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6202         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
6203         /* CLFE Pin: output 2 (0x0e) */
6204         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6205         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6206         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
6207         /* Side Pin: output 3 (0x0f) */
6208         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6209         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6210         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
6211         /* Mic (rear) pin: input vref at 80% */
6212         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6213         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6214         /* Front Mic pin: input vref at 80% */
6215         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6216         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6217         /* Line In pin: input */
6218         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6219         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6220         /* Line-2 In: Headphone output (output 0 - 0x0c) */
6221         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6222         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6223         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
6224         /* CD pin widget for input */
6225         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6226
6227         /* FIXME: use matrix-type input source selection */
6228         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6229         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6230         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6231         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6232         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6233         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6234         /* Input mixer2 */
6235         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6236         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6237         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6238         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6239         /* Input mixer3 */
6240         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6241         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6242         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6243         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6244         /* ADC1: mute amp left and right */
6245         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6246         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6247         /* ADC2: mute amp left and right */
6248         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6249         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6250         /* ADC3: mute amp left and right */
6251         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6252         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6253
6254         { }
6255 };
6256
6257 static struct hda_verb alc882_eapd_verbs[] = {
6258         /* change to EAPD mode */
6259         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
6260         {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
6261         { }
6262 };
6263
6264 /* Mac Pro test */
6265 static struct snd_kcontrol_new alc882_macpro_mixer[] = {
6266         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6267         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6268         HDA_CODEC_MUTE("Headphone Playback Switch", 0x18, 0x0, HDA_OUTPUT),
6269         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
6270         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
6271         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x02, HDA_INPUT),
6272         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x02, HDA_INPUT),
6273         { } /* end */
6274 };
6275
6276 static struct hda_verb alc882_macpro_init_verbs[] = {
6277         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6278         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6279         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6280         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6281         /* Front Pin: output 0 (0x0c) */
6282         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6283         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6284         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6285         /* Front Mic pin: input vref at 80% */
6286         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6287         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6288         /* Speaker:  output */
6289         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6290         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6291         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x04},
6292         /* Headphone output (output 0 - 0x0c) */
6293         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6294         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6295         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
6296
6297         /* FIXME: use matrix-type input source selection */
6298         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6299         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6300         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6301         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6302         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6303         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6304         /* Input mixer2 */
6305         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6306         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6307         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6308         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6309         /* Input mixer3 */
6310         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6311         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6312         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6313         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6314         /* ADC1: mute amp left and right */
6315         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6316         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6317         /* ADC2: mute amp left and right */
6318         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6319         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6320         /* ADC3: mute amp left and right */
6321         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6322         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6323
6324         { }
6325 };
6326
6327 /* Macbook Pro rev3 */
6328 static struct hda_verb alc885_mbp3_init_verbs[] = {
6329         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6330         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6331         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6332         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6333         /* Rear mixer */
6334         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6335         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6336         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6337         /* Front Pin: output 0 (0x0c) */
6338         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6339         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6340         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6341         /* HP Pin: output 0 (0x0d) */
6342         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},
6343         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6344         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6345         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6346         /* Mic (rear) pin: input vref at 80% */
6347         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6348         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6349         /* Front Mic pin: input vref at 80% */
6350         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6351         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6352         /* Line In pin: use output 1 when in LineOut mode */
6353         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6354         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6355         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
6356
6357         /* FIXME: use matrix-type input source selection */
6358         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6359         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6360         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6361         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6362         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6363         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6364         /* Input mixer2 */
6365         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6366         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6367         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6368         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6369         /* Input mixer3 */
6370         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6371         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6372         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6373         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6374         /* ADC1: mute amp left and right */
6375         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6376         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6377         /* ADC2: mute amp left and right */
6378         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6379         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6380         /* ADC3: mute amp left and right */
6381         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6382         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6383
6384         { }
6385 };
6386
6387 /* iMac 24 mixer. */
6388 static struct snd_kcontrol_new alc885_imac24_mixer[] = {
6389         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
6390         HDA_CODEC_MUTE("Master Playback Switch", 0x0c, 0x00, HDA_INPUT),
6391         { } /* end */
6392 };
6393
6394 /* iMac 24 init verbs. */
6395 static struct hda_verb alc885_imac24_init_verbs[] = {
6396         /* Internal speakers: output 0 (0x0c) */
6397         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6398         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6399         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
6400         /* Internal speakers: output 0 (0x0c) */
6401         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6402         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6403         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
6404         /* Headphone: output 0 (0x0c) */
6405         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6406         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6407         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6408         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6409         /* Front Mic: input vref at 80% */
6410         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6411         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6412         { }
6413 };
6414
6415 /* Toggle speaker-output according to the hp-jack state */
6416 static void alc885_imac24_automute(struct hda_codec *codec)
6417 {
6418         unsigned int present;
6419
6420         present = snd_hda_codec_read(codec, 0x14, 0,
6421                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6422         snd_hda_codec_amp_stereo(codec, 0x18, HDA_OUTPUT, 0,
6423                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6424         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
6425                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6426 }
6427
6428 /* Processes unsolicited events. */
6429 static void alc885_imac24_unsol_event(struct hda_codec *codec,
6430                                       unsigned int res)
6431 {
6432         /* Headphone insertion or removal. */
6433         if ((res >> 26) == ALC880_HP_EVENT)
6434                 alc885_imac24_automute(codec);
6435 }
6436
6437 static void alc885_mbp3_automute(struct hda_codec *codec)
6438 {
6439         unsigned int present;
6440
6441         present = snd_hda_codec_read(codec, 0x15, 0,
6442                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6443         snd_hda_codec_amp_stereo(codec, 0x14,  HDA_OUTPUT, 0,
6444                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6445         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
6446                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
6447
6448 }
6449 static void alc885_mbp3_unsol_event(struct hda_codec *codec,
6450                                     unsigned int res)
6451 {
6452         /* Headphone insertion or removal. */
6453         if ((res >> 26) == ALC880_HP_EVENT)
6454                 alc885_mbp3_automute(codec);
6455 }
6456
6457
6458 static struct hda_verb alc882_targa_verbs[] = {
6459         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6460         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6461
6462         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6463         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6464
6465         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6466         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6467         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6468
6469         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6470         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6471         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
6472         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
6473         { } /* end */
6474 };
6475
6476 /* toggle speaker-output according to the hp-jack state */
6477 static void alc882_targa_automute(struct hda_codec *codec)
6478 {
6479         unsigned int present;
6480
6481         present = snd_hda_codec_read(codec, 0x14, 0,
6482                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6483         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
6484                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6485         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
6486                                   present ? 1 : 3);
6487 }
6488
6489 static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res)
6490 {
6491         /* Looks like the unsol event is incompatible with the standard
6492          * definition.  4bit tag is placed at 26 bit!
6493          */
6494         if (((res >> 26) == ALC880_HP_EVENT)) {
6495                 alc882_targa_automute(codec);
6496         }
6497 }
6498
6499 static struct hda_verb alc882_asus_a7j_verbs[] = {
6500         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6501         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6502
6503         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6504         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6505         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6506
6507         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6508         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6509         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6510
6511         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6512         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6513         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6514         { } /* end */
6515 };
6516
6517 static struct hda_verb alc882_asus_a7m_verbs[] = {
6518         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6519         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6520
6521         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6522         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6523         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6524
6525         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6526         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6527         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6528
6529         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6530         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6531         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6532         { } /* end */
6533 };
6534
6535 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
6536 {
6537         unsigned int gpiostate, gpiomask, gpiodir;
6538
6539         gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
6540                                        AC_VERB_GET_GPIO_DATA, 0);
6541
6542         if (!muted)
6543                 gpiostate |= (1 << pin);
6544         else
6545                 gpiostate &= ~(1 << pin);
6546
6547         gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
6548                                       AC_VERB_GET_GPIO_MASK, 0);
6549         gpiomask |= (1 << pin);
6550
6551         gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
6552                                      AC_VERB_GET_GPIO_DIRECTION, 0);
6553         gpiodir |= (1 << pin);
6554
6555
6556         snd_hda_codec_write(codec, codec->afg, 0,
6557                             AC_VERB_SET_GPIO_MASK, gpiomask);
6558         snd_hda_codec_write(codec, codec->afg, 0,
6559                             AC_VERB_SET_GPIO_DIRECTION, gpiodir);
6560
6561         msleep(1);
6562
6563         snd_hda_codec_write(codec, codec->afg, 0,
6564                             AC_VERB_SET_GPIO_DATA, gpiostate);
6565 }
6566
6567 /* set up GPIO at initialization */
6568 static void alc885_macpro_init_hook(struct hda_codec *codec)
6569 {
6570         alc882_gpio_mute(codec, 0, 0);
6571         alc882_gpio_mute(codec, 1, 0);
6572 }
6573
6574 /* set up GPIO and update auto-muting at initialization */
6575 static void alc885_imac24_init_hook(struct hda_codec *codec)
6576 {
6577         alc885_macpro_init_hook(codec);
6578         alc885_imac24_automute(codec);
6579 }
6580
6581 /*
6582  * generic initialization of ADC, input mixers and output mixers
6583  */
6584 static struct hda_verb alc882_auto_init_verbs[] = {
6585         /*
6586          * Unmute ADC0-2 and set the default input to mic-in
6587          */
6588         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6589         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6590         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6591         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6592         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6593         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6594
6595         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
6596          * mixer widget
6597          * Note: PASD motherboards uses the Line In 2 as the input for
6598          * front panel mic (mic 2)
6599          */
6600         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
6601         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6602         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6603         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6604         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6605         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6606
6607         /*
6608          * Set up output mixers (0x0c - 0x0f)
6609          */
6610         /* set vol=0 to output mixers */
6611         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6612         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6613         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6614         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6615         /* set up input amps for analog loopback */
6616         /* Amp Indices: DAC = 0, mixer = 1 */
6617         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6618         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6619         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6620         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6621         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6622         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6623         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6624         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6625         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6626         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6627
6628         /* FIXME: use matrix-type input source selection */
6629         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6630         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6631         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6632         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6633         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6634         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6635         /* Input mixer2 */
6636         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6637         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6638         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6639         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6640         /* Input mixer3 */
6641         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6642         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6643         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6644         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6645
6646         { }
6647 };
6648
6649 #ifdef CONFIG_SND_HDA_POWER_SAVE
6650 #define alc882_loopbacks        alc880_loopbacks
6651 #endif
6652
6653 /* pcm configuration: identiacal with ALC880 */
6654 #define alc882_pcm_analog_playback      alc880_pcm_analog_playback
6655 #define alc882_pcm_analog_capture       alc880_pcm_analog_capture
6656 #define alc882_pcm_digital_playback     alc880_pcm_digital_playback
6657 #define alc882_pcm_digital_capture      alc880_pcm_digital_capture
6658
6659 /*
6660  * configuration and preset
6661  */
6662 static const char *alc882_models[ALC882_MODEL_LAST] = {
6663         [ALC882_3ST_DIG]        = "3stack-dig",
6664         [ALC882_6ST_DIG]        = "6stack-dig",
6665         [ALC882_ARIMA]          = "arima",
6666         [ALC882_W2JC]           = "w2jc",
6667         [ALC882_TARGA]          = "targa",
6668         [ALC882_ASUS_A7J]       = "asus-a7j",
6669         [ALC882_ASUS_A7M]       = "asus-a7m",
6670         [ALC885_MACPRO]         = "macpro",
6671         [ALC885_MBP3]           = "mbp3",
6672         [ALC885_IMAC24]         = "imac24",
6673         [ALC882_AUTO]           = "auto",
6674 };
6675
6676 static struct snd_pci_quirk alc882_cfg_tbl[] = {
6677         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),
6678         SND_PCI_QUIRK(0x1043, 0x060d, "Asus A7J", ALC882_ASUS_A7J),
6679         SND_PCI_QUIRK(0x1043, 0x1243, "Asus A7J", ALC882_ASUS_A7J),
6680         SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_ASUS_A7M),
6681         SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_W2JC),
6682         SND_PCI_QUIRK(0x1043, 0x817f, "Asus P5LD2", ALC882_6ST_DIG),
6683         SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
6684         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
6685         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte P35 DS3R", ALC882_6ST_DIG),
6686         SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8  */
6687         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
6688         SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA),
6689         {}
6690 };
6691
6692 static struct alc_config_preset alc882_presets[] = {
6693         [ALC882_3ST_DIG] = {
6694                 .mixers = { alc882_base_mixer },
6695                 .init_verbs = { alc882_init_verbs },
6696                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6697                 .dac_nids = alc882_dac_nids,
6698                 .dig_out_nid = ALC882_DIGOUT_NID,
6699                 .dig_in_nid = ALC882_DIGIN_NID,
6700                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6701                 .channel_mode = alc882_ch_modes,
6702                 .need_dac_fix = 1,
6703                 .input_mux = &alc882_capture_source,
6704         },
6705         [ALC882_6ST_DIG] = {
6706                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
6707                 .init_verbs = { alc882_init_verbs },
6708                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6709                 .dac_nids = alc882_dac_nids,
6710                 .dig_out_nid = ALC882_DIGOUT_NID,
6711                 .dig_in_nid = ALC882_DIGIN_NID,
6712                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
6713                 .channel_mode = alc882_sixstack_modes,
6714                 .input_mux = &alc882_capture_source,
6715         },
6716         [ALC882_ARIMA] = {
6717                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
6718                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs },
6719                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6720                 .dac_nids = alc882_dac_nids,
6721                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
6722                 .channel_mode = alc882_sixstack_modes,
6723                 .input_mux = &alc882_capture_source,
6724         },
6725         [ALC882_W2JC] = {
6726                 .mixers = { alc882_w2jc_mixer, alc882_chmode_mixer },
6727                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
6728                                 alc880_gpio1_init_verbs },
6729                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6730                 .dac_nids = alc882_dac_nids,
6731                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
6732                 .channel_mode = alc880_threestack_modes,
6733                 .need_dac_fix = 1,
6734                 .input_mux = &alc882_capture_source,
6735                 .dig_out_nid = ALC882_DIGOUT_NID,
6736         },
6737         [ALC885_MBP3] = {
6738                 .mixers = { alc885_mbp3_mixer, alc882_chmode_mixer },
6739                 .init_verbs = { alc885_mbp3_init_verbs,
6740                                 alc880_gpio1_init_verbs },
6741                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6742                 .dac_nids = alc882_dac_nids,
6743                 .channel_mode = alc885_mbp_6ch_modes,
6744                 .num_channel_mode = ARRAY_SIZE(alc885_mbp_6ch_modes),
6745                 .input_mux = &alc882_capture_source,
6746                 .dig_out_nid = ALC882_DIGOUT_NID,
6747                 .dig_in_nid = ALC882_DIGIN_NID,
6748                 .unsol_event = alc885_mbp3_unsol_event,
6749                 .init_hook = alc885_mbp3_automute,
6750         },
6751         [ALC885_MACPRO] = {
6752                 .mixers = { alc882_macpro_mixer },
6753                 .init_verbs = { alc882_macpro_init_verbs },
6754                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6755                 .dac_nids = alc882_dac_nids,
6756                 .dig_out_nid = ALC882_DIGOUT_NID,
6757                 .dig_in_nid = ALC882_DIGIN_NID,
6758                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6759                 .channel_mode = alc882_ch_modes,
6760                 .input_mux = &alc882_capture_source,
6761                 .init_hook = alc885_macpro_init_hook,
6762         },
6763         [ALC885_IMAC24] = {
6764                 .mixers = { alc885_imac24_mixer },
6765                 .init_verbs = { alc885_imac24_init_verbs },
6766                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6767                 .dac_nids = alc882_dac_nids,
6768                 .dig_out_nid = ALC882_DIGOUT_NID,
6769                 .dig_in_nid = ALC882_DIGIN_NID,
6770                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6771                 .channel_mode = alc882_ch_modes,
6772                 .input_mux = &alc882_capture_source,
6773                 .unsol_event = alc885_imac24_unsol_event,
6774                 .init_hook = alc885_imac24_init_hook,
6775         },
6776         [ALC882_TARGA] = {
6777                 .mixers = { alc882_targa_mixer, alc882_chmode_mixer },
6778                 .init_verbs = { alc882_init_verbs, alc882_targa_verbs},
6779                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6780                 .dac_nids = alc882_dac_nids,
6781                 .dig_out_nid = ALC882_DIGOUT_NID,
6782                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6783                 .adc_nids = alc882_adc_nids,
6784                 .capsrc_nids = alc882_capsrc_nids,
6785                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6786                 .channel_mode = alc882_3ST_6ch_modes,
6787                 .need_dac_fix = 1,
6788                 .input_mux = &alc882_capture_source,
6789                 .unsol_event = alc882_targa_unsol_event,
6790                 .init_hook = alc882_targa_automute,
6791         },
6792         [ALC882_ASUS_A7J] = {
6793                 .mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer },
6794                 .init_verbs = { alc882_init_verbs, alc882_asus_a7j_verbs},
6795                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6796                 .dac_nids = alc882_dac_nids,
6797                 .dig_out_nid = ALC882_DIGOUT_NID,
6798                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6799                 .adc_nids = alc882_adc_nids,
6800                 .capsrc_nids = alc882_capsrc_nids,
6801                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6802                 .channel_mode = alc882_3ST_6ch_modes,
6803                 .need_dac_fix = 1,
6804                 .input_mux = &alc882_capture_source,
6805         },
6806         [ALC882_ASUS_A7M] = {
6807                 .mixers = { alc882_asus_a7m_mixer, alc882_chmode_mixer },
6808                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
6809                                 alc880_gpio1_init_verbs,
6810                                 alc882_asus_a7m_verbs },
6811                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6812                 .dac_nids = alc882_dac_nids,
6813                 .dig_out_nid = ALC882_DIGOUT_NID,
6814                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
6815                 .channel_mode = alc880_threestack_modes,
6816                 .need_dac_fix = 1,
6817                 .input_mux = &alc882_capture_source,
6818         },
6819 };
6820
6821
6822 /*
6823  * Pin config fixes
6824  */
6825 enum {
6826         PINFIX_ABIT_AW9D_MAX
6827 };
6828
6829 static struct alc_pincfg alc882_abit_aw9d_pinfix[] = {
6830         { 0x15, 0x01080104 }, /* side */
6831         { 0x16, 0x01011012 }, /* rear */
6832         { 0x17, 0x01016011 }, /* clfe */
6833         { }
6834 };
6835
6836 static const struct alc_pincfg *alc882_pin_fixes[] = {
6837         [PINFIX_ABIT_AW9D_MAX] = alc882_abit_aw9d_pinfix,
6838 };
6839
6840 static struct snd_pci_quirk alc882_pinfix_tbl[] = {
6841         SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
6842         {}
6843 };
6844
6845 /*
6846  * BIOS auto configuration
6847  */
6848 static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
6849                                               hda_nid_t nid, int pin_type,
6850                                               int dac_idx)
6851 {
6852         /* set as output */
6853         struct alc_spec *spec = codec->spec;
6854         int idx;
6855
6856         alc_set_pin_output(codec, nid, pin_type);
6857         if (spec->multiout.dac_nids[dac_idx] == 0x25)
6858                 idx = 4;
6859         else
6860                 idx = spec->multiout.dac_nids[dac_idx] - 2;
6861         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
6862
6863 }
6864
6865 static void alc882_auto_init_multi_out(struct hda_codec *codec)
6866 {
6867         struct alc_spec *spec = codec->spec;
6868         int i;
6869
6870         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
6871         for (i = 0; i <= HDA_SIDE; i++) {
6872                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
6873                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
6874                 if (nid)
6875                         alc882_auto_set_output_and_unmute(codec, nid, pin_type,
6876                                                           i);
6877         }
6878 }
6879
6880 static void alc882_auto_init_hp_out(struct hda_codec *codec)
6881 {
6882         struct alc_spec *spec = codec->spec;
6883         hda_nid_t pin;
6884
6885         pin = spec->autocfg.hp_pins[0];
6886         if (pin) /* connect to front */
6887                 /* use dac 0 */
6888                 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
6889         pin = spec->autocfg.speaker_pins[0];
6890         if (pin)
6891                 alc882_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
6892 }
6893
6894 #define alc882_is_input_pin(nid)        alc880_is_input_pin(nid)
6895 #define ALC882_PIN_CD_NID               ALC880_PIN_CD_NID
6896
6897 static void alc882_auto_init_analog_input(struct hda_codec *codec)
6898 {
6899         struct alc_spec *spec = codec->spec;
6900         int i;
6901
6902         for (i = 0; i < AUTO_PIN_LAST; i++) {
6903                 hda_nid_t nid = spec->autocfg.input_pins[i];
6904                 unsigned int vref;
6905                 if (!nid)
6906                         continue;
6907                 vref = PIN_IN;
6908                 if (1 /*i <= AUTO_PIN_FRONT_MIC*/) {
6909                         unsigned int pincap;
6910                         pincap = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
6911                         if ((pincap >> AC_PINCAP_VREF_SHIFT) &
6912                             AC_PINCAP_VREF_80)
6913                                 vref = PIN_VREF80;
6914                 }
6915                 snd_hda_codec_write(codec, nid, 0,
6916                                     AC_VERB_SET_PIN_WIDGET_CONTROL, vref);
6917                 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
6918                         snd_hda_codec_write(codec, nid, 0,
6919                                             AC_VERB_SET_AMP_GAIN_MUTE,
6920                                             AMP_OUT_MUTE);
6921         }
6922 }
6923
6924 static void alc882_auto_init_input_src(struct hda_codec *codec)
6925 {
6926         struct alc_spec *spec = codec->spec;
6927         int c;
6928
6929         for (c = 0; c < spec->num_adc_nids; c++) {
6930                 hda_nid_t conn_list[HDA_MAX_NUM_INPUTS];
6931                 hda_nid_t nid = spec->capsrc_nids[c];
6932                 unsigned int mux_idx;
6933                 const struct hda_input_mux *imux;
6934                 int conns, mute, idx, item;
6935
6936                 conns = snd_hda_get_connections(codec, nid, conn_list,
6937                                                 ARRAY_SIZE(conn_list));
6938                 if (conns < 0)
6939                         continue;
6940                 mux_idx = c >= spec->num_mux_defs ? 0 : c;
6941                 imux = &spec->input_mux[mux_idx];
6942                 for (idx = 0; idx < conns; idx++) {
6943                         /* if the current connection is the selected one,
6944                          * unmute it as default - otherwise mute it
6945                          */
6946                         mute = AMP_IN_MUTE(idx);
6947                         for (item = 0; item < imux->num_items; item++) {
6948                                 if (imux->items[item].index == idx) {
6949                                         if (spec->cur_mux[c] == item)
6950                                                 mute = AMP_IN_UNMUTE(idx);
6951                                         break;
6952                                 }
6953                         }
6954                         /* check if we have a selector or mixer
6955                          * we could check for the widget type instead, but
6956                          * just check for Amp-In presence (in case of mixer
6957                          * without amp-in there is something wrong, this
6958                          * function shouldn't be used or capsrc nid is wrong)
6959                          */
6960                         if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)
6961                                 snd_hda_codec_write(codec, nid, 0,
6962                                                     AC_VERB_SET_AMP_GAIN_MUTE,
6963                                                     mute);
6964                         else if (mute != AMP_IN_MUTE(idx))
6965                                 snd_hda_codec_write(codec, nid, 0,
6966                                                     AC_VERB_SET_CONNECT_SEL,
6967                                                     idx);
6968                 }
6969         }
6970 }
6971
6972 /* add mic boosts if needed */
6973 static int alc_auto_add_mic_boost(struct hda_codec *codec)
6974 {
6975         struct alc_spec *spec = codec->spec;
6976         int err;
6977         hda_nid_t nid;
6978
6979         nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
6980         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
6981                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6982                                   "Mic Boost",
6983                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6984                 if (err < 0)
6985                         return err;
6986         }
6987         nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
6988         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
6989                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6990                                   "Front Mic Boost",
6991                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6992                 if (err < 0)
6993                         return err;
6994         }
6995         return 0;
6996 }
6997
6998 /* almost identical with ALC880 parser... */
6999 static int alc882_parse_auto_config(struct hda_codec *codec)
7000 {
7001         struct alc_spec *spec = codec->spec;
7002         int err = alc880_parse_auto_config(codec);
7003
7004         if (err < 0)
7005                 return err;
7006         else if (!err)
7007                 return 0; /* no config found */
7008
7009         err = alc_auto_add_mic_boost(codec);
7010         if (err < 0)
7011                 return err;
7012
7013         /* hack - override the init verbs */
7014         spec->init_verbs[0] = alc882_auto_init_verbs;
7015
7016         return 1; /* config found */
7017 }
7018
7019 /* additional initialization for auto-configuration model */
7020 static void alc882_auto_init(struct hda_codec *codec)
7021 {
7022         struct alc_spec *spec = codec->spec;
7023         alc882_auto_init_multi_out(codec);
7024         alc882_auto_init_hp_out(codec);
7025         alc882_auto_init_analog_input(codec);
7026         alc882_auto_init_input_src(codec);
7027         if (spec->unsol_event)
7028                 alc_inithook(codec);
7029 }
7030
7031 static int patch_alc883(struct hda_codec *codec); /* called in patch_alc882() */
7032
7033 static int patch_alc882(struct hda_codec *codec)
7034 {
7035         struct alc_spec *spec;
7036         int err, board_config;
7037
7038         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
7039         if (spec == NULL)
7040                 return -ENOMEM;
7041
7042         codec->spec = spec;
7043
7044         board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
7045                                                   alc882_models,
7046                                                   alc882_cfg_tbl);
7047
7048         if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
7049                 /* Pick up systems that don't supply PCI SSID */
7050                 switch (codec->subsystem_id) {
7051                 case 0x106b0c00: /* Mac Pro */
7052                         board_config = ALC885_MACPRO;
7053                         break;
7054                 case 0x106b1000: /* iMac 24 */
7055                 case 0x106b2800: /* AppleTV */
7056                         board_config = ALC885_IMAC24;
7057                         break;
7058                 case 0x106b00a1: /* Macbook (might be wrong - PCI SSID?) */
7059                 case 0x106b00a4: /* MacbookPro4,1 */
7060                 case 0x106b2c00: /* Macbook Pro rev3 */
7061                 case 0x106b3600: /* Macbook 3.1 */
7062                         board_config = ALC885_MBP3;
7063                         break;
7064                 default:
7065                         /* ALC889A is handled better as ALC888-compatible */
7066                         if (codec->revision_id == 0x100101 ||
7067                             codec->revision_id == 0x100103) {
7068                                 alc_free(codec);
7069                                 return patch_alc883(codec);
7070                         }
7071                         printk(KERN_INFO "hda_codec: Unknown model for ALC882, "
7072                                          "trying auto-probe from BIOS...\n");
7073                         board_config = ALC882_AUTO;
7074                 }
7075         }
7076
7077         alc_fix_pincfg(codec, alc882_pinfix_tbl, alc882_pin_fixes);
7078
7079         if (board_config == ALC882_AUTO) {
7080                 /* automatic parse from the BIOS config */
7081                 err = alc882_parse_auto_config(codec);
7082                 if (err < 0) {
7083                         alc_free(codec);
7084                         return err;
7085                 } else if (!err) {
7086                         printk(KERN_INFO
7087                                "hda_codec: Cannot set up configuration "
7088                                "from BIOS.  Using base mode...\n");
7089                         board_config = ALC882_3ST_DIG;
7090                 }
7091         }
7092
7093         if (board_config != ALC882_AUTO)
7094                 setup_preset(spec, &alc882_presets[board_config]);
7095
7096         if (codec->vendor_id == 0x10ec0885) {
7097                 spec->stream_name_analog = "ALC885 Analog";
7098                 spec->stream_name_digital = "ALC885 Digital";
7099         } else {
7100                 spec->stream_name_analog = "ALC882 Analog";
7101                 spec->stream_name_digital = "ALC882 Digital";
7102         }
7103
7104         spec->stream_analog_playback = &alc882_pcm_analog_playback;
7105         spec->stream_analog_capture = &alc882_pcm_analog_capture;
7106         /* FIXME: setup DAC5 */
7107         /*spec->stream_analog_alt_playback = &alc880_pcm_analog_alt_playback;*/
7108         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
7109
7110         spec->stream_digital_playback = &alc882_pcm_digital_playback;
7111         spec->stream_digital_capture = &alc882_pcm_digital_capture;
7112
7113         spec->capture_style = CAPT_MIX; /* matrix-style capture */
7114         if (!spec->adc_nids && spec->input_mux) {
7115                 /* check whether NID 0x07 is valid */
7116                 unsigned int wcap = get_wcaps(codec, 0x07);
7117                 /* get type */
7118                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
7119                 if (wcap != AC_WID_AUD_IN) {
7120                         spec->adc_nids = alc882_adc_nids_alt;
7121                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt);
7122                         spec->capsrc_nids = alc882_capsrc_nids_alt;
7123                 } else {
7124                         spec->adc_nids = alc882_adc_nids;
7125                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
7126                         spec->capsrc_nids = alc882_capsrc_nids;
7127                 }
7128         }
7129         set_capture_mixer(spec);
7130
7131         spec->vmaster_nid = 0x0c;
7132
7133         codec->patch_ops = alc_patch_ops;
7134         if (board_config == ALC882_AUTO)
7135                 spec->init_hook = alc882_auto_init;
7136 #ifdef CONFIG_SND_HDA_POWER_SAVE
7137         if (!spec->loopback.amplist)
7138                 spec->loopback.amplist = alc882_loopbacks;
7139 #endif
7140         codec->proc_widget_hook = print_realtek_coef;
7141
7142         return 0;
7143 }
7144
7145 /*
7146  * ALC883 support
7147  *
7148  * ALC883 is almost identical with ALC880 but has cleaner and more flexible
7149  * configuration.  Each pin widget can choose any input DACs and a mixer.
7150  * Each ADC is connected from a mixer of all inputs.  This makes possible
7151  * 6-channel independent captures.
7152  *
7153  * In addition, an independent DAC for the multi-playback (not used in this
7154  * driver yet).
7155  */
7156 #define ALC883_DIGOUT_NID       0x06
7157 #define ALC883_DIGIN_NID        0x0a
7158
7159 #define ALC1200_DIGOUT_NID      0x10
7160
7161 static hda_nid_t alc883_dac_nids[4] = {
7162         /* front, rear, clfe, rear_surr */
7163         0x02, 0x03, 0x04, 0x05
7164 };
7165
7166 static hda_nid_t alc883_adc_nids[2] = {
7167         /* ADC1-2 */
7168         0x08, 0x09,
7169 };
7170
7171 static hda_nid_t alc883_adc_nids_alt[1] = {
7172         /* ADC1 */
7173         0x08,
7174 };
7175
7176 static hda_nid_t alc883_adc_nids_rev[2] = {
7177         /* ADC2-1 */
7178         0x09, 0x08
7179 };
7180
7181 #define alc889_adc_nids         alc880_adc_nids
7182
7183 static hda_nid_t alc883_capsrc_nids[2] = { 0x23, 0x22 };
7184
7185 static hda_nid_t alc883_capsrc_nids_rev[2] = { 0x22, 0x23 };
7186
7187 #define alc889_capsrc_nids      alc882_capsrc_nids
7188
7189 /* input MUX */
7190 /* FIXME: should be a matrix-type input source selection */
7191
7192 static struct hda_input_mux alc883_capture_source = {
7193         .num_items = 4,
7194         .items = {
7195                 { "Mic", 0x0 },
7196                 { "Front Mic", 0x1 },
7197                 { "Line", 0x2 },
7198                 { "CD", 0x4 },
7199         },
7200 };
7201
7202 static struct hda_input_mux alc883_3stack_6ch_intel = {
7203         .num_items = 4,
7204         .items = {
7205                 { "Mic", 0x1 },
7206                 { "Front Mic", 0x0 },
7207                 { "Line", 0x2 },
7208                 { "CD", 0x4 },
7209         },
7210 };
7211
7212 static struct hda_input_mux alc883_lenovo_101e_capture_source = {
7213         .num_items = 2,
7214         .items = {
7215                 { "Mic", 0x1 },
7216                 { "Line", 0x2 },
7217         },
7218 };
7219
7220 static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
7221         .num_items = 4,
7222         .items = {
7223                 { "Mic", 0x0 },
7224                 { "iMic", 0x1 },
7225                 { "Line", 0x2 },
7226                 { "CD", 0x4 },
7227         },
7228 };
7229
7230 static struct hda_input_mux alc883_fujitsu_pi2515_capture_source = {
7231         .num_items = 2,
7232         .items = {
7233                 { "Mic", 0x0 },
7234                 { "Int Mic", 0x1 },
7235         },
7236 };
7237
7238 static struct hda_input_mux alc883_lenovo_sky_capture_source = {
7239         .num_items = 3,
7240         .items = {
7241                 { "Mic", 0x0 },
7242                 { "Front Mic", 0x1 },
7243                 { "Line", 0x4 },
7244         },
7245 };
7246
7247 static struct hda_input_mux alc883_asus_eee1601_capture_source = {
7248         .num_items = 2,
7249         .items = {
7250                 { "Mic", 0x0 },
7251                 { "Line", 0x2 },
7252         },
7253 };
7254
7255 /*
7256  * 2ch mode
7257  */
7258 static struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
7259         { 2, NULL }
7260 };
7261
7262 /*
7263  * 2ch mode
7264  */
7265 static struct hda_verb alc883_3ST_ch2_init[] = {
7266         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7267         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7268         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7269         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7270         { } /* end */
7271 };
7272
7273 /*
7274  * 4ch mode
7275  */
7276 static struct hda_verb alc883_3ST_ch4_init[] = {
7277         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7278         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7279         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7280         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7281         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7282         { } /* end */
7283 };
7284
7285 /*
7286  * 6ch mode
7287  */
7288 static struct hda_verb alc883_3ST_ch6_init[] = {
7289         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7290         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7291         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
7292         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7293         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7294         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7295         { } /* end */
7296 };
7297
7298 static struct hda_channel_mode alc883_3ST_6ch_modes[3] = {
7299         { 2, alc883_3ST_ch2_init },
7300         { 4, alc883_3ST_ch4_init },
7301         { 6, alc883_3ST_ch6_init },
7302 };
7303
7304 /*
7305  * 2ch mode
7306  */
7307 static struct hda_verb alc883_3ST_ch2_intel_init[] = {
7308         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7309         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7310         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7311         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7312         { } /* end */
7313 };
7314
7315 /*
7316  * 4ch mode
7317  */
7318 static struct hda_verb alc883_3ST_ch4_intel_init[] = {
7319         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7320         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7321         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7322         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7323         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7324         { } /* end */
7325 };
7326
7327 /*
7328  * 6ch mode
7329  */
7330 static struct hda_verb alc883_3ST_ch6_intel_init[] = {
7331         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7332         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7333         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x02 },
7334         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7335         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7336         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7337         { } /* end */
7338 };
7339
7340 static struct hda_channel_mode alc883_3ST_6ch_intel_modes[3] = {
7341         { 2, alc883_3ST_ch2_intel_init },
7342         { 4, alc883_3ST_ch4_intel_init },
7343         { 6, alc883_3ST_ch6_intel_init },
7344 };
7345
7346 /*
7347  * 6ch mode
7348  */
7349 static struct hda_verb alc883_sixstack_ch6_init[] = {
7350         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
7351         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7352         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7353         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7354         { } /* end */
7355 };
7356
7357 /*
7358  * 8ch mode
7359  */
7360 static struct hda_verb alc883_sixstack_ch8_init[] = {
7361         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7362         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7363         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7364         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7365         { } /* end */
7366 };
7367
7368 static struct hda_channel_mode alc883_sixstack_modes[2] = {
7369         { 6, alc883_sixstack_ch6_init },
7370         { 8, alc883_sixstack_ch8_init },
7371 };
7372
7373 static struct hda_verb alc883_medion_eapd_verbs[] = {
7374         /* eanable EAPD on medion laptop */
7375         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7376         {0x20, AC_VERB_SET_PROC_COEF, 0x3070},
7377         { }
7378 };
7379
7380 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
7381  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
7382  */
7383
7384 static struct snd_kcontrol_new alc883_base_mixer[] = {
7385         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7386         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7387         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7388         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7389         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7390         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7391         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7392         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7393         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7394         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7395         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7396         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7397         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7398         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7399         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7400         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7401         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7402         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7403         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7404         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7405         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7406         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7407         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7408         { } /* end */
7409 };
7410
7411 static struct snd_kcontrol_new alc883_mitac_mixer[] = {
7412         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7413         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7414         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7415         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7416         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7417         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7418         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7419         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7420         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7421         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7422         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7423         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7424         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7425         { } /* end */
7426 };
7427
7428 static struct snd_kcontrol_new alc883_clevo_m720_mixer[] = {
7429         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7430         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7431         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7432         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7433         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7434         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7435         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7436         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7437         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7438         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7439         { } /* end */
7440 };
7441
7442 static struct snd_kcontrol_new alc883_2ch_fujitsu_pi2515_mixer[] = {
7443         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7444         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7445         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7446         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7447         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7448         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7449         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7450         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7451         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7452         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7453         { } /* end */
7454 };
7455
7456 static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
7457         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7458         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7459         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7460         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7461         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7462         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7463         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7464         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7465         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7466         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7467         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7468         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7469         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7470         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7471         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7472         { } /* end */
7473 };
7474
7475 static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
7476         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7477         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7478         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7479         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7480         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7481         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7482         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7483         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7484         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7485         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7486         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7487         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7488         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7489         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7490         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7491         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7492         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7493         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7494         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7495         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7496         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7497         { } /* end */
7498 };
7499
7500 static struct snd_kcontrol_new alc883_3ST_6ch_intel_mixer[] = {
7501         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7502         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7503         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7504         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7505         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
7506                               HDA_OUTPUT),
7507         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7508         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7509         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7510         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7511         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7512         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7513         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7514         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7515         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7516         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
7517         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7518         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7519         HDA_CODEC_VOLUME("Front Mic Boost", 0x18, 0, HDA_INPUT),
7520         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7521         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7522         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7523         { } /* end */
7524 };
7525
7526 static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
7527         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7528         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7529         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7530         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7531         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7532         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7533         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7534         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7535         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7536         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7537         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7538         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7539         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7540         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7541         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7542         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7543         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7544         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7545         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7546         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7547         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7548         { } /* end */
7549 };
7550
7551 static struct snd_kcontrol_new alc883_tagra_mixer[] = {
7552         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7553         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7554         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7555         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7556         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7557         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7558         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7559         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7560         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7561         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7562         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7563         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7564         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7565         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7566         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7567         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7568         { } /* end */
7569 };
7570
7571 static struct snd_kcontrol_new alc883_tagra_2ch_mixer[] = {
7572         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7573         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7574         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7575         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7576         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7577         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7578         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7579         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7580         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7581         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7582         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7583         { } /* end */
7584 };
7585
7586 static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
7587         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7588         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7589         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7590         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7591         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7592         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7593         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7594         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7595         { } /* end */
7596 };
7597
7598 static struct snd_kcontrol_new alc883_lenovo_nb0763_mixer[] = {
7599         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7600         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
7601         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7602         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7603         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7604         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7605         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7606         HDA_CODEC_VOLUME("iMic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7607         HDA_CODEC_MUTE("iMic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7608         { } /* end */
7609 };
7610
7611 static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
7612         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7613         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7614         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7615         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7616         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7617         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7618         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7619         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7620         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7621         { } /* end */
7622 };
7623
7624 static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
7625         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7626         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7627         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7628         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7629         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7630         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7631         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7632         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7633         { } /* end */
7634 };
7635
7636 static struct snd_kcontrol_new alc888_lenovo_sky_mixer[] = {
7637         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7638         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7639         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
7640         HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
7641         HDA_CODEC_VOLUME_MONO("Center Playback Volume",
7642                                                 0x0d, 1, 0x0, HDA_OUTPUT),
7643         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
7644         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
7645         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
7646         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7647         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7648         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7649         HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
7650         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7651         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7652         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7653         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7654         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7655         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7656         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7657         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7658         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7659         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7660         { } /* end */
7661 };
7662
7663 static struct hda_bind_ctls alc883_bind_cap_vol = {
7664         .ops = &snd_hda_bind_vol,
7665         .values = {
7666                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
7667                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
7668                 0
7669         },
7670 };
7671
7672 static struct hda_bind_ctls alc883_bind_cap_switch = {
7673         .ops = &snd_hda_bind_sw,
7674         .values = {
7675                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
7676                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
7677                 0
7678         },
7679 };
7680
7681 static struct snd_kcontrol_new alc883_asus_eee1601_mixer[] = {
7682         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7683         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7684         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7685         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7686         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7687         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7688         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7689         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7690         { } /* end */
7691 };
7692
7693 static struct snd_kcontrol_new alc883_asus_eee1601_cap_mixer[] = {
7694         HDA_BIND_VOL("Capture Volume", &alc883_bind_cap_vol),
7695         HDA_BIND_SW("Capture Switch", &alc883_bind_cap_switch),
7696         {
7697                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7698                 /* .name = "Capture Source", */
7699                 .name = "Input Source",
7700                 .count = 1,
7701                 .info = alc_mux_enum_info,
7702                 .get = alc_mux_enum_get,
7703                 .put = alc_mux_enum_put,
7704         },
7705         { } /* end */
7706 };
7707
7708 static struct snd_kcontrol_new alc883_chmode_mixer[] = {
7709         {
7710                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7711                 .name = "Channel Mode",
7712                 .info = alc_ch_mode_info,
7713                 .get = alc_ch_mode_get,
7714                 .put = alc_ch_mode_put,
7715         },
7716         { } /* end */
7717 };
7718
7719 static struct hda_verb alc883_init_verbs[] = {
7720         /* ADC1: mute amp left and right */
7721         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7722         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7723         /* ADC2: mute amp left and right */
7724         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7725         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7726         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7727         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7728         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7729         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7730         /* Rear mixer */
7731         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7732         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7733         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7734         /* CLFE mixer */
7735         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7736         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7737         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7738         /* Side mixer */
7739         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7740         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7741         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7742
7743         /* mute analog input loopbacks */
7744         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7745         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7746         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7747         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7748         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7749
7750         /* Front Pin: output 0 (0x0c) */
7751         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7752         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7753         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7754         /* Rear Pin: output 1 (0x0d) */
7755         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7756         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7757         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7758         /* CLFE Pin: output 2 (0x0e) */
7759         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7760         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7761         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
7762         /* Side Pin: output 3 (0x0f) */
7763         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7764         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7765         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
7766         /* Mic (rear) pin: input vref at 80% */
7767         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7768         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7769         /* Front Mic pin: input vref at 80% */
7770         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7771         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7772         /* Line In pin: input */
7773         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7774         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7775         /* Line-2 In: Headphone output (output 0 - 0x0c) */
7776         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7777         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7778         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7779         /* CD pin widget for input */
7780         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7781
7782         /* FIXME: use matrix-type input source selection */
7783         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7784         /* Input mixer2 */
7785         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7786         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7787         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7788         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7789         /* Input mixer3 */
7790         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7791         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7792         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7793         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7794         { }
7795 };
7796
7797 /* toggle speaker-output according to the hp-jack state */
7798 static void alc883_mitac_hp_automute(struct hda_codec *codec)
7799 {
7800         unsigned int present;
7801
7802         present = snd_hda_codec_read(codec, 0x15, 0,
7803                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7804         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7805                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7806         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
7807                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7808 }
7809
7810 /* auto-toggle front mic */
7811 /*
7812 static void alc883_mitac_mic_automute(struct hda_codec *codec)
7813 {
7814         unsigned int present;
7815         unsigned char bits;
7816
7817         present = snd_hda_codec_read(codec, 0x18, 0,
7818                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7819         bits = present ? HDA_AMP_MUTE : 0;
7820         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
7821 }
7822 */
7823
7824 static void alc883_mitac_automute(struct hda_codec *codec)
7825 {
7826         alc883_mitac_hp_automute(codec);
7827         /* alc883_mitac_mic_automute(codec); */
7828 }
7829
7830 static void alc883_mitac_unsol_event(struct hda_codec *codec,
7831                                            unsigned int res)
7832 {
7833         switch (res >> 26) {
7834         case ALC880_HP_EVENT:
7835                 alc883_mitac_hp_automute(codec);
7836                 break;
7837         case ALC880_MIC_EVENT:
7838                 /* alc883_mitac_mic_automute(codec); */
7839                 break;
7840         }
7841 }
7842
7843 static struct hda_verb alc883_mitac_verbs[] = {
7844         /* HP */
7845         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7846         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7847         /* Subwoofer */
7848         {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
7849         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7850
7851         /* enable unsolicited event */
7852         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7853         /* {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN}, */
7854
7855         { } /* end */
7856 };
7857
7858 static struct hda_verb alc883_clevo_m720_verbs[] = {
7859         /* HP */
7860         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7861         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7862         /* Int speaker */
7863         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
7864         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7865
7866         /* enable unsolicited event */
7867         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7868         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
7869
7870         { } /* end */
7871 };
7872
7873 static struct hda_verb alc883_2ch_fujitsu_pi2515_verbs[] = {
7874         /* HP */
7875         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7876         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7877         /* Subwoofer */
7878         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7879         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7880
7881         /* enable unsolicited event */
7882         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7883
7884         { } /* end */
7885 };
7886
7887 static struct hda_verb alc883_tagra_verbs[] = {
7888         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7889         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7890
7891         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7892         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7893
7894         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
7895         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
7896         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7897
7898         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7899         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
7900         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
7901         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
7902
7903         { } /* end */
7904 };
7905
7906 static struct hda_verb alc883_lenovo_101e_verbs[] = {
7907         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7908         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT|AC_USRSP_EN},
7909         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT|AC_USRSP_EN},
7910         { } /* end */
7911 };
7912
7913 static struct hda_verb alc883_lenovo_nb0763_verbs[] = {
7914         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7915         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7916         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7917         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7918         { } /* end */
7919 };
7920
7921 static struct hda_verb alc888_lenovo_ms7195_verbs[] = {
7922         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7923         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7924         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7925         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT | AC_USRSP_EN},
7926         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT    | AC_USRSP_EN},
7927         { } /* end */
7928 };
7929
7930 static struct hda_verb alc883_haier_w66_verbs[] = {
7931         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7932         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7933
7934         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7935
7936         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7937         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7938         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7939         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7940         { } /* end */
7941 };
7942
7943 static struct hda_verb alc888_lenovo_sky_verbs[] = {
7944         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7945         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7946         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7947         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7948         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7949         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7950         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
7951         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7952         { } /* end */
7953 };
7954
7955 static struct hda_verb alc888_3st_hp_verbs[] = {
7956         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
7957         {0x16, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Rear : output 1 (0x0d) */
7958         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},  /* CLFE : output 2 (0x0e) */
7959         { }
7960 };
7961
7962 static struct hda_verb alc888_6st_dell_verbs[] = {
7963         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7964         { }
7965 };
7966
7967 static struct hda_verb alc888_3st_hp_2ch_init[] = {
7968         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7969         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7970         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7971         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7972         { }
7973 };
7974
7975 static struct hda_verb alc888_3st_hp_6ch_init[] = {
7976         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7977         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7978         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7979         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7980         { }
7981 };
7982
7983 static struct hda_channel_mode alc888_3st_hp_modes[2] = {
7984         { 2, alc888_3st_hp_2ch_init },
7985         { 6, alc888_3st_hp_6ch_init },
7986 };
7987
7988 /* toggle front-jack and RCA according to the hp-jack state */
7989 static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
7990 {
7991         unsigned int present;
7992
7993         present = snd_hda_codec_read(codec, 0x1b, 0,
7994                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7995         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7996                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7997         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7998                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7999 }
8000
8001 /* toggle RCA according to the front-jack state */
8002 static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
8003 {
8004         unsigned int present;
8005
8006         present = snd_hda_codec_read(codec, 0x14, 0,
8007                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8008         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8009                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8010 }
8011
8012 static void alc883_lenovo_ms7195_unsol_event(struct hda_codec *codec,
8013                                              unsigned int res)
8014 {
8015         if ((res >> 26) == ALC880_HP_EVENT)
8016                 alc888_lenovo_ms7195_front_automute(codec);
8017         if ((res >> 26) == ALC880_FRONT_EVENT)
8018                 alc888_lenovo_ms7195_rca_automute(codec);
8019 }
8020
8021 static struct hda_verb alc883_medion_md2_verbs[] = {
8022         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8023         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8024
8025         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8026
8027         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8028         { } /* end */
8029 };
8030
8031 /* toggle speaker-output according to the hp-jack state */
8032 static void alc883_medion_md2_automute(struct hda_codec *codec)
8033 {
8034         unsigned int present;
8035
8036         present = snd_hda_codec_read(codec, 0x14, 0,
8037                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8038         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8039                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8040 }
8041
8042 static void alc883_medion_md2_unsol_event(struct hda_codec *codec,
8043                                           unsigned int res)
8044 {
8045         if ((res >> 26) == ALC880_HP_EVENT)
8046                 alc883_medion_md2_automute(codec);
8047 }
8048
8049 /* toggle speaker-output according to the hp-jack state */
8050 static void alc883_tagra_automute(struct hda_codec *codec)
8051 {
8052         unsigned int present;
8053         unsigned char bits;
8054
8055         present = snd_hda_codec_read(codec, 0x14, 0,
8056                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8057         bits = present ? HDA_AMP_MUTE : 0;
8058         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
8059                                  HDA_AMP_MUTE, bits);
8060         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
8061                                   present ? 1 : 3);
8062 }
8063
8064 static void alc883_tagra_unsol_event(struct hda_codec *codec, unsigned int res)
8065 {
8066         if ((res >> 26) == ALC880_HP_EVENT)
8067                 alc883_tagra_automute(codec);
8068 }
8069
8070 /* toggle speaker-output according to the hp-jack state */
8071 static void alc883_clevo_m720_hp_automute(struct hda_codec *codec)
8072 {
8073         unsigned int present;
8074         unsigned char bits;
8075
8076         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
8077                 & AC_PINSENSE_PRESENCE;
8078         bits = present ? HDA_AMP_MUTE : 0;
8079         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8080                                  HDA_AMP_MUTE, bits);
8081 }
8082
8083 static void alc883_clevo_m720_mic_automute(struct hda_codec *codec)
8084 {
8085         unsigned int present;
8086
8087         present = snd_hda_codec_read(codec, 0x18, 0,
8088                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8089         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
8090                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8091 }
8092
8093 static void alc883_clevo_m720_automute(struct hda_codec *codec)
8094 {
8095         alc883_clevo_m720_hp_automute(codec);
8096         alc883_clevo_m720_mic_automute(codec);
8097 }
8098
8099 static void alc883_clevo_m720_unsol_event(struct hda_codec *codec,
8100                                            unsigned int res)
8101 {
8102         switch (res >> 26) {
8103         case ALC880_HP_EVENT:
8104                 alc883_clevo_m720_hp_automute(codec);
8105                 break;
8106         case ALC880_MIC_EVENT:
8107                 alc883_clevo_m720_mic_automute(codec);
8108                 break;
8109         }
8110 }
8111
8112 /* toggle speaker-output according to the hp-jack state */
8113 static void alc883_2ch_fujitsu_pi2515_automute(struct hda_codec *codec)
8114 {
8115         unsigned int present;
8116         unsigned char bits;
8117
8118         present = snd_hda_codec_read(codec, 0x14, 0, AC_VERB_GET_PIN_SENSE, 0)
8119                 & AC_PINSENSE_PRESENCE;
8120         bits = present ? HDA_AMP_MUTE : 0;
8121         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8122                                  HDA_AMP_MUTE, bits);
8123 }
8124
8125 static void alc883_2ch_fujitsu_pi2515_unsol_event(struct hda_codec *codec,
8126                                                   unsigned int res)
8127 {
8128         if ((res >> 26) == ALC880_HP_EVENT)
8129                 alc883_2ch_fujitsu_pi2515_automute(codec);
8130 }
8131
8132 static void alc883_haier_w66_automute(struct hda_codec *codec)
8133 {
8134         unsigned int present;
8135         unsigned char bits;
8136
8137         present = snd_hda_codec_read(codec, 0x1b, 0,
8138                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8139         bits = present ? 0x80 : 0;
8140         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8141                                  0x80, bits);
8142 }
8143
8144 static void alc883_haier_w66_unsol_event(struct hda_codec *codec,
8145                                          unsigned int res)
8146 {
8147         if ((res >> 26) == ALC880_HP_EVENT)
8148                 alc883_haier_w66_automute(codec);
8149 }
8150
8151 static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
8152 {
8153         unsigned int present;
8154         unsigned char bits;
8155
8156         present = snd_hda_codec_read(codec, 0x14, 0,
8157                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8158         bits = present ? HDA_AMP_MUTE : 0;
8159         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8160                                  HDA_AMP_MUTE, bits);
8161 }
8162
8163 static void alc883_lenovo_101e_all_automute(struct hda_codec *codec)
8164 {
8165         unsigned int present;
8166         unsigned char bits;
8167
8168         present = snd_hda_codec_read(codec, 0x1b, 0,
8169                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8170         bits = present ? HDA_AMP_MUTE : 0;
8171         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8172                                  HDA_AMP_MUTE, bits);
8173         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8174                                  HDA_AMP_MUTE, bits);
8175 }
8176
8177 static void alc883_lenovo_101e_unsol_event(struct hda_codec *codec,
8178                                            unsigned int res)
8179 {
8180         if ((res >> 26) == ALC880_HP_EVENT)
8181                 alc883_lenovo_101e_all_automute(codec);
8182         if ((res >> 26) == ALC880_FRONT_EVENT)
8183                 alc883_lenovo_101e_ispeaker_automute(codec);
8184 }
8185
8186 /* toggle speaker-output according to the hp-jack state */
8187 static void alc883_acer_aspire_automute(struct hda_codec *codec)
8188 {
8189         unsigned int present;
8190
8191         present = snd_hda_codec_read(codec, 0x14, 0,
8192                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8193         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8194                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8195         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8196                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8197 }
8198
8199 static void alc883_acer_aspire_unsol_event(struct hda_codec *codec,
8200                                            unsigned int res)
8201 {
8202         if ((res >> 26) == ALC880_HP_EVENT)
8203                 alc883_acer_aspire_automute(codec);
8204 }
8205
8206 static struct hda_verb alc883_acer_eapd_verbs[] = {
8207         /* HP Pin: output 0 (0x0c) */
8208         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8209         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8210         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8211         /* Front Pin: output 0 (0x0c) */
8212         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8213         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8214         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8215         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
8216         /* eanable EAPD on medion laptop */
8217         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
8218         {0x20, AC_VERB_SET_PROC_COEF, 0x3050},
8219         /* enable unsolicited event */
8220         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8221         { }
8222 };
8223
8224 static void alc888_6st_dell_front_automute(struct hda_codec *codec)
8225 {
8226         unsigned int present;
8227
8228         present = snd_hda_codec_read(codec, 0x1b, 0,
8229                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8230         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8231                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8232         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8233                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8234         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8235                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8236         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
8237                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8238 }
8239
8240 static void alc888_6st_dell_unsol_event(struct hda_codec *codec,
8241                                              unsigned int res)
8242 {
8243         switch (res >> 26) {
8244         case ALC880_HP_EVENT:
8245                 printk("hp_event\n");
8246                 alc888_6st_dell_front_automute(codec);
8247                 break;
8248         }
8249 }
8250
8251 static void alc888_lenovo_sky_front_automute(struct hda_codec *codec)
8252 {
8253         unsigned int mute;
8254         unsigned int present;
8255
8256         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
8257         present = snd_hda_codec_read(codec, 0x1b, 0,
8258                                      AC_VERB_GET_PIN_SENSE, 0);
8259         present = (present & 0x80000000) != 0;
8260         if (present) {
8261                 /* mute internal speaker */
8262                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8263                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8264                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8265                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8266                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8267                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8268                 snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
8269                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8270                 snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
8271                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8272         } else {
8273                 /* unmute internal speaker if necessary */
8274                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
8275                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8276                                          HDA_AMP_MUTE, mute);
8277                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8278                                          HDA_AMP_MUTE, mute);
8279                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8280                                          HDA_AMP_MUTE, mute);
8281                 snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
8282                                          HDA_AMP_MUTE, mute);
8283                 snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
8284                                          HDA_AMP_MUTE, mute);
8285         }
8286 }
8287
8288 static void alc883_lenovo_sky_unsol_event(struct hda_codec *codec,
8289                                              unsigned int res)
8290 {
8291         if ((res >> 26) == ALC880_HP_EVENT)
8292                 alc888_lenovo_sky_front_automute(codec);
8293 }
8294
8295 /*
8296  * generic initialization of ADC, input mixers and output mixers
8297  */
8298 static struct hda_verb alc883_auto_init_verbs[] = {
8299         /*
8300          * Unmute ADC0-2 and set the default input to mic-in
8301          */
8302         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8303         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8304         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8305         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8306
8307         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
8308          * mixer widget
8309          * Note: PASD motherboards uses the Line In 2 as the input for
8310          * front panel mic (mic 2)
8311          */
8312         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
8313         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8314         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8315         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8316         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8317         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8318
8319         /*
8320          * Set up output mixers (0x0c - 0x0f)
8321          */
8322         /* set vol=0 to output mixers */
8323         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8324         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8325         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8326         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8327         /* set up input amps for analog loopback */
8328         /* Amp Indices: DAC = 0, mixer = 1 */
8329         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8330         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8331         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8332         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8333         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8334         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8335         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8336         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8337         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8338         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8339
8340         /* FIXME: use matrix-type input source selection */
8341         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8342         /* Input mixer1 */
8343         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8344         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8345         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8346         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
8347         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
8348         /* Input mixer2 */
8349         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8350         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8351         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8352         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
8353         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
8354
8355         { }
8356 };
8357
8358 static struct hda_verb alc888_asus_m90v_verbs[] = {
8359         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8360         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8361         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8362         /* enable unsolicited event */
8363         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8364         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
8365         { } /* end */
8366 };
8367
8368 static void alc883_nb_mic_automute(struct hda_codec *codec)
8369 {
8370         unsigned int present;
8371
8372         present = snd_hda_codec_read(codec, 0x18, 0,
8373                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8374         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
8375                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
8376         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
8377                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
8378 }
8379
8380 static void alc883_M90V_speaker_automute(struct hda_codec *codec)
8381 {
8382         unsigned int present;
8383         unsigned char bits;
8384
8385         present = snd_hda_codec_read(codec, 0x1b, 0,
8386                                      AC_VERB_GET_PIN_SENSE, 0)
8387                 & AC_PINSENSE_PRESENCE;
8388         bits = present ? 0 : PIN_OUT;
8389         snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8390                             bits);
8391         snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8392                             bits);
8393         snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8394                             bits);
8395 }
8396
8397 static void alc883_mode2_unsol_event(struct hda_codec *codec,
8398                                            unsigned int res)
8399 {
8400         switch (res >> 26) {
8401         case ALC880_HP_EVENT:
8402                 alc883_M90V_speaker_automute(codec);
8403                 break;
8404         case ALC880_MIC_EVENT:
8405                 alc883_nb_mic_automute(codec);
8406                 break;
8407         }
8408 }
8409
8410 static void alc883_mode2_inithook(struct hda_codec *codec)
8411 {
8412         alc883_M90V_speaker_automute(codec);
8413         alc883_nb_mic_automute(codec);
8414 }
8415
8416 static struct hda_verb alc888_asus_eee1601_verbs[] = {
8417         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8418         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8419         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8420         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8421         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8422         {0x20, AC_VERB_SET_COEF_INDEX, 0x0b},
8423         {0x20, AC_VERB_SET_PROC_COEF,  0x0838},
8424         /* enable unsolicited event */
8425         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8426         { } /* end */
8427 };
8428
8429 static void alc883_eee1601_speaker_automute(struct hda_codec *codec)
8430 {
8431         unsigned int present;
8432         unsigned char bits;
8433
8434         present = snd_hda_codec_read(codec, 0x14, 0,
8435                                      AC_VERB_GET_PIN_SENSE, 0)
8436                 & AC_PINSENSE_PRESENCE;
8437         bits = present ? 0 : PIN_OUT;
8438         snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8439                             bits);
8440 }
8441
8442 static void alc883_eee1601_unsol_event(struct hda_codec *codec,
8443                                            unsigned int res)
8444 {
8445         switch (res >> 26) {
8446         case ALC880_HP_EVENT:
8447                 alc883_eee1601_speaker_automute(codec);
8448                 break;
8449         }
8450 }
8451
8452 static void alc883_eee1601_inithook(struct hda_codec *codec)
8453 {
8454         alc883_eee1601_speaker_automute(codec);
8455 }
8456
8457 #ifdef CONFIG_SND_HDA_POWER_SAVE
8458 #define alc883_loopbacks        alc880_loopbacks
8459 #endif
8460
8461 /* pcm configuration: identiacal with ALC880 */
8462 #define alc883_pcm_analog_playback      alc880_pcm_analog_playback
8463 #define alc883_pcm_analog_capture       alc880_pcm_analog_capture
8464 #define alc883_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
8465 #define alc883_pcm_digital_playback     alc880_pcm_digital_playback
8466 #define alc883_pcm_digital_capture      alc880_pcm_digital_capture
8467
8468 /*
8469  * configuration and preset
8470  */
8471 static const char *alc883_models[ALC883_MODEL_LAST] = {
8472         [ALC883_3ST_2ch_DIG]    = "3stack-dig",
8473         [ALC883_3ST_6ch_DIG]    = "3stack-6ch-dig",
8474         [ALC883_3ST_6ch]        = "3stack-6ch",
8475         [ALC883_6ST_DIG]        = "6stack-dig",
8476         [ALC883_TARGA_DIG]      = "targa-dig",
8477         [ALC883_TARGA_2ch_DIG]  = "targa-2ch-dig",
8478         [ALC883_ACER]           = "acer",
8479         [ALC883_ACER_ASPIRE]    = "acer-aspire",
8480         [ALC888_ACER_ASPIRE_4930G]      = "acer-aspire-4930g",
8481         [ALC883_MEDION]         = "medion",
8482         [ALC883_MEDION_MD2]     = "medion-md2",
8483         [ALC883_LAPTOP_EAPD]    = "laptop-eapd",
8484         [ALC883_LENOVO_101E_2ch] = "lenovo-101e",
8485         [ALC883_LENOVO_NB0763]  = "lenovo-nb0763",
8486         [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
8487         [ALC888_LENOVO_SKY] = "lenovo-sky",
8488         [ALC883_HAIER_W66]      = "haier-w66",
8489         [ALC888_3ST_HP]         = "3stack-hp",
8490         [ALC888_6ST_DELL]       = "6stack-dell",
8491         [ALC883_MITAC]          = "mitac",
8492         [ALC883_CLEVO_M720]     = "clevo-m720",
8493         [ALC883_FUJITSU_PI2515] = "fujitsu-pi2515",
8494         [ALC888_FUJITSU_XA3530] = "fujitsu-xa3530",
8495         [ALC883_3ST_6ch_INTEL]  = "3stack-6ch-intel",
8496         [ALC1200_ASUS_P5Q]      = "asus-p5q",
8497         [ALC883_AUTO]           = "auto",
8498 };
8499
8500 static struct snd_pci_quirk alc883_cfg_tbl[] = {
8501         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC883_3ST_6ch_DIG),
8502         SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE),
8503         SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_ACER_ASPIRE),
8504         SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE),
8505         SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE),
8506         SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_ACER_ASPIRE),
8507         SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
8508                 ALC888_ACER_ASPIRE_4930G),
8509         SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
8510                 ALC888_ACER_ASPIRE_4930G),
8511         SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
8512                 ALC888_ACER_ASPIRE_4930G),
8513         SND_PCI_QUIRK(0x1025, 0, "Acer laptop", ALC883_ACER), /* default Acer */
8514         SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL),
8515         SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
8516         SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
8517         SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
8518         SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG),
8519         SND_PCI_QUIRK(0x103c, 0x2a66, "HP Acacia", ALC888_3ST_HP),
8520         SND_PCI_QUIRK(0x1043, 0x1873, "Asus M90V", ALC888_ASUS_M90V),
8521         SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG),
8522         SND_PCI_QUIRK(0x1043, 0x82fe, "Asus P5Q-EM HDMI", ALC1200_ASUS_P5Q),
8523         SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_ASUS_EEE1601),
8524         SND_PCI_QUIRK(0x105b, 0x0ce8, "Foxconn P35AX-S", ALC883_6ST_DIG),
8525         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG),
8526         SND_PCI_QUIRK(0x1071, 0x8227, "Mitac 82801H", ALC883_MITAC),
8527         SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC),
8528         SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
8529         SND_PCI_QUIRK(0x10f1, 0x2350, "TYAN-S2350", ALC888_6ST_DELL),
8530         SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
8531         SND_PCI_QUIRK(0x1458, 0xa002, "MSI", ALC883_6ST_DIG),
8532         SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
8533         SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG),
8534         SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
8535         SND_PCI_QUIRK(0x1462, 0x2fb3, "MSI", ALC883_TARGA_2ch_DIG),
8536         SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
8537         SND_PCI_QUIRK(0x1462, 0x3783, "NEC S970", ALC883_TARGA_DIG),
8538         SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
8539         SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
8540         SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
8541         SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG),
8542         SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG),
8543         SND_PCI_QUIRK(0x1462, 0x3fdf, "MSI", ALC883_TARGA_DIG),
8544         SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
8545         SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
8546         SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
8547         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
8548         SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
8549         SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
8550         SND_PCI_QUIRK(0x1462, 0x7260, "MSI 7260", ALC883_TARGA_DIG),
8551         SND_PCI_QUIRK(0x1462, 0x7267, "MSI", ALC883_3ST_6ch_DIG),
8552         SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
8553         SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
8554         SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
8555         SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG),
8556         SND_PCI_QUIRK(0x1558, 0x0721, "Clevo laptop M720R", ALC883_CLEVO_M720),
8557         SND_PCI_QUIRK(0x1558, 0x0722, "Clevo laptop M720SR", ALC883_CLEVO_M720),
8558         SND_PCI_QUIRK(0x1558, 0, "Clevo laptop", ALC883_LAPTOP_EAPD),
8559         SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
8560         SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
8561         SND_PCI_QUIRK(0x1734, 0x1108, "Fujitsu AMILO Pi2515", ALC883_FUJITSU_PI2515),
8562         SND_PCI_QUIRK(0x1734, 0x113d, "Fujitsu AMILO Xa3530",
8563                 ALC888_FUJITSU_XA3530),
8564         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
8565         SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8566         SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8567         SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8568         SND_PCI_QUIRK(0x17aa, 0x101d, "Lenovo Sky", ALC888_LENOVO_SKY),
8569         SND_PCI_QUIRK(0x17c0, 0x4071, "MEDION MD2", ALC883_MEDION_MD2),
8570         SND_PCI_QUIRK(0x17c0, 0x4085, "MEDION MD96630", ALC888_LENOVO_MS7195_DIG),
8571         SND_PCI_QUIRK(0x17f2, 0x5000, "Albatron KI690-AM2", ALC883_6ST_DIG),
8572         SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66),
8573         SND_PCI_QUIRK(0x8086, 0x0001, "DG33BUC", ALC883_3ST_6ch_INTEL),
8574         SND_PCI_QUIRK(0x8086, 0x0002, "DG33FBC", ALC883_3ST_6ch_INTEL),
8575         SND_PCI_QUIRK(0x8086, 0x2503, "82801H", ALC883_MITAC),
8576         SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC883_3ST_6ch_INTEL),
8577         SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch),
8578         {}
8579 };
8580
8581 static struct alc_config_preset alc883_presets[] = {
8582         [ALC883_3ST_2ch_DIG] = {
8583                 .mixers = { alc883_3ST_2ch_mixer },
8584                 .init_verbs = { alc883_init_verbs },
8585                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8586                 .dac_nids = alc883_dac_nids,
8587                 .dig_out_nid = ALC883_DIGOUT_NID,
8588                 .dig_in_nid = ALC883_DIGIN_NID,
8589                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8590                 .channel_mode = alc883_3ST_2ch_modes,
8591                 .input_mux = &alc883_capture_source,
8592         },
8593         [ALC883_3ST_6ch_DIG] = {
8594                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8595                 .init_verbs = { alc883_init_verbs },
8596                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8597                 .dac_nids = alc883_dac_nids,
8598                 .dig_out_nid = ALC883_DIGOUT_NID,
8599                 .dig_in_nid = ALC883_DIGIN_NID,
8600                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8601                 .channel_mode = alc883_3ST_6ch_modes,
8602                 .need_dac_fix = 1,
8603                 .input_mux = &alc883_capture_source,
8604         },
8605         [ALC883_3ST_6ch] = {
8606                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8607                 .init_verbs = { alc883_init_verbs },
8608                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8609                 .dac_nids = alc883_dac_nids,
8610                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8611                 .channel_mode = alc883_3ST_6ch_modes,
8612                 .need_dac_fix = 1,
8613                 .input_mux = &alc883_capture_source,
8614         },
8615         [ALC883_3ST_6ch_INTEL] = {
8616                 .mixers = { alc883_3ST_6ch_intel_mixer, alc883_chmode_mixer },
8617                 .init_verbs = { alc883_init_verbs },
8618                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8619                 .dac_nids = alc883_dac_nids,
8620                 .dig_out_nid = ALC883_DIGOUT_NID,
8621                 .dig_in_nid = ALC883_DIGIN_NID,
8622                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_intel_modes),
8623                 .channel_mode = alc883_3ST_6ch_intel_modes,
8624                 .need_dac_fix = 1,
8625                 .input_mux = &alc883_3stack_6ch_intel,
8626         },
8627         [ALC883_6ST_DIG] = {
8628                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8629                 .init_verbs = { alc883_init_verbs },
8630                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8631                 .dac_nids = alc883_dac_nids,
8632                 .dig_out_nid = ALC883_DIGOUT_NID,
8633                 .dig_in_nid = ALC883_DIGIN_NID,
8634                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8635                 .channel_mode = alc883_sixstack_modes,
8636                 .input_mux = &alc883_capture_source,
8637         },
8638         [ALC883_TARGA_DIG] = {
8639                 .mixers = { alc883_tagra_mixer, alc883_chmode_mixer },
8640                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
8641                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8642                 .dac_nids = alc883_dac_nids,
8643                 .dig_out_nid = ALC883_DIGOUT_NID,
8644                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8645                 .channel_mode = alc883_3ST_6ch_modes,
8646                 .need_dac_fix = 1,
8647                 .input_mux = &alc883_capture_source,
8648                 .unsol_event = alc883_tagra_unsol_event,
8649                 .init_hook = alc883_tagra_automute,
8650         },
8651         [ALC883_TARGA_2ch_DIG] = {
8652                 .mixers = { alc883_tagra_2ch_mixer},
8653                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
8654                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8655                 .dac_nids = alc883_dac_nids,
8656                 .adc_nids = alc883_adc_nids_alt,
8657                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
8658                 .dig_out_nid = ALC883_DIGOUT_NID,
8659                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8660                 .channel_mode = alc883_3ST_2ch_modes,
8661                 .input_mux = &alc883_capture_source,
8662                 .unsol_event = alc883_tagra_unsol_event,
8663                 .init_hook = alc883_tagra_automute,
8664         },
8665         [ALC883_ACER] = {
8666                 .mixers = { alc883_base_mixer },
8667                 /* On TravelMate laptops, GPIO 0 enables the internal speaker
8668                  * and the headphone jack.  Turn this on and rely on the
8669                  * standard mute methods whenever the user wants to turn
8670                  * these outputs off.
8671                  */
8672                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
8673                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8674                 .dac_nids = alc883_dac_nids,
8675                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8676                 .channel_mode = alc883_3ST_2ch_modes,
8677                 .input_mux = &alc883_capture_source,
8678         },
8679         [ALC883_ACER_ASPIRE] = {
8680                 .mixers = { alc883_acer_aspire_mixer },
8681                 .init_verbs = { alc883_init_verbs, alc883_acer_eapd_verbs },
8682                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8683                 .dac_nids = alc883_dac_nids,
8684                 .dig_out_nid = ALC883_DIGOUT_NID,
8685                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8686                 .channel_mode = alc883_3ST_2ch_modes,
8687                 .input_mux = &alc883_capture_source,
8688                 .unsol_event = alc883_acer_aspire_unsol_event,
8689                 .init_hook = alc883_acer_aspire_automute,
8690         },
8691         [ALC888_ACER_ASPIRE_4930G] = {
8692                 .mixers = { alc888_base_mixer,
8693                                 alc883_chmode_mixer },
8694                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
8695                                 alc888_acer_aspire_4930g_verbs },
8696                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8697                 .dac_nids = alc883_dac_nids,
8698                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
8699                 .adc_nids = alc883_adc_nids_rev,
8700                 .capsrc_nids = alc883_capsrc_nids_rev,
8701                 .dig_out_nid = ALC883_DIGOUT_NID,
8702                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8703                 .channel_mode = alc883_3ST_6ch_modes,
8704                 .need_dac_fix = 1,
8705                 .num_mux_defs =
8706                         ARRAY_SIZE(alc888_2_capture_sources),
8707                 .input_mux = alc888_2_capture_sources,
8708                 .unsol_event = alc888_acer_aspire_4930g_unsol_event,
8709                 .init_hook = alc888_acer_aspire_4930g_automute,
8710         },
8711         [ALC883_MEDION] = {
8712                 .mixers = { alc883_fivestack_mixer,
8713                             alc883_chmode_mixer },
8714                 .init_verbs = { alc883_init_verbs,
8715                                 alc883_medion_eapd_verbs },
8716                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8717                 .dac_nids = alc883_dac_nids,
8718                 .adc_nids = alc883_adc_nids_alt,
8719                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
8720                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8721                 .channel_mode = alc883_sixstack_modes,
8722                 .input_mux = &alc883_capture_source,
8723         },
8724         [ALC883_MEDION_MD2] = {
8725                 .mixers = { alc883_medion_md2_mixer},
8726                 .init_verbs = { alc883_init_verbs, alc883_medion_md2_verbs},
8727                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8728                 .dac_nids = alc883_dac_nids,
8729                 .dig_out_nid = ALC883_DIGOUT_NID,
8730                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8731                 .channel_mode = alc883_3ST_2ch_modes,
8732                 .input_mux = &alc883_capture_source,
8733                 .unsol_event = alc883_medion_md2_unsol_event,
8734                 .init_hook = alc883_medion_md2_automute,
8735         },
8736         [ALC883_LAPTOP_EAPD] = {
8737                 .mixers = { alc883_base_mixer },
8738                 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
8739                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8740                 .dac_nids = alc883_dac_nids,
8741                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8742                 .channel_mode = alc883_3ST_2ch_modes,
8743                 .input_mux = &alc883_capture_source,
8744         },
8745         [ALC883_CLEVO_M720] = {
8746                 .mixers = { alc883_clevo_m720_mixer },
8747                 .init_verbs = { alc883_init_verbs, alc883_clevo_m720_verbs },
8748                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8749                 .dac_nids = alc883_dac_nids,
8750                 .dig_out_nid = ALC883_DIGOUT_NID,
8751                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8752                 .channel_mode = alc883_3ST_2ch_modes,
8753                 .input_mux = &alc883_capture_source,
8754                 .unsol_event = alc883_clevo_m720_unsol_event,
8755                 .init_hook = alc883_clevo_m720_automute,
8756         },
8757         [ALC883_LENOVO_101E_2ch] = {
8758                 .mixers = { alc883_lenovo_101e_2ch_mixer},
8759                 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
8760                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8761                 .dac_nids = alc883_dac_nids,
8762                 .adc_nids = alc883_adc_nids_alt,
8763                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
8764                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8765                 .channel_mode = alc883_3ST_2ch_modes,
8766                 .input_mux = &alc883_lenovo_101e_capture_source,
8767                 .unsol_event = alc883_lenovo_101e_unsol_event,
8768                 .init_hook = alc883_lenovo_101e_all_automute,
8769         },
8770         [ALC883_LENOVO_NB0763] = {
8771                 .mixers = { alc883_lenovo_nb0763_mixer },
8772                 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs},
8773                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8774                 .dac_nids = alc883_dac_nids,
8775                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8776                 .channel_mode = alc883_3ST_2ch_modes,
8777                 .need_dac_fix = 1,
8778                 .input_mux = &alc883_lenovo_nb0763_capture_source,
8779                 .unsol_event = alc883_medion_md2_unsol_event,
8780                 .init_hook = alc883_medion_md2_automute,
8781         },
8782         [ALC888_LENOVO_MS7195_DIG] = {
8783                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8784                 .init_verbs = { alc883_init_verbs, alc888_lenovo_ms7195_verbs},
8785                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8786                 .dac_nids = alc883_dac_nids,
8787                 .dig_out_nid = ALC883_DIGOUT_NID,
8788                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8789                 .channel_mode = alc883_3ST_6ch_modes,
8790                 .need_dac_fix = 1,
8791                 .input_mux = &alc883_capture_source,
8792                 .unsol_event = alc883_lenovo_ms7195_unsol_event,
8793                 .init_hook = alc888_lenovo_ms7195_front_automute,
8794         },
8795         [ALC883_HAIER_W66] = {
8796                 .mixers = { alc883_tagra_2ch_mixer},
8797                 .init_verbs = { alc883_init_verbs, alc883_haier_w66_verbs},
8798                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8799                 .dac_nids = alc883_dac_nids,
8800                 .dig_out_nid = ALC883_DIGOUT_NID,
8801                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8802                 .channel_mode = alc883_3ST_2ch_modes,
8803                 .input_mux = &alc883_capture_source,
8804                 .unsol_event = alc883_haier_w66_unsol_event,
8805                 .init_hook = alc883_haier_w66_automute,
8806         },
8807         [ALC888_3ST_HP] = {
8808                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8809                 .init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs },
8810                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8811                 .dac_nids = alc883_dac_nids,
8812                 .num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes),
8813                 .channel_mode = alc888_3st_hp_modes,
8814                 .need_dac_fix = 1,
8815                 .input_mux = &alc883_capture_source,
8816         },
8817         [ALC888_6ST_DELL] = {
8818                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8819                 .init_verbs = { alc883_init_verbs, alc888_6st_dell_verbs },
8820                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8821                 .dac_nids = alc883_dac_nids,
8822                 .dig_out_nid = ALC883_DIGOUT_NID,
8823                 .dig_in_nid = ALC883_DIGIN_NID,
8824                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8825                 .channel_mode = alc883_sixstack_modes,
8826                 .input_mux = &alc883_capture_source,
8827                 .unsol_event = alc888_6st_dell_unsol_event,
8828                 .init_hook = alc888_6st_dell_front_automute,
8829         },
8830         [ALC883_MITAC] = {
8831                 .mixers = { alc883_mitac_mixer },
8832                 .init_verbs = { alc883_init_verbs, alc883_mitac_verbs },
8833                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8834                 .dac_nids = alc883_dac_nids,
8835                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8836                 .channel_mode = alc883_3ST_2ch_modes,
8837                 .input_mux = &alc883_capture_source,
8838                 .unsol_event = alc883_mitac_unsol_event,
8839                 .init_hook = alc883_mitac_automute,
8840         },
8841         [ALC883_FUJITSU_PI2515] = {
8842                 .mixers = { alc883_2ch_fujitsu_pi2515_mixer },
8843                 .init_verbs = { alc883_init_verbs,
8844                                 alc883_2ch_fujitsu_pi2515_verbs},
8845                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8846                 .dac_nids = alc883_dac_nids,
8847                 .dig_out_nid = ALC883_DIGOUT_NID,
8848                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8849                 .channel_mode = alc883_3ST_2ch_modes,
8850                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
8851                 .unsol_event = alc883_2ch_fujitsu_pi2515_unsol_event,
8852                 .init_hook = alc883_2ch_fujitsu_pi2515_automute,
8853         },
8854         [ALC888_FUJITSU_XA3530] = {
8855                 .mixers = { alc888_base_mixer, alc883_chmode_mixer },
8856                 .init_verbs = { alc883_init_verbs,
8857                         alc888_fujitsu_xa3530_verbs },
8858                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8859                 .dac_nids = alc883_dac_nids,
8860                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
8861                 .adc_nids = alc883_adc_nids_rev,
8862                 .capsrc_nids = alc883_capsrc_nids_rev,
8863                 .dig_out_nid = ALC883_DIGOUT_NID,
8864                 .num_channel_mode = ARRAY_SIZE(alc888_4ST_8ch_intel_modes),
8865                 .channel_mode = alc888_4ST_8ch_intel_modes,
8866                 .num_mux_defs =
8867                         ARRAY_SIZE(alc888_2_capture_sources),
8868                 .input_mux = alc888_2_capture_sources,
8869                 .unsol_event = alc888_fujitsu_xa3530_unsol_event,
8870                 .init_hook = alc888_fujitsu_xa3530_automute,
8871         },
8872         [ALC888_LENOVO_SKY] = {
8873                 .mixers = { alc888_lenovo_sky_mixer, alc883_chmode_mixer },
8874                 .init_verbs = { alc883_init_verbs, alc888_lenovo_sky_verbs},
8875                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8876                 .dac_nids = alc883_dac_nids,
8877                 .dig_out_nid = ALC883_DIGOUT_NID,
8878                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8879                 .channel_mode = alc883_sixstack_modes,
8880                 .need_dac_fix = 1,
8881                 .input_mux = &alc883_lenovo_sky_capture_source,
8882                 .unsol_event = alc883_lenovo_sky_unsol_event,
8883                 .init_hook = alc888_lenovo_sky_front_automute,
8884         },
8885         [ALC888_ASUS_M90V] = {
8886                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8887                 .init_verbs = { alc883_init_verbs, alc888_asus_m90v_verbs },
8888                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8889                 .dac_nids = alc883_dac_nids,
8890                 .dig_out_nid = ALC883_DIGOUT_NID,
8891                 .dig_in_nid = ALC883_DIGIN_NID,
8892                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8893                 .channel_mode = alc883_3ST_6ch_modes,
8894                 .need_dac_fix = 1,
8895                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
8896                 .unsol_event = alc883_mode2_unsol_event,
8897                 .init_hook = alc883_mode2_inithook,
8898         },
8899         [ALC888_ASUS_EEE1601] = {
8900                 .mixers = { alc883_asus_eee1601_mixer },
8901                 .cap_mixer = alc883_asus_eee1601_cap_mixer,
8902                 .init_verbs = { alc883_init_verbs, alc888_asus_eee1601_verbs },
8903                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8904                 .dac_nids = alc883_dac_nids,
8905                 .dig_out_nid = ALC883_DIGOUT_NID,
8906                 .dig_in_nid = ALC883_DIGIN_NID,
8907                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8908                 .channel_mode = alc883_3ST_2ch_modes,
8909                 .need_dac_fix = 1,
8910                 .input_mux = &alc883_asus_eee1601_capture_source,
8911                 .unsol_event = alc883_eee1601_unsol_event,
8912                 .init_hook = alc883_eee1601_inithook,
8913         },
8914         [ALC1200_ASUS_P5Q] = {
8915                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8916                 .init_verbs = { alc883_init_verbs },
8917                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8918                 .dac_nids = alc883_dac_nids,
8919                 .dig_out_nid = ALC1200_DIGOUT_NID,
8920                 .dig_in_nid = ALC883_DIGIN_NID,
8921                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8922                 .channel_mode = alc883_sixstack_modes,
8923                 .input_mux = &alc883_capture_source,
8924         },
8925 };
8926
8927
8928 /*
8929  * BIOS auto configuration
8930  */
8931 static void alc883_auto_set_output_and_unmute(struct hda_codec *codec,
8932                                               hda_nid_t nid, int pin_type,
8933                                               int dac_idx)
8934 {
8935         /* set as output */
8936         struct alc_spec *spec = codec->spec;
8937         int idx;
8938
8939         alc_set_pin_output(codec, nid, pin_type);
8940         if (spec->multiout.dac_nids[dac_idx] == 0x25)
8941                 idx = 4;
8942         else
8943                 idx = spec->multiout.dac_nids[dac_idx] - 2;
8944         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
8945
8946 }
8947
8948 static void alc883_auto_init_multi_out(struct hda_codec *codec)
8949 {
8950         struct alc_spec *spec = codec->spec;
8951         int i;
8952
8953         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
8954         for (i = 0; i <= HDA_SIDE; i++) {
8955                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
8956                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
8957                 if (nid)
8958                         alc883_auto_set_output_and_unmute(codec, nid, pin_type,
8959                                                           i);
8960         }
8961 }
8962
8963 static void alc883_auto_init_hp_out(struct hda_codec *codec)
8964 {
8965         struct alc_spec *spec = codec->spec;
8966         hda_nid_t pin;
8967
8968         pin = spec->autocfg.hp_pins[0];
8969         if (pin) /* connect to front */
8970                 /* use dac 0 */
8971                 alc883_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
8972         pin = spec->autocfg.speaker_pins[0];
8973         if (pin)
8974                 alc883_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
8975 }
8976
8977 #define alc883_is_input_pin(nid)        alc880_is_input_pin(nid)
8978 #define ALC883_PIN_CD_NID               ALC880_PIN_CD_NID
8979
8980 static void alc883_auto_init_analog_input(struct hda_codec *codec)
8981 {
8982         struct alc_spec *spec = codec->spec;
8983         int i;
8984
8985         for (i = 0; i < AUTO_PIN_LAST; i++) {
8986                 hda_nid_t nid = spec->autocfg.input_pins[i];
8987                 if (alc883_is_input_pin(nid)) {
8988                         snd_hda_codec_write(codec, nid, 0,
8989                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
8990                                             (i <= AUTO_PIN_FRONT_MIC ?
8991                                              PIN_VREF80 : PIN_IN));
8992                         if (nid != ALC883_PIN_CD_NID)
8993                                 snd_hda_codec_write(codec, nid, 0,
8994                                                     AC_VERB_SET_AMP_GAIN_MUTE,
8995                                                     AMP_OUT_MUTE);
8996                 }
8997         }
8998 }
8999
9000 #define alc883_auto_init_input_src      alc882_auto_init_input_src
9001
9002 /* almost identical with ALC880 parser... */
9003 static int alc883_parse_auto_config(struct hda_codec *codec)
9004 {
9005         struct alc_spec *spec = codec->spec;
9006         int err = alc880_parse_auto_config(codec);
9007         struct auto_pin_cfg *cfg = &spec->autocfg;
9008         int i;
9009
9010         if (err < 0)
9011                 return err;
9012         else if (!err)
9013                 return 0; /* no config found */
9014
9015         err = alc_auto_add_mic_boost(codec);
9016         if (err < 0)
9017                 return err;
9018
9019         /* hack - override the init verbs */
9020         spec->init_verbs[0] = alc883_auto_init_verbs;
9021
9022         /* setup input_mux for ALC889 */
9023         if (codec->vendor_id == 0x10ec0889) {
9024                 /* digital-mic input pin is excluded in alc880_auto_create..()
9025                  * because it's under 0x18
9026                  */
9027                 if (cfg->input_pins[AUTO_PIN_MIC] == 0x12 ||
9028                     cfg->input_pins[AUTO_PIN_FRONT_MIC] == 0x12) {
9029                         struct hda_input_mux *imux = &spec->private_imux[0];
9030                         for (i = 1; i < 3; i++)
9031                                 memcpy(&spec->private_imux[i],
9032                                        &spec->private_imux[0],
9033                                        sizeof(spec->private_imux[0]));
9034                         imux->items[imux->num_items].label = "Int DMic";
9035                         imux->items[imux->num_items].index = 0x0b;
9036                         imux->num_items++;
9037                         spec->num_mux_defs = 3;
9038                         spec->input_mux = spec->private_imux;
9039                 }
9040         }
9041
9042         return 1; /* config found */
9043 }
9044
9045 /* additional initialization for auto-configuration model */
9046 static void alc883_auto_init(struct hda_codec *codec)
9047 {
9048         struct alc_spec *spec = codec->spec;
9049         alc883_auto_init_multi_out(codec);
9050         alc883_auto_init_hp_out(codec);
9051         alc883_auto_init_analog_input(codec);
9052         alc883_auto_init_input_src(codec);
9053         if (spec->unsol_event)
9054                 alc_inithook(codec);
9055 }
9056
9057 static int patch_alc883(struct hda_codec *codec)
9058 {
9059         struct alc_spec *spec;
9060         int err, board_config;
9061
9062         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
9063         if (spec == NULL)
9064                 return -ENOMEM;
9065
9066         codec->spec = spec;
9067
9068         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
9069
9070         board_config = snd_hda_check_board_config(codec, ALC883_MODEL_LAST,
9071                                                   alc883_models,
9072                                                   alc883_cfg_tbl);
9073         if (board_config < 0) {
9074                 printk(KERN_INFO "hda_codec: Unknown model for ALC883, "
9075                        "trying auto-probe from BIOS...\n");
9076                 board_config = ALC883_AUTO;
9077         }
9078
9079         if (board_config == ALC883_AUTO) {
9080                 /* automatic parse from the BIOS config */
9081                 err = alc883_parse_auto_config(codec);
9082                 if (err < 0) {
9083                         alc_free(codec);
9084                         return err;
9085                 } else if (!err) {
9086                         printk(KERN_INFO
9087                                "hda_codec: Cannot set up configuration "
9088                                "from BIOS.  Using base mode...\n");
9089                         board_config = ALC883_3ST_2ch_DIG;
9090                 }
9091         }
9092
9093         if (board_config != ALC883_AUTO)
9094                 setup_preset(spec, &alc883_presets[board_config]);
9095
9096         switch (codec->vendor_id) {
9097         case 0x10ec0888:
9098                 if (codec->revision_id == 0x100101) {
9099                         spec->stream_name_analog = "ALC1200 Analog";
9100                         spec->stream_name_digital = "ALC1200 Digital";
9101                 } else {
9102                         spec->stream_name_analog = "ALC888 Analog";
9103                         spec->stream_name_digital = "ALC888 Digital";
9104                 }
9105                 if (!spec->num_adc_nids) {
9106                         spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
9107                         spec->adc_nids = alc883_adc_nids;
9108                 }
9109                 if (!spec->capsrc_nids)
9110                         spec->capsrc_nids = alc883_capsrc_nids;
9111                 spec->capture_style = CAPT_MIX; /* matrix-style capture */
9112                 break;
9113         case 0x10ec0889:
9114                 spec->stream_name_analog = "ALC889 Analog";
9115                 spec->stream_name_digital = "ALC889 Digital";
9116                 if (!spec->num_adc_nids) {
9117                         spec->num_adc_nids = ARRAY_SIZE(alc889_adc_nids);
9118                         spec->adc_nids = alc889_adc_nids;
9119                 }
9120                 if (!spec->capsrc_nids)
9121                         spec->capsrc_nids = alc889_capsrc_nids;
9122                 spec->capture_style = CAPT_1MUX_MIX; /* 1mux/Nmix-style
9123                                                         capture */
9124                 break;
9125         default:
9126                 spec->stream_name_analog = "ALC883 Analog";
9127                 spec->stream_name_digital = "ALC883 Digital";
9128                 if (!spec->num_adc_nids) {
9129                         spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
9130                         spec->adc_nids = alc883_adc_nids;
9131                 }
9132                 if (!spec->capsrc_nids)
9133                         spec->capsrc_nids = alc883_capsrc_nids;
9134                 spec->capture_style = CAPT_MIX; /* matrix-style capture */
9135                 break;
9136         }
9137
9138         spec->stream_analog_playback = &alc883_pcm_analog_playback;
9139         spec->stream_analog_capture = &alc883_pcm_analog_capture;
9140         spec->stream_analog_alt_capture = &alc883_pcm_analog_alt_capture;
9141
9142         spec->stream_digital_playback = &alc883_pcm_digital_playback;
9143         spec->stream_digital_capture = &alc883_pcm_digital_capture;
9144
9145         if (!spec->cap_mixer)
9146                 set_capture_mixer(spec);
9147
9148         spec->vmaster_nid = 0x0c;
9149
9150         codec->patch_ops = alc_patch_ops;
9151         if (board_config == ALC883_AUTO)
9152                 spec->init_hook = alc883_auto_init;
9153
9154 #ifdef CONFIG_SND_HDA_POWER_SAVE
9155         if (!spec->loopback.amplist)
9156                 spec->loopback.amplist = alc883_loopbacks;
9157 #endif
9158         codec->proc_widget_hook = print_realtek_coef;
9159
9160         return 0;
9161 }
9162
9163 /*
9164  * ALC262 support
9165  */
9166
9167 #define ALC262_DIGOUT_NID       ALC880_DIGOUT_NID
9168 #define ALC262_DIGIN_NID        ALC880_DIGIN_NID
9169
9170 #define alc262_dac_nids         alc260_dac_nids
9171 #define alc262_adc_nids         alc882_adc_nids
9172 #define alc262_adc_nids_alt     alc882_adc_nids_alt
9173 #define alc262_capsrc_nids      alc882_capsrc_nids
9174 #define alc262_capsrc_nids_alt  alc882_capsrc_nids_alt
9175
9176 #define alc262_modes            alc260_modes
9177 #define alc262_capture_source   alc882_capture_source
9178
9179 static hda_nid_t alc262_dmic_adc_nids[1] = {
9180         /* ADC0 */
9181         0x09
9182 };
9183
9184 static hda_nid_t alc262_dmic_capsrc_nids[1] = { 0x22 };
9185
9186 static struct snd_kcontrol_new alc262_base_mixer[] = {
9187         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9188         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9189         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9190         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9191         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9192         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9193         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9194         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9195         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9196         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9197         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9198         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9199         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
9200            HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT), */
9201         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
9202         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9203         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
9204         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
9205         { } /* end */
9206 };
9207
9208 static struct snd_kcontrol_new alc262_hippo1_mixer[] = {
9209         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9210         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9211         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9212         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9213         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9214         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9215         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9216         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9217         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9218         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9219         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9220         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9221         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
9222            HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT), */
9223         /*HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),*/
9224         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9225         { } /* end */
9226 };
9227
9228 /* update HP, line and mono-out pins according to the master switch */
9229 static void alc262_hp_master_update(struct hda_codec *codec)
9230 {
9231         struct alc_spec *spec = codec->spec;
9232         int val = spec->master_sw;
9233
9234         /* HP & line-out */
9235         snd_hda_codec_write_cache(codec, 0x1b, 0,
9236                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9237                                   val ? PIN_HP : 0);
9238         snd_hda_codec_write_cache(codec, 0x15, 0,
9239                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9240                                   val ? PIN_HP : 0);
9241         /* mono (speaker) depending on the HP jack sense */
9242         val = val && !spec->jack_present;
9243         snd_hda_codec_write_cache(codec, 0x16, 0,
9244                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9245                                   val ? PIN_OUT : 0);
9246 }
9247
9248 static void alc262_hp_bpc_automute(struct hda_codec *codec)
9249 {
9250         struct alc_spec *spec = codec->spec;
9251         unsigned int presence;
9252         presence = snd_hda_codec_read(codec, 0x1b, 0,
9253                                       AC_VERB_GET_PIN_SENSE, 0);
9254         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
9255         alc262_hp_master_update(codec);
9256 }
9257
9258 static void alc262_hp_bpc_unsol_event(struct hda_codec *codec, unsigned int res)
9259 {
9260         if ((res >> 26) != ALC880_HP_EVENT)
9261                 return;
9262         alc262_hp_bpc_automute(codec);
9263 }
9264
9265 static void alc262_hp_wildwest_automute(struct hda_codec *codec)
9266 {
9267         struct alc_spec *spec = codec->spec;
9268         unsigned int presence;
9269         presence = snd_hda_codec_read(codec, 0x15, 0,
9270                                       AC_VERB_GET_PIN_SENSE, 0);
9271         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
9272         alc262_hp_master_update(codec);
9273 }
9274
9275 static void alc262_hp_wildwest_unsol_event(struct hda_codec *codec,
9276                                            unsigned int res)
9277 {
9278         if ((res >> 26) != ALC880_HP_EVENT)
9279                 return;
9280         alc262_hp_wildwest_automute(codec);
9281 }
9282
9283 static int alc262_hp_master_sw_get(struct snd_kcontrol *kcontrol,
9284                                    struct snd_ctl_elem_value *ucontrol)
9285 {
9286         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9287         struct alc_spec *spec = codec->spec;
9288         *ucontrol->value.integer.value = spec->master_sw;
9289         return 0;
9290 }
9291
9292 static int alc262_hp_master_sw_put(struct snd_kcontrol *kcontrol,
9293                                    struct snd_ctl_elem_value *ucontrol)
9294 {
9295         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9296         struct alc_spec *spec = codec->spec;
9297         int val = !!*ucontrol->value.integer.value;
9298
9299         if (val == spec->master_sw)
9300                 return 0;
9301         spec->master_sw = val;
9302         alc262_hp_master_update(codec);
9303         return 1;
9304 }
9305
9306 static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
9307         {
9308                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9309                 .name = "Master Playback Switch",
9310                 .info = snd_ctl_boolean_mono_info,
9311                 .get = alc262_hp_master_sw_get,
9312                 .put = alc262_hp_master_sw_put,
9313         },
9314         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9315         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9316         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9317         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
9318                               HDA_OUTPUT),
9319         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
9320                             HDA_OUTPUT),
9321         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9322         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9323         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9324         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9325         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9326         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9327         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9328         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9329         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9330         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9331         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
9332         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
9333         HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
9334         HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
9335         { } /* end */
9336 };
9337
9338 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
9339         {
9340                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9341                 .name = "Master Playback Switch",
9342                 .info = snd_ctl_boolean_mono_info,
9343                 .get = alc262_hp_master_sw_get,
9344                 .put = alc262_hp_master_sw_put,
9345         },
9346         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9347         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9348         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9349         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9350         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
9351                               HDA_OUTPUT),
9352         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
9353                             HDA_OUTPUT),
9354         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
9355         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
9356         HDA_CODEC_VOLUME("Front Mic Boost", 0x1a, 0, HDA_INPUT),
9357         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
9358         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
9359         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9360         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9361         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
9362         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
9363         { } /* end */
9364 };
9365
9366 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
9367         HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9368         HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9369         HDA_CODEC_VOLUME("Rear Mic Boost", 0x18, 0, HDA_INPUT),
9370         { } /* end */
9371 };
9372
9373 /* mute/unmute internal speaker according to the hp jack and mute state */
9374 static void alc262_hp_t5735_automute(struct hda_codec *codec, int force)
9375 {
9376         struct alc_spec *spec = codec->spec;
9377
9378         if (force || !spec->sense_updated) {
9379                 unsigned int present;
9380                 present = snd_hda_codec_read(codec, 0x15, 0,
9381                                              AC_VERB_GET_PIN_SENSE, 0);
9382                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
9383                 spec->sense_updated = 1;
9384         }
9385         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0, HDA_AMP_MUTE,
9386                                  spec->jack_present ? HDA_AMP_MUTE : 0);
9387 }
9388
9389 static void alc262_hp_t5735_unsol_event(struct hda_codec *codec,
9390                                         unsigned int res)
9391 {
9392         if ((res >> 26) != ALC880_HP_EVENT)
9393                 return;
9394         alc262_hp_t5735_automute(codec, 1);
9395 }
9396
9397 static void alc262_hp_t5735_init_hook(struct hda_codec *codec)
9398 {
9399         alc262_hp_t5735_automute(codec, 1);
9400 }
9401
9402 static struct snd_kcontrol_new alc262_hp_t5735_mixer[] = {
9403         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9404         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9405         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9406         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9407         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9408         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9409         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9410         { } /* end */
9411 };
9412
9413 static struct hda_verb alc262_hp_t5735_verbs[] = {
9414         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9415         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9416
9417         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9418         { }
9419 };
9420
9421 static struct snd_kcontrol_new alc262_hp_rp5700_mixer[] = {
9422         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9423         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9424         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
9425         HDA_CODEC_MUTE("Speaker Playback Switch", 0x16, 0x0, HDA_OUTPUT),
9426         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
9427         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
9428         { } /* end */
9429 };
9430
9431 static struct hda_verb alc262_hp_rp5700_verbs[] = {
9432         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9433         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9434         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9435         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9436         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9437         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9438         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9439         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9440         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
9441         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
9442         {}
9443 };
9444
9445 static struct hda_input_mux alc262_hp_rp5700_capture_source = {
9446         .num_items = 1,
9447         .items = {
9448                 { "Line", 0x1 },
9449         },
9450 };
9451
9452 /* bind hp and internal speaker mute (with plug check) */
9453 static int alc262_sony_master_sw_put(struct snd_kcontrol *kcontrol,
9454                                      struct snd_ctl_elem_value *ucontrol)
9455 {
9456         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9457         long *valp = ucontrol->value.integer.value;
9458         int change;
9459
9460         /* change hp mute */
9461         change = snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
9462                                           HDA_AMP_MUTE,
9463                                           valp[0] ? 0 : HDA_AMP_MUTE);
9464         change |= snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
9465                                            HDA_AMP_MUTE,
9466                                            valp[1] ? 0 : HDA_AMP_MUTE);
9467         if (change) {
9468                 /* change speaker according to HP jack state */
9469                 struct alc_spec *spec = codec->spec;
9470                 unsigned int mute;
9471                 if (spec->jack_present)
9472                         mute = HDA_AMP_MUTE;
9473                 else
9474                         mute = snd_hda_codec_amp_read(codec, 0x15, 0,
9475                                                       HDA_OUTPUT, 0);
9476                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9477                                          HDA_AMP_MUTE, mute);
9478         }
9479         return change;
9480 }
9481
9482 static struct snd_kcontrol_new alc262_sony_mixer[] = {
9483         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9484         {
9485                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9486                 .name = "Master Playback Switch",
9487                 .info = snd_hda_mixer_amp_switch_info,
9488                 .get = snd_hda_mixer_amp_switch_get,
9489                 .put = alc262_sony_master_sw_put,
9490                 .private_value = HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
9491         },
9492         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9493         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9494         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9495         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9496         { } /* end */
9497 };
9498
9499 static struct snd_kcontrol_new alc262_benq_t31_mixer[] = {
9500         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9501         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9502         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9503         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9504         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9505         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9506         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9507         { } /* end */
9508 };
9509
9510 #define alc262_capture_mixer            alc882_capture_mixer
9511 #define alc262_capture_alt_mixer        alc882_capture_alt_mixer
9512
9513 /*
9514  * generic initialization of ADC, input mixers and output mixers
9515  */
9516 static struct hda_verb alc262_init_verbs[] = {
9517         /*
9518          * Unmute ADC0-2 and set the default input to mic-in
9519          */
9520         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
9521         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9522         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9523         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9524         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9525         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9526
9527         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
9528          * mixer widget
9529          * Note: PASD motherboards uses the Line In 2 as the input for
9530          * front panel mic (mic 2)
9531          */
9532         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9533         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9534         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9535         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9536         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9537         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9538
9539         /*
9540          * Set up output mixers (0x0c - 0x0e)
9541          */
9542         /* set vol=0 to output mixers */
9543         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9544         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9545         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9546         /* set up input amps for analog loopback */
9547         /* Amp Indices: DAC = 0, mixer = 1 */
9548         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9549         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9550         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9551         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9552         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9553         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9554
9555         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
9556         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9557         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
9558         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9559         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9560         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9561
9562         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9563         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9564         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9565         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9566         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9567
9568         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
9569         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
9570
9571         /* FIXME: use matrix-type input source selection */
9572         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
9573         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9574         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9575         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9576         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9577         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9578         /* Input mixer2 */
9579         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9580         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9581         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9582         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9583         /* Input mixer3 */
9584         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9585         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9586         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9587         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9588
9589         { }
9590 };
9591
9592 static struct hda_verb alc262_eapd_verbs[] = {
9593         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
9594         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
9595         { }
9596 };
9597
9598 static struct hda_verb alc262_hippo_unsol_verbs[] = {
9599         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9600         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9601         {}
9602 };
9603
9604 static struct hda_verb alc262_hippo1_unsol_verbs[] = {
9605         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9606         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9607         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9608
9609         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9610         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9611         {}
9612 };
9613
9614 static struct hda_verb alc262_sony_unsol_verbs[] = {
9615         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9616         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9617         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},   // Front Mic
9618
9619         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9620         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9621         {}
9622 };
9623
9624 static struct hda_input_mux alc262_dmic_capture_source = {
9625         .num_items = 2,
9626         .items = {
9627                 { "Int DMic", 0x9 },
9628                 { "Mic", 0x0 },
9629         },
9630 };
9631
9632 static struct snd_kcontrol_new alc262_toshiba_s06_mixer[] = {
9633         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9634         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9635         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9636         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9637         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9638         { } /* end */
9639 };
9640
9641 static struct hda_verb alc262_toshiba_s06_verbs[] = {
9642         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9643         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9644         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9645         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9646         {0x22, AC_VERB_SET_CONNECT_SEL, 0x09},
9647         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9648         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
9649         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9650         {}
9651 };
9652
9653 static void alc262_dmic_automute(struct hda_codec *codec)
9654 {
9655         unsigned int present;
9656
9657         present = snd_hda_codec_read(codec, 0x18, 0,
9658                                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
9659         snd_hda_codec_write(codec, 0x22, 0,
9660                                 AC_VERB_SET_CONNECT_SEL, present ? 0x0 : 0x09);
9661 }
9662
9663 /* toggle speaker-output according to the hp-jack state */
9664 static void alc262_toshiba_s06_speaker_automute(struct hda_codec *codec)
9665 {
9666         unsigned int present;
9667         unsigned char bits;
9668
9669         present = snd_hda_codec_read(codec, 0x15, 0,
9670                                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
9671         bits = present ? 0 : PIN_OUT;
9672         snd_hda_codec_write(codec, 0x14, 0,
9673                                         AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
9674 }
9675
9676
9677
9678 /* unsolicited event for HP jack sensing */
9679 static void alc262_toshiba_s06_unsol_event(struct hda_codec *codec,
9680                                        unsigned int res)
9681 {
9682         if ((res >> 26) == ALC880_HP_EVENT)
9683                 alc262_toshiba_s06_speaker_automute(codec);
9684         if ((res >> 26) == ALC880_MIC_EVENT)
9685                 alc262_dmic_automute(codec);
9686
9687 }
9688
9689 static void alc262_toshiba_s06_init_hook(struct hda_codec *codec)
9690 {
9691         alc262_toshiba_s06_speaker_automute(codec);
9692         alc262_dmic_automute(codec);
9693 }
9694
9695 /* mute/unmute internal speaker according to the hp jack and mute state */
9696 static void alc262_hippo_automute(struct hda_codec *codec)
9697 {
9698         struct alc_spec *spec = codec->spec;
9699         unsigned int mute;
9700         unsigned int present;
9701
9702         /* need to execute and sync at first */
9703         snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
9704         present = snd_hda_codec_read(codec, 0x15, 0,
9705                                      AC_VERB_GET_PIN_SENSE, 0);
9706         spec->jack_present = (present & 0x80000000) != 0;
9707         if (spec->jack_present) {
9708                 /* mute internal speaker */
9709                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9710                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9711         } else {
9712                 /* unmute internal speaker if necessary */
9713                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
9714                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9715                                          HDA_AMP_MUTE, mute);
9716         }
9717 }
9718
9719 /* unsolicited event for HP jack sensing */
9720 static void alc262_hippo_unsol_event(struct hda_codec *codec,
9721                                        unsigned int res)
9722 {
9723         if ((res >> 26) != ALC880_HP_EVENT)
9724                 return;
9725         alc262_hippo_automute(codec);
9726 }
9727
9728 static void alc262_hippo1_automute(struct hda_codec *codec)
9729 {
9730         unsigned int mute;
9731         unsigned int present;
9732
9733         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9734         present = snd_hda_codec_read(codec, 0x1b, 0,
9735                                      AC_VERB_GET_PIN_SENSE, 0);
9736         present = (present & 0x80000000) != 0;
9737         if (present) {
9738                 /* mute internal speaker */
9739                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9740                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9741         } else {
9742                 /* unmute internal speaker if necessary */
9743                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
9744                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9745                                          HDA_AMP_MUTE, mute);
9746         }
9747 }
9748
9749 /* unsolicited event for HP jack sensing */
9750 static void alc262_hippo1_unsol_event(struct hda_codec *codec,
9751                                        unsigned int res)
9752 {
9753         if ((res >> 26) != ALC880_HP_EVENT)
9754                 return;
9755         alc262_hippo1_automute(codec);
9756 }
9757
9758 /*
9759  * nec model
9760  *  0x15 = headphone
9761  *  0x16 = internal speaker
9762  *  0x18 = external mic
9763  */
9764
9765 static struct snd_kcontrol_new alc262_nec_mixer[] = {
9766         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
9767         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 0, 0x0, HDA_OUTPUT),
9768
9769         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9770         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9771         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9772
9773         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9774         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9775         { } /* end */
9776 };
9777
9778 static struct hda_verb alc262_nec_verbs[] = {
9779         /* Unmute Speaker */
9780         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9781
9782         /* Headphone */
9783         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9784         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9785
9786         /* External mic to headphone */
9787         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9788         /* External mic to speaker */
9789         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9790         {}
9791 };
9792
9793 /*
9794  * fujitsu model
9795  *  0x14 = headphone/spdif-out, 0x15 = internal speaker,
9796  *  0x1b = port replicator headphone out
9797  */
9798
9799 #define ALC_HP_EVENT    0x37
9800
9801 static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
9802         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9803         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9804         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9805         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9806         {}
9807 };
9808
9809 static struct hda_verb alc262_lenovo_3000_unsol_verbs[] = {
9810         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9811         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9812         {}
9813 };
9814
9815 static struct hda_input_mux alc262_fujitsu_capture_source = {
9816         .num_items = 3,
9817         .items = {
9818                 { "Mic", 0x0 },
9819                 { "Int Mic", 0x1 },
9820                 { "CD", 0x4 },
9821         },
9822 };
9823
9824 static struct hda_input_mux alc262_HP_capture_source = {
9825         .num_items = 5,
9826         .items = {
9827                 { "Mic", 0x0 },
9828                 { "Front Mic", 0x1 },
9829                 { "Line", 0x2 },
9830                 { "CD", 0x4 },
9831                 { "AUX IN", 0x6 },
9832         },
9833 };
9834
9835 static struct hda_input_mux alc262_HP_D7000_capture_source = {
9836         .num_items = 4,
9837         .items = {
9838                 { "Mic", 0x0 },
9839                 { "Front Mic", 0x2 },
9840                 { "Line", 0x1 },
9841                 { "CD", 0x4 },
9842         },
9843 };
9844
9845 /* mute/unmute internal speaker according to the hp jacks and mute state */
9846 static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
9847 {
9848         struct alc_spec *spec = codec->spec;
9849         unsigned int mute;
9850
9851         if (force || !spec->sense_updated) {
9852                 unsigned int present;
9853                 /* need to execute and sync at first */
9854                 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
9855                 /* check laptop HP jack */
9856                 present = snd_hda_codec_read(codec, 0x14, 0,
9857                                              AC_VERB_GET_PIN_SENSE, 0);
9858                 /* need to execute and sync at first */
9859                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9860                 /* check docking HP jack */
9861                 present |= snd_hda_codec_read(codec, 0x1b, 0,
9862                                               AC_VERB_GET_PIN_SENSE, 0);
9863                 if (present & AC_PINSENSE_PRESENCE)
9864                         spec->jack_present = 1;
9865                 else
9866                         spec->jack_present = 0;
9867                 spec->sense_updated = 1;
9868         }
9869         /* unmute internal speaker only if both HPs are unplugged and
9870          * master switch is on
9871          */
9872         if (spec->jack_present)
9873                 mute = HDA_AMP_MUTE;
9874         else
9875                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
9876         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
9877                                  HDA_AMP_MUTE, mute);
9878 }
9879
9880 /* unsolicited event for HP jack sensing */
9881 static void alc262_fujitsu_unsol_event(struct hda_codec *codec,
9882                                        unsigned int res)
9883 {
9884         if ((res >> 26) != ALC_HP_EVENT)
9885                 return;
9886         alc262_fujitsu_automute(codec, 1);
9887 }
9888
9889 static void alc262_fujitsu_init_hook(struct hda_codec *codec)
9890 {
9891         alc262_fujitsu_automute(codec, 1);
9892 }
9893
9894 /* bind volumes of both NID 0x0c and 0x0d */
9895 static struct hda_bind_ctls alc262_fujitsu_bind_master_vol = {
9896         .ops = &snd_hda_bind_vol,
9897         .values = {
9898                 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
9899                 HDA_COMPOSE_AMP_VAL(0x0d, 3, 0, HDA_OUTPUT),
9900                 0
9901         },
9902 };
9903
9904 /* mute/unmute internal speaker according to the hp jack and mute state */
9905 static void alc262_lenovo_3000_automute(struct hda_codec *codec, int force)
9906 {
9907         struct alc_spec *spec = codec->spec;
9908         unsigned int mute;
9909
9910         if (force || !spec->sense_updated) {
9911                 unsigned int present_int_hp;
9912                 /* need to execute and sync at first */
9913                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9914                 present_int_hp = snd_hda_codec_read(codec, 0x1b, 0,
9915                                         AC_VERB_GET_PIN_SENSE, 0);
9916                 spec->jack_present = (present_int_hp & 0x80000000) != 0;
9917                 spec->sense_updated = 1;
9918         }
9919         if (spec->jack_present) {
9920                 /* mute internal speaker */
9921                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9922                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9923                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
9924                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9925         } else {
9926                 /* unmute internal speaker if necessary */
9927                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
9928                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9929                                          HDA_AMP_MUTE, mute);
9930                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
9931                                          HDA_AMP_MUTE, mute);
9932         }
9933 }
9934
9935 /* unsolicited event for HP jack sensing */
9936 static void alc262_lenovo_3000_unsol_event(struct hda_codec *codec,
9937                                        unsigned int res)
9938 {
9939         if ((res >> 26) != ALC_HP_EVENT)
9940                 return;
9941         alc262_lenovo_3000_automute(codec, 1);
9942 }
9943
9944 /* bind hp and internal speaker mute (with plug check) */
9945 static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
9946                                          struct snd_ctl_elem_value *ucontrol)
9947 {
9948         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9949         long *valp = ucontrol->value.integer.value;
9950         int change;
9951
9952         change = snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9953                                                  HDA_AMP_MUTE,
9954                                                  valp ? 0 : HDA_AMP_MUTE);
9955         change |= snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
9956                                                  HDA_AMP_MUTE,
9957                                                  valp ? 0 : HDA_AMP_MUTE);
9958
9959         if (change)
9960                 alc262_fujitsu_automute(codec, 0);
9961         return change;
9962 }
9963
9964 static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
9965         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9966         {
9967                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9968                 .name = "Master Playback Switch",
9969                 .info = snd_hda_mixer_amp_switch_info,
9970                 .get = snd_hda_mixer_amp_switch_get,
9971                 .put = alc262_fujitsu_master_sw_put,
9972                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
9973         },
9974         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9975         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9976         HDA_CODEC_VOLUME("PC Speaker Volume", 0x0b, 0x05, HDA_INPUT),
9977         HDA_CODEC_MUTE("PC Speaker Switch", 0x0b, 0x05, HDA_INPUT),
9978         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9979         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9980         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9981         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
9982         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9983         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9984         { } /* end */
9985 };
9986
9987 /* bind hp and internal speaker mute (with plug check) */
9988 static int alc262_lenovo_3000_master_sw_put(struct snd_kcontrol *kcontrol,
9989                                          struct snd_ctl_elem_value *ucontrol)
9990 {
9991         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9992         long *valp = ucontrol->value.integer.value;
9993         int change;
9994
9995         change = snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
9996                                                  HDA_AMP_MUTE,
9997                                                  valp ? 0 : HDA_AMP_MUTE);
9998
9999         if (change)
10000                 alc262_lenovo_3000_automute(codec, 0);
10001         return change;
10002 }
10003
10004 static struct snd_kcontrol_new alc262_lenovo_3000_mixer[] = {
10005         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
10006         {
10007                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10008                 .name = "Master Playback Switch",
10009                 .info = snd_hda_mixer_amp_switch_info,
10010                 .get = snd_hda_mixer_amp_switch_get,
10011                 .put = alc262_lenovo_3000_master_sw_put,
10012                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
10013         },
10014         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10015         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10016         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10017         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10018         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10019         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
10020         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
10021         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
10022         { } /* end */
10023 };
10024
10025 static struct snd_kcontrol_new alc262_toshiba_rx1_mixer[] = {
10026         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
10027         {
10028                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10029                 .name = "Master Playback Switch",
10030                 .info = snd_hda_mixer_amp_switch_info,
10031                 .get = snd_hda_mixer_amp_switch_get,
10032                 .put = alc262_sony_master_sw_put,
10033                 .private_value = HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
10034         },
10035         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10036         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10037         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10038         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10039         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10040         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10041         { } /* end */
10042 };
10043
10044 /* additional init verbs for Benq laptops */
10045 static struct hda_verb alc262_EAPD_verbs[] = {
10046         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
10047         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
10048         {}
10049 };
10050
10051 static struct hda_verb alc262_benq_t31_EAPD_verbs[] = {
10052         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10053         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10054
10055         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
10056         {0x20, AC_VERB_SET_PROC_COEF,  0x3050},
10057         {}
10058 };
10059
10060 /* Samsung Q1 Ultra Vista model setup */
10061 static struct snd_kcontrol_new alc262_ultra_mixer[] = {
10062         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10063         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
10064         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10065         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10066         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
10067         HDA_CODEC_VOLUME("Headphone Mic Boost", 0x15, 0, HDA_INPUT),
10068         { } /* end */
10069 };
10070
10071 static struct hda_verb alc262_ultra_verbs[] = {
10072         /* output mixer */
10073         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10074         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10075         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10076         /* speaker */
10077         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10078         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10079         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10080         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
10081         /* HP */
10082         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10083         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10084         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10085         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10086         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10087         /* internal mic */
10088         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10089         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10090         /* ADC, choose mic */
10091         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10092         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10093         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10094         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10095         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10096         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10097         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10098         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10099         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
10100         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(8)},
10101         {}
10102 };
10103
10104 /* mute/unmute internal speaker according to the hp jack and mute state */
10105 static void alc262_ultra_automute(struct hda_codec *codec)
10106 {
10107         struct alc_spec *spec = codec->spec;
10108         unsigned int mute;
10109
10110         mute = 0;
10111         /* auto-mute only when HP is used as HP */
10112         if (!spec->cur_mux[0]) {
10113                 unsigned int present;
10114                 /* need to execute and sync at first */
10115                 snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
10116                 present = snd_hda_codec_read(codec, 0x15, 0,
10117                                              AC_VERB_GET_PIN_SENSE, 0);
10118                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
10119                 if (spec->jack_present)
10120                         mute = HDA_AMP_MUTE;
10121         }
10122         /* mute/unmute internal speaker */
10123         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10124                                  HDA_AMP_MUTE, mute);
10125         /* mute/unmute HP */
10126         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
10127                                  HDA_AMP_MUTE, mute ? 0 : HDA_AMP_MUTE);
10128 }
10129
10130 /* unsolicited event for HP jack sensing */
10131 static void alc262_ultra_unsol_event(struct hda_codec *codec,
10132                                        unsigned int res)
10133 {
10134         if ((res >> 26) != ALC880_HP_EVENT)
10135                 return;
10136         alc262_ultra_automute(codec);
10137 }
10138
10139 static struct hda_input_mux alc262_ultra_capture_source = {
10140         .num_items = 2,
10141         .items = {
10142                 { "Mic", 0x1 },
10143                 { "Headphone", 0x7 },
10144         },
10145 };
10146
10147 static int alc262_ultra_mux_enum_put(struct snd_kcontrol *kcontrol,
10148                                      struct snd_ctl_elem_value *ucontrol)
10149 {
10150         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10151         struct alc_spec *spec = codec->spec;
10152         int ret;
10153
10154         ret = alc_mux_enum_put(kcontrol, ucontrol);
10155         if (!ret)
10156                 return 0;
10157         /* reprogram the HP pin as mic or HP according to the input source */
10158         snd_hda_codec_write_cache(codec, 0x15, 0,
10159                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
10160                                   spec->cur_mux[0] ? PIN_VREF80 : PIN_HP);
10161         alc262_ultra_automute(codec); /* mute/unmute HP */
10162         return ret;
10163 }
10164
10165 static struct snd_kcontrol_new alc262_ultra_capture_mixer[] = {
10166         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
10167         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
10168         {
10169                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10170                 .name = "Capture Source",
10171                 .info = alc_mux_enum_info,
10172                 .get = alc_mux_enum_get,
10173                 .put = alc262_ultra_mux_enum_put,
10174         },
10175         { } /* end */
10176 };
10177
10178 /* add playback controls from the parsed DAC table */
10179 static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
10180                                              const struct auto_pin_cfg *cfg)
10181 {
10182         hda_nid_t nid;
10183         int err;
10184
10185         spec->multiout.num_dacs = 1;    /* only use one dac */
10186         spec->multiout.dac_nids = spec->private_dac_nids;
10187         spec->multiout.dac_nids[0] = 2;
10188
10189         nid = cfg->line_out_pins[0];
10190         if (nid) {
10191                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
10192                                   "Front Playback Volume",
10193                                   HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT));
10194                 if (err < 0)
10195                         return err;
10196                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10197                                   "Front Playback Switch",
10198                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
10199                 if (err < 0)
10200                         return err;
10201         }
10202
10203         nid = cfg->speaker_pins[0];
10204         if (nid) {
10205                 if (nid == 0x16) {
10206                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
10207                                           "Speaker Playback Volume",
10208                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
10209                                                               HDA_OUTPUT));
10210                         if (err < 0)
10211                                 return err;
10212                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10213                                           "Speaker Playback Switch",
10214                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
10215                                                               HDA_OUTPUT));
10216                         if (err < 0)
10217                                 return err;
10218                 } else {
10219                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10220                                           "Speaker Playback Switch",
10221                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
10222                                                               HDA_OUTPUT));
10223                         if (err < 0)
10224                                 return err;
10225                 }
10226         }
10227         nid = cfg->hp_pins[0];
10228         if (nid) {
10229                 /* spec->multiout.hp_nid = 2; */
10230                 if (nid == 0x16) {
10231                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
10232                                           "Headphone Playback Volume",
10233                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
10234                                                               HDA_OUTPUT));
10235                         if (err < 0)
10236                                 return err;
10237                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10238                                           "Headphone Playback Switch",
10239                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
10240                                                               HDA_OUTPUT));
10241                         if (err < 0)
10242                                 return err;
10243                 } else {
10244                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10245                                           "Headphone Playback Switch",
10246                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
10247                                                               HDA_OUTPUT));
10248                         if (err < 0)
10249                                 return err;
10250                 }
10251         }
10252         return 0;
10253 }
10254
10255 /* identical with ALC880 */
10256 #define alc262_auto_create_analog_input_ctls \
10257         alc880_auto_create_analog_input_ctls
10258
10259 /*
10260  * generic initialization of ADC, input mixers and output mixers
10261  */
10262 static struct hda_verb alc262_volume_init_verbs[] = {
10263         /*
10264          * Unmute ADC0-2 and set the default input to mic-in
10265          */
10266         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10267         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10268         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10269         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10270         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10271         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10272
10273         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10274          * mixer widget
10275          * Note: PASD motherboards uses the Line In 2 as the input for
10276          * front panel mic (mic 2)
10277          */
10278         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10279         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10280         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10281         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10282         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10283         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10284
10285         /*
10286          * Set up output mixers (0x0c - 0x0f)
10287          */
10288         /* set vol=0 to output mixers */
10289         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10290         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10291         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10292
10293         /* set up input amps for analog loopback */
10294         /* Amp Indices: DAC = 0, mixer = 1 */
10295         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10296         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10297         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10298         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10299         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10300         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10301
10302         /* FIXME: use matrix-type input source selection */
10303         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10304         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10305         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10306         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10307         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10308         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10309         /* Input mixer2 */
10310         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10311         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10312         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10313         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10314         /* Input mixer3 */
10315         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10316         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10317         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10318         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10319
10320         { }
10321 };
10322
10323 static struct hda_verb alc262_HP_BPC_init_verbs[] = {
10324         /*
10325          * Unmute ADC0-2 and set the default input to mic-in
10326          */
10327         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10328         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10329         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10330         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10331         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10332         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10333
10334         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10335          * mixer widget
10336          * Note: PASD motherboards uses the Line In 2 as the input for
10337          * front panel mic (mic 2)
10338          */
10339         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10340         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10341         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10342         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10343         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10344         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10345         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10346         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10347
10348         /*
10349          * Set up output mixers (0x0c - 0x0e)
10350          */
10351         /* set vol=0 to output mixers */
10352         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10353         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10354         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10355
10356         /* set up input amps for analog loopback */
10357         /* Amp Indices: DAC = 0, mixer = 1 */
10358         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10359         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10360         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10361         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10362         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10363         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10364
10365         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10366         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10367         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10368
10369         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10370         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10371
10372         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10373         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10374
10375         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10376         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10377         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10378         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10379         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10380
10381         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
10382         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10383         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10384         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
10385         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10386         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10387
10388
10389         /* FIXME: use matrix-type input source selection */
10390         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10391         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10392         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10393         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10394         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10395         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10396         /* Input mixer2 */
10397         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10398         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10399         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10400         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10401         /* Input mixer3 */
10402         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10403         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10404         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10405         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10406
10407         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10408
10409         { }
10410 };
10411
10412 static struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
10413         /*
10414          * Unmute ADC0-2 and set the default input to mic-in
10415          */
10416         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10417         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10418         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10419         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10420         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10421         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10422
10423         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10424          * mixer widget
10425          * Note: PASD motherboards uses the Line In 2 as the input for front
10426          * panel mic (mic 2)
10427          */
10428         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10429         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10430         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10431         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10432         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10433         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10434         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10435         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10436         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
10437         /*
10438          * Set up output mixers (0x0c - 0x0e)
10439          */
10440         /* set vol=0 to output mixers */
10441         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10442         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10443         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10444
10445         /* set up input amps for analog loopback */
10446         /* Amp Indices: DAC = 0, mixer = 1 */
10447         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10448         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10449         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10450         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10451         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10452         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10453
10454
10455         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP */
10456         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Mono */
10457         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* rear MIC */
10458         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* Line in */
10459         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
10460         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Line out */
10461         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* CD in */
10462
10463         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10464         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10465
10466         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10467         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
10468
10469         /* {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 }, */
10470         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10471         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10472         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
10473         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10474         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10475
10476         /* FIXME: use matrix-type input source selection */
10477         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10478         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10479         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, /*rear MIC*/
10480         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, /*Line in*/
10481         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))}, /*F MIC*/
10482         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))}, /*Front*/
10483         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))}, /*CD*/
10484         /* {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))},  */
10485         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))}, /*HP*/
10486         /* Input mixer2 */
10487         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10488         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10489         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10490         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10491         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10492         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
10493         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
10494         /* Input mixer3 */
10495         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10496         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10497         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10498         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10499         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10500         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
10501         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
10502
10503         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10504
10505         { }
10506 };
10507
10508 static struct hda_verb alc262_toshiba_rx1_unsol_verbs[] = {
10509
10510         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Front Speaker */
10511         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10512         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
10513
10514         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* MIC jack */
10515         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
10516         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
10517         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
10518
10519         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP  jack */
10520         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10521         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10522         {}
10523 };
10524
10525
10526 #ifdef CONFIG_SND_HDA_POWER_SAVE
10527 #define alc262_loopbacks        alc880_loopbacks
10528 #endif
10529
10530 /* pcm configuration: identiacal with ALC880 */
10531 #define alc262_pcm_analog_playback      alc880_pcm_analog_playback
10532 #define alc262_pcm_analog_capture       alc880_pcm_analog_capture
10533 #define alc262_pcm_digital_playback     alc880_pcm_digital_playback
10534 #define alc262_pcm_digital_capture      alc880_pcm_digital_capture
10535
10536 /*
10537  * BIOS auto configuration
10538  */
10539 static int alc262_parse_auto_config(struct hda_codec *codec)
10540 {
10541         struct alc_spec *spec = codec->spec;
10542         int err;
10543         static hda_nid_t alc262_ignore[] = { 0x1d, 0 };
10544
10545         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
10546                                            alc262_ignore);
10547         if (err < 0)
10548                 return err;
10549         if (!spec->autocfg.line_outs) {
10550                 if (spec->autocfg.dig_out_pin || spec->autocfg.dig_in_pin) {
10551                         spec->multiout.max_channels = 2;
10552                         spec->no_analog = 1;
10553                         goto dig_only;
10554                 }
10555                 return 0; /* can't find valid BIOS pin config */
10556         }
10557         err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
10558         if (err < 0)
10559                 return err;
10560         err = alc262_auto_create_analog_input_ctls(spec, &spec->autocfg);
10561         if (err < 0)
10562                 return err;
10563
10564         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
10565
10566  dig_only:
10567         if (spec->autocfg.dig_out_pin) {
10568                 spec->multiout.dig_out_nid = ALC262_DIGOUT_NID;
10569                 spec->dig_out_type = spec->autocfg.dig_out_type;
10570         }
10571         if (spec->autocfg.dig_in_pin)
10572                 spec->dig_in_nid = ALC262_DIGIN_NID;
10573
10574         if (spec->kctls.list)
10575                 add_mixer(spec, spec->kctls.list);
10576
10577         add_verb(spec, alc262_volume_init_verbs);
10578         spec->num_mux_defs = 1;
10579         spec->input_mux = &spec->private_imux[0];
10580
10581         err = alc_auto_add_mic_boost(codec);
10582         if (err < 0)
10583                 return err;
10584
10585         store_pin_configs(codec);
10586         return 1;
10587 }
10588
10589 #define alc262_auto_init_multi_out      alc882_auto_init_multi_out
10590 #define alc262_auto_init_hp_out         alc882_auto_init_hp_out
10591 #define alc262_auto_init_analog_input   alc882_auto_init_analog_input
10592 #define alc262_auto_init_input_src      alc882_auto_init_input_src
10593
10594
10595 /* init callback for auto-configuration model -- overriding the default init */
10596 static void alc262_auto_init(struct hda_codec *codec)
10597 {
10598         struct alc_spec *spec = codec->spec;
10599         alc262_auto_init_multi_out(codec);
10600         alc262_auto_init_hp_out(codec);
10601         alc262_auto_init_analog_input(codec);
10602         alc262_auto_init_input_src(codec);
10603         if (spec->unsol_event)
10604                 alc_inithook(codec);
10605 }
10606
10607 /*
10608  * configuration and preset
10609  */
10610 static const char *alc262_models[ALC262_MODEL_LAST] = {
10611         [ALC262_BASIC]          = "basic",
10612         [ALC262_HIPPO]          = "hippo",
10613         [ALC262_HIPPO_1]        = "hippo_1",
10614         [ALC262_FUJITSU]        = "fujitsu",
10615         [ALC262_HP_BPC]         = "hp-bpc",
10616         [ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000",
10617         [ALC262_HP_TC_T5735]    = "hp-tc-t5735",
10618         [ALC262_HP_RP5700]      = "hp-rp5700",
10619         [ALC262_BENQ_ED8]       = "benq",
10620         [ALC262_BENQ_T31]       = "benq-t31",
10621         [ALC262_SONY_ASSAMD]    = "sony-assamd",
10622         [ALC262_TOSHIBA_S06]    = "toshiba-s06",
10623         [ALC262_TOSHIBA_RX1]    = "toshiba-rx1",
10624         [ALC262_ULTRA]          = "ultra",
10625         [ALC262_LENOVO_3000]    = "lenovo-3000",
10626         [ALC262_NEC]            = "nec",
10627         [ALC262_AUTO]           = "auto",
10628 };
10629
10630 static struct snd_pci_quirk alc262_cfg_tbl[] = {
10631         SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
10632         SND_PCI_QUIRK(0x1033, 0x8895, "NEC Versa S9100", ALC262_NEC),
10633         SND_PCI_QUIRK(0x103c, 0x12fe, "HP xw9400", ALC262_HP_BPC),
10634         SND_PCI_QUIRK(0x103c, 0x12ff, "HP xw4550", ALC262_HP_BPC),
10635         SND_PCI_QUIRK(0x103c, 0x1306, "HP xw8600", ALC262_HP_BPC),
10636         SND_PCI_QUIRK(0x103c, 0x1307, "HP xw6600", ALC262_HP_BPC),
10637         SND_PCI_QUIRK(0x103c, 0x1308, "HP xw4600", ALC262_HP_BPC),
10638         SND_PCI_QUIRK(0x103c, 0x1309, "HP xw4*00", ALC262_HP_BPC),
10639         SND_PCI_QUIRK(0x103c, 0x130a, "HP xw6*00", ALC262_HP_BPC),
10640         SND_PCI_QUIRK(0x103c, 0x130b, "HP xw8*00", ALC262_HP_BPC),
10641         SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
10642         SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
10643         SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
10644         SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF),
10645         SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL),
10646         SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF),
10647         SND_PCI_QUIRK(0x103c, 0x2806, "HP D7000", ALC262_HP_BPC_D7000_WL),
10648         SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF),
10649         SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC),
10650         SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC),
10651         SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC),
10652         SND_PCI_QUIRK(0x103c, 0x302f, "HP Thin Client T5735",
10653                       ALC262_HP_TC_T5735),
10654         SND_PCI_QUIRK(0x103c, 0x2817, "HP RP5700", ALC262_HP_RP5700),
10655         SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10656         SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
10657         SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10658         SND_PCI_QUIRK(0x104d, 0x900e, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10659         SND_PCI_QUIRK(0x104d, 0x9015, "Sony 0x9015", ALC262_SONY_ASSAMD),
10660         SND_PCI_QUIRK(0x104d, 0x9033, "Sony VAIO VGN-SR19XN",
10661                       ALC262_SONY_ASSAMD),
10662         SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
10663                       ALC262_TOSHIBA_RX1),
10664         SND_PCI_QUIRK(0x1179, 0xff7b, "Toshiba S06", ALC262_TOSHIBA_S06),
10665         SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
10666         SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU),
10667         SND_PCI_QUIRK(0x144d, 0xc032, "Samsung Q1 Ultra", ALC262_ULTRA),
10668         SND_PCI_QUIRK(0x144d, 0xc039, "Samsung Q1U EL", ALC262_ULTRA),
10669         SND_PCI_QUIRK(0x144d, 0xc510, "Samsung Q45", ALC262_HIPPO),
10670         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 y410", ALC262_LENOVO_3000),
10671         SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
10672         SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
10673         SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
10674         {}
10675 };
10676
10677 static struct alc_config_preset alc262_presets[] = {
10678         [ALC262_BASIC] = {
10679                 .mixers = { alc262_base_mixer },
10680                 .init_verbs = { alc262_init_verbs },
10681                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10682                 .dac_nids = alc262_dac_nids,
10683                 .hp_nid = 0x03,
10684                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10685                 .channel_mode = alc262_modes,
10686                 .input_mux = &alc262_capture_source,
10687         },
10688         [ALC262_HIPPO] = {
10689                 .mixers = { alc262_base_mixer },
10690                 .init_verbs = { alc262_init_verbs, alc262_hippo_unsol_verbs},
10691                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10692                 .dac_nids = alc262_dac_nids,
10693                 .hp_nid = 0x03,
10694                 .dig_out_nid = ALC262_DIGOUT_NID,
10695                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10696                 .channel_mode = alc262_modes,
10697                 .input_mux = &alc262_capture_source,
10698                 .unsol_event = alc262_hippo_unsol_event,
10699                 .init_hook = alc262_hippo_automute,
10700         },
10701         [ALC262_HIPPO_1] = {
10702                 .mixers = { alc262_hippo1_mixer },
10703                 .init_verbs = { alc262_init_verbs, alc262_hippo1_unsol_verbs},
10704                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10705                 .dac_nids = alc262_dac_nids,
10706                 .hp_nid = 0x02,
10707                 .dig_out_nid = ALC262_DIGOUT_NID,
10708                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10709                 .channel_mode = alc262_modes,
10710                 .input_mux = &alc262_capture_source,
10711                 .unsol_event = alc262_hippo1_unsol_event,
10712                 .init_hook = alc262_hippo1_automute,
10713         },
10714         [ALC262_FUJITSU] = {
10715                 .mixers = { alc262_fujitsu_mixer },
10716                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
10717                                 alc262_fujitsu_unsol_verbs },
10718                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10719                 .dac_nids = alc262_dac_nids,
10720                 .hp_nid = 0x03,
10721                 .dig_out_nid = ALC262_DIGOUT_NID,
10722                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10723                 .channel_mode = alc262_modes,
10724                 .input_mux = &alc262_fujitsu_capture_source,
10725                 .unsol_event = alc262_fujitsu_unsol_event,
10726                 .init_hook = alc262_fujitsu_init_hook,
10727         },
10728         [ALC262_HP_BPC] = {
10729                 .mixers = { alc262_HP_BPC_mixer },
10730                 .init_verbs = { alc262_HP_BPC_init_verbs },
10731                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10732                 .dac_nids = alc262_dac_nids,
10733                 .hp_nid = 0x03,
10734                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10735                 .channel_mode = alc262_modes,
10736                 .input_mux = &alc262_HP_capture_source,
10737                 .unsol_event = alc262_hp_bpc_unsol_event,
10738                 .init_hook = alc262_hp_bpc_automute,
10739         },
10740         [ALC262_HP_BPC_D7000_WF] = {
10741                 .mixers = { alc262_HP_BPC_WildWest_mixer },
10742                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
10743                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10744                 .dac_nids = alc262_dac_nids,
10745                 .hp_nid = 0x03,
10746                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10747                 .channel_mode = alc262_modes,
10748                 .input_mux = &alc262_HP_D7000_capture_source,
10749                 .unsol_event = alc262_hp_wildwest_unsol_event,
10750                 .init_hook = alc262_hp_wildwest_automute,
10751         },
10752         [ALC262_HP_BPC_D7000_WL] = {
10753                 .mixers = { alc262_HP_BPC_WildWest_mixer,
10754                             alc262_HP_BPC_WildWest_option_mixer },
10755                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
10756                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10757                 .dac_nids = alc262_dac_nids,
10758                 .hp_nid = 0x03,
10759                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10760                 .channel_mode = alc262_modes,
10761                 .input_mux = &alc262_HP_D7000_capture_source,
10762                 .unsol_event = alc262_hp_wildwest_unsol_event,
10763                 .init_hook = alc262_hp_wildwest_automute,
10764         },
10765         [ALC262_HP_TC_T5735] = {
10766                 .mixers = { alc262_hp_t5735_mixer },
10767                 .init_verbs = { alc262_init_verbs, alc262_hp_t5735_verbs },
10768                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10769                 .dac_nids = alc262_dac_nids,
10770                 .hp_nid = 0x03,
10771                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10772                 .channel_mode = alc262_modes,
10773                 .input_mux = &alc262_capture_source,
10774                 .unsol_event = alc262_hp_t5735_unsol_event,
10775                 .init_hook = alc262_hp_t5735_init_hook,
10776         },
10777         [ALC262_HP_RP5700] = {
10778                 .mixers = { alc262_hp_rp5700_mixer },
10779                 .init_verbs = { alc262_init_verbs, alc262_hp_rp5700_verbs },
10780                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10781                 .dac_nids = alc262_dac_nids,
10782                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10783                 .channel_mode = alc262_modes,
10784                 .input_mux = &alc262_hp_rp5700_capture_source,
10785         },
10786         [ALC262_BENQ_ED8] = {
10787                 .mixers = { alc262_base_mixer },
10788                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs },
10789                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10790                 .dac_nids = alc262_dac_nids,
10791                 .hp_nid = 0x03,
10792                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10793                 .channel_mode = alc262_modes,
10794                 .input_mux = &alc262_capture_source,
10795         },
10796         [ALC262_SONY_ASSAMD] = {
10797                 .mixers = { alc262_sony_mixer },
10798                 .init_verbs = { alc262_init_verbs, alc262_sony_unsol_verbs},
10799                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10800                 .dac_nids = alc262_dac_nids,
10801                 .hp_nid = 0x02,
10802                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10803                 .channel_mode = alc262_modes,
10804                 .input_mux = &alc262_capture_source,
10805                 .unsol_event = alc262_hippo_unsol_event,
10806                 .init_hook = alc262_hippo_automute,
10807         },
10808         [ALC262_BENQ_T31] = {
10809                 .mixers = { alc262_benq_t31_mixer },
10810                 .init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs, alc262_hippo_unsol_verbs },
10811                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10812                 .dac_nids = alc262_dac_nids,
10813                 .hp_nid = 0x03,
10814                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10815                 .channel_mode = alc262_modes,
10816                 .input_mux = &alc262_capture_source,
10817                 .unsol_event = alc262_hippo_unsol_event,
10818                 .init_hook = alc262_hippo_automute,
10819         },
10820         [ALC262_ULTRA] = {
10821                 .mixers = { alc262_ultra_mixer },
10822                 .cap_mixer = alc262_ultra_capture_mixer,
10823                 .init_verbs = { alc262_ultra_verbs },
10824                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10825                 .dac_nids = alc262_dac_nids,
10826                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10827                 .channel_mode = alc262_modes,
10828                 .input_mux = &alc262_ultra_capture_source,
10829                 .adc_nids = alc262_adc_nids, /* ADC0 */
10830                 .capsrc_nids = alc262_capsrc_nids,
10831                 .num_adc_nids = 1, /* single ADC */
10832                 .unsol_event = alc262_ultra_unsol_event,
10833                 .init_hook = alc262_ultra_automute,
10834         },
10835         [ALC262_LENOVO_3000] = {
10836                 .mixers = { alc262_lenovo_3000_mixer },
10837                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
10838                                 alc262_lenovo_3000_unsol_verbs },
10839                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10840                 .dac_nids = alc262_dac_nids,
10841                 .hp_nid = 0x03,
10842                 .dig_out_nid = ALC262_DIGOUT_NID,
10843                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10844                 .channel_mode = alc262_modes,
10845                 .input_mux = &alc262_fujitsu_capture_source,
10846                 .unsol_event = alc262_lenovo_3000_unsol_event,
10847         },
10848         [ALC262_NEC] = {
10849                 .mixers = { alc262_nec_mixer },
10850                 .init_verbs = { alc262_nec_verbs },
10851                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10852                 .dac_nids = alc262_dac_nids,
10853                 .hp_nid = 0x03,
10854                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10855                 .channel_mode = alc262_modes,
10856                 .input_mux = &alc262_capture_source,
10857         },
10858         [ALC262_TOSHIBA_S06] = {
10859                 .mixers = { alc262_toshiba_s06_mixer },
10860                 .init_verbs = { alc262_init_verbs, alc262_toshiba_s06_verbs,
10861                                                         alc262_eapd_verbs },
10862                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10863                 .capsrc_nids = alc262_dmic_capsrc_nids,
10864                 .dac_nids = alc262_dac_nids,
10865                 .adc_nids = alc262_dmic_adc_nids, /* ADC0 */
10866                 .dig_out_nid = ALC262_DIGOUT_NID,
10867                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10868                 .channel_mode = alc262_modes,
10869                 .input_mux = &alc262_dmic_capture_source,
10870                 .unsol_event = alc262_toshiba_s06_unsol_event,
10871                 .init_hook = alc262_toshiba_s06_init_hook,
10872         },
10873         [ALC262_TOSHIBA_RX1] = {
10874                 .mixers = { alc262_toshiba_rx1_mixer },
10875                 .init_verbs = { alc262_init_verbs, alc262_toshiba_rx1_unsol_verbs },
10876                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10877                 .dac_nids = alc262_dac_nids,
10878                 .hp_nid = 0x03,
10879                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10880                 .channel_mode = alc262_modes,
10881                 .input_mux = &alc262_capture_source,
10882                 .unsol_event = alc262_hippo_unsol_event,
10883                 .init_hook = alc262_hippo_automute,
10884         },
10885 };
10886
10887 static int patch_alc262(struct hda_codec *codec)
10888 {
10889         struct alc_spec *spec;
10890         int board_config;
10891         int err;
10892
10893         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
10894         if (spec == NULL)
10895                 return -ENOMEM;
10896
10897         codec->spec = spec;
10898 #if 0
10899         /* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is
10900          * under-run
10901          */
10902         {
10903         int tmp;
10904         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
10905         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
10906         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
10907         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
10908         }
10909 #endif
10910
10911         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
10912
10913         board_config = snd_hda_check_board_config(codec, ALC262_MODEL_LAST,
10914                                                   alc262_models,
10915                                                   alc262_cfg_tbl);
10916
10917         if (board_config < 0) {
10918                 printk(KERN_INFO "hda_codec: Unknown model for ALC262, "
10919                        "trying auto-probe from BIOS...\n");
10920                 board_config = ALC262_AUTO;
10921         }
10922
10923         if (board_config == ALC262_AUTO) {
10924                 /* automatic parse from the BIOS config */
10925                 err = alc262_parse_auto_config(codec);
10926                 if (err < 0) {
10927                         alc_free(codec);
10928                         return err;
10929                 } else if (!err) {
10930                         printk(KERN_INFO
10931                                "hda_codec: Cannot set up configuration "
10932                                "from BIOS.  Using base mode...\n");
10933                         board_config = ALC262_BASIC;
10934                 }
10935         }
10936
10937         if (board_config != ALC262_AUTO)
10938                 setup_preset(spec, &alc262_presets[board_config]);
10939
10940         spec->stream_name_analog = "ALC262 Analog";
10941         spec->stream_analog_playback = &alc262_pcm_analog_playback;
10942         spec->stream_analog_capture = &alc262_pcm_analog_capture;
10943
10944         spec->stream_name_digital = "ALC262 Digital";
10945         spec->stream_digital_playback = &alc262_pcm_digital_playback;
10946         spec->stream_digital_capture = &alc262_pcm_digital_capture;
10947
10948         spec->capture_style = CAPT_MIX;
10949         if (!spec->adc_nids && spec->input_mux) {
10950                 /* check whether NID 0x07 is valid */
10951                 unsigned int wcap = get_wcaps(codec, 0x07);
10952
10953                 /* get type */
10954                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
10955                 if (wcap != AC_WID_AUD_IN) {
10956                         spec->adc_nids = alc262_adc_nids_alt;
10957                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids_alt);
10958                         spec->capsrc_nids = alc262_capsrc_nids_alt;
10959                 } else {
10960                         spec->adc_nids = alc262_adc_nids;
10961                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids);
10962                         spec->capsrc_nids = alc262_capsrc_nids;
10963                 }
10964         }
10965         if (!spec->cap_mixer && !spec->no_analog)
10966                 set_capture_mixer(spec);
10967
10968         spec->vmaster_nid = 0x0c;
10969
10970         codec->patch_ops = alc_patch_ops;
10971         if (board_config == ALC262_AUTO)
10972                 spec->init_hook = alc262_auto_init;
10973 #ifdef CONFIG_SND_HDA_POWER_SAVE
10974         if (!spec->loopback.amplist)
10975                 spec->loopback.amplist = alc262_loopbacks;
10976 #endif
10977         codec->proc_widget_hook = print_realtek_coef;
10978
10979         return 0;
10980 }
10981
10982 /*
10983  *  ALC268 channel source setting (2 channel)
10984  */
10985 #define ALC268_DIGOUT_NID       ALC880_DIGOUT_NID
10986 #define alc268_modes            alc260_modes
10987
10988 static hda_nid_t alc268_dac_nids[2] = {
10989         /* front, hp */
10990         0x02, 0x03
10991 };
10992
10993 static hda_nid_t alc268_adc_nids[2] = {
10994         /* ADC0-1 */
10995         0x08, 0x07
10996 };
10997
10998 static hda_nid_t alc268_adc_nids_alt[1] = {
10999         /* ADC0 */
11000         0x08
11001 };
11002
11003 static hda_nid_t alc268_capsrc_nids[2] = { 0x23, 0x24 };
11004
11005 static struct snd_kcontrol_new alc268_base_mixer[] = {
11006         /* output mixer control */
11007         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
11008         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11009         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
11010         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11011         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11012         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
11013         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11014         { }
11015 };
11016
11017 /* bind Beep switches of both NID 0x0f and 0x10 */
11018 static struct hda_bind_ctls alc268_bind_beep_sw = {
11019         .ops = &snd_hda_bind_sw,
11020         .values = {
11021                 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
11022                 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
11023                 0
11024         },
11025 };
11026
11027 static struct snd_kcontrol_new alc268_beep_mixer[] = {
11028         HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
11029         HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
11030         { }
11031 };
11032
11033 static struct hda_verb alc268_eapd_verbs[] = {
11034         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
11035         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
11036         { }
11037 };
11038
11039 /* Toshiba specific */
11040 #define alc268_toshiba_automute alc262_hippo_automute
11041
11042 static struct hda_verb alc268_toshiba_verbs[] = {
11043         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11044         { } /* end */
11045 };
11046
11047 static struct hda_input_mux alc268_acer_lc_capture_source = {
11048         .num_items = 2,
11049         .items = {
11050                 { "i-Mic", 0x6 },
11051                 { "E-Mic", 0x0 },
11052         },
11053 };
11054
11055 /* Acer specific */
11056 /* bind volumes of both NID 0x02 and 0x03 */
11057 static struct hda_bind_ctls alc268_acer_bind_master_vol = {
11058         .ops = &snd_hda_bind_vol,
11059         .values = {
11060                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
11061                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
11062                 0
11063         },
11064 };
11065
11066 /* mute/unmute internal speaker according to the hp jack and mute state */
11067 static void alc268_acer_automute(struct hda_codec *codec, int force)
11068 {
11069         struct alc_spec *spec = codec->spec;
11070         unsigned int mute;
11071
11072         if (force || !spec->sense_updated) {
11073                 unsigned int present;
11074                 present = snd_hda_codec_read(codec, 0x14, 0,
11075                                          AC_VERB_GET_PIN_SENSE, 0);
11076                 spec->jack_present = (present & 0x80000000) != 0;
11077                 spec->sense_updated = 1;
11078         }
11079         if (spec->jack_present)
11080                 mute = HDA_AMP_MUTE; /* mute internal speaker */
11081         else /* unmute internal speaker if necessary */
11082                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
11083         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
11084                                  HDA_AMP_MUTE, mute);
11085 }
11086
11087
11088 /* bind hp and internal speaker mute (with plug check) */
11089 static int alc268_acer_master_sw_put(struct snd_kcontrol *kcontrol,
11090                                      struct snd_ctl_elem_value *ucontrol)
11091 {
11092         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
11093         long *valp = ucontrol->value.integer.value;
11094         int change;
11095
11096         change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
11097                                           HDA_AMP_MUTE,
11098                                           valp[0] ? 0 : HDA_AMP_MUTE);
11099         change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
11100                                            HDA_AMP_MUTE,
11101                                            valp[1] ? 0 : HDA_AMP_MUTE);
11102         if (change)
11103                 alc268_acer_automute(codec, 0);
11104         return change;
11105 }
11106
11107 static struct snd_kcontrol_new alc268_acer_aspire_one_mixer[] = {
11108         /* output mixer control */
11109         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11110         {
11111                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11112                 .name = "Master Playback Switch",
11113                 .info = snd_hda_mixer_amp_switch_info,
11114                 .get = snd_hda_mixer_amp_switch_get,
11115                 .put = alc268_acer_master_sw_put,
11116                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11117         },
11118         HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x18, 0, HDA_INPUT),
11119         { }
11120 };
11121
11122 static struct snd_kcontrol_new alc268_acer_mixer[] = {
11123         /* output mixer control */
11124         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11125         {
11126                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11127                 .name = "Master Playback Switch",
11128                 .info = snd_hda_mixer_amp_switch_info,
11129                 .get = snd_hda_mixer_amp_switch_get,
11130                 .put = alc268_acer_master_sw_put,
11131                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11132         },
11133         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11134         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
11135         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11136         { }
11137 };
11138
11139 static struct snd_kcontrol_new alc268_acer_dmic_mixer[] = {
11140         /* output mixer control */
11141         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11142         {
11143                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11144                 .name = "Master Playback Switch",
11145                 .info = snd_hda_mixer_amp_switch_info,
11146                 .get = snd_hda_mixer_amp_switch_get,
11147                 .put = alc268_acer_master_sw_put,
11148                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11149         },
11150         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11151         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11152         { }
11153 };
11154
11155 static struct hda_verb alc268_acer_aspire_one_verbs[] = {
11156         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11157         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11158         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11159         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
11160         {0x23, AC_VERB_SET_CONNECT_SEL, 0x06},
11161         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, 0xa017},
11162         { }
11163 };
11164
11165 static struct hda_verb alc268_acer_verbs[] = {
11166         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* internal dmic? */
11167         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11168         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11169         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11170         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11171         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11172         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11173         { }
11174 };
11175
11176 /* unsolicited event for HP jack sensing */
11177 static void alc268_toshiba_unsol_event(struct hda_codec *codec,
11178                                        unsigned int res)
11179 {
11180         if ((res >> 26) != ALC880_HP_EVENT)
11181                 return;
11182         alc268_toshiba_automute(codec);
11183 }
11184
11185 static void alc268_acer_unsol_event(struct hda_codec *codec,
11186                                        unsigned int res)
11187 {
11188         if ((res >> 26) != ALC880_HP_EVENT)
11189                 return;
11190         alc268_acer_automute(codec, 1);
11191 }
11192
11193 static void alc268_acer_init_hook(struct hda_codec *codec)
11194 {
11195         alc268_acer_automute(codec, 1);
11196 }
11197
11198 /* toggle speaker-output according to the hp-jack state */
11199 static void alc268_aspire_one_speaker_automute(struct hda_codec *codec)
11200 {
11201         unsigned int present;
11202         unsigned char bits;
11203
11204         present = snd_hda_codec_read(codec, 0x15, 0,
11205                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11206         bits = present ? AMP_IN_MUTE(0) : 0;
11207         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 0,
11208                                 AMP_IN_MUTE(0), bits);
11209         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 1,
11210                                 AMP_IN_MUTE(0), bits);
11211 }
11212
11213
11214 static void alc268_acer_mic_automute(struct hda_codec *codec)
11215 {
11216         unsigned int present;
11217
11218         present = snd_hda_codec_read(codec, 0x18, 0,
11219                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11220         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_CONNECT_SEL,
11221                             present ? 0x0 : 0x6);
11222 }
11223
11224 static void alc268_acer_lc_unsol_event(struct hda_codec *codec,
11225                                     unsigned int res)
11226 {
11227         if ((res >> 26) == ALC880_HP_EVENT)
11228                 alc268_aspire_one_speaker_automute(codec);
11229         if ((res >> 26) == ALC880_MIC_EVENT)
11230                 alc268_acer_mic_automute(codec);
11231 }
11232
11233 static void alc268_acer_lc_init_hook(struct hda_codec *codec)
11234 {
11235         alc268_aspire_one_speaker_automute(codec);
11236         alc268_acer_mic_automute(codec);
11237 }
11238
11239 static struct snd_kcontrol_new alc268_dell_mixer[] = {
11240         /* output mixer control */
11241         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11242         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11243         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
11244         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11245         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11246         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
11247         { }
11248 };
11249
11250 static struct hda_verb alc268_dell_verbs[] = {
11251         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11252         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11253         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11254         { }
11255 };
11256
11257 /* mute/unmute internal speaker according to the hp jack and mute state */
11258 static void alc268_dell_automute(struct hda_codec *codec)
11259 {
11260         unsigned int present;
11261         unsigned int mute;
11262
11263         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0);
11264         if (present & 0x80000000)
11265                 mute = HDA_AMP_MUTE;
11266         else
11267                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
11268         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
11269                                  HDA_AMP_MUTE, mute);
11270 }
11271
11272 static void alc268_dell_unsol_event(struct hda_codec *codec,
11273                                     unsigned int res)
11274 {
11275         if ((res >> 26) != ALC880_HP_EVENT)
11276                 return;
11277         alc268_dell_automute(codec);
11278 }
11279
11280 #define alc268_dell_init_hook   alc268_dell_automute
11281
11282 static struct snd_kcontrol_new alc267_quanta_il1_mixer[] = {
11283         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x2, 0x0, HDA_OUTPUT),
11284         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11285         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
11286         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11287         HDA_CODEC_VOLUME("Mic Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11288         HDA_BIND_MUTE("Mic Capture Switch", 0x23, 2, HDA_OUTPUT),
11289         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
11290         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
11291         { }
11292 };
11293
11294 static struct hda_verb alc267_quanta_il1_verbs[] = {
11295         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11296         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
11297         { }
11298 };
11299
11300 static void alc267_quanta_il1_hp_automute(struct hda_codec *codec)
11301 {
11302         unsigned int present;
11303
11304         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
11305                 & AC_PINSENSE_PRESENCE;
11306         snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
11307                             present ? 0 : PIN_OUT);
11308 }
11309
11310 static void alc267_quanta_il1_mic_automute(struct hda_codec *codec)
11311 {
11312         unsigned int present;
11313
11314         present = snd_hda_codec_read(codec, 0x18, 0,
11315                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11316         snd_hda_codec_write(codec, 0x23, 0,
11317                             AC_VERB_SET_CONNECT_SEL,
11318                             present ? 0x00 : 0x01);
11319 }
11320
11321 static void alc267_quanta_il1_automute(struct hda_codec *codec)
11322 {
11323         alc267_quanta_il1_hp_automute(codec);
11324         alc267_quanta_il1_mic_automute(codec);
11325 }
11326
11327 static void alc267_quanta_il1_unsol_event(struct hda_codec *codec,
11328                                            unsigned int res)
11329 {
11330         switch (res >> 26) {
11331         case ALC880_HP_EVENT:
11332                 alc267_quanta_il1_hp_automute(codec);
11333                 break;
11334         case ALC880_MIC_EVENT:
11335                 alc267_quanta_il1_mic_automute(codec);
11336                 break;
11337         }
11338 }
11339
11340 /*
11341  * generic initialization of ADC, input mixers and output mixers
11342  */
11343 static struct hda_verb alc268_base_init_verbs[] = {
11344         /* Unmute DAC0-1 and set vol = 0 */
11345         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11346         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11347
11348         /*
11349          * Set up output mixers (0x0c - 0x0e)
11350          */
11351         /* set vol=0 to output mixers */
11352         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11353         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
11354
11355         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11356         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11357
11358         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
11359         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
11360         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
11361         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11362         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11363         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11364         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11365         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11366
11367         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11368         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11369         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11370         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11371         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11372
11373         /* set PCBEEP vol = 0, mute connections */
11374         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11375         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11376         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11377
11378         /* Unmute Selector 23h,24h and set the default input to mic-in */
11379
11380         {0x23, AC_VERB_SET_CONNECT_SEL, 0x00},
11381         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11382         {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
11383         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11384
11385         { }
11386 };
11387
11388 /*
11389  * generic initialization of ADC, input mixers and output mixers
11390  */
11391 static struct hda_verb alc268_volume_init_verbs[] = {
11392         /* set output DAC */
11393         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11394         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11395
11396         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11397         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11398         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11399         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11400         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11401
11402         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11403         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11404         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11405
11406         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11407         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11408
11409         /* set PCBEEP vol = 0, mute connections */
11410         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11411         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11412         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11413
11414         { }
11415 };
11416
11417 static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
11418         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11419         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
11420         {
11421                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11422                 /* The multiple "Capture Source" controls confuse alsamixer
11423                  * So call somewhat different..
11424                  */
11425                 /* .name = "Capture Source", */
11426                 .name = "Input Source",
11427                 .count = 1,
11428                 .info = alc_mux_enum_info,
11429                 .get = alc_mux_enum_get,
11430                 .put = alc_mux_enum_put,
11431         },
11432         { } /* end */
11433 };
11434
11435 static struct snd_kcontrol_new alc268_capture_mixer[] = {
11436         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11437         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
11438         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
11439         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
11440         {
11441                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11442                 /* The multiple "Capture Source" controls confuse alsamixer
11443                  * So call somewhat different..
11444                  */
11445                 /* .name = "Capture Source", */
11446                 .name = "Input Source",
11447                 .count = 2,
11448                 .info = alc_mux_enum_info,
11449                 .get = alc_mux_enum_get,
11450                 .put = alc_mux_enum_put,
11451         },
11452         { } /* end */
11453 };
11454
11455 static struct hda_input_mux alc268_capture_source = {
11456         .num_items = 4,
11457         .items = {
11458                 { "Mic", 0x0 },
11459                 { "Front Mic", 0x1 },
11460                 { "Line", 0x2 },
11461                 { "CD", 0x3 },
11462         },
11463 };
11464
11465 static struct hda_input_mux alc268_acer_capture_source = {
11466         .num_items = 3,
11467         .items = {
11468                 { "Mic", 0x0 },
11469                 { "Internal Mic", 0x1 },
11470                 { "Line", 0x2 },
11471         },
11472 };
11473
11474 static struct hda_input_mux alc268_acer_dmic_capture_source = {
11475         .num_items = 3,
11476         .items = {
11477                 { "Mic", 0x0 },
11478                 { "Internal Mic", 0x6 },
11479                 { "Line", 0x2 },
11480         },
11481 };
11482
11483 #ifdef CONFIG_SND_DEBUG
11484 static struct snd_kcontrol_new alc268_test_mixer[] = {
11485         /* Volume widgets */
11486         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11487         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x03, 0x0, HDA_OUTPUT),
11488         HDA_BIND_MUTE_MONO("Mono sum Playback Switch", 0x0e, 1, 2, HDA_INPUT),
11489         HDA_BIND_MUTE("LINE-OUT sum Playback Switch", 0x0f, 2, HDA_INPUT),
11490         HDA_BIND_MUTE("HP-OUT sum Playback Switch", 0x10, 2, HDA_INPUT),
11491         HDA_BIND_MUTE("LINE-OUT Playback Switch", 0x14, 2, HDA_OUTPUT),
11492         HDA_BIND_MUTE("HP-OUT Playback Switch", 0x15, 2, HDA_OUTPUT),
11493         HDA_BIND_MUTE("Mono Playback Switch", 0x16, 2, HDA_OUTPUT),
11494         HDA_CODEC_VOLUME("MIC1 Capture Volume", 0x18, 0x0, HDA_INPUT),
11495         HDA_BIND_MUTE("MIC1 Capture Switch", 0x18, 2, HDA_OUTPUT),
11496         HDA_CODEC_VOLUME("MIC2 Capture Volume", 0x19, 0x0, HDA_INPUT),
11497         HDA_CODEC_VOLUME("LINE1 Capture Volume", 0x1a, 0x0, HDA_INPUT),
11498         HDA_BIND_MUTE("LINE1 Capture Switch", 0x1a, 2, HDA_OUTPUT),
11499         /* The below appears problematic on some hardwares */
11500         /*HDA_CODEC_VOLUME("PCBEEP Playback Volume", 0x1d, 0x0, HDA_INPUT),*/
11501         HDA_CODEC_VOLUME("PCM-IN1 Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11502         HDA_BIND_MUTE("PCM-IN1 Capture Switch", 0x23, 2, HDA_OUTPUT),
11503         HDA_CODEC_VOLUME("PCM-IN2 Capture Volume", 0x24, 0x0, HDA_OUTPUT),
11504         HDA_BIND_MUTE("PCM-IN2 Capture Switch", 0x24, 2, HDA_OUTPUT),
11505
11506         /* Modes for retasking pin widgets */
11507         ALC_PIN_MODE("LINE-OUT pin mode", 0x14, ALC_PIN_DIR_INOUT),
11508         ALC_PIN_MODE("HP-OUT pin mode", 0x15, ALC_PIN_DIR_INOUT),
11509         ALC_PIN_MODE("MIC1 pin mode", 0x18, ALC_PIN_DIR_INOUT),
11510         ALC_PIN_MODE("LINE1 pin mode", 0x1a, ALC_PIN_DIR_INOUT),
11511
11512         /* Controls for GPIO pins, assuming they are configured as outputs */
11513         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
11514         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
11515         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
11516         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
11517
11518         /* Switches to allow the digital SPDIF output pin to be enabled.
11519          * The ALC268 does not have an SPDIF input.
11520          */
11521         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x06, 0x01),
11522
11523         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
11524          * this output to turn on an external amplifier.
11525          */
11526         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
11527         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
11528
11529         { } /* end */
11530 };
11531 #endif
11532
11533 /* create input playback/capture controls for the given pin */
11534 static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
11535                                     const char *ctlname, int idx)
11536 {
11537         char name[32];
11538         int err;
11539
11540         sprintf(name, "%s Playback Volume", ctlname);
11541         if (nid == 0x14) {
11542                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
11543                                   HDA_COMPOSE_AMP_VAL(0x02, 3, idx,
11544                                                       HDA_OUTPUT));
11545                 if (err < 0)
11546                         return err;
11547         } else if (nid == 0x15) {
11548                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
11549                                   HDA_COMPOSE_AMP_VAL(0x03, 3, idx,
11550                                                       HDA_OUTPUT));
11551                 if (err < 0)
11552                         return err;
11553         } else
11554                 return -1;
11555         sprintf(name, "%s Playback Switch", ctlname);
11556         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
11557                           HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
11558         if (err < 0)
11559                 return err;
11560         return 0;
11561 }
11562
11563 /* add playback controls from the parsed DAC table */
11564 static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
11565                                              const struct auto_pin_cfg *cfg)
11566 {
11567         hda_nid_t nid;
11568         int err;
11569
11570         spec->multiout.num_dacs = 2;    /* only use one dac */
11571         spec->multiout.dac_nids = spec->private_dac_nids;
11572         spec->multiout.dac_nids[0] = 2;
11573         spec->multiout.dac_nids[1] = 3;
11574
11575         nid = cfg->line_out_pins[0];
11576         if (nid)
11577                 alc268_new_analog_output(spec, nid, "Front", 0);
11578
11579         nid = cfg->speaker_pins[0];
11580         if (nid == 0x1d) {
11581                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
11582                                   "Speaker Playback Volume",
11583                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
11584                 if (err < 0)
11585                         return err;
11586         }
11587         nid = cfg->hp_pins[0];
11588         if (nid)
11589                 alc268_new_analog_output(spec, nid, "Headphone", 0);
11590
11591         nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
11592         if (nid == 0x16) {
11593                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11594                                   "Mono Playback Switch",
11595                                   HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_INPUT));
11596                 if (err < 0)
11597                         return err;
11598         }
11599         return 0;
11600 }
11601
11602 /* create playback/capture controls for input pins */
11603 static int alc268_auto_create_analog_input_ctls(struct alc_spec *spec,
11604                                                 const struct auto_pin_cfg *cfg)
11605 {
11606         struct hda_input_mux *imux = &spec->private_imux[0];
11607         int i, idx1;
11608
11609         for (i = 0; i < AUTO_PIN_LAST; i++) {
11610                 switch(cfg->input_pins[i]) {
11611                 case 0x18:
11612                         idx1 = 0;       /* Mic 1 */
11613                         break;
11614                 case 0x19:
11615                         idx1 = 1;       /* Mic 2 */
11616                         break;
11617                 case 0x1a:
11618                         idx1 = 2;       /* Line In */
11619                         break;
11620                 case 0x1c:
11621                         idx1 = 3;       /* CD */
11622                         break;
11623                 case 0x12:
11624                 case 0x13:
11625                         idx1 = 6;       /* digital mics */
11626                         break;
11627                 default:
11628                         continue;
11629                 }
11630                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
11631                 imux->items[imux->num_items].index = idx1;
11632                 imux->num_items++;
11633         }
11634         return 0;
11635 }
11636
11637 static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
11638 {
11639         struct alc_spec *spec = codec->spec;
11640         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
11641         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
11642         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
11643         unsigned int    dac_vol1, dac_vol2;
11644
11645         if (speaker_nid) {
11646                 snd_hda_codec_write(codec, speaker_nid, 0,
11647                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
11648                 snd_hda_codec_write(codec, 0x0f, 0,
11649                                     AC_VERB_SET_AMP_GAIN_MUTE,
11650                                     AMP_IN_UNMUTE(1));
11651                 snd_hda_codec_write(codec, 0x10, 0,
11652                                     AC_VERB_SET_AMP_GAIN_MUTE,
11653                                     AMP_IN_UNMUTE(1));
11654         } else {
11655                 snd_hda_codec_write(codec, 0x0f, 0,
11656                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
11657                 snd_hda_codec_write(codec, 0x10, 0,
11658                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
11659         }
11660
11661         dac_vol1 = dac_vol2 = 0xb000 | 0x40;    /* set max volume  */
11662         if (line_nid == 0x14)
11663                 dac_vol2 = AMP_OUT_ZERO;
11664         else if (line_nid == 0x15)
11665                 dac_vol1 = AMP_OUT_ZERO;
11666         if (hp_nid == 0x14)
11667                 dac_vol2 = AMP_OUT_ZERO;
11668         else if (hp_nid == 0x15)
11669                 dac_vol1 = AMP_OUT_ZERO;
11670         if (line_nid != 0x16 || hp_nid != 0x16 ||
11671             spec->autocfg.line_out_pins[1] != 0x16 ||
11672             spec->autocfg.line_out_pins[2] != 0x16)
11673                 dac_vol1 = dac_vol2 = AMP_OUT_ZERO;
11674
11675         snd_hda_codec_write(codec, 0x02, 0,
11676                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol1);
11677         snd_hda_codec_write(codec, 0x03, 0,
11678                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol2);
11679 }
11680
11681 /* pcm configuration: identiacal with ALC880 */
11682 #define alc268_pcm_analog_playback      alc880_pcm_analog_playback
11683 #define alc268_pcm_analog_capture       alc880_pcm_analog_capture
11684 #define alc268_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
11685 #define alc268_pcm_digital_playback     alc880_pcm_digital_playback
11686
11687 /*
11688  * BIOS auto configuration
11689  */
11690 static int alc268_parse_auto_config(struct hda_codec *codec)
11691 {
11692         struct alc_spec *spec = codec->spec;
11693         int err;
11694         static hda_nid_t alc268_ignore[] = { 0 };
11695
11696         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
11697                                            alc268_ignore);
11698         if (err < 0)
11699                 return err;
11700         if (!spec->autocfg.line_outs)
11701                 return 0; /* can't find valid BIOS pin config */
11702
11703         err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
11704         if (err < 0)
11705                 return err;
11706         err = alc268_auto_create_analog_input_ctls(spec, &spec->autocfg);
11707         if (err < 0)
11708                 return err;
11709
11710         spec->multiout.max_channels = 2;
11711
11712         /* digital only support output */
11713         if (spec->autocfg.dig_out_pin)
11714                 spec->multiout.dig_out_nid = ALC268_DIGOUT_NID;
11715
11716         if (spec->kctls.list)
11717                 add_mixer(spec, spec->kctls.list);
11718
11719         if (spec->autocfg.speaker_pins[0] != 0x1d)
11720                 add_mixer(spec, alc268_beep_mixer);
11721
11722         add_verb(spec, alc268_volume_init_verbs);
11723         spec->num_mux_defs = 1;
11724         spec->input_mux = &spec->private_imux[0];
11725
11726         err = alc_auto_add_mic_boost(codec);
11727         if (err < 0)
11728                 return err;
11729
11730         store_pin_configs(codec);
11731         return 1;
11732 }
11733
11734 #define alc268_auto_init_multi_out      alc882_auto_init_multi_out
11735 #define alc268_auto_init_hp_out         alc882_auto_init_hp_out
11736 #define alc268_auto_init_analog_input   alc882_auto_init_analog_input
11737
11738 /* init callback for auto-configuration model -- overriding the default init */
11739 static void alc268_auto_init(struct hda_codec *codec)
11740 {
11741         struct alc_spec *spec = codec->spec;
11742         alc268_auto_init_multi_out(codec);
11743         alc268_auto_init_hp_out(codec);
11744         alc268_auto_init_mono_speaker_out(codec);
11745         alc268_auto_init_analog_input(codec);
11746         if (spec->unsol_event)
11747                 alc_inithook(codec);
11748 }
11749
11750 /*
11751  * configuration and preset
11752  */
11753 static const char *alc268_models[ALC268_MODEL_LAST] = {
11754         [ALC267_QUANTA_IL1]     = "quanta-il1",
11755         [ALC268_3ST]            = "3stack",
11756         [ALC268_TOSHIBA]        = "toshiba",
11757         [ALC268_ACER]           = "acer",
11758         [ALC268_ACER_DMIC]      = "acer-dmic",
11759         [ALC268_ACER_ASPIRE_ONE]        = "acer-aspire",
11760         [ALC268_DELL]           = "dell",
11761         [ALC268_ZEPTO]          = "zepto",
11762 #ifdef CONFIG_SND_DEBUG
11763         [ALC268_TEST]           = "test",
11764 #endif
11765         [ALC268_AUTO]           = "auto",
11766 };
11767
11768 static struct snd_pci_quirk alc268_cfg_tbl[] = {
11769         SND_PCI_QUIRK(0x1025, 0x011e, "Acer Aspire 5720z", ALC268_ACER),
11770         SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
11771         SND_PCI_QUIRK(0x1025, 0x012e, "Acer Aspire 5310", ALC268_ACER),
11772         SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
11773         SND_PCI_QUIRK(0x1025, 0x0136, "Acer Aspire 5315", ALC268_ACER),
11774         SND_PCI_QUIRK(0x1025, 0x015b, "Acer Aspire One",
11775                                                 ALC268_ACER_ASPIRE_ONE),
11776         SND_PCI_QUIRK(0x1028, 0x0253, "Dell OEM", ALC268_DELL),
11777         SND_PCI_QUIRK(0x1028, 0x02b0, "Dell Inspiron Mini9", ALC268_DELL),
11778         SND_PCI_QUIRK(0x103c, 0x30cc, "TOSHIBA", ALC268_TOSHIBA),
11779         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
11780         SND_PCI_QUIRK(0x1179, 0xff10, "TOSHIBA A205", ALC268_TOSHIBA),
11781         SND_PCI_QUIRK(0x1179, 0xff50, "TOSHIBA A305", ALC268_TOSHIBA),
11782         SND_PCI_QUIRK(0x1179, 0xff64, "TOSHIBA L305", ALC268_TOSHIBA),
11783         SND_PCI_QUIRK(0x14c0, 0x0025, "COMPAL IFL90/JFL-92", ALC268_TOSHIBA),
11784         SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER),
11785         SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1),
11786         SND_PCI_QUIRK(0x1170, 0x0040, "ZEPTO", ALC268_ZEPTO),
11787         {}
11788 };
11789
11790 static struct alc_config_preset alc268_presets[] = {
11791         [ALC267_QUANTA_IL1] = {
11792                 .mixers = { alc267_quanta_il1_mixer },
11793                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11794                                 alc267_quanta_il1_verbs },
11795                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11796                 .dac_nids = alc268_dac_nids,
11797                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11798                 .adc_nids = alc268_adc_nids_alt,
11799                 .hp_nid = 0x03,
11800                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11801                 .channel_mode = alc268_modes,
11802                 .input_mux = &alc268_capture_source,
11803                 .unsol_event = alc267_quanta_il1_unsol_event,
11804                 .init_hook = alc267_quanta_il1_automute,
11805         },
11806         [ALC268_3ST] = {
11807                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
11808                             alc268_beep_mixer },
11809                 .init_verbs = { alc268_base_init_verbs },
11810                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11811                 .dac_nids = alc268_dac_nids,
11812                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11813                 .adc_nids = alc268_adc_nids_alt,
11814                 .capsrc_nids = alc268_capsrc_nids,
11815                 .hp_nid = 0x03,
11816                 .dig_out_nid = ALC268_DIGOUT_NID,
11817                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11818                 .channel_mode = alc268_modes,
11819                 .input_mux = &alc268_capture_source,
11820         },
11821         [ALC268_TOSHIBA] = {
11822                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
11823                             alc268_beep_mixer },
11824                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11825                                 alc268_toshiba_verbs },
11826                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11827                 .dac_nids = alc268_dac_nids,
11828                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11829                 .adc_nids = alc268_adc_nids_alt,
11830                 .capsrc_nids = alc268_capsrc_nids,
11831                 .hp_nid = 0x03,
11832                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11833                 .channel_mode = alc268_modes,
11834                 .input_mux = &alc268_capture_source,
11835                 .unsol_event = alc268_toshiba_unsol_event,
11836                 .init_hook = alc268_toshiba_automute,
11837         },
11838         [ALC268_ACER] = {
11839                 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer,
11840                             alc268_beep_mixer },
11841                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11842                                 alc268_acer_verbs },
11843                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11844                 .dac_nids = alc268_dac_nids,
11845                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11846                 .adc_nids = alc268_adc_nids_alt,
11847                 .capsrc_nids = alc268_capsrc_nids,
11848                 .hp_nid = 0x02,
11849                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11850                 .channel_mode = alc268_modes,
11851                 .input_mux = &alc268_acer_capture_source,
11852                 .unsol_event = alc268_acer_unsol_event,
11853                 .init_hook = alc268_acer_init_hook,
11854         },
11855         [ALC268_ACER_DMIC] = {
11856                 .mixers = { alc268_acer_dmic_mixer, alc268_capture_alt_mixer,
11857                             alc268_beep_mixer },
11858                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11859                                 alc268_acer_verbs },
11860                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11861                 .dac_nids = alc268_dac_nids,
11862                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11863                 .adc_nids = alc268_adc_nids_alt,
11864                 .capsrc_nids = alc268_capsrc_nids,
11865                 .hp_nid = 0x02,
11866                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11867                 .channel_mode = alc268_modes,
11868                 .input_mux = &alc268_acer_dmic_capture_source,
11869                 .unsol_event = alc268_acer_unsol_event,
11870                 .init_hook = alc268_acer_init_hook,
11871         },
11872         [ALC268_ACER_ASPIRE_ONE] = {
11873                 .mixers = { alc268_acer_aspire_one_mixer,
11874                                 alc268_capture_alt_mixer },
11875                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11876                                 alc268_acer_aspire_one_verbs },
11877                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11878                 .dac_nids = alc268_dac_nids,
11879                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11880                 .adc_nids = alc268_adc_nids_alt,
11881                 .capsrc_nids = alc268_capsrc_nids,
11882                 .hp_nid = 0x03,
11883                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11884                 .channel_mode = alc268_modes,
11885                 .input_mux = &alc268_acer_lc_capture_source,
11886                 .unsol_event = alc268_acer_lc_unsol_event,
11887                 .init_hook = alc268_acer_lc_init_hook,
11888         },
11889         [ALC268_DELL] = {
11890                 .mixers = { alc268_dell_mixer, alc268_beep_mixer },
11891                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11892                                 alc268_dell_verbs },
11893                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11894                 .dac_nids = alc268_dac_nids,
11895                 .hp_nid = 0x02,
11896                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11897                 .channel_mode = alc268_modes,
11898                 .unsol_event = alc268_dell_unsol_event,
11899                 .init_hook = alc268_dell_init_hook,
11900                 .input_mux = &alc268_capture_source,
11901         },
11902         [ALC268_ZEPTO] = {
11903                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
11904                             alc268_beep_mixer },
11905                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11906                                 alc268_toshiba_verbs },
11907                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11908                 .dac_nids = alc268_dac_nids,
11909                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11910                 .adc_nids = alc268_adc_nids_alt,
11911                 .capsrc_nids = alc268_capsrc_nids,
11912                 .hp_nid = 0x03,
11913                 .dig_out_nid = ALC268_DIGOUT_NID,
11914                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11915                 .channel_mode = alc268_modes,
11916                 .input_mux = &alc268_capture_source,
11917                 .unsol_event = alc268_toshiba_unsol_event,
11918                 .init_hook = alc268_toshiba_automute
11919         },
11920 #ifdef CONFIG_SND_DEBUG
11921         [ALC268_TEST] = {
11922                 .mixers = { alc268_test_mixer, alc268_capture_mixer },
11923                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11924                                 alc268_volume_init_verbs },
11925                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11926                 .dac_nids = alc268_dac_nids,
11927                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11928                 .adc_nids = alc268_adc_nids_alt,
11929                 .capsrc_nids = alc268_capsrc_nids,
11930                 .hp_nid = 0x03,
11931                 .dig_out_nid = ALC268_DIGOUT_NID,
11932                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11933                 .channel_mode = alc268_modes,
11934                 .input_mux = &alc268_capture_source,
11935         },
11936 #endif
11937 };
11938
11939 static int patch_alc268(struct hda_codec *codec)
11940 {
11941         struct alc_spec *spec;
11942         int board_config;
11943         int err;
11944
11945         spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
11946         if (spec == NULL)
11947                 return -ENOMEM;
11948
11949         codec->spec = spec;
11950
11951         board_config = snd_hda_check_board_config(codec, ALC268_MODEL_LAST,
11952                                                   alc268_models,
11953                                                   alc268_cfg_tbl);
11954
11955         if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
11956                 printk(KERN_INFO "hda_codec: Unknown model for ALC268, "
11957                        "trying auto-probe from BIOS...\n");
11958                 board_config = ALC268_AUTO;
11959         }
11960
11961         if (board_config == ALC268_AUTO) {
11962                 /* automatic parse from the BIOS config */
11963                 err = alc268_parse_auto_config(codec);
11964                 if (err < 0) {
11965                         alc_free(codec);
11966                         return err;
11967                 } else if (!err) {
11968                         printk(KERN_INFO
11969                                "hda_codec: Cannot set up configuration "
11970                                "from BIOS.  Using base mode...\n");
11971                         board_config = ALC268_3ST;
11972                 }
11973         }
11974
11975         if (board_config != ALC268_AUTO)
11976                 setup_preset(spec, &alc268_presets[board_config]);
11977
11978         if (codec->vendor_id == 0x10ec0267) {
11979                 spec->stream_name_analog = "ALC267 Analog";
11980                 spec->stream_name_digital = "ALC267 Digital";
11981         } else {
11982                 spec->stream_name_analog = "ALC268 Analog";
11983                 spec->stream_name_digital = "ALC268 Digital";
11984         }
11985
11986         spec->stream_analog_playback = &alc268_pcm_analog_playback;
11987         spec->stream_analog_capture = &alc268_pcm_analog_capture;
11988         spec->stream_analog_alt_capture = &alc268_pcm_analog_alt_capture;
11989
11990         spec->stream_digital_playback = &alc268_pcm_digital_playback;
11991
11992         if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
11993                 /* override the amp caps for beep generator */
11994                 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
11995                                           (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
11996                                           (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
11997                                           (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
11998                                           (0 << AC_AMPCAP_MUTE_SHIFT));
11999
12000         if (!spec->adc_nids && spec->input_mux) {
12001                 /* check whether NID 0x07 is valid */
12002                 unsigned int wcap = get_wcaps(codec, 0x07);
12003                 int i;
12004
12005                 /* get type */
12006                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
12007                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
12008                         spec->adc_nids = alc268_adc_nids_alt;
12009                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt);
12010                         add_mixer(spec, alc268_capture_alt_mixer);
12011                 } else {
12012                         spec->adc_nids = alc268_adc_nids;
12013                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids);
12014                         add_mixer(spec, alc268_capture_mixer);
12015                 }
12016                 spec->capsrc_nids = alc268_capsrc_nids;
12017                 /* set default input source */
12018                 for (i = 0; i < spec->num_adc_nids; i++)
12019                         snd_hda_codec_write_cache(codec, alc268_capsrc_nids[i],
12020                                 0, AC_VERB_SET_CONNECT_SEL,
12021                                 spec->input_mux->items[0].index);
12022         }
12023
12024         spec->vmaster_nid = 0x02;
12025
12026         codec->patch_ops = alc_patch_ops;
12027         if (board_config == ALC268_AUTO)
12028                 spec->init_hook = alc268_auto_init;
12029
12030         codec->proc_widget_hook = print_realtek_coef;
12031
12032         return 0;
12033 }
12034
12035 /*
12036  *  ALC269 channel source setting (2 channel)
12037  */
12038 #define ALC269_DIGOUT_NID       ALC880_DIGOUT_NID
12039
12040 #define alc269_dac_nids         alc260_dac_nids
12041
12042 static hda_nid_t alc269_adc_nids[1] = {
12043         /* ADC1 */
12044         0x08,
12045 };
12046
12047 static hda_nid_t alc269_capsrc_nids[1] = {
12048         0x23,
12049 };
12050
12051 /* NOTE: ADC2 (0x07) is connected from a recording *MIXER* (0x24),
12052  *       not a mux!
12053  */
12054
12055 static struct hda_input_mux alc269_eeepc_dmic_capture_source = {
12056         .num_items = 2,
12057         .items = {
12058                 { "i-Mic", 0x5 },
12059                 { "e-Mic", 0x0 },
12060         },
12061 };
12062
12063 static struct hda_input_mux alc269_eeepc_amic_capture_source = {
12064         .num_items = 2,
12065         .items = {
12066                 { "i-Mic", 0x1 },
12067                 { "e-Mic", 0x0 },
12068         },
12069 };
12070
12071 #define alc269_modes            alc260_modes
12072 #define alc269_capture_source   alc880_lg_lw_capture_source
12073
12074 static struct snd_kcontrol_new alc269_base_mixer[] = {
12075         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12076         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12077         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
12078         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
12079         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12080         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12081         HDA_CODEC_VOLUME("Beep Playback Volume", 0x0b, 0x4, HDA_INPUT),
12082         HDA_CODEC_MUTE("Beep Playback Switch", 0x0b, 0x4, HDA_INPUT),
12083         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12084         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12085         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12086         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
12087         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12088         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
12089         { } /* end */
12090 };
12091
12092 static struct snd_kcontrol_new alc269_quanta_fl1_mixer[] = {
12093         /* output mixer control */
12094         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
12095         {
12096                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12097                 .name = "Master Playback Switch",
12098                 .info = snd_hda_mixer_amp_switch_info,
12099                 .get = snd_hda_mixer_amp_switch_get,
12100                 .put = alc268_acer_master_sw_put,
12101                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
12102         },
12103         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12104         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12105         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12106         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12107         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12108         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
12109         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x04, HDA_INPUT),
12110         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x04, HDA_INPUT),
12111         { }
12112 };
12113
12114 static struct snd_kcontrol_new alc269_lifebook_mixer[] = {
12115         /* output mixer control */
12116         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
12117         {
12118                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12119                 .name = "Master Playback Switch",
12120                 .info = snd_hda_mixer_amp_switch_info,
12121                 .get = snd_hda_mixer_amp_switch_get,
12122                 .put = alc268_acer_master_sw_put,
12123                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
12124         },
12125         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12126         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12127         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12128         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12129         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12130         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
12131         HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x0b, 0x03, HDA_INPUT),
12132         HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x0b, 0x03, HDA_INPUT),
12133         HDA_CODEC_VOLUME("Dock Mic Boost", 0x1b, 0, HDA_INPUT),
12134         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x04, HDA_INPUT),
12135         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x04, HDA_INPUT),
12136         { }
12137 };
12138
12139 /* bind volumes of both NID 0x0c and 0x0d */
12140 static struct hda_bind_ctls alc269_epc_bind_vol = {
12141         .ops = &snd_hda_bind_vol,
12142         .values = {
12143                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
12144                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
12145                 0
12146         },
12147 };
12148
12149 static struct snd_kcontrol_new alc269_eeepc_mixer[] = {
12150         HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12151         HDA_BIND_VOL("LineOut Playback Volume", &alc269_epc_bind_vol),
12152         HDA_CODEC_MUTE("LineOut Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12153         { } /* end */
12154 };
12155
12156 /* capture mixer elements */
12157 static struct snd_kcontrol_new alc269_epc_capture_mixer[] = {
12158         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
12159         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
12160         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12161         { } /* end */
12162 };
12163
12164 /* FSC amilo */
12165 static struct snd_kcontrol_new alc269_fujitsu_mixer[] = {
12166         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12167         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12168         HDA_BIND_VOL("PCM Playback Volume", &alc269_epc_bind_vol),
12169         { } /* end */
12170 };
12171
12172 /* beep control */
12173 static struct snd_kcontrol_new alc269_beep_mixer[] = {
12174         HDA_CODEC_VOLUME("Beep Playback Volume", 0x0b, 0x4, HDA_INPUT),
12175         HDA_CODEC_MUTE("Beep Playback Switch", 0x0b, 0x4, HDA_INPUT),
12176         { } /* end */
12177 };
12178
12179 static struct hda_verb alc269_quanta_fl1_verbs[] = {
12180         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12181         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12182         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12183         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12184         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12185         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12186         { }
12187 };
12188
12189 static struct hda_verb alc269_lifebook_verbs[] = {
12190         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12191         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
12192         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12193         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12194         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12195         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12196         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12197         {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12198         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12199         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12200         { }
12201 };
12202
12203 /* toggle speaker-output according to the hp-jack state */
12204 static void alc269_quanta_fl1_speaker_automute(struct hda_codec *codec)
12205 {
12206         unsigned int present;
12207         unsigned char bits;
12208
12209         present = snd_hda_codec_read(codec, 0x15, 0,
12210                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12211         bits = present ? AMP_IN_MUTE(0) : 0;
12212         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
12213                         AMP_IN_MUTE(0), bits);
12214         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
12215                         AMP_IN_MUTE(0), bits);
12216
12217         snd_hda_codec_write(codec, 0x20, 0,
12218                         AC_VERB_SET_COEF_INDEX, 0x0c);
12219         snd_hda_codec_write(codec, 0x20, 0,
12220                         AC_VERB_SET_PROC_COEF, 0x680);
12221
12222         snd_hda_codec_write(codec, 0x20, 0,
12223                         AC_VERB_SET_COEF_INDEX, 0x0c);
12224         snd_hda_codec_write(codec, 0x20, 0,
12225                         AC_VERB_SET_PROC_COEF, 0x480);
12226 }
12227
12228 /* toggle speaker-output according to the hp-jacks state */
12229 static void alc269_lifebook_speaker_automute(struct hda_codec *codec)
12230 {
12231         unsigned int present;
12232         unsigned char bits;
12233
12234         /* Check laptop headphone socket */
12235         present = snd_hda_codec_read(codec, 0x15, 0,
12236                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12237
12238         /* Check port replicator headphone socket */
12239         present |= snd_hda_codec_read(codec, 0x1a, 0,
12240                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12241
12242         bits = present ? AMP_IN_MUTE(0) : 0;
12243         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
12244                         AMP_IN_MUTE(0), bits);
12245         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
12246                         AMP_IN_MUTE(0), bits);
12247
12248         snd_hda_codec_write(codec, 0x20, 0,
12249                         AC_VERB_SET_COEF_INDEX, 0x0c);
12250         snd_hda_codec_write(codec, 0x20, 0,
12251                         AC_VERB_SET_PROC_COEF, 0x680);
12252
12253         snd_hda_codec_write(codec, 0x20, 0,
12254                         AC_VERB_SET_COEF_INDEX, 0x0c);
12255         snd_hda_codec_write(codec, 0x20, 0,
12256                         AC_VERB_SET_PROC_COEF, 0x480);
12257 }
12258
12259 static void alc269_quanta_fl1_mic_automute(struct hda_codec *codec)
12260 {
12261         unsigned int present;
12262
12263         present = snd_hda_codec_read(codec, 0x18, 0,
12264                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12265         snd_hda_codec_write(codec, 0x23, 0,
12266                             AC_VERB_SET_CONNECT_SEL, present ? 0x0 : 0x1);
12267 }
12268
12269 static void alc269_lifebook_mic_autoswitch(struct hda_codec *codec)
12270 {
12271         unsigned int present_laptop;
12272         unsigned int present_dock;
12273
12274         present_laptop = snd_hda_codec_read(codec, 0x18, 0,
12275                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12276
12277         present_dock = snd_hda_codec_read(codec, 0x1b, 0,
12278                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12279
12280         /* Laptop mic port overrides dock mic port, design decision */
12281         if (present_dock)
12282                 snd_hda_codec_write(codec, 0x23, 0,
12283                                 AC_VERB_SET_CONNECT_SEL, 0x3);
12284         if (present_laptop)
12285                 snd_hda_codec_write(codec, 0x23, 0,
12286                                 AC_VERB_SET_CONNECT_SEL, 0x0);
12287         if (!present_dock && !present_laptop)
12288                 snd_hda_codec_write(codec, 0x23, 0,
12289                                 AC_VERB_SET_CONNECT_SEL, 0x1);
12290 }
12291
12292 static void alc269_quanta_fl1_unsol_event(struct hda_codec *codec,
12293                                     unsigned int res)
12294 {
12295         if ((res >> 26) == ALC880_HP_EVENT)
12296                 alc269_quanta_fl1_speaker_automute(codec);
12297         if ((res >> 26) == ALC880_MIC_EVENT)
12298                 alc269_quanta_fl1_mic_automute(codec);
12299 }
12300
12301 static void alc269_lifebook_unsol_event(struct hda_codec *codec,
12302                                         unsigned int res)
12303 {
12304         if ((res >> 26) == ALC880_HP_EVENT)
12305                 alc269_lifebook_speaker_automute(codec);
12306         if ((res >> 26) == ALC880_MIC_EVENT)
12307                 alc269_lifebook_mic_autoswitch(codec);
12308 }
12309
12310 static void alc269_quanta_fl1_init_hook(struct hda_codec *codec)
12311 {
12312         alc269_quanta_fl1_speaker_automute(codec);
12313         alc269_quanta_fl1_mic_automute(codec);
12314 }
12315
12316 static void alc269_lifebook_init_hook(struct hda_codec *codec)
12317 {
12318         alc269_lifebook_speaker_automute(codec);
12319         alc269_lifebook_mic_autoswitch(codec);
12320 }
12321
12322 static struct hda_verb alc269_eeepc_dmic_init_verbs[] = {
12323         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12324         {0x23, AC_VERB_SET_CONNECT_SEL, 0x05},
12325         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
12326         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))},
12327         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12328         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12329         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12330         {}
12331 };
12332
12333 static struct hda_verb alc269_eeepc_amic_init_verbs[] = {
12334         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12335         {0x23, AC_VERB_SET_CONNECT_SEL, 0x01},
12336         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
12337         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x701b | (0x00 << 8))},
12338         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12339         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12340         {}
12341 };
12342
12343 /* toggle speaker-output according to the hp-jack state */
12344 static void alc269_speaker_automute(struct hda_codec *codec)
12345 {
12346         unsigned int present;
12347         unsigned char bits;
12348
12349         present = snd_hda_codec_read(codec, 0x15, 0,
12350                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12351         bits = present ? AMP_IN_MUTE(0) : 0;
12352         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
12353                                 AMP_IN_MUTE(0), bits);
12354         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
12355                                 AMP_IN_MUTE(0), bits);
12356 }
12357
12358 static void alc269_eeepc_dmic_automute(struct hda_codec *codec)
12359 {
12360         unsigned int present;
12361
12362         present = snd_hda_codec_read(codec, 0x18, 0,
12363                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12364         snd_hda_codec_write(codec, 0x23, 0,
12365                                 AC_VERB_SET_CONNECT_SEL,  (present ? 0 : 5));
12366 }
12367
12368 static void alc269_eeepc_amic_automute(struct hda_codec *codec)
12369 {
12370         unsigned int present;
12371
12372         present = snd_hda_codec_read(codec, 0x18, 0,
12373                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12374         snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
12375                                 0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
12376         snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
12377                                 0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
12378 }
12379
12380 /* unsolicited event for HP jack sensing */
12381 static void alc269_eeepc_dmic_unsol_event(struct hda_codec *codec,
12382                                      unsigned int res)
12383 {
12384         if ((res >> 26) == ALC880_HP_EVENT)
12385                 alc269_speaker_automute(codec);
12386
12387         if ((res >> 26) == ALC880_MIC_EVENT)
12388                 alc269_eeepc_dmic_automute(codec);
12389 }
12390
12391 static void alc269_eeepc_dmic_inithook(struct hda_codec *codec)
12392 {
12393         alc269_speaker_automute(codec);
12394         alc269_eeepc_dmic_automute(codec);
12395 }
12396
12397 /* unsolicited event for HP jack sensing */
12398 static void alc269_eeepc_amic_unsol_event(struct hda_codec *codec,
12399                                      unsigned int res)
12400 {
12401         if ((res >> 26) == ALC880_HP_EVENT)
12402                 alc269_speaker_automute(codec);
12403
12404         if ((res >> 26) == ALC880_MIC_EVENT)
12405                 alc269_eeepc_amic_automute(codec);
12406 }
12407
12408 static void alc269_eeepc_amic_inithook(struct hda_codec *codec)
12409 {
12410         alc269_speaker_automute(codec);
12411         alc269_eeepc_amic_automute(codec);
12412 }
12413
12414 /*
12415  * generic initialization of ADC, input mixers and output mixers
12416  */
12417 static struct hda_verb alc269_init_verbs[] = {
12418         /*
12419          * Unmute ADC0 and set the default input to mic-in
12420          */
12421         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12422
12423         /* Mute input amps (PCBeep, Line In, Mic 1 & Mic 2) of the
12424          * analog-loopback mixer widget
12425          * Note: PASD motherboards uses the Line In 2 as the input for
12426          * front panel mic (mic 2)
12427          */
12428         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
12429         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12430         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12431         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12432         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12433         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
12434
12435         /*
12436          * Set up output mixers (0x0c - 0x0e)
12437          */
12438         /* set vol=0 to output mixers */
12439         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12440         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12441
12442         /* set up input amps for analog loopback */
12443         /* Amp Indices: DAC = 0, mixer = 1 */
12444         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12445         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12446         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12447         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12448         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12449         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12450
12451         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12452         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12453         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12454         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12455         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12456         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12457         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12458
12459         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12460         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12461         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12462         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12463         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12464         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12465         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12466
12467         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
12468         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
12469
12470         /* FIXME: use matrix-type input source selection */
12471         /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
12472         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
12473         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12474         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12475         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12476         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12477
12478         /* set EAPD */
12479         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
12480         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
12481         { }
12482 };
12483
12484 /* add playback controls from the parsed DAC table */
12485 static int alc269_auto_create_multi_out_ctls(struct alc_spec *spec,
12486                                              const struct auto_pin_cfg *cfg)
12487 {
12488         hda_nid_t nid;
12489         int err;
12490
12491         spec->multiout.num_dacs = 1;    /* only use one dac */
12492         spec->multiout.dac_nids = spec->private_dac_nids;
12493         spec->multiout.dac_nids[0] = 2;
12494
12495         nid = cfg->line_out_pins[0];
12496         if (nid) {
12497                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
12498                                   "Front Playback Volume",
12499                                   HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT));
12500                 if (err < 0)
12501                         return err;
12502                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12503                                   "Front Playback Switch",
12504                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
12505                 if (err < 0)
12506                         return err;
12507         }
12508
12509         nid = cfg->speaker_pins[0];
12510         if (nid) {
12511                 if (!cfg->line_out_pins[0]) {
12512                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
12513                                           "Speaker Playback Volume",
12514                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
12515                                                               HDA_OUTPUT));
12516                         if (err < 0)
12517                                 return err;
12518                 }
12519                 if (nid == 0x16) {
12520                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12521                                           "Speaker Playback Switch",
12522                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
12523                                                               HDA_OUTPUT));
12524                         if (err < 0)
12525                                 return err;
12526                 } else {
12527                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12528                                           "Speaker Playback Switch",
12529                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
12530                                                               HDA_OUTPUT));
12531                         if (err < 0)
12532                                 return err;
12533                 }
12534         }
12535         nid = cfg->hp_pins[0];
12536         if (nid) {
12537                 /* spec->multiout.hp_nid = 2; */
12538                 if (!cfg->line_out_pins[0] && !cfg->speaker_pins[0]) {
12539                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
12540                                           "Headphone Playback Volume",
12541                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
12542                                                               HDA_OUTPUT));
12543                         if (err < 0)
12544                                 return err;
12545                 }
12546                 if (nid == 0x16) {
12547                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12548                                           "Headphone Playback Switch",
12549                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
12550                                                               HDA_OUTPUT));
12551                         if (err < 0)
12552                                 return err;
12553                 } else {
12554                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12555                                           "Headphone Playback Switch",
12556                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
12557                                                               HDA_OUTPUT));
12558                         if (err < 0)
12559                                 return err;
12560                 }
12561         }
12562         return 0;
12563 }
12564
12565 static int alc269_auto_create_analog_input_ctls(struct alc_spec *spec,
12566                                                 const struct auto_pin_cfg *cfg)
12567 {
12568         int err;
12569
12570         err = alc880_auto_create_analog_input_ctls(spec, cfg);
12571         if (err < 0)
12572                 return err;
12573         /* digital-mic input pin is excluded in alc880_auto_create..()
12574          * because it's under 0x18
12575          */
12576         if (cfg->input_pins[AUTO_PIN_MIC] == 0x12 ||
12577             cfg->input_pins[AUTO_PIN_FRONT_MIC] == 0x12) {
12578                 struct hda_input_mux *imux = &spec->private_imux[0];
12579                 imux->items[imux->num_items].label = "Int Mic";
12580                 imux->items[imux->num_items].index = 0x05;
12581                 imux->num_items++;
12582         }
12583         return 0;
12584 }
12585
12586 #ifdef CONFIG_SND_HDA_POWER_SAVE
12587 #define alc269_loopbacks        alc880_loopbacks
12588 #endif
12589
12590 /* pcm configuration: identiacal with ALC880 */
12591 #define alc269_pcm_analog_playback      alc880_pcm_analog_playback
12592 #define alc269_pcm_analog_capture       alc880_pcm_analog_capture
12593 #define alc269_pcm_digital_playback     alc880_pcm_digital_playback
12594 #define alc269_pcm_digital_capture      alc880_pcm_digital_capture
12595
12596 /*
12597  * BIOS auto configuration
12598  */
12599 static int alc269_parse_auto_config(struct hda_codec *codec)
12600 {
12601         struct alc_spec *spec = codec->spec;
12602         int i, err;
12603         static hda_nid_t alc269_ignore[] = { 0x1d, 0 };
12604
12605         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
12606                                            alc269_ignore);
12607         if (err < 0)
12608                 return err;
12609
12610         err = alc269_auto_create_multi_out_ctls(spec, &spec->autocfg);
12611         if (err < 0)
12612                 return err;
12613         err = alc269_auto_create_analog_input_ctls(spec, &spec->autocfg);
12614         if (err < 0)
12615                 return err;
12616
12617         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
12618
12619         if (spec->autocfg.dig_out_pin)
12620                 spec->multiout.dig_out_nid = ALC269_DIGOUT_NID;
12621
12622         if (spec->kctls.list)
12623                 add_mixer(spec, spec->kctls.list);
12624
12625         /* create a beep mixer control if the pin 0x1d isn't assigned */
12626         for (i = 0; i < ARRAY_SIZE(spec->autocfg.input_pins); i++)
12627                 if (spec->autocfg.input_pins[i] == 0x1d)
12628                         break;
12629         if (i >= ARRAY_SIZE(spec->autocfg.input_pins))
12630                 add_mixer(spec, alc269_beep_mixer);
12631
12632         add_verb(spec, alc269_init_verbs);
12633         spec->num_mux_defs = 1;
12634         spec->input_mux = &spec->private_imux[0];
12635         /* set default input source */
12636         snd_hda_codec_write_cache(codec, alc269_capsrc_nids[0],
12637                                   0, AC_VERB_SET_CONNECT_SEL,
12638                                   spec->input_mux->items[0].index);
12639
12640         err = alc_auto_add_mic_boost(codec);
12641         if (err < 0)
12642                 return err;
12643
12644         if (!spec->cap_mixer)
12645                 set_capture_mixer(spec);
12646
12647         store_pin_configs(codec);
12648         return 1;
12649 }
12650
12651 #define alc269_auto_init_multi_out      alc882_auto_init_multi_out
12652 #define alc269_auto_init_hp_out         alc882_auto_init_hp_out
12653 #define alc269_auto_init_analog_input   alc882_auto_init_analog_input
12654
12655
12656 /* init callback for auto-configuration model -- overriding the default init */
12657 static void alc269_auto_init(struct hda_codec *codec)
12658 {
12659         struct alc_spec *spec = codec->spec;
12660         alc269_auto_init_multi_out(codec);
12661         alc269_auto_init_hp_out(codec);
12662         alc269_auto_init_analog_input(codec);
12663         if (spec->unsol_event)
12664                 alc_inithook(codec);
12665 }
12666
12667 /*
12668  * configuration and preset
12669  */
12670 static const char *alc269_models[ALC269_MODEL_LAST] = {
12671         [ALC269_BASIC]                  = "basic",
12672         [ALC269_QUANTA_FL1]             = "quanta",
12673         [ALC269_ASUS_EEEPC_P703]        = "eeepc-p703",
12674         [ALC269_ASUS_EEEPC_P901]        = "eeepc-p901",
12675         [ALC269_FUJITSU]                = "fujitsu",
12676         [ALC269_LIFEBOOK]               = "lifebook"
12677 };
12678
12679 static struct snd_pci_quirk alc269_cfg_tbl[] = {
12680         SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_QUANTA_FL1),
12681         SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
12682                       ALC269_ASUS_EEEPC_P703),
12683         SND_PCI_QUIRK(0x1043, 0x831a, "ASUS Eeepc P901",
12684                       ALC269_ASUS_EEEPC_P901),
12685         SND_PCI_QUIRK(0x1043, 0x834a, "ASUS Eeepc S101",
12686                       ALC269_ASUS_EEEPC_P901),
12687         SND_PCI_QUIRK(0x1734, 0x115d, "FSC Amilo", ALC269_FUJITSU),
12688         SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook ICH9M-based", ALC269_LIFEBOOK),
12689         {}
12690 };
12691
12692 static struct alc_config_preset alc269_presets[] = {
12693         [ALC269_BASIC] = {
12694                 .mixers = { alc269_base_mixer },
12695                 .init_verbs = { alc269_init_verbs },
12696                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12697                 .dac_nids = alc269_dac_nids,
12698                 .hp_nid = 0x03,
12699                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12700                 .channel_mode = alc269_modes,
12701                 .input_mux = &alc269_capture_source,
12702         },
12703         [ALC269_QUANTA_FL1] = {
12704                 .mixers = { alc269_quanta_fl1_mixer },
12705                 .init_verbs = { alc269_init_verbs, alc269_quanta_fl1_verbs },
12706                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12707                 .dac_nids = alc269_dac_nids,
12708                 .hp_nid = 0x03,
12709                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12710                 .channel_mode = alc269_modes,
12711                 .input_mux = &alc269_capture_source,
12712                 .unsol_event = alc269_quanta_fl1_unsol_event,
12713                 .init_hook = alc269_quanta_fl1_init_hook,
12714         },
12715         [ALC269_ASUS_EEEPC_P703] = {
12716                 .mixers = { alc269_eeepc_mixer },
12717                 .cap_mixer = alc269_epc_capture_mixer,
12718                 .init_verbs = { alc269_init_verbs,
12719                                 alc269_eeepc_amic_init_verbs },
12720                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12721                 .dac_nids = alc269_dac_nids,
12722                 .hp_nid = 0x03,
12723                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12724                 .channel_mode = alc269_modes,
12725                 .input_mux = &alc269_eeepc_amic_capture_source,
12726                 .unsol_event = alc269_eeepc_amic_unsol_event,
12727                 .init_hook = alc269_eeepc_amic_inithook,
12728         },
12729         [ALC269_ASUS_EEEPC_P901] = {
12730                 .mixers = { alc269_eeepc_mixer },
12731                 .cap_mixer = alc269_epc_capture_mixer,
12732                 .init_verbs = { alc269_init_verbs,
12733                                 alc269_eeepc_dmic_init_verbs },
12734                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12735                 .dac_nids = alc269_dac_nids,
12736                 .hp_nid = 0x03,
12737                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12738                 .channel_mode = alc269_modes,
12739                 .input_mux = &alc269_eeepc_dmic_capture_source,
12740                 .unsol_event = alc269_eeepc_dmic_unsol_event,
12741                 .init_hook = alc269_eeepc_dmic_inithook,
12742         },
12743         [ALC269_FUJITSU] = {
12744                 .mixers = { alc269_fujitsu_mixer, alc269_beep_mixer },
12745                 .cap_mixer = alc269_epc_capture_mixer,
12746                 .init_verbs = { alc269_init_verbs,
12747                                 alc269_eeepc_dmic_init_verbs },
12748                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12749                 .dac_nids = alc269_dac_nids,
12750                 .hp_nid = 0x03,
12751                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12752                 .channel_mode = alc269_modes,
12753                 .input_mux = &alc269_eeepc_dmic_capture_source,
12754                 .unsol_event = alc269_eeepc_dmic_unsol_event,
12755                 .init_hook = alc269_eeepc_dmic_inithook,
12756         },
12757         [ALC269_LIFEBOOK] = {
12758                 .mixers = { alc269_lifebook_mixer },
12759                 .init_verbs = { alc269_init_verbs, alc269_lifebook_verbs },
12760                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12761                 .dac_nids = alc269_dac_nids,
12762                 .hp_nid = 0x03,
12763                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12764                 .channel_mode = alc269_modes,
12765                 .input_mux = &alc269_capture_source,
12766                 .unsol_event = alc269_lifebook_unsol_event,
12767                 .init_hook = alc269_lifebook_init_hook,
12768         },
12769 };
12770
12771 static int patch_alc269(struct hda_codec *codec)
12772 {
12773         struct alc_spec *spec;
12774         int board_config;
12775         int err;
12776
12777         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
12778         if (spec == NULL)
12779                 return -ENOMEM;
12780
12781         codec->spec = spec;
12782
12783         alc_fix_pll_init(codec, 0x20, 0x04, 15);
12784
12785         board_config = snd_hda_check_board_config(codec, ALC269_MODEL_LAST,
12786                                                   alc269_models,
12787                                                   alc269_cfg_tbl);
12788
12789         if (board_config < 0) {
12790                 printk(KERN_INFO "hda_codec: Unknown model for ALC269, "
12791                        "trying auto-probe from BIOS...\n");
12792                 board_config = ALC269_AUTO;
12793         }
12794
12795         if (board_config == ALC269_AUTO) {
12796                 /* automatic parse from the BIOS config */
12797                 err = alc269_parse_auto_config(codec);
12798                 if (err < 0) {
12799                         alc_free(codec);
12800                         return err;
12801                 } else if (!err) {
12802                         printk(KERN_INFO
12803                                "hda_codec: Cannot set up configuration "
12804                                "from BIOS.  Using base mode...\n");
12805                         board_config = ALC269_BASIC;
12806                 }
12807         }
12808
12809         if (board_config != ALC269_AUTO)
12810                 setup_preset(spec, &alc269_presets[board_config]);
12811
12812         spec->stream_name_analog = "ALC269 Analog";
12813         spec->stream_analog_playback = &alc269_pcm_analog_playback;
12814         spec->stream_analog_capture = &alc269_pcm_analog_capture;
12815
12816         spec->stream_name_digital = "ALC269 Digital";
12817         spec->stream_digital_playback = &alc269_pcm_digital_playback;
12818         spec->stream_digital_capture = &alc269_pcm_digital_capture;
12819
12820         spec->adc_nids = alc269_adc_nids;
12821         spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids);
12822         spec->capsrc_nids = alc269_capsrc_nids;
12823         if (!spec->cap_mixer)
12824                 set_capture_mixer(spec);
12825
12826         codec->patch_ops = alc_patch_ops;
12827         if (board_config == ALC269_AUTO)
12828                 spec->init_hook = alc269_auto_init;
12829 #ifdef CONFIG_SND_HDA_POWER_SAVE
12830         if (!spec->loopback.amplist)
12831                 spec->loopback.amplist = alc269_loopbacks;
12832 #endif
12833         codec->proc_widget_hook = print_realtek_coef;
12834
12835         return 0;
12836 }
12837
12838 /*
12839  *  ALC861 channel source setting (2/6 channel selection for 3-stack)
12840  */
12841
12842 /*
12843  * set the path ways for 2 channel output
12844  * need to set the codec line out and mic 1 pin widgets to inputs
12845  */
12846 static struct hda_verb alc861_threestack_ch2_init[] = {
12847         /* set pin widget 1Ah (line in) for input */
12848         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12849         /* set pin widget 18h (mic1/2) for input, for mic also enable
12850          * the vref
12851          */
12852         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12853
12854         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
12855 #if 0
12856         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
12857         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
12858 #endif
12859         { } /* end */
12860 };
12861 /*
12862  * 6ch mode
12863  * need to set the codec line out and mic 1 pin widgets to outputs
12864  */
12865 static struct hda_verb alc861_threestack_ch6_init[] = {
12866         /* set pin widget 1Ah (line in) for output (Back Surround)*/
12867         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12868         /* set pin widget 18h (mic1) for output (CLFE)*/
12869         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12870
12871         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
12872         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
12873
12874         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
12875 #if 0
12876         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
12877         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
12878 #endif
12879         { } /* end */
12880 };
12881
12882 static struct hda_channel_mode alc861_threestack_modes[2] = {
12883         { 2, alc861_threestack_ch2_init },
12884         { 6, alc861_threestack_ch6_init },
12885 };
12886 /* Set mic1 as input and unmute the mixer */
12887 static struct hda_verb alc861_uniwill_m31_ch2_init[] = {
12888         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12889         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
12890         { } /* end */
12891 };
12892 /* Set mic1 as output and mute mixer */
12893 static struct hda_verb alc861_uniwill_m31_ch4_init[] = {
12894         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12895         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
12896         { } /* end */
12897 };
12898
12899 static struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
12900         { 2, alc861_uniwill_m31_ch2_init },
12901         { 4, alc861_uniwill_m31_ch4_init },
12902 };
12903
12904 /* Set mic1 and line-in as input and unmute the mixer */
12905 static struct hda_verb alc861_asus_ch2_init[] = {
12906         /* set pin widget 1Ah (line in) for input */
12907         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12908         /* set pin widget 18h (mic1/2) for input, for mic also enable
12909          * the vref
12910          */
12911         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12912
12913         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
12914 #if 0
12915         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
12916         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
12917 #endif
12918         { } /* end */
12919 };
12920 /* Set mic1 nad line-in as output and mute mixer */
12921 static struct hda_verb alc861_asus_ch6_init[] = {
12922         /* set pin widget 1Ah (line in) for output (Back Surround)*/
12923         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12924         /* { 0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
12925         /* set pin widget 18h (mic1) for output (CLFE)*/
12926         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12927         /* { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
12928         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
12929         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
12930
12931         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
12932 #if 0
12933         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
12934         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
12935 #endif
12936         { } /* end */
12937 };
12938
12939 static struct hda_channel_mode alc861_asus_modes[2] = {
12940         { 2, alc861_asus_ch2_init },
12941         { 6, alc861_asus_ch6_init },
12942 };
12943
12944 /* patch-ALC861 */
12945
12946 static struct snd_kcontrol_new alc861_base_mixer[] = {
12947         /* output mixer control */
12948         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12949         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12950         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12951         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12952         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
12953
12954         /*Input mixer control */
12955         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12956            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
12957         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12958         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12959         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12960         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12961         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12962         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12963         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12964         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
12965
12966         { } /* end */
12967 };
12968
12969 static struct snd_kcontrol_new alc861_3ST_mixer[] = {
12970         /* output mixer control */
12971         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12972         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12973         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12974         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12975         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
12976
12977         /* Input mixer control */
12978         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12979            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
12980         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12981         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12982         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12983         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12984         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12985         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12986         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12987         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
12988
12989         {
12990                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12991                 .name = "Channel Mode",
12992                 .info = alc_ch_mode_info,
12993                 .get = alc_ch_mode_get,
12994                 .put = alc_ch_mode_put,
12995                 .private_value = ARRAY_SIZE(alc861_threestack_modes),
12996         },
12997         { } /* end */
12998 };
12999
13000 static struct snd_kcontrol_new alc861_toshiba_mixer[] = {
13001         /* output mixer control */
13002         HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13003         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13004         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13005
13006         { } /* end */
13007 };
13008
13009 static struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
13010         /* output mixer control */
13011         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13012         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
13013         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
13014         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13015         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
13016
13017         /* Input mixer control */
13018         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13019            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
13020         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13021         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13022         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13023         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13024         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13025         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13026         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13027         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
13028
13029         {
13030                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13031                 .name = "Channel Mode",
13032                 .info = alc_ch_mode_info,
13033                 .get = alc_ch_mode_get,
13034                 .put = alc_ch_mode_put,
13035                 .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
13036         },
13037         { } /* end */
13038 };
13039
13040 static struct snd_kcontrol_new alc861_asus_mixer[] = {
13041         /* output mixer control */
13042         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13043         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
13044         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
13045         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13046         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
13047
13048         /* Input mixer control */
13049         HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13050         HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT),
13051         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13052         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13053         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13054         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13055         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13056         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13057         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13058         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT),
13059
13060         {
13061                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13062                 .name = "Channel Mode",
13063                 .info = alc_ch_mode_info,
13064                 .get = alc_ch_mode_get,
13065                 .put = alc_ch_mode_put,
13066                 .private_value = ARRAY_SIZE(alc861_asus_modes),
13067         },
13068         { }
13069 };
13070
13071 /* additional mixer */
13072 static struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
13073         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13074         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13075         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x23, 0x0, HDA_OUTPUT),
13076         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x23, 0x0, HDA_OUTPUT),
13077         { }
13078 };
13079
13080 /*
13081  * generic initialization of ADC, input mixers and output mixers
13082  */
13083 static struct hda_verb alc861_base_init_verbs[] = {
13084         /*
13085          * Unmute ADC0 and set the default input to mic-in
13086          */
13087         /* port-A for surround (rear panel) */
13088         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13089         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
13090         /* port-B for mic-in (rear panel) with vref */
13091         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13092         /* port-C for line-in (rear panel) */
13093         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13094         /* port-D for Front */
13095         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13096         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13097         /* port-E for HP out (front panel) */
13098         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
13099         /* route front PCM to HP */
13100         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13101         /* port-F for mic-in (front panel) with vref */
13102         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13103         /* port-G for CLFE (rear panel) */
13104         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13105         { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13106         /* port-H for side (rear panel) */
13107         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13108         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
13109         /* CD-in */
13110         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13111         /* route front mic to ADC1*/
13112         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13113         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13114
13115         /* Unmute DAC0~3 & spdif out*/
13116         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13117         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13118         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13119         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13120         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13121
13122         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13123         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13124         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13125         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13126         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13127
13128         /* Unmute Stereo Mixer 15 */
13129         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13130         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13131         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13132         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13133
13134         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13135         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13136         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13137         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13138         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13139         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13140         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13141         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13142         /* hp used DAC 3 (Front) */
13143         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13144         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13145
13146         { }
13147 };
13148
13149 static struct hda_verb alc861_threestack_init_verbs[] = {
13150         /*
13151          * Unmute ADC0 and set the default input to mic-in
13152          */
13153         /* port-A for surround (rear panel) */
13154         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13155         /* port-B for mic-in (rear panel) with vref */
13156         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13157         /* port-C for line-in (rear panel) */
13158         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13159         /* port-D for Front */
13160         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13161         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13162         /* port-E for HP out (front panel) */
13163         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
13164         /* route front PCM to HP */
13165         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13166         /* port-F for mic-in (front panel) with vref */
13167         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13168         /* port-G for CLFE (rear panel) */
13169         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13170         /* port-H for side (rear panel) */
13171         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13172         /* CD-in */
13173         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13174         /* route front mic to ADC1*/
13175         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13176         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13177         /* Unmute DAC0~3 & spdif out*/
13178         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13179         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13180         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13181         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13182         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13183
13184         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13185         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13186         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13187         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13188         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13189
13190         /* Unmute Stereo Mixer 15 */
13191         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13192         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13193         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13194         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13195
13196         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13197         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13198         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13199         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13200         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13201         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13202         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13203         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13204         /* hp used DAC 3 (Front) */
13205         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13206         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13207         { }
13208 };
13209
13210 static struct hda_verb alc861_uniwill_m31_init_verbs[] = {
13211         /*
13212          * Unmute ADC0 and set the default input to mic-in
13213          */
13214         /* port-A for surround (rear panel) */
13215         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13216         /* port-B for mic-in (rear panel) with vref */
13217         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13218         /* port-C for line-in (rear panel) */
13219         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13220         /* port-D for Front */
13221         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13222         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13223         /* port-E for HP out (front panel) */
13224         /* this has to be set to VREF80 */
13225         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13226         /* route front PCM to HP */
13227         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13228         /* port-F for mic-in (front panel) with vref */
13229         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13230         /* port-G for CLFE (rear panel) */
13231         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13232         /* port-H for side (rear panel) */
13233         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13234         /* CD-in */
13235         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13236         /* route front mic to ADC1*/
13237         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13238         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13239         /* Unmute DAC0~3 & spdif out*/
13240         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13241         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13242         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13243         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13244         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13245
13246         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13247         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13248         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13249         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13250         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13251
13252         /* Unmute Stereo Mixer 15 */
13253         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13254         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13255         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13256         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13257
13258         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13259         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13260         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13261         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13262         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13263         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13264         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13265         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13266         /* hp used DAC 3 (Front) */
13267         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13268         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13269         { }
13270 };
13271
13272 static struct hda_verb alc861_asus_init_verbs[] = {
13273         /*
13274          * Unmute ADC0 and set the default input to mic-in
13275          */
13276         /* port-A for surround (rear panel)
13277          * according to codec#0 this is the HP jack
13278          */
13279         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, /* was 0x00 */
13280         /* route front PCM to HP */
13281         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x01 },
13282         /* port-B for mic-in (rear panel) with vref */
13283         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13284         /* port-C for line-in (rear panel) */
13285         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13286         /* port-D for Front */
13287         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13288         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13289         /* port-E for HP out (front panel) */
13290         /* this has to be set to VREF80 */
13291         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13292         /* route front PCM to HP */
13293         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13294         /* port-F for mic-in (front panel) with vref */
13295         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13296         /* port-G for CLFE (rear panel) */
13297         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13298         /* port-H for side (rear panel) */
13299         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13300         /* CD-in */
13301         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13302         /* route front mic to ADC1*/
13303         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13304         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13305         /* Unmute DAC0~3 & spdif out*/
13306         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13307         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13308         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13309         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13310         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13311         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13312         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13313         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13314         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13315         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13316
13317         /* Unmute Stereo Mixer 15 */
13318         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13319         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13320         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13321         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13322
13323         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13324         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13325         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13326         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13327         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13328         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13329         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13330         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13331         /* hp used DAC 3 (Front) */
13332         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13333         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13334         { }
13335 };
13336
13337 /* additional init verbs for ASUS laptops */
13338 static struct hda_verb alc861_asus_laptop_init_verbs[] = {
13339         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x45 }, /* HP-out */
13340         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2) }, /* mute line-in */
13341         { }
13342 };
13343
13344 /*
13345  * generic initialization of ADC, input mixers and output mixers
13346  */
13347 static struct hda_verb alc861_auto_init_verbs[] = {
13348         /*
13349          * Unmute ADC0 and set the default input to mic-in
13350          */
13351         /* {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, */
13352         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13353
13354         /* Unmute DAC0~3 & spdif out*/
13355         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13356         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13357         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13358         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13359         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13360
13361         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13362         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13363         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13364         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13365         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13366
13367         /* Unmute Stereo Mixer 15 */
13368         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13369         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13370         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13371         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c},
13372
13373         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13374         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13375         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13376         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13377         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13378         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13379         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13380         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13381
13382         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13383         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13384         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13385         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13386         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13387         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13388         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13389         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13390
13391         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},  /* set Mic 1 */
13392
13393         { }
13394 };
13395
13396 static struct hda_verb alc861_toshiba_init_verbs[] = {
13397         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13398
13399         { }
13400 };
13401
13402 /* toggle speaker-output according to the hp-jack state */
13403 static void alc861_toshiba_automute(struct hda_codec *codec)
13404 {
13405         unsigned int present;
13406
13407         present = snd_hda_codec_read(codec, 0x0f, 0,
13408                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13409         snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
13410                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
13411         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
13412                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
13413 }
13414
13415 static void alc861_toshiba_unsol_event(struct hda_codec *codec,
13416                                        unsigned int res)
13417 {
13418         if ((res >> 26) == ALC880_HP_EVENT)
13419                 alc861_toshiba_automute(codec);
13420 }
13421
13422 /* pcm configuration: identiacal with ALC880 */
13423 #define alc861_pcm_analog_playback      alc880_pcm_analog_playback
13424 #define alc861_pcm_analog_capture       alc880_pcm_analog_capture
13425 #define alc861_pcm_digital_playback     alc880_pcm_digital_playback
13426 #define alc861_pcm_digital_capture      alc880_pcm_digital_capture
13427
13428
13429 #define ALC861_DIGOUT_NID       0x07
13430
13431 static struct hda_channel_mode alc861_8ch_modes[1] = {
13432         { 8, NULL }
13433 };
13434
13435 static hda_nid_t alc861_dac_nids[4] = {
13436         /* front, surround, clfe, side */
13437         0x03, 0x06, 0x05, 0x04
13438 };
13439
13440 static hda_nid_t alc660_dac_nids[3] = {
13441         /* front, clfe, surround */
13442         0x03, 0x05, 0x06
13443 };
13444
13445 static hda_nid_t alc861_adc_nids[1] = {
13446         /* ADC0-2 */
13447         0x08,
13448 };
13449
13450 static struct hda_input_mux alc861_capture_source = {
13451         .num_items = 5,
13452         .items = {
13453                 { "Mic", 0x0 },
13454                 { "Front Mic", 0x3 },
13455                 { "Line", 0x1 },
13456                 { "CD", 0x4 },
13457                 { "Mixer", 0x5 },
13458         },
13459 };
13460
13461 /* fill in the dac_nids table from the parsed pin configuration */
13462 static int alc861_auto_fill_dac_nids(struct alc_spec *spec,
13463                                      const struct auto_pin_cfg *cfg)
13464 {
13465         int i;
13466         hda_nid_t nid;
13467
13468         spec->multiout.dac_nids = spec->private_dac_nids;
13469         for (i = 0; i < cfg->line_outs; i++) {
13470                 nid = cfg->line_out_pins[i];
13471                 if (nid) {
13472                         if (i >= ARRAY_SIZE(alc861_dac_nids))
13473                                 continue;
13474                         spec->multiout.dac_nids[i] = alc861_dac_nids[i];
13475                 }
13476         }
13477         spec->multiout.num_dacs = cfg->line_outs;
13478         return 0;
13479 }
13480
13481 /* add playback controls from the parsed DAC table */
13482 static int alc861_auto_create_multi_out_ctls(struct alc_spec *spec,
13483                                              const struct auto_pin_cfg *cfg)
13484 {
13485         char name[32];
13486         static const char *chname[4] = {
13487                 "Front", "Surround", NULL /*CLFE*/, "Side"
13488         };
13489         hda_nid_t nid;
13490         int i, idx, err;
13491
13492         for (i = 0; i < cfg->line_outs; i++) {
13493                 nid = spec->multiout.dac_nids[i];
13494                 if (!nid)
13495                         continue;
13496                 if (nid == 0x05) {
13497                         /* Center/LFE */
13498                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13499                                           "Center Playback Switch",
13500                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
13501                                                               HDA_OUTPUT));
13502                         if (err < 0)
13503                                 return err;
13504                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13505                                           "LFE Playback Switch",
13506                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
13507                                                               HDA_OUTPUT));
13508                         if (err < 0)
13509                                 return err;
13510                 } else {
13511                         for (idx = 0; idx < ARRAY_SIZE(alc861_dac_nids) - 1;
13512                              idx++)
13513                                 if (nid == alc861_dac_nids[idx])
13514                                         break;
13515                         sprintf(name, "%s Playback Switch", chname[idx]);
13516                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
13517                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
13518                                                               HDA_OUTPUT));
13519                         if (err < 0)
13520                                 return err;
13521                 }
13522         }
13523         return 0;
13524 }
13525
13526 static int alc861_auto_create_hp_ctls(struct alc_spec *spec, hda_nid_t pin)
13527 {
13528         int err;
13529         hda_nid_t nid;
13530
13531         if (!pin)
13532                 return 0;
13533
13534         if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
13535                 nid = 0x03;
13536                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
13537                                   "Headphone Playback Switch",
13538                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
13539                 if (err < 0)
13540                         return err;
13541                 spec->multiout.hp_nid = nid;
13542         }
13543         return 0;
13544 }
13545
13546 /* create playback/capture controls for input pins */
13547 static int alc861_auto_create_analog_input_ctls(struct alc_spec *spec,
13548                                                 const struct auto_pin_cfg *cfg)
13549 {
13550         struct hda_input_mux *imux = &spec->private_imux[0];
13551         int i, err, idx, idx1;
13552
13553         for (i = 0; i < AUTO_PIN_LAST; i++) {
13554                 switch (cfg->input_pins[i]) {
13555                 case 0x0c:
13556                         idx1 = 1;
13557                         idx = 2;        /* Line In */
13558                         break;
13559                 case 0x0f:
13560                         idx1 = 2;
13561                         idx = 2;        /* Line In */
13562                         break;
13563                 case 0x0d:
13564                         idx1 = 0;
13565                         idx = 1;        /* Mic In */
13566                         break;
13567                 case 0x10:
13568                         idx1 = 3;
13569                         idx = 1;        /* Mic In */
13570                         break;
13571                 case 0x11:
13572                         idx1 = 4;
13573                         idx = 0;        /* CD */
13574                         break;
13575                 default:
13576                         continue;
13577                 }
13578
13579                 err = new_analog_input(spec, cfg->input_pins[i],
13580                                        auto_pin_cfg_labels[i], idx, 0x15);
13581                 if (err < 0)
13582                         return err;
13583
13584                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
13585                 imux->items[imux->num_items].index = idx1;
13586                 imux->num_items++;
13587         }
13588         return 0;
13589 }
13590
13591 static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
13592                                               hda_nid_t nid,
13593                                               int pin_type, int dac_idx)
13594 {
13595         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
13596                             pin_type);
13597         snd_hda_codec_write(codec, dac_idx, 0, AC_VERB_SET_AMP_GAIN_MUTE,
13598                             AMP_OUT_UNMUTE);
13599 }
13600
13601 static void alc861_auto_init_multi_out(struct hda_codec *codec)
13602 {
13603         struct alc_spec *spec = codec->spec;
13604         int i;
13605
13606         alc_subsystem_id(codec, 0x0e, 0x0f, 0x0b);
13607         for (i = 0; i < spec->autocfg.line_outs; i++) {
13608                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
13609                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
13610                 if (nid)
13611                         alc861_auto_set_output_and_unmute(codec, nid, pin_type,
13612                                                           spec->multiout.dac_nids[i]);
13613         }
13614 }
13615
13616 static void alc861_auto_init_hp_out(struct hda_codec *codec)
13617 {
13618         struct alc_spec *spec = codec->spec;
13619         hda_nid_t pin;
13620
13621         pin = spec->autocfg.hp_pins[0];
13622         if (pin) /* connect to front */
13623                 alc861_auto_set_output_and_unmute(codec, pin, PIN_HP,
13624                                                   spec->multiout.dac_nids[0]);
13625         pin = spec->autocfg.speaker_pins[0];
13626         if (pin)
13627                 alc861_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
13628 }
13629
13630 static void alc861_auto_init_analog_input(struct hda_codec *codec)
13631 {
13632         struct alc_spec *spec = codec->spec;
13633         int i;
13634
13635         for (i = 0; i < AUTO_PIN_LAST; i++) {
13636                 hda_nid_t nid = spec->autocfg.input_pins[i];
13637                 if (nid >= 0x0c && nid <= 0x11) {
13638                         snd_hda_codec_write(codec, nid, 0,
13639                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
13640                                             i <= AUTO_PIN_FRONT_MIC ?
13641                                             PIN_VREF80 : PIN_IN);
13642                 }
13643         }
13644 }
13645
13646 /* parse the BIOS configuration and set up the alc_spec */
13647 /* return 1 if successful, 0 if the proper config is not found,
13648  * or a negative error code
13649  */
13650 static int alc861_parse_auto_config(struct hda_codec *codec)
13651 {
13652         struct alc_spec *spec = codec->spec;
13653         int err;
13654         static hda_nid_t alc861_ignore[] = { 0x1d, 0 };
13655
13656         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
13657                                            alc861_ignore);
13658         if (err < 0)
13659                 return err;
13660         if (!spec->autocfg.line_outs)
13661                 return 0; /* can't find valid BIOS pin config */
13662
13663         err = alc861_auto_fill_dac_nids(spec, &spec->autocfg);
13664         if (err < 0)
13665                 return err;
13666         err = alc861_auto_create_multi_out_ctls(spec, &spec->autocfg);
13667         if (err < 0)
13668                 return err;
13669         err = alc861_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
13670         if (err < 0)
13671                 return err;
13672         err = alc861_auto_create_analog_input_ctls(spec, &spec->autocfg);
13673         if (err < 0)
13674                 return err;
13675
13676         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
13677
13678         if (spec->autocfg.dig_out_pin)
13679                 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;
13680
13681         if (spec->kctls.list)
13682                 add_mixer(spec, spec->kctls.list);
13683
13684         add_verb(spec, alc861_auto_init_verbs);
13685
13686         spec->num_mux_defs = 1;
13687         spec->input_mux = &spec->private_imux[0];
13688
13689         spec->adc_nids = alc861_adc_nids;
13690         spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
13691         set_capture_mixer(spec);
13692
13693         store_pin_configs(codec);
13694         return 1;
13695 }
13696
13697 /* additional initialization for auto-configuration model */
13698 static void alc861_auto_init(struct hda_codec *codec)
13699 {
13700         struct alc_spec *spec = codec->spec;
13701         alc861_auto_init_multi_out(codec);
13702         alc861_auto_init_hp_out(codec);
13703         alc861_auto_init_analog_input(codec);
13704         if (spec->unsol_event)
13705                 alc_inithook(codec);
13706 }
13707
13708 #ifdef CONFIG_SND_HDA_POWER_SAVE
13709 static struct hda_amp_list alc861_loopbacks[] = {
13710         { 0x15, HDA_INPUT, 0 },
13711         { 0x15, HDA_INPUT, 1 },
13712         { 0x15, HDA_INPUT, 2 },
13713         { 0x15, HDA_INPUT, 3 },
13714         { } /* end */
13715 };
13716 #endif
13717
13718
13719 /*
13720  * configuration and preset
13721  */
13722 static const char *alc861_models[ALC861_MODEL_LAST] = {
13723         [ALC861_3ST]            = "3stack",
13724         [ALC660_3ST]            = "3stack-660",
13725         [ALC861_3ST_DIG]        = "3stack-dig",
13726         [ALC861_6ST_DIG]        = "6stack-dig",
13727         [ALC861_UNIWILL_M31]    = "uniwill-m31",
13728         [ALC861_TOSHIBA]        = "toshiba",
13729         [ALC861_ASUS]           = "asus",
13730         [ALC861_ASUS_LAPTOP]    = "asus-laptop",
13731         [ALC861_AUTO]           = "auto",
13732 };
13733
13734 static struct snd_pci_quirk alc861_cfg_tbl[] = {
13735         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC861_3ST),
13736         SND_PCI_QUIRK(0x1043, 0x1335, "ASUS F2/3", ALC861_ASUS_LAPTOP),
13737         SND_PCI_QUIRK(0x1043, 0x1338, "ASUS F2/3", ALC861_ASUS_LAPTOP),
13738         SND_PCI_QUIRK(0x1043, 0x1393, "ASUS", ALC861_ASUS),
13739         SND_PCI_QUIRK(0x1043, 0x13d7, "ASUS A9rp", ALC861_ASUS_LAPTOP),
13740         SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS P1-AH2", ALC861_3ST_DIG),
13741         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba", ALC861_TOSHIBA),
13742         /* FIXME: the entry below breaks Toshiba A100 (model=auto works!)
13743          *        Any other models that need this preset?
13744          */
13745         /* SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba", ALC861_TOSHIBA), */
13746         SND_PCI_QUIRK(0x1462, 0x7254, "HP dx2200 (MSI MS-7254)", ALC861_3ST),
13747         SND_PCI_QUIRK(0x1462, 0x7297, "HP dx2250 (MSI MS-7297)", ALC861_3ST),
13748         SND_PCI_QUIRK(0x1584, 0x2b01, "Uniwill X40AIx", ALC861_UNIWILL_M31),
13749         SND_PCI_QUIRK(0x1584, 0x9072, "Uniwill m31", ALC861_UNIWILL_M31),
13750         SND_PCI_QUIRK(0x1584, 0x9075, "Airis Praxis N1212", ALC861_ASUS_LAPTOP),
13751         /* FIXME: the below seems conflict */
13752         /* SND_PCI_QUIRK(0x1584, 0x9075, "Uniwill", ALC861_UNIWILL_M31), */
13753         SND_PCI_QUIRK(0x1849, 0x0660, "Asrock 939SLI32", ALC660_3ST),
13754         SND_PCI_QUIRK(0x8086, 0xd600, "Intel", ALC861_3ST),
13755         {}
13756 };
13757
13758 static struct alc_config_preset alc861_presets[] = {
13759         [ALC861_3ST] = {
13760                 .mixers = { alc861_3ST_mixer },
13761                 .init_verbs = { alc861_threestack_init_verbs },
13762                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13763                 .dac_nids = alc861_dac_nids,
13764                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
13765                 .channel_mode = alc861_threestack_modes,
13766                 .need_dac_fix = 1,
13767                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13768                 .adc_nids = alc861_adc_nids,
13769                 .input_mux = &alc861_capture_source,
13770         },
13771         [ALC861_3ST_DIG] = {
13772                 .mixers = { alc861_base_mixer },
13773                 .init_verbs = { alc861_threestack_init_verbs },
13774                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13775                 .dac_nids = alc861_dac_nids,
13776                 .dig_out_nid = ALC861_DIGOUT_NID,
13777                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
13778                 .channel_mode = alc861_threestack_modes,
13779                 .need_dac_fix = 1,
13780                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13781                 .adc_nids = alc861_adc_nids,
13782                 .input_mux = &alc861_capture_source,
13783         },
13784         [ALC861_6ST_DIG] = {
13785                 .mixers = { alc861_base_mixer },
13786                 .init_verbs = { alc861_base_init_verbs },
13787                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13788                 .dac_nids = alc861_dac_nids,
13789                 .dig_out_nid = ALC861_DIGOUT_NID,
13790                 .num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
13791                 .channel_mode = alc861_8ch_modes,
13792                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13793                 .adc_nids = alc861_adc_nids,
13794                 .input_mux = &alc861_capture_source,
13795         },
13796         [ALC660_3ST] = {
13797                 .mixers = { alc861_3ST_mixer },
13798                 .init_verbs = { alc861_threestack_init_verbs },
13799                 .num_dacs = ARRAY_SIZE(alc660_dac_nids),
13800                 .dac_nids = alc660_dac_nids,
13801                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
13802                 .channel_mode = alc861_threestack_modes,
13803                 .need_dac_fix = 1,
13804                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13805                 .adc_nids = alc861_adc_nids,
13806                 .input_mux = &alc861_capture_source,
13807         },
13808         [ALC861_UNIWILL_M31] = {
13809                 .mixers = { alc861_uniwill_m31_mixer },
13810                 .init_verbs = { alc861_uniwill_m31_init_verbs },
13811                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13812                 .dac_nids = alc861_dac_nids,
13813                 .dig_out_nid = ALC861_DIGOUT_NID,
13814                 .num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
13815                 .channel_mode = alc861_uniwill_m31_modes,
13816                 .need_dac_fix = 1,
13817                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13818                 .adc_nids = alc861_adc_nids,
13819                 .input_mux = &alc861_capture_source,
13820         },
13821         [ALC861_TOSHIBA] = {
13822                 .mixers = { alc861_toshiba_mixer },
13823                 .init_verbs = { alc861_base_init_verbs,
13824                                 alc861_toshiba_init_verbs },
13825                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13826                 .dac_nids = alc861_dac_nids,
13827                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
13828                 .channel_mode = alc883_3ST_2ch_modes,
13829                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13830                 .adc_nids = alc861_adc_nids,
13831                 .input_mux = &alc861_capture_source,
13832                 .unsol_event = alc861_toshiba_unsol_event,
13833                 .init_hook = alc861_toshiba_automute,
13834         },
13835         [ALC861_ASUS] = {
13836                 .mixers = { alc861_asus_mixer },
13837                 .init_verbs = { alc861_asus_init_verbs },
13838                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13839                 .dac_nids = alc861_dac_nids,
13840                 .dig_out_nid = ALC861_DIGOUT_NID,
13841                 .num_channel_mode = ARRAY_SIZE(alc861_asus_modes),
13842                 .channel_mode = alc861_asus_modes,
13843                 .need_dac_fix = 1,
13844                 .hp_nid = 0x06,
13845                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13846                 .adc_nids = alc861_adc_nids,
13847                 .input_mux = &alc861_capture_source,
13848         },
13849         [ALC861_ASUS_LAPTOP] = {
13850                 .mixers = { alc861_toshiba_mixer, alc861_asus_laptop_mixer },
13851                 .init_verbs = { alc861_asus_init_verbs,
13852                                 alc861_asus_laptop_init_verbs },
13853                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13854                 .dac_nids = alc861_dac_nids,
13855                 .dig_out_nid = ALC861_DIGOUT_NID,
13856                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
13857                 .channel_mode = alc883_3ST_2ch_modes,
13858                 .need_dac_fix = 1,
13859                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13860                 .adc_nids = alc861_adc_nids,
13861                 .input_mux = &alc861_capture_source,
13862         },
13863 };
13864
13865
13866 static int patch_alc861(struct hda_codec *codec)
13867 {
13868         struct alc_spec *spec;
13869         int board_config;
13870         int err;
13871
13872         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
13873         if (spec == NULL)
13874                 return -ENOMEM;
13875
13876         codec->spec = spec;
13877
13878         board_config = snd_hda_check_board_config(codec, ALC861_MODEL_LAST,
13879                                                   alc861_models,
13880                                                   alc861_cfg_tbl);
13881
13882         if (board_config < 0) {
13883                 printk(KERN_INFO "hda_codec: Unknown model for ALC861, "
13884                        "trying auto-probe from BIOS...\n");
13885                 board_config = ALC861_AUTO;
13886         }
13887
13888         if (board_config == ALC861_AUTO) {
13889                 /* automatic parse from the BIOS config */
13890                 err = alc861_parse_auto_config(codec);
13891                 if (err < 0) {
13892                         alc_free(codec);
13893                         return err;
13894                 } else if (!err) {
13895                         printk(KERN_INFO
13896                                "hda_codec: Cannot set up configuration "
13897                                "from BIOS.  Using base mode...\n");
13898                    board_config = ALC861_3ST_DIG;
13899                 }
13900         }
13901
13902         if (board_config != ALC861_AUTO)
13903                 setup_preset(spec, &alc861_presets[board_config]);
13904
13905         spec->stream_name_analog = "ALC861 Analog";
13906         spec->stream_analog_playback = &alc861_pcm_analog_playback;
13907         spec->stream_analog_capture = &alc861_pcm_analog_capture;
13908
13909         spec->stream_name_digital = "ALC861 Digital";
13910         spec->stream_digital_playback = &alc861_pcm_digital_playback;
13911         spec->stream_digital_capture = &alc861_pcm_digital_capture;
13912
13913         spec->vmaster_nid = 0x03;
13914
13915         codec->patch_ops = alc_patch_ops;
13916         if (board_config == ALC861_AUTO)
13917                 spec->init_hook = alc861_auto_init;
13918 #ifdef CONFIG_SND_HDA_POWER_SAVE
13919         if (!spec->loopback.amplist)
13920                 spec->loopback.amplist = alc861_loopbacks;
13921 #endif
13922         codec->proc_widget_hook = print_realtek_coef;
13923
13924         return 0;
13925 }
13926
13927 /*
13928  * ALC861-VD support
13929  *
13930  * Based on ALC882
13931  *
13932  * In addition, an independent DAC
13933  */
13934 #define ALC861VD_DIGOUT_NID     0x06
13935
13936 static hda_nid_t alc861vd_dac_nids[4] = {
13937         /* front, surr, clfe, side surr */
13938         0x02, 0x03, 0x04, 0x05
13939 };
13940
13941 /* dac_nids for ALC660vd are in a different order - according to
13942  * Realtek's driver.
13943  * This should probably tesult in a different mixer for 6stack models
13944  * of ALC660vd codecs, but for now there is only 3stack mixer
13945  * - and it is the same as in 861vd.
13946  * adc_nids in ALC660vd are (is) the same as in 861vd
13947  */
13948 static hda_nid_t alc660vd_dac_nids[3] = {
13949         /* front, rear, clfe, rear_surr */
13950         0x02, 0x04, 0x03
13951 };
13952
13953 static hda_nid_t alc861vd_adc_nids[1] = {
13954         /* ADC0 */
13955         0x09,
13956 };
13957
13958 static hda_nid_t alc861vd_capsrc_nids[1] = { 0x22 };
13959
13960 /* input MUX */
13961 /* FIXME: should be a matrix-type input source selection */
13962 static struct hda_input_mux alc861vd_capture_source = {
13963         .num_items = 4,
13964         .items = {
13965                 { "Mic", 0x0 },
13966                 { "Front Mic", 0x1 },
13967                 { "Line", 0x2 },
13968                 { "CD", 0x4 },
13969         },
13970 };
13971
13972 static struct hda_input_mux alc861vd_dallas_capture_source = {
13973         .num_items = 2,
13974         .items = {
13975                 { "Ext Mic", 0x0 },
13976                 { "Int Mic", 0x1 },
13977         },
13978 };
13979
13980 static struct hda_input_mux alc861vd_hp_capture_source = {
13981         .num_items = 2,
13982         .items = {
13983                 { "Front Mic", 0x0 },
13984                 { "ATAPI Mic", 0x1 },
13985         },
13986 };
13987
13988 /*
13989  * 2ch mode
13990  */
13991 static struct hda_channel_mode alc861vd_3stack_2ch_modes[1] = {
13992         { 2, NULL }
13993 };
13994
13995 /*
13996  * 6ch mode
13997  */
13998 static struct hda_verb alc861vd_6stack_ch6_init[] = {
13999         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
14000         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14001         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14002         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14003         { } /* end */
14004 };
14005
14006 /*
14007  * 8ch mode
14008  */
14009 static struct hda_verb alc861vd_6stack_ch8_init[] = {
14010         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14011         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14012         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14013         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14014         { } /* end */
14015 };
14016
14017 static struct hda_channel_mode alc861vd_6stack_modes[2] = {
14018         { 6, alc861vd_6stack_ch6_init },
14019         { 8, alc861vd_6stack_ch8_init },
14020 };
14021
14022 static struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
14023         {
14024                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
14025                 .name = "Channel Mode",
14026                 .info = alc_ch_mode_info,
14027                 .get = alc_ch_mode_get,
14028                 .put = alc_ch_mode_put,
14029         },
14030         { } /* end */
14031 };
14032
14033 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
14034  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
14035  */
14036 static struct snd_kcontrol_new alc861vd_6st_mixer[] = {
14037         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14038         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14039
14040         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14041         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
14042
14043         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0,
14044                                 HDA_OUTPUT),
14045         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0,
14046                                 HDA_OUTPUT),
14047         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
14048         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
14049
14050         HDA_CODEC_VOLUME("Side Playback Volume", 0x05, 0x0, HDA_OUTPUT),
14051         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
14052
14053         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14054
14055         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
14056         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14057         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14058
14059         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
14060         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14061         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14062
14063         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14064         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14065
14066         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14067         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14068
14069         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
14070         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
14071
14072         { } /* end */
14073 };
14074
14075 static struct snd_kcontrol_new alc861vd_3st_mixer[] = {
14076         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14077         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14078
14079         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14080
14081         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
14082         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14083         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14084
14085         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
14086         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14087         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14088
14089         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14090         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14091
14092         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14093         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14094
14095         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
14096         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
14097
14098         { } /* end */
14099 };
14100
14101 static struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
14102         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14103         /*HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),*/
14104         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14105
14106         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14107
14108         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
14109         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14110         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14111
14112         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
14113         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14114         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14115
14116         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14117         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14118
14119         { } /* end */
14120 };
14121
14122 /* Pin assignment: Speaker=0x14, HP = 0x15,
14123  *                 Ext Mic=0x18, Int Mic = 0x19, CD = 0x1c, PC Beep = 0x1d
14124  */
14125 static struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
14126         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14127         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
14128         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14129         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
14130         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
14131         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14132         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14133         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
14134         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14135         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14136         HDA_CODEC_VOLUME("PC Beep Volume", 0x0b, 0x05, HDA_INPUT),
14137         HDA_CODEC_MUTE("PC Beep Switch", 0x0b, 0x05, HDA_INPUT),
14138         { } /* end */
14139 };
14140
14141 /* Pin assignment: Speaker=0x14, Line-out = 0x15,
14142  *                 Front Mic=0x18, ATAPI Mic = 0x19,
14143  */
14144 static struct snd_kcontrol_new alc861vd_hp_mixer[] = {
14145         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14146         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14147         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14148         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
14149         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14150         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14151         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14152         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14153
14154         { } /* end */
14155 };
14156
14157 /*
14158  * generic initialization of ADC, input mixers and output mixers
14159  */
14160 static struct hda_verb alc861vd_volume_init_verbs[] = {
14161         /*
14162          * Unmute ADC0 and set the default input to mic-in
14163          */
14164         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
14165         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14166
14167         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of
14168          * the analog-loopback mixer widget
14169          */
14170         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
14171         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14172         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14173         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14174         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14175         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14176
14177         /* Capture mixer: unmute Mic, F-Mic, Line, CD inputs */
14178         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14179         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14180         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14181         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
14182
14183         /*
14184          * Set up output mixers (0x02 - 0x05)
14185          */
14186         /* set vol=0 to output mixers */
14187         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14188         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14189         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14190         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14191
14192         /* set up input amps for analog loopback */
14193         /* Amp Indices: DAC = 0, mixer = 1 */
14194         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14195         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14196         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14197         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14198         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14199         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14200         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14201         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14202
14203         { }
14204 };
14205
14206 /*
14207  * 3-stack pin configuration:
14208  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
14209  */
14210 static struct hda_verb alc861vd_3stack_init_verbs[] = {
14211         /*
14212          * Set pin mode and muting
14213          */
14214         /* set front pin widgets 0x14 for output */
14215         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14216         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14217         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
14218
14219         /* Mic (rear) pin: input vref at 80% */
14220         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14221         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14222         /* Front Mic pin: input vref at 80% */
14223         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14224         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14225         /* Line In pin: input */
14226         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14227         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14228         /* Line-2 In: Headphone output (output 0 - 0x0c) */
14229         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14230         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14231         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
14232         /* CD pin widget for input */
14233         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14234
14235         { }
14236 };
14237
14238 /*
14239  * 6-stack pin configuration:
14240  */
14241 static struct hda_verb alc861vd_6stack_init_verbs[] = {
14242         /*
14243          * Set pin mode and muting
14244          */
14245         /* set front pin widgets 0x14 for output */
14246         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14247         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14248         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
14249
14250         /* Rear Pin: output 1 (0x0d) */
14251         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14252         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14253         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
14254         /* CLFE Pin: output 2 (0x0e) */
14255         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14256         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14257         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
14258         /* Side Pin: output 3 (0x0f) */
14259         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14260         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14261         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
14262
14263         /* Mic (rear) pin: input vref at 80% */
14264         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14265         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14266         /* Front Mic pin: input vref at 80% */
14267         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14268         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14269         /* Line In pin: input */
14270         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14271         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14272         /* Line-2 In: Headphone output (output 0 - 0x0c) */
14273         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14274         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14275         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
14276         /* CD pin widget for input */
14277         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14278
14279         { }
14280 };
14281
14282 static struct hda_verb alc861vd_eapd_verbs[] = {
14283         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
14284         { }
14285 };
14286
14287 static struct hda_verb alc660vd_eapd_verbs[] = {
14288         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
14289         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
14290         { }
14291 };
14292
14293 static struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
14294         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14295         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14296         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
14297         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14298         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14299         {}
14300 };
14301
14302 /* toggle speaker-output according to the hp-jack state */
14303 static void alc861vd_lenovo_hp_automute(struct hda_codec *codec)
14304 {
14305         unsigned int present;
14306         unsigned char bits;
14307
14308         present = snd_hda_codec_read(codec, 0x1b, 0,
14309                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14310         bits = present ? HDA_AMP_MUTE : 0;
14311         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
14312                                  HDA_AMP_MUTE, bits);
14313 }
14314
14315 static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
14316 {
14317         unsigned int present;
14318         unsigned char bits;
14319
14320         present = snd_hda_codec_read(codec, 0x18, 0,
14321                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14322         bits = present ? HDA_AMP_MUTE : 0;
14323         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
14324                                  HDA_AMP_MUTE, bits);
14325 }
14326
14327 static void alc861vd_lenovo_automute(struct hda_codec *codec)
14328 {
14329         alc861vd_lenovo_hp_automute(codec);
14330         alc861vd_lenovo_mic_automute(codec);
14331 }
14332
14333 static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
14334                                         unsigned int res)
14335 {
14336         switch (res >> 26) {
14337         case ALC880_HP_EVENT:
14338                 alc861vd_lenovo_hp_automute(codec);
14339                 break;
14340         case ALC880_MIC_EVENT:
14341                 alc861vd_lenovo_mic_automute(codec);
14342                 break;
14343         }
14344 }
14345
14346 static struct hda_verb alc861vd_dallas_verbs[] = {
14347         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14348         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14349         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14350         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14351
14352         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14353         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14354         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14355         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14356         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14357         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14358         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14359         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14360
14361         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14362         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14363         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14364         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14365         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14366         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14367         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14368         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14369
14370         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
14371         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14372         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
14373         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14374         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14375         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14376         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14377         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14378
14379         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14380         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14381         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14382         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14383
14384         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14385         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
14386         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14387
14388         { } /* end */
14389 };
14390
14391 /* toggle speaker-output according to the hp-jack state */
14392 static void alc861vd_dallas_automute(struct hda_codec *codec)
14393 {
14394         unsigned int present;
14395
14396         present = snd_hda_codec_read(codec, 0x15, 0,
14397                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14398         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
14399                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
14400 }
14401
14402 static void alc861vd_dallas_unsol_event(struct hda_codec *codec, unsigned int res)
14403 {
14404         if ((res >> 26) == ALC880_HP_EVENT)
14405                 alc861vd_dallas_automute(codec);
14406 }
14407
14408 #ifdef CONFIG_SND_HDA_POWER_SAVE
14409 #define alc861vd_loopbacks      alc880_loopbacks
14410 #endif
14411
14412 /* pcm configuration: identiacal with ALC880 */
14413 #define alc861vd_pcm_analog_playback    alc880_pcm_analog_playback
14414 #define alc861vd_pcm_analog_capture     alc880_pcm_analog_capture
14415 #define alc861vd_pcm_digital_playback   alc880_pcm_digital_playback
14416 #define alc861vd_pcm_digital_capture    alc880_pcm_digital_capture
14417
14418 /*
14419  * configuration and preset
14420  */
14421 static const char *alc861vd_models[ALC861VD_MODEL_LAST] = {
14422         [ALC660VD_3ST]          = "3stack-660",
14423         [ALC660VD_3ST_DIG]      = "3stack-660-digout",
14424         [ALC660VD_ASUS_V1S]     = "asus-v1s",
14425         [ALC861VD_3ST]          = "3stack",
14426         [ALC861VD_3ST_DIG]      = "3stack-digout",
14427         [ALC861VD_6ST_DIG]      = "6stack-digout",
14428         [ALC861VD_LENOVO]       = "lenovo",
14429         [ALC861VD_DALLAS]       = "dallas",
14430         [ALC861VD_HP]           = "hp",
14431         [ALC861VD_AUTO]         = "auto",
14432 };
14433
14434 static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
14435         SND_PCI_QUIRK(0x1019, 0xa88d, "Realtek ALC660 demo", ALC660VD_3ST),
14436         SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_HP),
14437         SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST),
14438         SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),
14439         SND_PCI_QUIRK(0x1043, 0x1633, "Asus V1Sn", ALC660VD_ASUS_V1S),
14440         SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG),
14441         SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
14442         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
14443         /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
14444         SND_PCI_QUIRK(0x1179, 0xff01, "DALLAS", ALC861VD_DALLAS),
14445         SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
14446         SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_DALLAS),
14447         SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
14448         SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo", ALC861VD_LENOVO),
14449         SND_PCI_QUIRK(0x17aa, 0x3802, "Lenovo 3000 C200", ALC861VD_LENOVO),
14450         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 N200", ALC861VD_LENOVO),
14451         SND_PCI_QUIRK(0x1849, 0x0862, "ASRock K8NF6G-VSTA", ALC861VD_6ST_DIG),
14452         {}
14453 };
14454
14455 static struct alc_config_preset alc861vd_presets[] = {
14456         [ALC660VD_3ST] = {
14457                 .mixers = { alc861vd_3st_mixer },
14458                 .init_verbs = { alc861vd_volume_init_verbs,
14459                                  alc861vd_3stack_init_verbs },
14460                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14461                 .dac_nids = alc660vd_dac_nids,
14462                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14463                 .channel_mode = alc861vd_3stack_2ch_modes,
14464                 .input_mux = &alc861vd_capture_source,
14465         },
14466         [ALC660VD_3ST_DIG] = {
14467                 .mixers = { alc861vd_3st_mixer },
14468                 .init_verbs = { alc861vd_volume_init_verbs,
14469                                  alc861vd_3stack_init_verbs },
14470                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14471                 .dac_nids = alc660vd_dac_nids,
14472                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14473                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14474                 .channel_mode = alc861vd_3stack_2ch_modes,
14475                 .input_mux = &alc861vd_capture_source,
14476         },
14477         [ALC861VD_3ST] = {
14478                 .mixers = { alc861vd_3st_mixer },
14479                 .init_verbs = { alc861vd_volume_init_verbs,
14480                                  alc861vd_3stack_init_verbs },
14481                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14482                 .dac_nids = alc861vd_dac_nids,
14483                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14484                 .channel_mode = alc861vd_3stack_2ch_modes,
14485                 .input_mux = &alc861vd_capture_source,
14486         },
14487         [ALC861VD_3ST_DIG] = {
14488                 .mixers = { alc861vd_3st_mixer },
14489                 .init_verbs = { alc861vd_volume_init_verbs,
14490                                  alc861vd_3stack_init_verbs },
14491                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14492                 .dac_nids = alc861vd_dac_nids,
14493                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14494                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14495                 .channel_mode = alc861vd_3stack_2ch_modes,
14496                 .input_mux = &alc861vd_capture_source,
14497         },
14498         [ALC861VD_6ST_DIG] = {
14499                 .mixers = { alc861vd_6st_mixer, alc861vd_chmode_mixer },
14500                 .init_verbs = { alc861vd_volume_init_verbs,
14501                                 alc861vd_6stack_init_verbs },
14502                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14503                 .dac_nids = alc861vd_dac_nids,
14504                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14505                 .num_channel_mode = ARRAY_SIZE(alc861vd_6stack_modes),
14506                 .channel_mode = alc861vd_6stack_modes,
14507                 .input_mux = &alc861vd_capture_source,
14508         },
14509         [ALC861VD_LENOVO] = {
14510                 .mixers = { alc861vd_lenovo_mixer },
14511                 .init_verbs = { alc861vd_volume_init_verbs,
14512                                 alc861vd_3stack_init_verbs,
14513                                 alc861vd_eapd_verbs,
14514                                 alc861vd_lenovo_unsol_verbs },
14515                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14516                 .dac_nids = alc660vd_dac_nids,
14517                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14518                 .channel_mode = alc861vd_3stack_2ch_modes,
14519                 .input_mux = &alc861vd_capture_source,
14520                 .unsol_event = alc861vd_lenovo_unsol_event,
14521                 .init_hook = alc861vd_lenovo_automute,
14522         },
14523         [ALC861VD_DALLAS] = {
14524                 .mixers = { alc861vd_dallas_mixer },
14525                 .init_verbs = { alc861vd_dallas_verbs },
14526                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14527                 .dac_nids = alc861vd_dac_nids,
14528                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14529                 .channel_mode = alc861vd_3stack_2ch_modes,
14530                 .input_mux = &alc861vd_dallas_capture_source,
14531                 .unsol_event = alc861vd_dallas_unsol_event,
14532                 .init_hook = alc861vd_dallas_automute,
14533         },
14534         [ALC861VD_HP] = {
14535                 .mixers = { alc861vd_hp_mixer },
14536                 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs },
14537                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14538                 .dac_nids = alc861vd_dac_nids,
14539                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14540                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14541                 .channel_mode = alc861vd_3stack_2ch_modes,
14542                 .input_mux = &alc861vd_hp_capture_source,
14543                 .unsol_event = alc861vd_dallas_unsol_event,
14544                 .init_hook = alc861vd_dallas_automute,
14545         },
14546         [ALC660VD_ASUS_V1S] = {
14547                 .mixers = { alc861vd_lenovo_mixer },
14548                 .init_verbs = { alc861vd_volume_init_verbs,
14549                                 alc861vd_3stack_init_verbs,
14550                                 alc861vd_eapd_verbs,
14551                                 alc861vd_lenovo_unsol_verbs },
14552                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14553                 .dac_nids = alc660vd_dac_nids,
14554                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14555                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14556                 .channel_mode = alc861vd_3stack_2ch_modes,
14557                 .input_mux = &alc861vd_capture_source,
14558                 .unsol_event = alc861vd_lenovo_unsol_event,
14559                 .init_hook = alc861vd_lenovo_automute,
14560         },
14561 };
14562
14563 /*
14564  * BIOS auto configuration
14565  */
14566 static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
14567                                 hda_nid_t nid, int pin_type, int dac_idx)
14568 {
14569         alc_set_pin_output(codec, nid, pin_type);
14570 }
14571
14572 static void alc861vd_auto_init_multi_out(struct hda_codec *codec)
14573 {
14574         struct alc_spec *spec = codec->spec;
14575         int i;
14576
14577         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
14578         for (i = 0; i <= HDA_SIDE; i++) {
14579                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
14580                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
14581                 if (nid)
14582                         alc861vd_auto_set_output_and_unmute(codec, nid,
14583                                                             pin_type, i);
14584         }
14585 }
14586
14587
14588 static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
14589 {
14590         struct alc_spec *spec = codec->spec;
14591         hda_nid_t pin;
14592
14593         pin = spec->autocfg.hp_pins[0];
14594         if (pin) /* connect to front and  use dac 0 */
14595                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
14596         pin = spec->autocfg.speaker_pins[0];
14597         if (pin)
14598                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
14599 }
14600
14601 #define alc861vd_is_input_pin(nid)      alc880_is_input_pin(nid)
14602 #define ALC861VD_PIN_CD_NID             ALC880_PIN_CD_NID
14603
14604 static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
14605 {
14606         struct alc_spec *spec = codec->spec;
14607         int i;
14608
14609         for (i = 0; i < AUTO_PIN_LAST; i++) {
14610                 hda_nid_t nid = spec->autocfg.input_pins[i];
14611                 if (alc861vd_is_input_pin(nid)) {
14612                         snd_hda_codec_write(codec, nid, 0,
14613                                         AC_VERB_SET_PIN_WIDGET_CONTROL,
14614                                         i <= AUTO_PIN_FRONT_MIC ?
14615                                                         PIN_VREF80 : PIN_IN);
14616                         if (nid != ALC861VD_PIN_CD_NID)
14617                                 snd_hda_codec_write(codec, nid, 0,
14618                                                 AC_VERB_SET_AMP_GAIN_MUTE,
14619                                                 AMP_OUT_MUTE);
14620                 }
14621         }
14622 }
14623
14624 #define alc861vd_auto_init_input_src    alc882_auto_init_input_src
14625
14626 #define alc861vd_idx_to_mixer_vol(nid)          ((nid) + 0x02)
14627 #define alc861vd_idx_to_mixer_switch(nid)       ((nid) + 0x0c)
14628
14629 /* add playback controls from the parsed DAC table */
14630 /* Based on ALC880 version. But ALC861VD has separate,
14631  * different NIDs for mute/unmute switch and volume control */
14632 static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
14633                                              const struct auto_pin_cfg *cfg)
14634 {
14635         char name[32];
14636         static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"};
14637         hda_nid_t nid_v, nid_s;
14638         int i, err;
14639
14640         for (i = 0; i < cfg->line_outs; i++) {
14641                 if (!spec->multiout.dac_nids[i])
14642                         continue;
14643                 nid_v = alc861vd_idx_to_mixer_vol(
14644                                 alc880_dac_to_idx(
14645                                         spec->multiout.dac_nids[i]));
14646                 nid_s = alc861vd_idx_to_mixer_switch(
14647                                 alc880_dac_to_idx(
14648                                         spec->multiout.dac_nids[i]));
14649
14650                 if (i == 2) {
14651                         /* Center/LFE */
14652                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
14653                                           "Center Playback Volume",
14654                                           HDA_COMPOSE_AMP_VAL(nid_v, 1, 0,
14655                                                               HDA_OUTPUT));
14656                         if (err < 0)
14657                                 return err;
14658                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
14659                                           "LFE Playback Volume",
14660                                           HDA_COMPOSE_AMP_VAL(nid_v, 2, 0,
14661                                                               HDA_OUTPUT));
14662                         if (err < 0)
14663                                 return err;
14664                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14665                                           "Center Playback Switch",
14666                                           HDA_COMPOSE_AMP_VAL(nid_s, 1, 2,
14667                                                               HDA_INPUT));
14668                         if (err < 0)
14669                                 return err;
14670                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14671                                           "LFE Playback Switch",
14672                                           HDA_COMPOSE_AMP_VAL(nid_s, 2, 2,
14673                                                               HDA_INPUT));
14674                         if (err < 0)
14675                                 return err;
14676                 } else {
14677                         sprintf(name, "%s Playback Volume", chname[i]);
14678                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
14679                                           HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
14680                                                               HDA_OUTPUT));
14681                         if (err < 0)
14682                                 return err;
14683                         sprintf(name, "%s Playback Switch", chname[i]);
14684                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
14685                                           HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
14686                                                               HDA_INPUT));
14687                         if (err < 0)
14688                                 return err;
14689                 }
14690         }
14691         return 0;
14692 }
14693
14694 /* add playback controls for speaker and HP outputs */
14695 /* Based on ALC880 version. But ALC861VD has separate,
14696  * different NIDs for mute/unmute switch and volume control */
14697 static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
14698                                         hda_nid_t pin, const char *pfx)
14699 {
14700         hda_nid_t nid_v, nid_s;
14701         int err;
14702         char name[32];
14703
14704         if (!pin)
14705                 return 0;
14706
14707         if (alc880_is_fixed_pin(pin)) {
14708                 nid_v = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
14709                 /* specify the DAC as the extra output */
14710                 if (!spec->multiout.hp_nid)
14711                         spec->multiout.hp_nid = nid_v;
14712                 else
14713                         spec->multiout.extra_out_nid[0] = nid_v;
14714                 /* control HP volume/switch on the output mixer amp */
14715                 nid_v = alc861vd_idx_to_mixer_vol(
14716                                 alc880_fixed_pin_idx(pin));
14717                 nid_s = alc861vd_idx_to_mixer_switch(
14718                                 alc880_fixed_pin_idx(pin));
14719
14720                 sprintf(name, "%s Playback Volume", pfx);
14721                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
14722                                   HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT));
14723                 if (err < 0)
14724                         return err;
14725                 sprintf(name, "%s Playback Switch", pfx);
14726                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
14727                                   HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT));
14728                 if (err < 0)
14729                         return err;
14730         } else if (alc880_is_multi_pin(pin)) {
14731                 /* set manual connection */
14732                 /* we have only a switch on HP-out PIN */
14733                 sprintf(name, "%s Playback Switch", pfx);
14734                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
14735                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
14736                 if (err < 0)
14737                         return err;
14738         }
14739         return 0;
14740 }
14741
14742 /* parse the BIOS configuration and set up the alc_spec
14743  * return 1 if successful, 0 if the proper config is not found,
14744  * or a negative error code
14745  * Based on ALC880 version - had to change it to override
14746  * alc880_auto_create_extra_out and alc880_auto_create_multi_out_ctls */
14747 static int alc861vd_parse_auto_config(struct hda_codec *codec)
14748 {
14749         struct alc_spec *spec = codec->spec;
14750         int err;
14751         static hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
14752
14753         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
14754                                            alc861vd_ignore);
14755         if (err < 0)
14756                 return err;
14757         if (!spec->autocfg.line_outs)
14758                 return 0; /* can't find valid BIOS pin config */
14759
14760         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
14761         if (err < 0)
14762                 return err;
14763         err = alc861vd_auto_create_multi_out_ctls(spec, &spec->autocfg);
14764         if (err < 0)
14765                 return err;
14766         err = alc861vd_auto_create_extra_out(spec,
14767                                              spec->autocfg.speaker_pins[0],
14768                                              "Speaker");
14769         if (err < 0)
14770                 return err;
14771         err = alc861vd_auto_create_extra_out(spec,
14772                                              spec->autocfg.hp_pins[0],
14773                                              "Headphone");
14774         if (err < 0)
14775                 return err;
14776         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
14777         if (err < 0)
14778                 return err;
14779
14780         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
14781
14782         if (spec->autocfg.dig_out_pin)
14783                 spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID;
14784
14785         if (spec->kctls.list)
14786                 add_mixer(spec, spec->kctls.list);
14787
14788         add_verb(spec, alc861vd_volume_init_verbs);
14789
14790         spec->num_mux_defs = 1;
14791         spec->input_mux = &spec->private_imux[0];
14792
14793         err = alc_auto_add_mic_boost(codec);
14794         if (err < 0)
14795                 return err;
14796
14797         store_pin_configs(codec);
14798         return 1;
14799 }
14800
14801 /* additional initialization for auto-configuration model */
14802 static void alc861vd_auto_init(struct hda_codec *codec)
14803 {
14804         struct alc_spec *spec = codec->spec;
14805         alc861vd_auto_init_multi_out(codec);
14806         alc861vd_auto_init_hp_out(codec);
14807         alc861vd_auto_init_analog_input(codec);
14808         alc861vd_auto_init_input_src(codec);
14809         if (spec->unsol_event)
14810                 alc_inithook(codec);
14811 }
14812
14813 static int patch_alc861vd(struct hda_codec *codec)
14814 {
14815         struct alc_spec *spec;
14816         int err, board_config;
14817
14818         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
14819         if (spec == NULL)
14820                 return -ENOMEM;
14821
14822         codec->spec = spec;
14823
14824         board_config = snd_hda_check_board_config(codec, ALC861VD_MODEL_LAST,
14825                                                   alc861vd_models,
14826                                                   alc861vd_cfg_tbl);
14827
14828         if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) {
14829                 printk(KERN_INFO "hda_codec: Unknown model for ALC660VD/"
14830                         "ALC861VD, trying auto-probe from BIOS...\n");
14831                 board_config = ALC861VD_AUTO;
14832         }
14833
14834         if (board_config == ALC861VD_AUTO) {
14835                 /* automatic parse from the BIOS config */
14836                 err = alc861vd_parse_auto_config(codec);
14837                 if (err < 0) {
14838                         alc_free(codec);
14839                         return err;
14840                 } else if (!err) {
14841                         printk(KERN_INFO
14842                                "hda_codec: Cannot set up configuration "
14843                                "from BIOS.  Using base mode...\n");
14844                         board_config = ALC861VD_3ST;
14845                 }
14846         }
14847
14848         if (board_config != ALC861VD_AUTO)
14849                 setup_preset(spec, &alc861vd_presets[board_config]);
14850
14851         if (codec->vendor_id == 0x10ec0660) {
14852                 spec->stream_name_analog = "ALC660-VD Analog";
14853                 spec->stream_name_digital = "ALC660-VD Digital";
14854                 /* always turn on EAPD */
14855                 add_verb(spec, alc660vd_eapd_verbs);
14856         } else {
14857                 spec->stream_name_analog = "ALC861VD Analog";
14858                 spec->stream_name_digital = "ALC861VD Digital";
14859         }
14860
14861         spec->stream_analog_playback = &alc861vd_pcm_analog_playback;
14862         spec->stream_analog_capture = &alc861vd_pcm_analog_capture;
14863
14864         spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
14865         spec->stream_digital_capture = &alc861vd_pcm_digital_capture;
14866
14867         spec->adc_nids = alc861vd_adc_nids;
14868         spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
14869         spec->capsrc_nids = alc861vd_capsrc_nids;
14870         spec->capture_style = CAPT_MIX;
14871
14872         set_capture_mixer(spec);
14873
14874         spec->vmaster_nid = 0x02;
14875
14876         codec->patch_ops = alc_patch_ops;
14877
14878         if (board_config == ALC861VD_AUTO)
14879                 spec->init_hook = alc861vd_auto_init;
14880 #ifdef CONFIG_SND_HDA_POWER_SAVE
14881         if (!spec->loopback.amplist)
14882                 spec->loopback.amplist = alc861vd_loopbacks;
14883 #endif
14884         codec->proc_widget_hook = print_realtek_coef;
14885
14886         return 0;
14887 }
14888
14889 /*
14890  * ALC662 support
14891  *
14892  * ALC662 is almost identical with ALC880 but has cleaner and more flexible
14893  * configuration.  Each pin widget can choose any input DACs and a mixer.
14894  * Each ADC is connected from a mixer of all inputs.  This makes possible
14895  * 6-channel independent captures.
14896  *
14897  * In addition, an independent DAC for the multi-playback (not used in this
14898  * driver yet).
14899  */
14900 #define ALC662_DIGOUT_NID       0x06
14901 #define ALC662_DIGIN_NID        0x0a
14902
14903 static hda_nid_t alc662_dac_nids[4] = {
14904         /* front, rear, clfe, rear_surr */
14905         0x02, 0x03, 0x04
14906 };
14907
14908 static hda_nid_t alc662_adc_nids[1] = {
14909         /* ADC1-2 */
14910         0x09,
14911 };
14912
14913 static hda_nid_t alc662_capsrc_nids[1] = { 0x22 };
14914
14915 /* input MUX */
14916 /* FIXME: should be a matrix-type input source selection */
14917 static struct hda_input_mux alc662_capture_source = {
14918         .num_items = 4,
14919         .items = {
14920                 { "Mic", 0x0 },
14921                 { "Front Mic", 0x1 },
14922                 { "Line", 0x2 },
14923                 { "CD", 0x4 },
14924         },
14925 };
14926
14927 static struct hda_input_mux alc662_lenovo_101e_capture_source = {
14928         .num_items = 2,
14929         .items = {
14930                 { "Mic", 0x1 },
14931                 { "Line", 0x2 },
14932         },
14933 };
14934
14935 static struct hda_input_mux alc662_eeepc_capture_source = {
14936         .num_items = 2,
14937         .items = {
14938                 { "i-Mic", 0x1 },
14939                 { "e-Mic", 0x0 },
14940         },
14941 };
14942
14943 static struct hda_input_mux alc663_capture_source = {
14944         .num_items = 3,
14945         .items = {
14946                 { "Mic", 0x0 },
14947                 { "Front Mic", 0x1 },
14948                 { "Line", 0x2 },
14949         },
14950 };
14951
14952 static struct hda_input_mux alc663_m51va_capture_source = {
14953         .num_items = 2,
14954         .items = {
14955                 { "Ext-Mic", 0x0 },
14956                 { "D-Mic", 0x9 },
14957         },
14958 };
14959
14960 /*
14961  * 2ch mode
14962  */
14963 static struct hda_channel_mode alc662_3ST_2ch_modes[1] = {
14964         { 2, NULL }
14965 };
14966
14967 /*
14968  * 2ch mode
14969  */
14970 static struct hda_verb alc662_3ST_ch2_init[] = {
14971         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
14972         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
14973         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
14974         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
14975         { } /* end */
14976 };
14977
14978 /*
14979  * 6ch mode
14980  */
14981 static struct hda_verb alc662_3ST_ch6_init[] = {
14982         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14983         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
14984         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
14985         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14986         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
14987         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
14988         { } /* end */
14989 };
14990
14991 static struct hda_channel_mode alc662_3ST_6ch_modes[2] = {
14992         { 2, alc662_3ST_ch2_init },
14993         { 6, alc662_3ST_ch6_init },
14994 };
14995
14996 /*
14997  * 2ch mode
14998  */
14999 static struct hda_verb alc662_sixstack_ch6_init[] = {
15000         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
15001         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
15002         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15003         { } /* end */
15004 };
15005
15006 /*
15007  * 6ch mode
15008  */
15009 static struct hda_verb alc662_sixstack_ch8_init[] = {
15010         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15011         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15012         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15013         { } /* end */
15014 };
15015
15016 static struct hda_channel_mode alc662_5stack_modes[2] = {
15017         { 2, alc662_sixstack_ch6_init },
15018         { 6, alc662_sixstack_ch8_init },
15019 };
15020
15021 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
15022  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
15023  */
15024
15025 static struct snd_kcontrol_new alc662_base_mixer[] = {
15026         /* output mixer control */
15027         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
15028         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
15029         HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
15030         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
15031         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15032         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15033         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
15034         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
15035         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15036
15037         /*Input mixer control */
15038         HDA_CODEC_VOLUME("CD Playback Volume", 0xb, 0x4, HDA_INPUT),
15039         HDA_CODEC_MUTE("CD Playback Switch", 0xb, 0x4, HDA_INPUT),
15040         HDA_CODEC_VOLUME("Line Playback Volume", 0xb, 0x02, HDA_INPUT),
15041         HDA_CODEC_MUTE("Line Playback Switch", 0xb, 0x02, HDA_INPUT),
15042         HDA_CODEC_VOLUME("Mic Playback Volume", 0xb, 0x0, HDA_INPUT),
15043         HDA_CODEC_MUTE("Mic Playback Switch", 0xb, 0x0, HDA_INPUT),
15044         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0xb, 0x01, HDA_INPUT),
15045         HDA_CODEC_MUTE("Front Mic Playback Switch", 0xb, 0x01, HDA_INPUT),
15046         { } /* end */
15047 };
15048
15049 static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
15050         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15051         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
15052         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15053         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
15054         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
15055         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15056         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15057         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15058         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15059         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15060         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15061         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
15062         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
15063         { } /* end */
15064 };
15065
15066 static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
15067         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15068         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
15069         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15070         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
15071         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15072         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15073         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
15074         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
15075         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15076         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
15077         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
15078         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15079         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15080         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15081         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15082         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15083         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15084         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
15085         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
15086         { } /* end */
15087 };
15088
15089 static struct snd_kcontrol_new alc662_lenovo_101e_mixer[] = {
15090         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15091         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
15092         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15093         HDA_BIND_MUTE("Speaker Playback Switch", 0x03, 2, HDA_INPUT),
15094         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15095         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15096         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15097         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15098         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15099         { } /* end */
15100 };
15101
15102 static struct snd_kcontrol_new alc662_eeepc_p701_mixer[] = {
15103         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15104
15105         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15106         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15107
15108         HDA_CODEC_VOLUME("e-Mic Boost", 0x18, 0, HDA_INPUT),
15109         HDA_CODEC_VOLUME("e-Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15110         HDA_CODEC_MUTE("e-Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15111
15112         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
15113         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15114         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15115         { } /* end */
15116 };
15117
15118 static struct snd_kcontrol_new alc662_eeepc_ep20_mixer[] = {
15119         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15120         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15121         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15122         HDA_BIND_MUTE("Surround Playback Switch", 0x03, 2, HDA_INPUT),
15123         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15124         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15125         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT),
15126         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT),
15127         HDA_CODEC_MUTE("Speaker Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15128         HDA_BIND_MUTE("MuteCtrl Playback Switch", 0x0c, 2, HDA_INPUT),
15129         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15130         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15131         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15132         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15133         { } /* end */
15134 };
15135
15136 static struct hda_bind_ctls alc663_asus_bind_master_vol = {
15137         .ops = &snd_hda_bind_vol,
15138         .values = {
15139                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
15140                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
15141                 0
15142         },
15143 };
15144
15145 static struct hda_bind_ctls alc663_asus_one_bind_switch = {
15146         .ops = &snd_hda_bind_sw,
15147         .values = {
15148                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15149                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
15150                 0
15151         },
15152 };
15153
15154 static struct snd_kcontrol_new alc663_m51va_mixer[] = {
15155         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15156         HDA_BIND_SW("Master Playback Switch", &alc663_asus_one_bind_switch),
15157         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15158         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15159         { } /* end */
15160 };
15161
15162 static struct hda_bind_ctls alc663_asus_tree_bind_switch = {
15163         .ops = &snd_hda_bind_sw,
15164         .values = {
15165                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15166                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
15167                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
15168                 0
15169         },
15170 };
15171
15172 static struct snd_kcontrol_new alc663_two_hp_m1_mixer[] = {
15173         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15174         HDA_BIND_SW("Master Playback Switch", &alc663_asus_tree_bind_switch),
15175         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15176         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15177         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15178         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15179
15180         { } /* end */
15181 };
15182
15183 static struct hda_bind_ctls alc663_asus_four_bind_switch = {
15184         .ops = &snd_hda_bind_sw,
15185         .values = {
15186                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15187                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
15188                 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
15189                 0
15190         },
15191 };
15192
15193 static struct snd_kcontrol_new alc663_two_hp_m2_mixer[] = {
15194         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15195         HDA_BIND_SW("Master Playback Switch", &alc663_asus_four_bind_switch),
15196         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15197         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15198         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15199         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15200         { } /* end */
15201 };
15202
15203 static struct snd_kcontrol_new alc662_1bjd_mixer[] = {
15204         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15205         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15206         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15207         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15208         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15209         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15210         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15211         { } /* end */
15212 };
15213
15214 static struct hda_bind_ctls alc663_asus_two_bind_master_vol = {
15215         .ops = &snd_hda_bind_vol,
15216         .values = {
15217                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
15218                 HDA_COMPOSE_AMP_VAL(0x04, 3, 0, HDA_OUTPUT),
15219                 0
15220         },
15221 };
15222
15223 static struct hda_bind_ctls alc663_asus_two_bind_switch = {
15224         .ops = &snd_hda_bind_sw,
15225         .values = {
15226                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15227                 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT),
15228                 0
15229         },
15230 };
15231
15232 static struct snd_kcontrol_new alc663_asus_21jd_clfe_mixer[] = {
15233         HDA_BIND_VOL("Master Playback Volume",
15234                                 &alc663_asus_two_bind_master_vol),
15235         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
15236         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15237         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
15238         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15239         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15240         { } /* end */
15241 };
15242
15243 static struct snd_kcontrol_new alc663_asus_15jd_clfe_mixer[] = {
15244         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15245         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
15246         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15247         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
15248         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15249         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15250         { } /* end */
15251 };
15252
15253 static struct snd_kcontrol_new alc663_g71v_mixer[] = {
15254         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15255         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15256         HDA_CODEC_VOLUME("Front Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15257         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
15258         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
15259
15260         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15261         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15262         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15263         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15264         { } /* end */
15265 };
15266
15267 static struct snd_kcontrol_new alc663_g50v_mixer[] = {
15268         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15269         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15270         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
15271
15272         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15273         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15274         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15275         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15276         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15277         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15278         { } /* end */
15279 };
15280
15281 static struct snd_kcontrol_new alc662_chmode_mixer[] = {
15282         {
15283                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
15284                 .name = "Channel Mode",
15285                 .info = alc_ch_mode_info,
15286                 .get = alc_ch_mode_get,
15287                 .put = alc_ch_mode_put,
15288         },
15289         { } /* end */
15290 };
15291
15292 static struct hda_verb alc662_init_verbs[] = {
15293         /* ADC: mute amp left and right */
15294         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15295         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
15296         /* Front mixer: unmute input/output amp left and right (volume = 0) */
15297
15298         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15299         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15300         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
15301         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
15302         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
15303
15304         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15305         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15306         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15307         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15308         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15309         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15310
15311         /* Front Pin: output 0 (0x0c) */
15312         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15313         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15314
15315         /* Rear Pin: output 1 (0x0d) */
15316         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15317         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15318
15319         /* CLFE Pin: output 2 (0x0e) */
15320         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15321         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15322
15323         /* Mic (rear) pin: input vref at 80% */
15324         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
15325         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15326         /* Front Mic pin: input vref at 80% */
15327         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
15328         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15329         /* Line In pin: input */
15330         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15331         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15332         /* Line-2 In: Headphone output (output 0 - 0x0c) */
15333         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15334         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15335         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
15336         /* CD pin widget for input */
15337         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15338
15339         /* FIXME: use matrix-type input source selection */
15340         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
15341         /* Input mixer */
15342         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15343         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15344         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
15345         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
15346
15347         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15348         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15349         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
15350         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
15351
15352         /* always trun on EAPD */
15353         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
15354         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
15355
15356         { }
15357 };
15358
15359 static struct hda_verb alc662_sue_init_verbs[] = {
15360         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
15361         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
15362         {}
15363 };
15364
15365 static struct hda_verb alc662_eeepc_sue_init_verbs[] = {
15366         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15367         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15368         {}
15369 };
15370
15371 /* Set Unsolicited Event*/
15372 static struct hda_verb alc662_eeepc_ep20_sue_init_verbs[] = {
15373         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15374         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15375         {}
15376 };
15377
15378 /*
15379  * generic initialization of ADC, input mixers and output mixers
15380  */
15381 static struct hda_verb alc662_auto_init_verbs[] = {
15382         /*
15383          * Unmute ADC and set the default input to mic-in
15384          */
15385         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
15386         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15387
15388         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
15389          * mixer widget
15390          * Note: PASD motherboards uses the Line In 2 as the input for front
15391          * panel mic (mic 2)
15392          */
15393         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
15394         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15395         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15396         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
15397         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
15398         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
15399
15400         /*
15401          * Set up output mixers (0x0c - 0x0f)
15402          */
15403         /* set vol=0 to output mixers */
15404         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15405         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15406         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15407
15408         /* set up input amps for analog loopback */
15409         /* Amp Indices: DAC = 0, mixer = 1 */
15410         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15411         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15412         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15413         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15414         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15415         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15416
15417
15418         /* FIXME: use matrix-type input source selection */
15419         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
15420         /* Input mixer */
15421         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15422         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15423         { }
15424 };
15425
15426 /* additional verbs for ALC663 */
15427 static struct hda_verb alc663_auto_init_verbs[] = {
15428         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15429         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15430         { }
15431 };
15432
15433 static struct hda_verb alc663_m51va_init_verbs[] = {
15434         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15435         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15436         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15437         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15438         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15439         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15440         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
15441         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15442         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15443         {}
15444 };
15445
15446 static struct hda_verb alc663_21jd_amic_init_verbs[] = {
15447         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15448         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15449         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15450         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15451         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15452         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15453         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15454         {}
15455 };
15456
15457 static struct hda_verb alc662_1bjd_amic_init_verbs[] = {
15458         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15459         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15460         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15461         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
15462         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15463         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15464         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15465         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15466         {}
15467 };
15468
15469 static struct hda_verb alc663_15jd_amic_init_verbs[] = {
15470         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15471         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15472         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15473         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15474         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15475         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15476         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15477         {}
15478 };
15479
15480 static struct hda_verb alc663_two_hp_amic_m1_init_verbs[] = {
15481         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15482         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15483         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15484         {0x21, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
15485         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15486         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15487         {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
15488         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15489         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15490         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15491         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15492         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15493         {}
15494 };
15495
15496 static struct hda_verb alc663_two_hp_amic_m2_init_verbs[] = {
15497         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15498         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15499         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15500         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15501         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15502         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15503         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15504         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15505         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15506         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15507         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15508         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15509         {}
15510 };
15511
15512 static struct hda_verb alc663_g71v_init_verbs[] = {
15513         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15514         /* {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
15515         /* {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, */ /* Headphone */
15516
15517         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15518         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15519         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
15520
15521         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
15522         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_MIC_EVENT},
15523         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
15524         {}
15525 };
15526
15527 static struct hda_verb alc663_g50v_init_verbs[] = {
15528         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15529         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15530         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
15531
15532         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15533         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15534         {}
15535 };
15536
15537 static struct hda_verb alc662_ecs_init_verbs[] = {
15538         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0x701f},
15539         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15540         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15541         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15542         {}
15543 };
15544
15545 static struct snd_kcontrol_new alc662_auto_capture_mixer[] = {
15546         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
15547         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
15548         { } /* end */
15549 };
15550
15551 static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
15552 {
15553         unsigned int present;
15554         unsigned char bits;
15555
15556         present = snd_hda_codec_read(codec, 0x14, 0,
15557                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15558         bits = present ? HDA_AMP_MUTE : 0;
15559         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
15560                                  HDA_AMP_MUTE, bits);
15561 }
15562
15563 static void alc662_lenovo_101e_all_automute(struct hda_codec *codec)
15564 {
15565         unsigned int present;
15566         unsigned char bits;
15567
15568         present = snd_hda_codec_read(codec, 0x1b, 0,
15569                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15570         bits = present ? HDA_AMP_MUTE : 0;
15571         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
15572                                  HDA_AMP_MUTE, bits);
15573         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
15574                                  HDA_AMP_MUTE, bits);
15575 }
15576
15577 static void alc662_lenovo_101e_unsol_event(struct hda_codec *codec,
15578                                            unsigned int res)
15579 {
15580         if ((res >> 26) == ALC880_HP_EVENT)
15581                 alc662_lenovo_101e_all_automute(codec);
15582         if ((res >> 26) == ALC880_FRONT_EVENT)
15583                 alc662_lenovo_101e_ispeaker_automute(codec);
15584 }
15585
15586 static void alc662_eeepc_mic_automute(struct hda_codec *codec)
15587 {
15588         unsigned int present;
15589
15590         present = snd_hda_codec_read(codec, 0x18, 0,
15591                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15592         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15593                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15594         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15595                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15596         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15597                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
15598         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15599                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
15600 }
15601
15602 /* unsolicited event for HP jack sensing */
15603 static void alc662_eeepc_unsol_event(struct hda_codec *codec,
15604                                      unsigned int res)
15605 {
15606         if ((res >> 26) == ALC880_HP_EVENT)
15607                 alc262_hippo1_automute( codec );
15608
15609         if ((res >> 26) == ALC880_MIC_EVENT)
15610                 alc662_eeepc_mic_automute(codec);
15611 }
15612
15613 static void alc662_eeepc_inithook(struct hda_codec *codec)
15614 {
15615         alc262_hippo1_automute( codec );
15616         alc662_eeepc_mic_automute(codec);
15617 }
15618
15619 static void alc662_eeepc_ep20_automute(struct hda_codec *codec)
15620 {
15621         unsigned int mute;
15622         unsigned int present;
15623
15624         snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
15625         present = snd_hda_codec_read(codec, 0x14, 0,
15626                                      AC_VERB_GET_PIN_SENSE, 0);
15627         present = (present & 0x80000000) != 0;
15628         if (present) {
15629                 /* mute internal speaker */
15630                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
15631                                         HDA_AMP_MUTE, HDA_AMP_MUTE);
15632         } else {
15633                 /* unmute internal speaker if necessary */
15634                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
15635                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
15636                                         HDA_AMP_MUTE, mute);
15637         }
15638 }
15639
15640 /* unsolicited event for HP jack sensing */
15641 static void alc662_eeepc_ep20_unsol_event(struct hda_codec *codec,
15642                                           unsigned int res)
15643 {
15644         if ((res >> 26) == ALC880_HP_EVENT)
15645                 alc662_eeepc_ep20_automute(codec);
15646 }
15647
15648 static void alc662_eeepc_ep20_inithook(struct hda_codec *codec)
15649 {
15650         alc662_eeepc_ep20_automute(codec);
15651 }
15652
15653 static void alc663_m51va_speaker_automute(struct hda_codec *codec)
15654 {
15655         unsigned int present;
15656         unsigned char bits;
15657
15658         present = snd_hda_codec_read(codec, 0x21, 0,
15659                         AC_VERB_GET_PIN_SENSE, 0)
15660                         & AC_PINSENSE_PRESENCE;
15661         bits = present ? HDA_AMP_MUTE : 0;
15662         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15663                                 AMP_IN_MUTE(0), bits);
15664         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15665                                 AMP_IN_MUTE(0), bits);
15666 }
15667
15668 static void alc663_21jd_two_speaker_automute(struct hda_codec *codec)
15669 {
15670         unsigned int present;
15671         unsigned char bits;
15672
15673         present = snd_hda_codec_read(codec, 0x21, 0,
15674                         AC_VERB_GET_PIN_SENSE, 0)
15675                         & AC_PINSENSE_PRESENCE;
15676         bits = present ? HDA_AMP_MUTE : 0;
15677         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15678                                 AMP_IN_MUTE(0), bits);
15679         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15680                                 AMP_IN_MUTE(0), bits);
15681         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
15682                                 AMP_IN_MUTE(0), bits);
15683         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
15684                                 AMP_IN_MUTE(0), bits);
15685 }
15686
15687 static void alc663_15jd_two_speaker_automute(struct hda_codec *codec)
15688 {
15689         unsigned int present;
15690         unsigned char bits;
15691
15692         present = snd_hda_codec_read(codec, 0x15, 0,
15693                         AC_VERB_GET_PIN_SENSE, 0)
15694                         & AC_PINSENSE_PRESENCE;
15695         bits = present ? HDA_AMP_MUTE : 0;
15696         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15697                                 AMP_IN_MUTE(0), bits);
15698         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15699                                 AMP_IN_MUTE(0), bits);
15700         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
15701                                 AMP_IN_MUTE(0), bits);
15702         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
15703                                 AMP_IN_MUTE(0), bits);
15704 }
15705
15706 static void alc662_f5z_speaker_automute(struct hda_codec *codec)
15707 {
15708         unsigned int present;
15709         unsigned char bits;
15710
15711         present = snd_hda_codec_read(codec, 0x1b, 0,
15712                         AC_VERB_GET_PIN_SENSE, 0)
15713                         & AC_PINSENSE_PRESENCE;
15714         bits = present ? 0 : PIN_OUT;
15715         snd_hda_codec_write(codec, 0x14, 0,
15716                          AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
15717 }
15718
15719 static void alc663_two_hp_m1_speaker_automute(struct hda_codec *codec)
15720 {
15721         unsigned int present1, present2;
15722
15723         present1 = snd_hda_codec_read(codec, 0x21, 0,
15724                         AC_VERB_GET_PIN_SENSE, 0)
15725                         & AC_PINSENSE_PRESENCE;
15726         present2 = snd_hda_codec_read(codec, 0x15, 0,
15727                         AC_VERB_GET_PIN_SENSE, 0)
15728                         & AC_PINSENSE_PRESENCE;
15729
15730         if (present1 || present2) {
15731                 snd_hda_codec_write_cache(codec, 0x14, 0,
15732                         AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
15733         } else {
15734                 snd_hda_codec_write_cache(codec, 0x14, 0,
15735                         AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
15736         }
15737 }
15738
15739 static void alc663_two_hp_m2_speaker_automute(struct hda_codec *codec)
15740 {
15741         unsigned int present1, present2;
15742
15743         present1 = snd_hda_codec_read(codec, 0x1b, 0,
15744                                 AC_VERB_GET_PIN_SENSE, 0)
15745                                 & AC_PINSENSE_PRESENCE;
15746         present2 = snd_hda_codec_read(codec, 0x15, 0,
15747                                 AC_VERB_GET_PIN_SENSE, 0)
15748                                 & AC_PINSENSE_PRESENCE;
15749
15750         if (present1 || present2) {
15751                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15752                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
15753                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15754                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
15755         } else {
15756                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15757                                 AMP_IN_MUTE(0), 0);
15758                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15759                                 AMP_IN_MUTE(0), 0);
15760         }
15761 }
15762
15763 static void alc663_m51va_mic_automute(struct hda_codec *codec)
15764 {
15765         unsigned int present;
15766
15767         present = snd_hda_codec_read(codec, 0x18, 0,
15768                         AC_VERB_GET_PIN_SENSE, 0)
15769                         & AC_PINSENSE_PRESENCE;
15770         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15771                         0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15772         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15773                         0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15774         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15775                         0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
15776         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15777                         0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
15778 }
15779
15780 static void alc663_m51va_unsol_event(struct hda_codec *codec,
15781                                            unsigned int res)
15782 {
15783         switch (res >> 26) {
15784         case ALC880_HP_EVENT:
15785                 alc663_m51va_speaker_automute(codec);
15786                 break;
15787         case ALC880_MIC_EVENT:
15788                 alc663_m51va_mic_automute(codec);
15789                 break;
15790         }
15791 }
15792
15793 static void alc663_m51va_inithook(struct hda_codec *codec)
15794 {
15795         alc663_m51va_speaker_automute(codec);
15796         alc663_m51va_mic_automute(codec);
15797 }
15798
15799 /* ***************** Mode1 ******************************/
15800 static void alc663_mode1_unsol_event(struct hda_codec *codec,
15801                                            unsigned int res)
15802 {
15803         switch (res >> 26) {
15804         case ALC880_HP_EVENT:
15805                 alc663_m51va_speaker_automute(codec);
15806                 break;
15807         case ALC880_MIC_EVENT:
15808                 alc662_eeepc_mic_automute(codec);
15809                 break;
15810         }
15811 }
15812
15813 static void alc663_mode1_inithook(struct hda_codec *codec)
15814 {
15815         alc663_m51va_speaker_automute(codec);
15816         alc662_eeepc_mic_automute(codec);
15817 }
15818 /* ***************** Mode2 ******************************/
15819 static void alc662_mode2_unsol_event(struct hda_codec *codec,
15820                                            unsigned int res)
15821 {
15822         switch (res >> 26) {
15823         case ALC880_HP_EVENT:
15824                 alc662_f5z_speaker_automute(codec);
15825                 break;
15826         case ALC880_MIC_EVENT:
15827                 alc662_eeepc_mic_automute(codec);
15828                 break;
15829         }
15830 }
15831
15832 static void alc662_mode2_inithook(struct hda_codec *codec)
15833 {
15834         alc662_f5z_speaker_automute(codec);
15835         alc662_eeepc_mic_automute(codec);
15836 }
15837 /* ***************** Mode3 ******************************/
15838 static void alc663_mode3_unsol_event(struct hda_codec *codec,
15839                                            unsigned int res)
15840 {
15841         switch (res >> 26) {
15842         case ALC880_HP_EVENT:
15843                 alc663_two_hp_m1_speaker_automute(codec);
15844                 break;
15845         case ALC880_MIC_EVENT:
15846                 alc662_eeepc_mic_automute(codec);
15847                 break;
15848         }
15849 }
15850
15851 static void alc663_mode3_inithook(struct hda_codec *codec)
15852 {
15853         alc663_two_hp_m1_speaker_automute(codec);
15854         alc662_eeepc_mic_automute(codec);
15855 }
15856 /* ***************** Mode4 ******************************/
15857 static void alc663_mode4_unsol_event(struct hda_codec *codec,
15858                                            unsigned int res)
15859 {
15860         switch (res >> 26) {
15861         case ALC880_HP_EVENT:
15862                 alc663_21jd_two_speaker_automute(codec);
15863                 break;
15864         case ALC880_MIC_EVENT:
15865                 alc662_eeepc_mic_automute(codec);
15866                 break;
15867         }
15868 }
15869
15870 static void alc663_mode4_inithook(struct hda_codec *codec)
15871 {
15872         alc663_21jd_two_speaker_automute(codec);
15873         alc662_eeepc_mic_automute(codec);
15874 }
15875 /* ***************** Mode5 ******************************/
15876 static void alc663_mode5_unsol_event(struct hda_codec *codec,
15877                                            unsigned int res)
15878 {
15879         switch (res >> 26) {
15880         case ALC880_HP_EVENT:
15881                 alc663_15jd_two_speaker_automute(codec);
15882                 break;
15883         case ALC880_MIC_EVENT:
15884                 alc662_eeepc_mic_automute(codec);
15885                 break;
15886         }
15887 }
15888
15889 static void alc663_mode5_inithook(struct hda_codec *codec)
15890 {
15891         alc663_15jd_two_speaker_automute(codec);
15892         alc662_eeepc_mic_automute(codec);
15893 }
15894 /* ***************** Mode6 ******************************/
15895 static void alc663_mode6_unsol_event(struct hda_codec *codec,
15896                                            unsigned int res)
15897 {
15898         switch (res >> 26) {
15899         case ALC880_HP_EVENT:
15900                 alc663_two_hp_m2_speaker_automute(codec);
15901                 break;
15902         case ALC880_MIC_EVENT:
15903                 alc662_eeepc_mic_automute(codec);
15904                 break;
15905         }
15906 }
15907
15908 static void alc663_mode6_inithook(struct hda_codec *codec)
15909 {
15910         alc663_two_hp_m2_speaker_automute(codec);
15911         alc662_eeepc_mic_automute(codec);
15912 }
15913
15914 static void alc663_g71v_hp_automute(struct hda_codec *codec)
15915 {
15916         unsigned int present;
15917         unsigned char bits;
15918
15919         present = snd_hda_codec_read(codec, 0x21, 0,
15920                                      AC_VERB_GET_PIN_SENSE, 0)
15921                 & AC_PINSENSE_PRESENCE;
15922         bits = present ? HDA_AMP_MUTE : 0;
15923         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
15924                                  HDA_AMP_MUTE, bits);
15925         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
15926                                  HDA_AMP_MUTE, bits);
15927 }
15928
15929 static void alc663_g71v_front_automute(struct hda_codec *codec)
15930 {
15931         unsigned int present;
15932         unsigned char bits;
15933
15934         present = snd_hda_codec_read(codec, 0x15, 0,
15935                                      AC_VERB_GET_PIN_SENSE, 0)
15936                 & AC_PINSENSE_PRESENCE;
15937         bits = present ? HDA_AMP_MUTE : 0;
15938         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
15939                                  HDA_AMP_MUTE, bits);
15940 }
15941
15942 static void alc663_g71v_unsol_event(struct hda_codec *codec,
15943                                            unsigned int res)
15944 {
15945         switch (res >> 26) {
15946         case ALC880_HP_EVENT:
15947                 alc663_g71v_hp_automute(codec);
15948                 break;
15949         case ALC880_FRONT_EVENT:
15950                 alc663_g71v_front_automute(codec);
15951                 break;
15952         case ALC880_MIC_EVENT:
15953                 alc662_eeepc_mic_automute(codec);
15954                 break;
15955         }
15956 }
15957
15958 static void alc663_g71v_inithook(struct hda_codec *codec)
15959 {
15960         alc663_g71v_front_automute(codec);
15961         alc663_g71v_hp_automute(codec);
15962         alc662_eeepc_mic_automute(codec);
15963 }
15964
15965 static void alc663_g50v_unsol_event(struct hda_codec *codec,
15966                                            unsigned int res)
15967 {
15968         switch (res >> 26) {
15969         case ALC880_HP_EVENT:
15970                 alc663_m51va_speaker_automute(codec);
15971                 break;
15972         case ALC880_MIC_EVENT:
15973                 alc662_eeepc_mic_automute(codec);
15974                 break;
15975         }
15976 }
15977
15978 static void alc663_g50v_inithook(struct hda_codec *codec)
15979 {
15980         alc663_m51va_speaker_automute(codec);
15981         alc662_eeepc_mic_automute(codec);
15982 }
15983
15984 /* bind hp and internal speaker mute (with plug check) */
15985 static int alc662_ecs_master_sw_put(struct snd_kcontrol *kcontrol,
15986                                      struct snd_ctl_elem_value *ucontrol)
15987 {
15988         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
15989         long *valp = ucontrol->value.integer.value;
15990         int change;
15991
15992         change = snd_hda_codec_amp_update(codec, 0x1b, 0, HDA_OUTPUT, 0,
15993                                           HDA_AMP_MUTE,
15994                                           valp[0] ? 0 : HDA_AMP_MUTE);
15995         change |= snd_hda_codec_amp_update(codec, 0x1b, 1, HDA_OUTPUT, 0,
15996                                            HDA_AMP_MUTE,
15997                                            valp[1] ? 0 : HDA_AMP_MUTE);
15998         if (change)
15999                 alc262_hippo1_automute(codec);
16000         return change;
16001 }
16002
16003 static struct snd_kcontrol_new alc662_ecs_mixer[] = {
16004         HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16005         {
16006                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
16007                 .name = "Master Playback Switch",
16008                 .info = snd_hda_mixer_amp_switch_info,
16009                 .get = snd_hda_mixer_amp_switch_get,
16010                 .put = alc662_ecs_master_sw_put,
16011                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
16012         },
16013
16014         HDA_CODEC_VOLUME("e-Mic/LineIn Boost", 0x18, 0, HDA_INPUT),
16015         HDA_CODEC_VOLUME("e-Mic/LineIn Playback Volume", 0x0b, 0x0, HDA_INPUT),
16016         HDA_CODEC_MUTE("e-Mic/LineIn Playback Switch", 0x0b, 0x0, HDA_INPUT),
16017
16018         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
16019         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16020         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16021         { } /* end */
16022 };
16023
16024 #ifdef CONFIG_SND_HDA_POWER_SAVE
16025 #define alc662_loopbacks        alc880_loopbacks
16026 #endif
16027
16028
16029 /* pcm configuration: identiacal with ALC880 */
16030 #define alc662_pcm_analog_playback      alc880_pcm_analog_playback
16031 #define alc662_pcm_analog_capture       alc880_pcm_analog_capture
16032 #define alc662_pcm_digital_playback     alc880_pcm_digital_playback
16033 #define alc662_pcm_digital_capture      alc880_pcm_digital_capture
16034
16035 /*
16036  * configuration and preset
16037  */
16038 static const char *alc662_models[ALC662_MODEL_LAST] = {
16039         [ALC662_3ST_2ch_DIG]    = "3stack-dig",
16040         [ALC662_3ST_6ch_DIG]    = "3stack-6ch-dig",
16041         [ALC662_3ST_6ch]        = "3stack-6ch",
16042         [ALC662_5ST_DIG]        = "6stack-dig",
16043         [ALC662_LENOVO_101E]    = "lenovo-101e",
16044         [ALC662_ASUS_EEEPC_P701] = "eeepc-p701",
16045         [ALC662_ASUS_EEEPC_EP20] = "eeepc-ep20",
16046         [ALC662_ECS] = "ecs",
16047         [ALC663_ASUS_M51VA] = "m51va",
16048         [ALC663_ASUS_G71V] = "g71v",
16049         [ALC663_ASUS_H13] = "h13",
16050         [ALC663_ASUS_G50V] = "g50v",
16051         [ALC663_ASUS_MODE1] = "asus-mode1",
16052         [ALC662_ASUS_MODE2] = "asus-mode2",
16053         [ALC663_ASUS_MODE3] = "asus-mode3",
16054         [ALC663_ASUS_MODE4] = "asus-mode4",
16055         [ALC663_ASUS_MODE5] = "asus-mode5",
16056         [ALC663_ASUS_MODE6] = "asus-mode6",
16057         [ALC662_AUTO]           = "auto",
16058 };
16059
16060 static struct snd_pci_quirk alc662_cfg_tbl[] = {
16061         SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M51VA", ALC663_ASUS_M51VA),
16062         SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS G50V", ALC663_ASUS_G50V),
16063         SND_PCI_QUIRK(0x1043, 0x8290, "ASUS P5GC-MX", ALC662_3ST_6ch_DIG),
16064         SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
16065         SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20),
16066         SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC663_ASUS_MODE1),
16067         SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M50Vr", ALC663_ASUS_MODE1),
16068         SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC663_ASUS_MODE1),
16069         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC663_ASUS_MODE1),
16070         SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC663_ASUS_MODE1),
16071         SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS NB", ALC663_ASUS_MODE1),
16072         SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC663_ASUS_MODE1),
16073         SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC663_ASUS_MODE1),
16074         SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC663_ASUS_MODE1),
16075         SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC663_ASUS_MODE1),
16076         SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_ASUS_MODE2),
16077         SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_ASUS_MODE2),
16078         SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_ASUS_MODE2),
16079         SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_ASUS_MODE2),
16080         SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_ASUS_MODE2),
16081         SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_ASUS_MODE2),
16082         SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_ASUS_MODE2),
16083         SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_ASUS_MODE2),
16084         SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_ASUS_MODE2),
16085         SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_ASUS_MODE2),
16086         SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_ASUS_MODE2),
16087         SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_ASUS_MODE2),
16088         SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC663_ASUS_MODE3),
16089         SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC663_ASUS_MODE3),
16090         SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC663_ASUS_MODE3),
16091         SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC663_ASUS_MODE3),
16092         SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC663_ASUS_MODE3),
16093         SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC663_ASUS_MODE4),
16094         SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC663_ASUS_MODE5),
16095         SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC663_ASUS_MODE6),
16096         SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC663_ASUS_MODE6),
16097         SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC663_ASUS_MODE6),
16098         SND_PCI_QUIRK(0x105b, 0x0d47, "Foxconn 45CMX/45GMX/45CMX-K",
16099                       ALC662_3ST_6ch_DIG),
16100         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
16101         SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_ECS),
16102         SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_ECS),
16103         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte 945GCM-S2L",
16104                       ALC662_3ST_6ch_DIG),
16105         SND_PCI_QUIRK(0x1565, 0x820f, "Biostar TA780G M2+", ALC662_3ST_6ch_DIG),
16106         SND_PCI_QUIRK(0x1849, 0x3662, "ASROCK K10N78FullHD-hSLI R3.0",
16107                                         ALC662_3ST_6ch_DIG),
16108         SND_PCI_QUIRK(0x1854, 0x2000, "ASUS H13-2000", ALC663_ASUS_H13),
16109         SND_PCI_QUIRK(0x1854, 0x2001, "ASUS H13-2001", ALC663_ASUS_H13),
16110         SND_PCI_QUIRK(0x1854, 0x2002, "ASUS H13-2002", ALC663_ASUS_H13),
16111         {}
16112 };
16113
16114 static struct alc_config_preset alc662_presets[] = {
16115         [ALC662_3ST_2ch_DIG] = {
16116                 .mixers = { alc662_3ST_2ch_mixer },
16117                 .init_verbs = { alc662_init_verbs },
16118                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16119                 .dac_nids = alc662_dac_nids,
16120                 .dig_out_nid = ALC662_DIGOUT_NID,
16121                 .dig_in_nid = ALC662_DIGIN_NID,
16122                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16123                 .channel_mode = alc662_3ST_2ch_modes,
16124                 .input_mux = &alc662_capture_source,
16125         },
16126         [ALC662_3ST_6ch_DIG] = {
16127                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
16128                 .init_verbs = { alc662_init_verbs },
16129                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16130                 .dac_nids = alc662_dac_nids,
16131                 .dig_out_nid = ALC662_DIGOUT_NID,
16132                 .dig_in_nid = ALC662_DIGIN_NID,
16133                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16134                 .channel_mode = alc662_3ST_6ch_modes,
16135                 .need_dac_fix = 1,
16136                 .input_mux = &alc662_capture_source,
16137         },
16138         [ALC662_3ST_6ch] = {
16139                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
16140                 .init_verbs = { alc662_init_verbs },
16141                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16142                 .dac_nids = alc662_dac_nids,
16143                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16144                 .channel_mode = alc662_3ST_6ch_modes,
16145                 .need_dac_fix = 1,
16146                 .input_mux = &alc662_capture_source,
16147         },
16148         [ALC662_5ST_DIG] = {
16149                 .mixers = { alc662_base_mixer, alc662_chmode_mixer },
16150                 .init_verbs = { alc662_init_verbs },
16151                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16152                 .dac_nids = alc662_dac_nids,
16153                 .dig_out_nid = ALC662_DIGOUT_NID,
16154                 .dig_in_nid = ALC662_DIGIN_NID,
16155                 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
16156                 .channel_mode = alc662_5stack_modes,
16157                 .input_mux = &alc662_capture_source,
16158         },
16159         [ALC662_LENOVO_101E] = {
16160                 .mixers = { alc662_lenovo_101e_mixer },
16161                 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs },
16162                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16163                 .dac_nids = alc662_dac_nids,
16164                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16165                 .channel_mode = alc662_3ST_2ch_modes,
16166                 .input_mux = &alc662_lenovo_101e_capture_source,
16167                 .unsol_event = alc662_lenovo_101e_unsol_event,
16168                 .init_hook = alc662_lenovo_101e_all_automute,
16169         },
16170         [ALC662_ASUS_EEEPC_P701] = {
16171                 .mixers = { alc662_eeepc_p701_mixer },
16172                 .init_verbs = { alc662_init_verbs,
16173                                 alc662_eeepc_sue_init_verbs },
16174                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16175                 .dac_nids = alc662_dac_nids,
16176                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16177                 .channel_mode = alc662_3ST_2ch_modes,
16178                 .input_mux = &alc662_eeepc_capture_source,
16179                 .unsol_event = alc662_eeepc_unsol_event,
16180                 .init_hook = alc662_eeepc_inithook,
16181         },
16182         [ALC662_ASUS_EEEPC_EP20] = {
16183                 .mixers = { alc662_eeepc_ep20_mixer,
16184                             alc662_chmode_mixer },
16185                 .init_verbs = { alc662_init_verbs,
16186                                 alc662_eeepc_ep20_sue_init_verbs },
16187                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16188                 .dac_nids = alc662_dac_nids,
16189                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16190                 .channel_mode = alc662_3ST_6ch_modes,
16191                 .input_mux = &alc662_lenovo_101e_capture_source,
16192                 .unsol_event = alc662_eeepc_ep20_unsol_event,
16193                 .init_hook = alc662_eeepc_ep20_inithook,
16194         },
16195         [ALC662_ECS] = {
16196                 .mixers = { alc662_ecs_mixer },
16197                 .init_verbs = { alc662_init_verbs,
16198                                 alc662_ecs_init_verbs },
16199                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16200                 .dac_nids = alc662_dac_nids,
16201                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16202                 .channel_mode = alc662_3ST_2ch_modes,
16203                 .input_mux = &alc662_eeepc_capture_source,
16204                 .unsol_event = alc662_eeepc_unsol_event,
16205                 .init_hook = alc662_eeepc_inithook,
16206         },
16207         [ALC663_ASUS_M51VA] = {
16208                 .mixers = { alc663_m51va_mixer },
16209                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
16210                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16211                 .dac_nids = alc662_dac_nids,
16212                 .dig_out_nid = ALC662_DIGOUT_NID,
16213                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16214                 .channel_mode = alc662_3ST_2ch_modes,
16215                 .input_mux = &alc663_m51va_capture_source,
16216                 .unsol_event = alc663_m51va_unsol_event,
16217                 .init_hook = alc663_m51va_inithook,
16218         },
16219         [ALC663_ASUS_G71V] = {
16220                 .mixers = { alc663_g71v_mixer },
16221                 .init_verbs = { alc662_init_verbs, alc663_g71v_init_verbs },
16222                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16223                 .dac_nids = alc662_dac_nids,
16224                 .dig_out_nid = ALC662_DIGOUT_NID,
16225                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16226                 .channel_mode = alc662_3ST_2ch_modes,
16227                 .input_mux = &alc662_eeepc_capture_source,
16228                 .unsol_event = alc663_g71v_unsol_event,
16229                 .init_hook = alc663_g71v_inithook,
16230         },
16231         [ALC663_ASUS_H13] = {
16232                 .mixers = { alc663_m51va_mixer },
16233                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
16234                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16235                 .dac_nids = alc662_dac_nids,
16236                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16237                 .channel_mode = alc662_3ST_2ch_modes,
16238                 .input_mux = &alc663_m51va_capture_source,
16239                 .unsol_event = alc663_m51va_unsol_event,
16240                 .init_hook = alc663_m51va_inithook,
16241         },
16242         [ALC663_ASUS_G50V] = {
16243                 .mixers = { alc663_g50v_mixer },
16244                 .init_verbs = { alc662_init_verbs, alc663_g50v_init_verbs },
16245                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16246                 .dac_nids = alc662_dac_nids,
16247                 .dig_out_nid = ALC662_DIGOUT_NID,
16248                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16249                 .channel_mode = alc662_3ST_6ch_modes,
16250                 .input_mux = &alc663_capture_source,
16251                 .unsol_event = alc663_g50v_unsol_event,
16252                 .init_hook = alc663_g50v_inithook,
16253         },
16254         [ALC663_ASUS_MODE1] = {
16255                 .mixers = { alc663_m51va_mixer },
16256                 .cap_mixer = alc662_auto_capture_mixer,
16257                 .init_verbs = { alc662_init_verbs,
16258                                 alc663_21jd_amic_init_verbs },
16259                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16260                 .hp_nid = 0x03,
16261                 .dac_nids = alc662_dac_nids,
16262                 .dig_out_nid = ALC662_DIGOUT_NID,
16263                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16264                 .channel_mode = alc662_3ST_2ch_modes,
16265                 .input_mux = &alc662_eeepc_capture_source,
16266                 .unsol_event = alc663_mode1_unsol_event,
16267                 .init_hook = alc663_mode1_inithook,
16268         },
16269         [ALC662_ASUS_MODE2] = {
16270                 .mixers = { alc662_1bjd_mixer },
16271                 .cap_mixer = alc662_auto_capture_mixer,
16272                 .init_verbs = { alc662_init_verbs,
16273                                 alc662_1bjd_amic_init_verbs },
16274                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16275                 .dac_nids = alc662_dac_nids,
16276                 .dig_out_nid = ALC662_DIGOUT_NID,
16277                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16278                 .channel_mode = alc662_3ST_2ch_modes,
16279                 .input_mux = &alc662_eeepc_capture_source,
16280                 .unsol_event = alc662_mode2_unsol_event,
16281                 .init_hook = alc662_mode2_inithook,
16282         },
16283         [ALC663_ASUS_MODE3] = {
16284                 .mixers = { alc663_two_hp_m1_mixer },
16285                 .cap_mixer = alc662_auto_capture_mixer,
16286                 .init_verbs = { alc662_init_verbs,
16287                                 alc663_two_hp_amic_m1_init_verbs },
16288                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16289                 .hp_nid = 0x03,
16290                 .dac_nids = alc662_dac_nids,
16291                 .dig_out_nid = ALC662_DIGOUT_NID,
16292                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16293                 .channel_mode = alc662_3ST_2ch_modes,
16294                 .input_mux = &alc662_eeepc_capture_source,
16295                 .unsol_event = alc663_mode3_unsol_event,
16296                 .init_hook = alc663_mode3_inithook,
16297         },
16298         [ALC663_ASUS_MODE4] = {
16299                 .mixers = { alc663_asus_21jd_clfe_mixer },
16300                 .cap_mixer = alc662_auto_capture_mixer,
16301                 .init_verbs = { alc662_init_verbs,
16302                                 alc663_21jd_amic_init_verbs},
16303                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16304                 .hp_nid = 0x03,
16305                 .dac_nids = alc662_dac_nids,
16306                 .dig_out_nid = ALC662_DIGOUT_NID,
16307                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16308                 .channel_mode = alc662_3ST_2ch_modes,
16309                 .input_mux = &alc662_eeepc_capture_source,
16310                 .unsol_event = alc663_mode4_unsol_event,
16311                 .init_hook = alc663_mode4_inithook,
16312         },
16313         [ALC663_ASUS_MODE5] = {
16314                 .mixers = { alc663_asus_15jd_clfe_mixer },
16315                 .cap_mixer = alc662_auto_capture_mixer,
16316                 .init_verbs = { alc662_init_verbs,
16317                                 alc663_15jd_amic_init_verbs },
16318                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16319                 .hp_nid = 0x03,
16320                 .dac_nids = alc662_dac_nids,
16321                 .dig_out_nid = ALC662_DIGOUT_NID,
16322                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16323                 .channel_mode = alc662_3ST_2ch_modes,
16324                 .input_mux = &alc662_eeepc_capture_source,
16325                 .unsol_event = alc663_mode5_unsol_event,
16326                 .init_hook = alc663_mode5_inithook,
16327         },
16328         [ALC663_ASUS_MODE6] = {
16329                 .mixers = { alc663_two_hp_m2_mixer },
16330                 .cap_mixer = alc662_auto_capture_mixer,
16331                 .init_verbs = { alc662_init_verbs,
16332                                 alc663_two_hp_amic_m2_init_verbs },
16333                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16334                 .hp_nid = 0x03,
16335                 .dac_nids = alc662_dac_nids,
16336                 .dig_out_nid = ALC662_DIGOUT_NID,
16337                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16338                 .channel_mode = alc662_3ST_2ch_modes,
16339                 .input_mux = &alc662_eeepc_capture_source,
16340                 .unsol_event = alc663_mode6_unsol_event,
16341                 .init_hook = alc663_mode6_inithook,
16342         },
16343 };
16344
16345
16346 /*
16347  * BIOS auto configuration
16348  */
16349
16350 /* add playback controls from the parsed DAC table */
16351 static int alc662_auto_create_multi_out_ctls(struct alc_spec *spec,
16352                                              const struct auto_pin_cfg *cfg)
16353 {
16354         char name[32];
16355         static const char *chname[4] = {
16356                 "Front", "Surround", NULL /*CLFE*/, "Side"
16357         };
16358         hda_nid_t nid;
16359         int i, err;
16360
16361         for (i = 0; i < cfg->line_outs; i++) {
16362                 if (!spec->multiout.dac_nids[i])
16363                         continue;
16364                 nid = alc880_idx_to_dac(i);
16365                 if (i == 2) {
16366                         /* Center/LFE */
16367                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
16368                                           "Center Playback Volume",
16369                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
16370                                                               HDA_OUTPUT));
16371                         if (err < 0)
16372                                 return err;
16373                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
16374                                           "LFE Playback Volume",
16375                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
16376                                                               HDA_OUTPUT));
16377                         if (err < 0)
16378                                 return err;
16379                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
16380                                           "Center Playback Switch",
16381                                           HDA_COMPOSE_AMP_VAL(0x0e, 1, 0,
16382                                                               HDA_INPUT));
16383                         if (err < 0)
16384                                 return err;
16385                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
16386                                           "LFE Playback Switch",
16387                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
16388                                                               HDA_INPUT));
16389                         if (err < 0)
16390                                 return err;
16391                 } else {
16392                         sprintf(name, "%s Playback Volume", chname[i]);
16393                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
16394                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
16395                                                               HDA_OUTPUT));
16396                         if (err < 0)
16397                                 return err;
16398                         sprintf(name, "%s Playback Switch", chname[i]);
16399                         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
16400                                 HDA_COMPOSE_AMP_VAL(alc880_idx_to_mixer(i),
16401                                                     3, 0, HDA_INPUT));
16402                         if (err < 0)
16403                                 return err;
16404                 }
16405         }
16406         return 0;
16407 }
16408
16409 /* add playback controls for speaker and HP outputs */
16410 static int alc662_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
16411                                         const char *pfx)
16412 {
16413         hda_nid_t nid;
16414         int err;
16415         char name[32];
16416
16417         if (!pin)
16418                 return 0;
16419
16420         if (pin == 0x17) {
16421                 /* ALC663 has a mono output pin on 0x17 */
16422                 sprintf(name, "%s Playback Switch", pfx);
16423                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
16424                                   HDA_COMPOSE_AMP_VAL(pin, 2, 0, HDA_OUTPUT));
16425                 return err;
16426         }
16427
16428         if (alc880_is_fixed_pin(pin)) {
16429                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
16430                 /* printk("DAC nid=%x\n",nid); */
16431                 /* specify the DAC as the extra output */
16432                 if (!spec->multiout.hp_nid)
16433                         spec->multiout.hp_nid = nid;
16434                 else
16435                         spec->multiout.extra_out_nid[0] = nid;
16436                 /* control HP volume/switch on the output mixer amp */
16437                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
16438                 sprintf(name, "%s Playback Volume", pfx);
16439                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
16440                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
16441                 if (err < 0)
16442                         return err;
16443                 sprintf(name, "%s Playback Switch", pfx);
16444                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
16445                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
16446                 if (err < 0)
16447                         return err;
16448         } else if (alc880_is_multi_pin(pin)) {
16449                 /* set manual connection */
16450                 /* we have only a switch on HP-out PIN */
16451                 sprintf(name, "%s Playback Switch", pfx);
16452                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
16453                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
16454                 if (err < 0)
16455                         return err;
16456         }
16457         return 0;
16458 }
16459
16460 /* create playback/capture controls for input pins */
16461 static int alc662_auto_create_analog_input_ctls(struct alc_spec *spec,
16462                                                 const struct auto_pin_cfg *cfg)
16463 {
16464         struct hda_input_mux *imux = &spec->private_imux[0];
16465         int i, err, idx;
16466
16467         for (i = 0; i < AUTO_PIN_LAST; i++) {
16468                 if (alc880_is_input_pin(cfg->input_pins[i])) {
16469                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
16470                         err = new_analog_input(spec, cfg->input_pins[i],
16471                                                auto_pin_cfg_labels[i],
16472                                                idx, 0x0b);
16473                         if (err < 0)
16474                                 return err;
16475                         imux->items[imux->num_items].label =
16476                                 auto_pin_cfg_labels[i];
16477                         imux->items[imux->num_items].index =
16478                                 alc880_input_pin_idx(cfg->input_pins[i]);
16479                         imux->num_items++;
16480                 }
16481         }
16482         return 0;
16483 }
16484
16485 static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
16486                                               hda_nid_t nid, int pin_type,
16487                                               int dac_idx)
16488 {
16489         alc_set_pin_output(codec, nid, pin_type);
16490         /* need the manual connection? */
16491         if (alc880_is_multi_pin(nid)) {
16492                 struct alc_spec *spec = codec->spec;
16493                 int idx = alc880_multi_pin_idx(nid);
16494                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
16495                                     AC_VERB_SET_CONNECT_SEL,
16496                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
16497         }
16498 }
16499
16500 static void alc662_auto_init_multi_out(struct hda_codec *codec)
16501 {
16502         struct alc_spec *spec = codec->spec;
16503         int i;
16504
16505         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
16506         for (i = 0; i <= HDA_SIDE; i++) {
16507                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
16508                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
16509                 if (nid)
16510                         alc662_auto_set_output_and_unmute(codec, nid, pin_type,
16511                                                           i);
16512         }
16513 }
16514
16515 static void alc662_auto_init_hp_out(struct hda_codec *codec)
16516 {
16517         struct alc_spec *spec = codec->spec;
16518         hda_nid_t pin;
16519
16520         pin = spec->autocfg.hp_pins[0];
16521         if (pin) /* connect to front */
16522                 /* use dac 0 */
16523                 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
16524         pin = spec->autocfg.speaker_pins[0];
16525         if (pin)
16526                 alc662_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
16527 }
16528
16529 #define alc662_is_input_pin(nid)        alc880_is_input_pin(nid)
16530 #define ALC662_PIN_CD_NID               ALC880_PIN_CD_NID
16531
16532 static void alc662_auto_init_analog_input(struct hda_codec *codec)
16533 {
16534         struct alc_spec *spec = codec->spec;
16535         int i;
16536
16537         for (i = 0; i < AUTO_PIN_LAST; i++) {
16538                 hda_nid_t nid = spec->autocfg.input_pins[i];
16539                 if (alc662_is_input_pin(nid)) {
16540                         snd_hda_codec_write(codec, nid, 0,
16541                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
16542                                             (i <= AUTO_PIN_FRONT_MIC ?
16543                                              PIN_VREF80 : PIN_IN));
16544                         if (nid != ALC662_PIN_CD_NID)
16545                                 snd_hda_codec_write(codec, nid, 0,
16546                                                     AC_VERB_SET_AMP_GAIN_MUTE,
16547                                                     AMP_OUT_MUTE);
16548                 }
16549         }
16550 }
16551
16552 #define alc662_auto_init_input_src      alc882_auto_init_input_src
16553
16554 static int alc662_parse_auto_config(struct hda_codec *codec)
16555 {
16556         struct alc_spec *spec = codec->spec;
16557         int err;
16558         static hda_nid_t alc662_ignore[] = { 0x1d, 0 };
16559
16560         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
16561                                            alc662_ignore);
16562         if (err < 0)
16563                 return err;
16564         if (!spec->autocfg.line_outs)
16565                 return 0; /* can't find valid BIOS pin config */
16566
16567         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
16568         if (err < 0)
16569                 return err;
16570         err = alc662_auto_create_multi_out_ctls(spec, &spec->autocfg);
16571         if (err < 0)
16572                 return err;
16573         err = alc662_auto_create_extra_out(spec,
16574                                            spec->autocfg.speaker_pins[0],
16575                                            "Speaker");
16576         if (err < 0)
16577                 return err;
16578         err = alc662_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
16579                                            "Headphone");
16580         if (err < 0)
16581                 return err;
16582         err = alc662_auto_create_analog_input_ctls(spec, &spec->autocfg);
16583         if (err < 0)
16584                 return err;
16585
16586         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
16587
16588         if (spec->autocfg.dig_out_pin)
16589                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
16590
16591         if (spec->kctls.list)
16592                 add_mixer(spec, spec->kctls.list);
16593
16594         spec->num_mux_defs = 1;
16595         spec->input_mux = &spec->private_imux[0];
16596
16597         add_verb(spec, alc662_auto_init_verbs);
16598         if (codec->vendor_id == 0x10ec0663)
16599                 add_verb(spec, alc663_auto_init_verbs);
16600
16601         err = alc_auto_add_mic_boost(codec);
16602         if (err < 0)
16603                 return err;
16604
16605         store_pin_configs(codec);
16606         return 1;
16607 }
16608
16609 /* additional initialization for auto-configuration model */
16610 static void alc662_auto_init(struct hda_codec *codec)
16611 {
16612         struct alc_spec *spec = codec->spec;
16613         alc662_auto_init_multi_out(codec);
16614         alc662_auto_init_hp_out(codec);
16615         alc662_auto_init_analog_input(codec);
16616         alc662_auto_init_input_src(codec);
16617         if (spec->unsol_event)
16618                 alc_inithook(codec);
16619 }
16620
16621 static int patch_alc662(struct hda_codec *codec)
16622 {
16623         struct alc_spec *spec;
16624         int err, board_config;
16625
16626         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
16627         if (!spec)
16628                 return -ENOMEM;
16629
16630         codec->spec = spec;
16631
16632         alc_fix_pll_init(codec, 0x20, 0x04, 15);
16633
16634         board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
16635                                                   alc662_models,
16636                                                   alc662_cfg_tbl);
16637         if (board_config < 0) {
16638                 printk(KERN_INFO "hda_codec: Unknown model for ALC662, "
16639                        "trying auto-probe from BIOS...\n");
16640                 board_config = ALC662_AUTO;
16641         }
16642
16643         if (board_config == ALC662_AUTO) {
16644                 /* automatic parse from the BIOS config */
16645                 err = alc662_parse_auto_config(codec);
16646                 if (err < 0) {
16647                         alc_free(codec);
16648                         return err;
16649                 } else if (!err) {
16650                         printk(KERN_INFO
16651                                "hda_codec: Cannot set up configuration "
16652                                "from BIOS.  Using base mode...\n");
16653                         board_config = ALC662_3ST_2ch_DIG;
16654                 }
16655         }
16656
16657         if (board_config != ALC662_AUTO)
16658                 setup_preset(spec, &alc662_presets[board_config]);
16659
16660         if (codec->vendor_id == 0x10ec0663) {
16661                 spec->stream_name_analog = "ALC663 Analog";
16662                 spec->stream_name_digital = "ALC663 Digital";
16663         } else if (codec->vendor_id == 0x10ec0272) {
16664                 spec->stream_name_analog = "ALC272 Analog";
16665                 spec->stream_name_digital = "ALC272 Digital";
16666         } else {
16667                 spec->stream_name_analog = "ALC662 Analog";
16668                 spec->stream_name_digital = "ALC662 Digital";
16669         }
16670
16671         spec->stream_analog_playback = &alc662_pcm_analog_playback;
16672         spec->stream_analog_capture = &alc662_pcm_analog_capture;
16673
16674         spec->stream_digital_playback = &alc662_pcm_digital_playback;
16675         spec->stream_digital_capture = &alc662_pcm_digital_capture;
16676
16677         spec->adc_nids = alc662_adc_nids;
16678         spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
16679         spec->capsrc_nids = alc662_capsrc_nids;
16680         spec->capture_style = CAPT_MIX;
16681
16682         if (!spec->cap_mixer)
16683                 set_capture_mixer(spec);
16684
16685         spec->vmaster_nid = 0x02;
16686
16687         codec->patch_ops = alc_patch_ops;
16688         if (board_config == ALC662_AUTO)
16689                 spec->init_hook = alc662_auto_init;
16690 #ifdef CONFIG_SND_HDA_POWER_SAVE
16691         if (!spec->loopback.amplist)
16692                 spec->loopback.amplist = alc662_loopbacks;
16693 #endif
16694         codec->proc_widget_hook = print_realtek_coef;
16695
16696         return 0;
16697 }
16698
16699 /*
16700  * patch entries
16701  */
16702 static struct hda_codec_preset snd_hda_preset_realtek[] = {
16703         { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
16704         { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
16705         { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
16706         { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
16707         { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
16708         { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
16709         { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
16710           .patch = patch_alc861 },
16711         { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
16712         { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
16713         { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
16714         { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
16715           .patch = patch_alc883 },
16716         { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
16717           .patch = patch_alc662 },
16718         { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
16719         { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
16720         { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
16721         { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 },
16722         { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
16723           .patch = patch_alc882 }, /* should be patch_alc883() in future */
16724         { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
16725           .patch = patch_alc882 }, /* should be patch_alc883() in future */
16726         { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
16727         { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc883 },
16728         { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
16729           .patch = patch_alc883 },
16730         { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc883 },
16731         { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc883 },
16732         {} /* terminator */
16733 };
16734
16735 MODULE_ALIAS("snd-hda-codec-id:10ec*");
16736
16737 MODULE_LICENSE("GPL");
16738 MODULE_DESCRIPTION("Realtek HD-audio codec");
16739
16740 static struct hda_codec_preset_list realtek_list = {
16741         .preset = snd_hda_preset_realtek,
16742         .owner = THIS_MODULE,
16743 };
16744
16745 static int __init patch_realtek_init(void)
16746 {
16747         return snd_hda_add_codec_preset(&realtek_list);
16748 }
16749
16750 static void __exit patch_realtek_exit(void)
16751 {
16752         snd_hda_delete_codec_preset(&realtek_list);
16753 }
16754
16755 module_init(patch_realtek_init)
16756 module_exit(patch_realtek_exit)