ALSA: hda - Fix invalid amp init for ALC268 codec
[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 /* for GPIO Poll */
242 #define GPIO_MASK       0x03
243
244 struct alc_spec {
245         /* codec parameterization */
246         struct snd_kcontrol_new *mixers[5];     /* mixer arrays */
247         unsigned int num_mixers;
248         struct snd_kcontrol_new *cap_mixer;     /* capture mixer */
249
250         const struct hda_verb *init_verbs[5];   /* initialization verbs
251                                                  * don't forget NULL
252                                                  * termination!
253                                                  */
254         unsigned int num_init_verbs;
255
256         char *stream_name_analog;       /* analog PCM stream */
257         struct hda_pcm_stream *stream_analog_playback;
258         struct hda_pcm_stream *stream_analog_capture;
259         struct hda_pcm_stream *stream_analog_alt_playback;
260         struct hda_pcm_stream *stream_analog_alt_capture;
261
262         char *stream_name_digital;      /* digital PCM stream */
263         struct hda_pcm_stream *stream_digital_playback;
264         struct hda_pcm_stream *stream_digital_capture;
265
266         /* playback */
267         struct hda_multi_out multiout;  /* playback set-up
268                                          * max_channels, dacs must be set
269                                          * dig_out_nid and hp_nid are optional
270                                          */
271         hda_nid_t alt_dac_nid;
272         int dig_out_type;
273
274         /* capture */
275         unsigned int num_adc_nids;
276         hda_nid_t *adc_nids;
277         hda_nid_t *capsrc_nids;
278         hda_nid_t dig_in_nid;           /* digital-in NID; optional */
279         unsigned char is_mix_capture;   /* matrix-style capture (non-mux) */
280
281         /* capture source */
282         unsigned int num_mux_defs;
283         const struct hda_input_mux *input_mux;
284         unsigned int cur_mux[3];
285
286         /* channel model */
287         const struct hda_channel_mode *channel_mode;
288         int num_channel_mode;
289         int need_dac_fix;
290
291         /* PCM information */
292         struct hda_pcm pcm_rec[3];      /* used in alc_build_pcms() */
293
294         /* dynamic controls, init_verbs and input_mux */
295         struct auto_pin_cfg autocfg;
296         struct snd_array kctls;
297         struct hda_input_mux private_imux;
298         hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
299
300         /* hooks */
301         void (*init_hook)(struct hda_codec *codec);
302         void (*unsol_event)(struct hda_codec *codec, unsigned int res);
303
304         /* for pin sensing */
305         unsigned int sense_updated: 1;
306         unsigned int jack_present: 1;
307         unsigned int master_sw: 1;
308
309         /* other flags */
310         unsigned int no_analog :1; /* digital I/O only */
311
312         /* for virtual master */
313         hda_nid_t vmaster_nid;
314 #ifdef CONFIG_SND_HDA_POWER_SAVE
315         struct hda_loopback_check loopback;
316 #endif
317
318         /* for PLL fix */
319         hda_nid_t pll_nid;
320         unsigned int pll_coef_idx, pll_coef_bit;
321
322 #ifdef SND_HDA_NEEDS_RESUME
323 #define ALC_MAX_PINS    16
324         unsigned int num_pins;
325         hda_nid_t pin_nids[ALC_MAX_PINS];
326         unsigned int pin_cfgs[ALC_MAX_PINS];
327 #endif
328 };
329
330 /*
331  * configuration template - to be copied to the spec instance
332  */
333 struct alc_config_preset {
334         struct snd_kcontrol_new *mixers[5]; /* should be identical size
335                                              * with spec
336                                              */
337         struct snd_kcontrol_new *cap_mixer; /* capture mixer */
338         const struct hda_verb *init_verbs[5];
339         unsigned int num_dacs;
340         hda_nid_t *dac_nids;
341         hda_nid_t dig_out_nid;          /* optional */
342         hda_nid_t hp_nid;               /* optional */
343         unsigned int num_adc_nids;
344         hda_nid_t *adc_nids;
345         hda_nid_t *capsrc_nids;
346         hda_nid_t dig_in_nid;
347         unsigned int num_channel_mode;
348         const struct hda_channel_mode *channel_mode;
349         int need_dac_fix;
350         unsigned int num_mux_defs;
351         const struct hda_input_mux *input_mux;
352         void (*unsol_event)(struct hda_codec *, unsigned int);
353         void (*init_hook)(struct hda_codec *);
354 #ifdef CONFIG_SND_HDA_POWER_SAVE
355         struct hda_amp_list *loopbacks;
356 #endif
357 };
358
359
360 /*
361  * input MUX handling
362  */
363 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
364                              struct snd_ctl_elem_info *uinfo)
365 {
366         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
367         struct alc_spec *spec = codec->spec;
368         unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
369         if (mux_idx >= spec->num_mux_defs)
370                 mux_idx = 0;
371         return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
372 }
373
374 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
375                             struct snd_ctl_elem_value *ucontrol)
376 {
377         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
378         struct alc_spec *spec = codec->spec;
379         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
380
381         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
382         return 0;
383 }
384
385 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
386                             struct snd_ctl_elem_value *ucontrol)
387 {
388         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
389         struct alc_spec *spec = codec->spec;
390         const struct hda_input_mux *imux;
391         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
392         unsigned int mux_idx;
393         hda_nid_t nid = spec->capsrc_nids ?
394                 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
395
396         mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
397         imux = &spec->input_mux[mux_idx];
398
399         if (spec->is_mix_capture) {
400                 /* Matrix-mixer style (e.g. ALC882) */
401                 unsigned int *cur_val = &spec->cur_mux[adc_idx];
402                 unsigned int i, idx;
403
404                 idx = ucontrol->value.enumerated.item[0];
405                 if (idx >= imux->num_items)
406                         idx = imux->num_items - 1;
407                 if (*cur_val == idx)
408                         return 0;
409                 for (i = 0; i < imux->num_items; i++) {
410                         unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
411                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
412                                                  imux->items[i].index,
413                                                  HDA_AMP_MUTE, v);
414                 }
415                 *cur_val = idx;
416                 return 1;
417         } else {
418                 /* MUX style (e.g. ALC880) */
419                 return snd_hda_input_mux_put(codec, imux, ucontrol, nid,
420                                              &spec->cur_mux[adc_idx]);
421         }
422 }
423
424 /*
425  * channel mode setting
426  */
427 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
428                             struct snd_ctl_elem_info *uinfo)
429 {
430         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
431         struct alc_spec *spec = codec->spec;
432         return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
433                                     spec->num_channel_mode);
434 }
435
436 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
437                            struct snd_ctl_elem_value *ucontrol)
438 {
439         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
440         struct alc_spec *spec = codec->spec;
441         return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
442                                    spec->num_channel_mode,
443                                    spec->multiout.max_channels);
444 }
445
446 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
447                            struct snd_ctl_elem_value *ucontrol)
448 {
449         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
450         struct alc_spec *spec = codec->spec;
451         int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
452                                       spec->num_channel_mode,
453                                       &spec->multiout.max_channels);
454         if (err >= 0 && spec->need_dac_fix)
455                 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
456         return err;
457 }
458
459 /*
460  * Control the mode of pin widget settings via the mixer.  "pc" is used
461  * instead of "%" to avoid consequences of accidently treating the % as
462  * being part of a format specifier.  Maximum allowed length of a value is
463  * 63 characters plus NULL terminator.
464  *
465  * Note: some retasking pin complexes seem to ignore requests for input
466  * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
467  * are requested.  Therefore order this list so that this behaviour will not
468  * cause problems when mixer clients move through the enum sequentially.
469  * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
470  * March 2006.
471  */
472 static char *alc_pin_mode_names[] = {
473         "Mic 50pc bias", "Mic 80pc bias",
474         "Line in", "Line out", "Headphone out",
475 };
476 static unsigned char alc_pin_mode_values[] = {
477         PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
478 };
479 /* The control can present all 5 options, or it can limit the options based
480  * in the pin being assumed to be exclusively an input or an output pin.  In
481  * addition, "input" pins may or may not process the mic bias option
482  * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
483  * accept requests for bias as of chip versions up to March 2006) and/or
484  * wiring in the computer.
485  */
486 #define ALC_PIN_DIR_IN              0x00
487 #define ALC_PIN_DIR_OUT             0x01
488 #define ALC_PIN_DIR_INOUT           0x02
489 #define ALC_PIN_DIR_IN_NOMICBIAS    0x03
490 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
491
492 /* Info about the pin modes supported by the different pin direction modes.
493  * For each direction the minimum and maximum values are given.
494  */
495 static signed char alc_pin_mode_dir_info[5][2] = {
496         { 0, 2 },    /* ALC_PIN_DIR_IN */
497         { 3, 4 },    /* ALC_PIN_DIR_OUT */
498         { 0, 4 },    /* ALC_PIN_DIR_INOUT */
499         { 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
500         { 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
501 };
502 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
503 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
504 #define alc_pin_mode_n_items(_dir) \
505         (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
506
507 static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
508                              struct snd_ctl_elem_info *uinfo)
509 {
510         unsigned int item_num = uinfo->value.enumerated.item;
511         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
512
513         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
514         uinfo->count = 1;
515         uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
516
517         if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
518                 item_num = alc_pin_mode_min(dir);
519         strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
520         return 0;
521 }
522
523 static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
524                             struct snd_ctl_elem_value *ucontrol)
525 {
526         unsigned int i;
527         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
528         hda_nid_t nid = kcontrol->private_value & 0xffff;
529         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
530         long *valp = ucontrol->value.integer.value;
531         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
532                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
533                                                  0x00);
534
535         /* Find enumerated value for current pinctl setting */
536         i = alc_pin_mode_min(dir);
537         while (alc_pin_mode_values[i] != pinctl && i <= alc_pin_mode_max(dir))
538                 i++;
539         *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
540         return 0;
541 }
542
543 static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
544                             struct snd_ctl_elem_value *ucontrol)
545 {
546         signed int change;
547         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
548         hda_nid_t nid = kcontrol->private_value & 0xffff;
549         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
550         long val = *ucontrol->value.integer.value;
551         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
552                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
553                                                  0x00);
554
555         if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
556                 val = alc_pin_mode_min(dir);
557
558         change = pinctl != alc_pin_mode_values[val];
559         if (change) {
560                 /* Set pin mode to that requested */
561                 snd_hda_codec_write_cache(codec, nid, 0,
562                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
563                                           alc_pin_mode_values[val]);
564
565                 /* Also enable the retasking pin's input/output as required
566                  * for the requested pin mode.  Enum values of 2 or less are
567                  * input modes.
568                  *
569                  * Dynamically switching the input/output buffers probably
570                  * reduces noise slightly (particularly on input) so we'll
571                  * do it.  However, having both input and output buffers
572                  * enabled simultaneously doesn't seem to be problematic if
573                  * this turns out to be necessary in the future.
574                  */
575                 if (val <= 2) {
576                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
577                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
578                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
579                                                  HDA_AMP_MUTE, 0);
580                 } else {
581                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
582                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
583                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
584                                                  HDA_AMP_MUTE, 0);
585                 }
586         }
587         return change;
588 }
589
590 #define ALC_PIN_MODE(xname, nid, dir) \
591         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
592           .info = alc_pin_mode_info, \
593           .get = alc_pin_mode_get, \
594           .put = alc_pin_mode_put, \
595           .private_value = nid | (dir<<16) }
596
597 /* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
598  * together using a mask with more than one bit set.  This control is
599  * currently used only by the ALC260 test model.  At this stage they are not
600  * needed for any "production" models.
601  */
602 #ifdef CONFIG_SND_DEBUG
603 #define alc_gpio_data_info      snd_ctl_boolean_mono_info
604
605 static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
606                              struct snd_ctl_elem_value *ucontrol)
607 {
608         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
609         hda_nid_t nid = kcontrol->private_value & 0xffff;
610         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
611         long *valp = ucontrol->value.integer.value;
612         unsigned int val = snd_hda_codec_read(codec, nid, 0,
613                                               AC_VERB_GET_GPIO_DATA, 0x00);
614
615         *valp = (val & mask) != 0;
616         return 0;
617 }
618 static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
619                              struct snd_ctl_elem_value *ucontrol)
620 {
621         signed int change;
622         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
623         hda_nid_t nid = kcontrol->private_value & 0xffff;
624         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
625         long val = *ucontrol->value.integer.value;
626         unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
627                                                     AC_VERB_GET_GPIO_DATA,
628                                                     0x00);
629
630         /* Set/unset the masked GPIO bit(s) as needed */
631         change = (val == 0 ? 0 : mask) != (gpio_data & mask);
632         if (val == 0)
633                 gpio_data &= ~mask;
634         else
635                 gpio_data |= mask;
636         snd_hda_codec_write_cache(codec, nid, 0,
637                                   AC_VERB_SET_GPIO_DATA, gpio_data);
638
639         return change;
640 }
641 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
642         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
643           .info = alc_gpio_data_info, \
644           .get = alc_gpio_data_get, \
645           .put = alc_gpio_data_put, \
646           .private_value = nid | (mask<<16) }
647 #endif   /* CONFIG_SND_DEBUG */
648
649 /* A switch control to allow the enabling of the digital IO pins on the
650  * ALC260.  This is incredibly simplistic; the intention of this control is
651  * to provide something in the test model allowing digital outputs to be
652  * identified if present.  If models are found which can utilise these
653  * outputs a more complete mixer control can be devised for those models if
654  * necessary.
655  */
656 #ifdef CONFIG_SND_DEBUG
657 #define alc_spdif_ctrl_info     snd_ctl_boolean_mono_info
658
659 static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
660                               struct snd_ctl_elem_value *ucontrol)
661 {
662         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
663         hda_nid_t nid = kcontrol->private_value & 0xffff;
664         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
665         long *valp = ucontrol->value.integer.value;
666         unsigned int val = snd_hda_codec_read(codec, nid, 0,
667                                               AC_VERB_GET_DIGI_CONVERT_1, 0x00);
668
669         *valp = (val & mask) != 0;
670         return 0;
671 }
672 static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
673                               struct snd_ctl_elem_value *ucontrol)
674 {
675         signed int change;
676         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
677         hda_nid_t nid = kcontrol->private_value & 0xffff;
678         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
679         long val = *ucontrol->value.integer.value;
680         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
681                                                     AC_VERB_GET_DIGI_CONVERT_1,
682                                                     0x00);
683
684         /* Set/unset the masked control bit(s) as needed */
685         change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
686         if (val==0)
687                 ctrl_data &= ~mask;
688         else
689                 ctrl_data |= mask;
690         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
691                                   ctrl_data);
692
693         return change;
694 }
695 #define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
696         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
697           .info = alc_spdif_ctrl_info, \
698           .get = alc_spdif_ctrl_get, \
699           .put = alc_spdif_ctrl_put, \
700           .private_value = nid | (mask<<16) }
701 #endif   /* CONFIG_SND_DEBUG */
702
703 /* A switch control to allow the enabling EAPD digital outputs on the ALC26x.
704  * Again, this is only used in the ALC26x test models to help identify when
705  * the EAPD line must be asserted for features to work.
706  */
707 #ifdef CONFIG_SND_DEBUG
708 #define alc_eapd_ctrl_info      snd_ctl_boolean_mono_info
709
710 static int alc_eapd_ctrl_get(struct snd_kcontrol *kcontrol,
711                               struct snd_ctl_elem_value *ucontrol)
712 {
713         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
714         hda_nid_t nid = kcontrol->private_value & 0xffff;
715         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
716         long *valp = ucontrol->value.integer.value;
717         unsigned int val = snd_hda_codec_read(codec, nid, 0,
718                                               AC_VERB_GET_EAPD_BTLENABLE, 0x00);
719
720         *valp = (val & mask) != 0;
721         return 0;
722 }
723
724 static int alc_eapd_ctrl_put(struct snd_kcontrol *kcontrol,
725                               struct snd_ctl_elem_value *ucontrol)
726 {
727         int change;
728         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
729         hda_nid_t nid = kcontrol->private_value & 0xffff;
730         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
731         long val = *ucontrol->value.integer.value;
732         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
733                                                     AC_VERB_GET_EAPD_BTLENABLE,
734                                                     0x00);
735
736         /* Set/unset the masked control bit(s) as needed */
737         change = (!val ? 0 : mask) != (ctrl_data & mask);
738         if (!val)
739                 ctrl_data &= ~mask;
740         else
741                 ctrl_data |= mask;
742         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
743                                   ctrl_data);
744
745         return change;
746 }
747
748 #define ALC_EAPD_CTRL_SWITCH(xname, nid, mask) \
749         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
750           .info = alc_eapd_ctrl_info, \
751           .get = alc_eapd_ctrl_get, \
752           .put = alc_eapd_ctrl_put, \
753           .private_value = nid | (mask<<16) }
754 #endif   /* CONFIG_SND_DEBUG */
755
756 /*
757  */
758 static void add_mixer(struct alc_spec *spec, struct snd_kcontrol_new *mix)
759 {
760         if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
761                 return;
762         spec->mixers[spec->num_mixers++] = mix;
763 }
764
765 static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
766 {
767         if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
768                 return;
769         spec->init_verbs[spec->num_init_verbs++] = verb;
770 }
771
772 #ifdef CONFIG_PROC_FS
773 /*
774  * hook for proc
775  */
776 static void print_realtek_coef(struct snd_info_buffer *buffer,
777                                struct hda_codec *codec, hda_nid_t nid)
778 {
779         int coeff;
780
781         if (nid != 0x20)
782                 return;
783         coeff = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PROC_COEF, 0);
784         snd_iprintf(buffer, "  Processing Coefficient: 0x%02x\n", coeff);
785         coeff = snd_hda_codec_read(codec, nid, 0,
786                                    AC_VERB_GET_COEF_INDEX, 0);
787         snd_iprintf(buffer, "  Coefficient Index: 0x%02x\n", coeff);
788 }
789 #else
790 #define print_realtek_coef      NULL
791 #endif
792
793 /*
794  * set up from the preset table
795  */
796 static void setup_preset(struct alc_spec *spec,
797                          const struct alc_config_preset *preset)
798 {
799         int i;
800
801         for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
802                 add_mixer(spec, preset->mixers[i]);
803         spec->cap_mixer = preset->cap_mixer;
804         for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
805              i++)
806                 add_verb(spec, preset->init_verbs[i]);
807
808         spec->channel_mode = preset->channel_mode;
809         spec->num_channel_mode = preset->num_channel_mode;
810         spec->need_dac_fix = preset->need_dac_fix;
811
812         spec->multiout.max_channels = spec->channel_mode[0].channels;
813
814         spec->multiout.num_dacs = preset->num_dacs;
815         spec->multiout.dac_nids = preset->dac_nids;
816         spec->multiout.dig_out_nid = preset->dig_out_nid;
817         spec->multiout.hp_nid = preset->hp_nid;
818
819         spec->num_mux_defs = preset->num_mux_defs;
820         if (!spec->num_mux_defs)
821                 spec->num_mux_defs = 1;
822         spec->input_mux = preset->input_mux;
823
824         spec->num_adc_nids = preset->num_adc_nids;
825         spec->adc_nids = preset->adc_nids;
826         spec->capsrc_nids = preset->capsrc_nids;
827         spec->dig_in_nid = preset->dig_in_nid;
828
829         spec->unsol_event = preset->unsol_event;
830         spec->init_hook = preset->init_hook;
831 #ifdef CONFIG_SND_HDA_POWER_SAVE
832         spec->loopback.amplist = preset->loopbacks;
833 #endif
834 }
835
836 /* Enable GPIO mask and set output */
837 static struct hda_verb alc_gpio1_init_verbs[] = {
838         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
839         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
840         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
841         { }
842 };
843
844 static struct hda_verb alc_gpio2_init_verbs[] = {
845         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
846         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
847         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
848         { }
849 };
850
851 static struct hda_verb alc_gpio3_init_verbs[] = {
852         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
853         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
854         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
855         { }
856 };
857
858 /*
859  * Fix hardware PLL issue
860  * On some codecs, the analog PLL gating control must be off while
861  * the default value is 1.
862  */
863 static void alc_fix_pll(struct hda_codec *codec)
864 {
865         struct alc_spec *spec = codec->spec;
866         unsigned int val;
867
868         if (!spec->pll_nid)
869                 return;
870         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
871                             spec->pll_coef_idx);
872         val = snd_hda_codec_read(codec, spec->pll_nid, 0,
873                                  AC_VERB_GET_PROC_COEF, 0);
874         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
875                             spec->pll_coef_idx);
876         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
877                             val & ~(1 << spec->pll_coef_bit));
878 }
879
880 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
881                              unsigned int coef_idx, unsigned int coef_bit)
882 {
883         struct alc_spec *spec = codec->spec;
884         spec->pll_nid = nid;
885         spec->pll_coef_idx = coef_idx;
886         spec->pll_coef_bit = coef_bit;
887         alc_fix_pll(codec);
888 }
889
890 static void alc_sku_automute(struct hda_codec *codec)
891 {
892         struct alc_spec *spec = codec->spec;
893         unsigned int present;
894         unsigned int hp_nid = spec->autocfg.hp_pins[0];
895         unsigned int sp_nid = spec->autocfg.speaker_pins[0];
896
897         /* need to execute and sync at first */
898         snd_hda_codec_read(codec, hp_nid, 0, AC_VERB_SET_PIN_SENSE, 0);
899         present = snd_hda_codec_read(codec, hp_nid, 0,
900                                      AC_VERB_GET_PIN_SENSE, 0);
901         spec->jack_present = (present & 0x80000000) != 0;
902         snd_hda_codec_write(codec, sp_nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
903                             spec->jack_present ? 0 : PIN_OUT);
904 }
905
906 #if 0 /* it's broken in some acses -- temporarily disabled */
907 static void alc_mic_automute(struct hda_codec *codec)
908 {
909         struct alc_spec *spec = codec->spec;
910         unsigned int present;
911         unsigned int mic_nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
912         unsigned int fmic_nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
913         unsigned int mix_nid = spec->capsrc_nids[0];
914         unsigned int capsrc_idx_mic, capsrc_idx_fmic;
915
916         capsrc_idx_mic = mic_nid - 0x18;
917         capsrc_idx_fmic = fmic_nid - 0x18;
918         present = snd_hda_codec_read(codec, mic_nid, 0,
919                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
920         snd_hda_codec_write(codec, mix_nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
921                     0x7000 | (capsrc_idx_mic << 8) | (present ? 0 : 0x80));
922         snd_hda_codec_write(codec, mix_nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
923                     0x7000 | (capsrc_idx_fmic << 8) | (present ? 0x80 : 0));
924         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, capsrc_idx_fmic,
925                          HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
926 }
927 #else
928 #define alc_mic_automute(codec) /* NOP */
929 #endif /* disabled */
930
931 /* unsolicited event for HP jack sensing */
932 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
933 {
934         if (codec->vendor_id == 0x10ec0880)
935                 res >>= 28;
936         else
937                 res >>= 26;
938         if (res == ALC880_HP_EVENT)
939                 alc_sku_automute(codec);
940
941         if (res == ALC880_MIC_EVENT)
942                 alc_mic_automute(codec);
943 }
944
945 static void alc_inithook(struct hda_codec *codec)
946 {
947         alc_sku_automute(codec);
948         alc_mic_automute(codec);
949 }
950
951 /* additional initialization for ALC888 variants */
952 static void alc888_coef_init(struct hda_codec *codec)
953 {
954         unsigned int tmp;
955
956         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
957         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
958         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
959         if ((tmp & 0xf0) == 2)
960                 /* alc888S-VC */
961                 snd_hda_codec_read(codec, 0x20, 0,
962                                    AC_VERB_SET_PROC_COEF, 0x830);
963          else
964                  /* alc888-VB */
965                  snd_hda_codec_read(codec, 0x20, 0,
966                                     AC_VERB_SET_PROC_COEF, 0x3030);
967 }
968
969 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
970  *      31 ~ 16 :       Manufacture ID
971  *      15 ~ 8  :       SKU ID
972  *      7  ~ 0  :       Assembly ID
973  *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
974  */
975 static void alc_subsystem_id(struct hda_codec *codec,
976                              unsigned int porta, unsigned int porte,
977                              unsigned int portd)
978 {
979         unsigned int ass, tmp, i;
980         unsigned nid;
981         struct alc_spec *spec = codec->spec;
982
983         ass = codec->subsystem_id & 0xffff;
984         if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
985                 goto do_sku;
986
987         /*
988          * 31~30        : port conetcivity
989          * 29~21        : reserve
990          * 20           : PCBEEP input
991          * 19~16        : Check sum (15:1)
992          * 15~1         : Custom
993          * 0            : override
994         */
995         nid = 0x1d;
996         if (codec->vendor_id == 0x10ec0260)
997                 nid = 0x17;
998         ass = snd_hda_codec_read(codec, nid, 0,
999                                  AC_VERB_GET_CONFIG_DEFAULT, 0);
1000         if (!(ass & 1) && !(ass & 0x100000))
1001                 return;
1002         if ((ass >> 30) != 1)   /* no physical connection */
1003                 return;
1004
1005         /* check sum */
1006         tmp = 0;
1007         for (i = 1; i < 16; i++) {
1008                 if ((ass >> i) & 1)
1009                         tmp++;
1010         }
1011         if (((ass >> 16) & 0xf) != tmp)
1012                 return;
1013 do_sku:
1014         /*
1015          * 0 : override
1016          * 1 :  Swap Jack
1017          * 2 : 0 --> Desktop, 1 --> Laptop
1018          * 3~5 : External Amplifier control
1019          * 7~6 : Reserved
1020         */
1021         tmp = (ass & 0x38) >> 3;        /* external Amp control */
1022         switch (tmp) {
1023         case 1:
1024                 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
1025                 break;
1026         case 3:
1027                 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
1028                 break;
1029         case 7:
1030                 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
1031                 break;
1032         case 5: /* set EAPD output high */
1033                 switch (codec->vendor_id) {
1034                 case 0x10ec0260:
1035                         snd_hda_codec_write(codec, 0x0f, 0,
1036                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1037                         snd_hda_codec_write(codec, 0x10, 0,
1038                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1039                         break;
1040                 case 0x10ec0262:
1041                 case 0x10ec0267:
1042                 case 0x10ec0268:
1043                 case 0x10ec0269:
1044                 case 0x10ec0660:
1045                 case 0x10ec0662:
1046                 case 0x10ec0663:
1047                 case 0x10ec0862:
1048                 case 0x10ec0889:
1049                         snd_hda_codec_write(codec, 0x14, 0,
1050                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1051                         snd_hda_codec_write(codec, 0x15, 0,
1052                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1053                         break;
1054                 }
1055                 switch (codec->vendor_id) {
1056                 case 0x10ec0260:
1057                         snd_hda_codec_write(codec, 0x1a, 0,
1058                                             AC_VERB_SET_COEF_INDEX, 7);
1059                         tmp = snd_hda_codec_read(codec, 0x1a, 0,
1060                                                  AC_VERB_GET_PROC_COEF, 0);
1061                         snd_hda_codec_write(codec, 0x1a, 0,
1062                                             AC_VERB_SET_COEF_INDEX, 7);
1063                         snd_hda_codec_write(codec, 0x1a, 0,
1064                                             AC_VERB_SET_PROC_COEF,
1065                                             tmp | 0x2010);
1066                         break;
1067                 case 0x10ec0262:
1068                 case 0x10ec0880:
1069                 case 0x10ec0882:
1070                 case 0x10ec0883:
1071                 case 0x10ec0885:
1072                 case 0x10ec0889:
1073                         snd_hda_codec_write(codec, 0x20, 0,
1074                                             AC_VERB_SET_COEF_INDEX, 7);
1075                         tmp = snd_hda_codec_read(codec, 0x20, 0,
1076                                                  AC_VERB_GET_PROC_COEF, 0);
1077                         snd_hda_codec_write(codec, 0x20, 0,
1078                                             AC_VERB_SET_COEF_INDEX, 7);
1079                         snd_hda_codec_write(codec, 0x20, 0,
1080                                             AC_VERB_SET_PROC_COEF,
1081                                             tmp | 0x2010);
1082                         break;
1083                 case 0x10ec0888:
1084                         /*alc888_coef_init(codec);*/ /* called in alc_init() */
1085                         break;
1086                 case 0x10ec0267:
1087                 case 0x10ec0268:
1088                         snd_hda_codec_write(codec, 0x20, 0,
1089                                             AC_VERB_SET_COEF_INDEX, 7);
1090                         tmp = snd_hda_codec_read(codec, 0x20, 0,
1091                                                  AC_VERB_GET_PROC_COEF, 0);
1092                         snd_hda_codec_write(codec, 0x20, 0,
1093                                             AC_VERB_SET_COEF_INDEX, 7);
1094                         snd_hda_codec_write(codec, 0x20, 0,
1095                                             AC_VERB_SET_PROC_COEF,
1096                                             tmp | 0x3000);
1097                         break;
1098                 }
1099         default:
1100                 break;
1101         }
1102
1103         /* is laptop or Desktop and enable the function "Mute internal speaker
1104          * when the external headphone out jack is plugged"
1105          */
1106         if (!(ass & 0x8000))
1107                 return;
1108         /*
1109          * 10~8 : Jack location
1110          * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1111          * 14~13: Resvered
1112          * 15   : 1 --> enable the function "Mute internal speaker
1113          *              when the external headphone out jack is plugged"
1114          */
1115         if (!spec->autocfg.speaker_pins[0]) {
1116                 if (spec->autocfg.line_out_pins[0])
1117                         spec->autocfg.speaker_pins[0] =
1118                                 spec->autocfg.line_out_pins[0];
1119                 else
1120                         return;
1121         }
1122
1123         if (!spec->autocfg.hp_pins[0]) {
1124                 tmp = (ass >> 11) & 0x3;        /* HP to chassis */
1125                 if (tmp == 0)
1126                         spec->autocfg.hp_pins[0] = porta;
1127                 else if (tmp == 1)
1128                         spec->autocfg.hp_pins[0] = porte;
1129                 else if (tmp == 2)
1130                         spec->autocfg.hp_pins[0] = portd;
1131                 else
1132                         return;
1133         }
1134         if (spec->autocfg.hp_pins[0])
1135                 snd_hda_codec_write(codec, spec->autocfg.hp_pins[0], 0,
1136                         AC_VERB_SET_UNSOLICITED_ENABLE,
1137                         AC_USRSP_EN | ALC880_HP_EVENT);
1138
1139 #if 0 /* it's broken in some acses -- temporarily disabled */
1140         if (spec->autocfg.input_pins[AUTO_PIN_MIC] &&
1141                 spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC])
1142                 snd_hda_codec_write(codec,
1143                         spec->autocfg.input_pins[AUTO_PIN_MIC], 0,
1144                         AC_VERB_SET_UNSOLICITED_ENABLE,
1145                         AC_USRSP_EN | ALC880_MIC_EVENT);
1146 #endif /* disabled */
1147
1148         spec->unsol_event = alc_sku_unsol_event;
1149 }
1150
1151 /*
1152  * Fix-up pin default configurations
1153  */
1154
1155 struct alc_pincfg {
1156         hda_nid_t nid;
1157         u32 val;
1158 };
1159
1160 static void alc_fix_pincfg(struct hda_codec *codec,
1161                            const struct snd_pci_quirk *quirk,
1162                            const struct alc_pincfg **pinfix)
1163 {
1164         const struct alc_pincfg *cfg;
1165
1166         quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1167         if (!quirk)
1168                 return;
1169
1170         cfg = pinfix[quirk->value];
1171         for (; cfg->nid; cfg++) {
1172                 int i;
1173                 u32 val = cfg->val;
1174                 for (i = 0; i < 4; i++) {
1175                         snd_hda_codec_write(codec, cfg->nid, 0,
1176                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_0 + i,
1177                                     val & 0xff);
1178                         val >>= 8;
1179                 }
1180         }
1181 }
1182
1183 /*
1184  * ALC888
1185  */
1186
1187 /*
1188  * 2ch mode
1189  */
1190 static struct hda_verb alc888_4ST_ch2_intel_init[] = {
1191 /* Mic-in jack as mic in */
1192         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1193         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1194 /* Line-in jack as Line in */
1195         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1196         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1197 /* Line-Out as Front */
1198         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1199         { } /* end */
1200 };
1201
1202 /*
1203  * 4ch mode
1204  */
1205 static struct hda_verb alc888_4ST_ch4_intel_init[] = {
1206 /* Mic-in jack as mic in */
1207         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1208         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1209 /* Line-in jack as Surround */
1210         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1211         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1212 /* Line-Out as Front */
1213         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1214         { } /* end */
1215 };
1216
1217 /*
1218  * 6ch mode
1219  */
1220 static struct hda_verb alc888_4ST_ch6_intel_init[] = {
1221 /* Mic-in jack as CLFE */
1222         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1223         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1224 /* Line-in jack as Surround */
1225         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1226         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1227 /* Line-Out as CLFE (workaround because Mic-in is not loud enough) */
1228         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1229         { } /* end */
1230 };
1231
1232 /*
1233  * 8ch mode
1234  */
1235 static struct hda_verb alc888_4ST_ch8_intel_init[] = {
1236 /* Mic-in jack as CLFE */
1237         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1238         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1239 /* Line-in jack as Surround */
1240         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1241         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1242 /* Line-Out as Side */
1243         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1244         { } /* end */
1245 };
1246
1247 static struct hda_channel_mode alc888_4ST_8ch_intel_modes[4] = {
1248         { 2, alc888_4ST_ch2_intel_init },
1249         { 4, alc888_4ST_ch4_intel_init },
1250         { 6, alc888_4ST_ch6_intel_init },
1251         { 8, alc888_4ST_ch8_intel_init },
1252 };
1253
1254 /*
1255  * ALC888 Fujitsu Siemens Amillo xa3530
1256  */
1257
1258 static struct hda_verb alc888_fujitsu_xa3530_verbs[] = {
1259 /* Front Mic: set to PIN_IN (empty by default) */
1260         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1261 /* Connect Internal HP to Front */
1262         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1263         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1264         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1265 /* Connect Bass HP to Front */
1266         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1267         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1268         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1269 /* Connect Line-Out side jack (SPDIF) to Side */
1270         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1271         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1272         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1273 /* Connect Mic jack to CLFE */
1274         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1275         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1276         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},
1277 /* Connect Line-in jack to Surround */
1278         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1279         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1280         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
1281 /* Connect HP out jack to Front */
1282         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1283         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1284         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1285 /* Enable unsolicited event for HP jack and Line-out jack */
1286         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1287         {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1288         {}
1289 };
1290
1291 static void alc888_fujitsu_xa3530_automute(struct hda_codec *codec)
1292 {
1293         unsigned int present;
1294         unsigned int bits;
1295         /* Line out presence */
1296         present = snd_hda_codec_read(codec, 0x17, 0,
1297                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1298         /* HP out presence */
1299         present = present || snd_hda_codec_read(codec, 0x1b, 0,
1300                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1301         bits = present ? HDA_AMP_MUTE : 0;
1302         /* Toggle internal speakers muting */
1303         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
1304                                  HDA_AMP_MUTE, bits);
1305         /* Toggle internal bass muting */
1306         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
1307                                  HDA_AMP_MUTE, bits);
1308 }
1309
1310 static void alc888_fujitsu_xa3530_unsol_event(struct hda_codec *codec,
1311                 unsigned int res)
1312 {
1313         if (res >> 26 == ALC880_HP_EVENT)
1314                 alc888_fujitsu_xa3530_automute(codec);
1315 }
1316
1317
1318 /*
1319  * ALC888 Acer Aspire 4930G model
1320  */
1321
1322 static struct hda_verb alc888_acer_aspire_4930g_verbs[] = {
1323 /* Front Mic: set to PIN_IN (empty by default) */
1324         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1325 /* Unselect Front Mic by default in input mixer 3 */
1326         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1327 /* Enable unsolicited event for HP jack */
1328         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1329 /* Connect Internal HP to front */
1330         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1331         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1332         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1333 /* Connect HP out to front */
1334         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1335         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1336         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1337         { }
1338 };
1339
1340 static struct hda_input_mux alc888_2_capture_sources[2] = {
1341         /* Front mic only available on one ADC */
1342         {
1343                 .num_items = 4,
1344                 .items = {
1345                         { "Mic", 0x0 },
1346                         { "Line", 0x2 },
1347                         { "CD", 0x4 },
1348                         { "Front Mic", 0xb },
1349                 },
1350         },
1351         {
1352                 .num_items = 3,
1353                 .items = {
1354                         { "Mic", 0x0 },
1355                         { "Line", 0x2 },
1356                         { "CD", 0x4 },
1357                 },
1358         }
1359 };
1360
1361 static struct snd_kcontrol_new alc888_base_mixer[] = {
1362         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1363         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1364         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1365         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1366         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
1367                 HDA_OUTPUT),
1368         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1369         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1370         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1371         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1372         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1373         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1374         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1375         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1376         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1377         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1378         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
1379         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1380         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1381         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1382         { } /* end */
1383 };
1384
1385 static void alc888_acer_aspire_4930g_automute(struct hda_codec *codec)
1386 {
1387         unsigned int present;
1388         unsigned int bits;
1389         present = snd_hda_codec_read(codec, 0x15, 0,
1390                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1391         bits = present ? HDA_AMP_MUTE : 0;
1392         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
1393                                  HDA_AMP_MUTE, bits);
1394 }
1395
1396 static void alc888_acer_aspire_4930g_unsol_event(struct hda_codec *codec,
1397                 unsigned int res)
1398 {
1399         if (res >> 26 == ALC880_HP_EVENT)
1400                 alc888_acer_aspire_4930g_automute(codec);
1401 }
1402
1403 /*
1404  * ALC880 3-stack model
1405  *
1406  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
1407  * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
1408  *                 F-Mic = 0x1b, HP = 0x19
1409  */
1410
1411 static hda_nid_t alc880_dac_nids[4] = {
1412         /* front, rear, clfe, rear_surr */
1413         0x02, 0x05, 0x04, 0x03
1414 };
1415
1416 static hda_nid_t alc880_adc_nids[3] = {
1417         /* ADC0-2 */
1418         0x07, 0x08, 0x09,
1419 };
1420
1421 /* The datasheet says the node 0x07 is connected from inputs,
1422  * but it shows zero connection in the real implementation on some devices.
1423  * Note: this is a 915GAV bug, fixed on 915GLV
1424  */
1425 static hda_nid_t alc880_adc_nids_alt[2] = {
1426         /* ADC1-2 */
1427         0x08, 0x09,
1428 };
1429
1430 #define ALC880_DIGOUT_NID       0x06
1431 #define ALC880_DIGIN_NID        0x0a
1432
1433 static struct hda_input_mux alc880_capture_source = {
1434         .num_items = 4,
1435         .items = {
1436                 { "Mic", 0x0 },
1437                 { "Front Mic", 0x3 },
1438                 { "Line", 0x2 },
1439                 { "CD", 0x4 },
1440         },
1441 };
1442
1443 /* channel source setting (2/6 channel selection for 3-stack) */
1444 /* 2ch mode */
1445 static struct hda_verb alc880_threestack_ch2_init[] = {
1446         /* set line-in to input, mute it */
1447         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1448         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1449         /* set mic-in to input vref 80%, mute it */
1450         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1451         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1452         { } /* end */
1453 };
1454
1455 /* 6ch mode */
1456 static struct hda_verb alc880_threestack_ch6_init[] = {
1457         /* set line-in to output, unmute it */
1458         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1459         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1460         /* set mic-in to output, unmute it */
1461         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1462         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1463         { } /* end */
1464 };
1465
1466 static struct hda_channel_mode alc880_threestack_modes[2] = {
1467         { 2, alc880_threestack_ch2_init },
1468         { 6, alc880_threestack_ch6_init },
1469 };
1470
1471 static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
1472         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1473         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1474         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1475         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
1476         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1477         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1478         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1479         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1480         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1481         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1482         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1483         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1484         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1485         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1486         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
1487         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
1488         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1489         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1490         HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
1491         {
1492                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1493                 .name = "Channel Mode",
1494                 .info = alc_ch_mode_info,
1495                 .get = alc_ch_mode_get,
1496                 .put = alc_ch_mode_put,
1497         },
1498         { } /* end */
1499 };
1500
1501 /* capture mixer elements */
1502 static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1503                             struct snd_ctl_elem_info *uinfo)
1504 {
1505         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1506         struct alc_spec *spec = codec->spec;
1507         int err;
1508
1509         mutex_lock(&codec->control_mutex);
1510         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1511                                                       HDA_INPUT);
1512         err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
1513         mutex_unlock(&codec->control_mutex);
1514         return err;
1515 }
1516
1517 static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1518                            unsigned int size, unsigned int __user *tlv)
1519 {
1520         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1521         struct alc_spec *spec = codec->spec;
1522         int err;
1523
1524         mutex_lock(&codec->control_mutex);
1525         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1526                                                       HDA_INPUT);
1527         err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
1528         mutex_unlock(&codec->control_mutex);
1529         return err;
1530 }
1531
1532 typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1533                              struct snd_ctl_elem_value *ucontrol);
1534
1535 static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1536                                  struct snd_ctl_elem_value *ucontrol,
1537                                  getput_call_t func)
1538 {
1539         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1540         struct alc_spec *spec = codec->spec;
1541         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1542         int err;
1543
1544         mutex_lock(&codec->control_mutex);
1545         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[adc_idx],
1546                                                       3, 0, HDA_INPUT);
1547         err = func(kcontrol, ucontrol);
1548         mutex_unlock(&codec->control_mutex);
1549         return err;
1550 }
1551
1552 static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1553                            struct snd_ctl_elem_value *ucontrol)
1554 {
1555         return alc_cap_getput_caller(kcontrol, ucontrol,
1556                                      snd_hda_mixer_amp_volume_get);
1557 }
1558
1559 static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1560                            struct snd_ctl_elem_value *ucontrol)
1561 {
1562         return alc_cap_getput_caller(kcontrol, ucontrol,
1563                                      snd_hda_mixer_amp_volume_put);
1564 }
1565
1566 /* capture mixer elements */
1567 #define alc_cap_sw_info         snd_ctl_boolean_stereo_info
1568
1569 static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1570                           struct snd_ctl_elem_value *ucontrol)
1571 {
1572         return alc_cap_getput_caller(kcontrol, ucontrol,
1573                                      snd_hda_mixer_amp_switch_get);
1574 }
1575
1576 static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1577                           struct snd_ctl_elem_value *ucontrol)
1578 {
1579         return alc_cap_getput_caller(kcontrol, ucontrol,
1580                                      snd_hda_mixer_amp_switch_put);
1581 }
1582
1583 #define DEFINE_CAPMIX(num) \
1584 static struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1585         { \
1586                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1587                 .name = "Capture Switch", \
1588                 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1589                 .count = num, \
1590                 .info = alc_cap_sw_info, \
1591                 .get = alc_cap_sw_get, \
1592                 .put = alc_cap_sw_put, \
1593         }, \
1594         { \
1595                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1596                 .name = "Capture Volume", \
1597                 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1598                            SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1599                            SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1600                 .count = num, \
1601                 .info = alc_cap_vol_info, \
1602                 .get = alc_cap_vol_get, \
1603                 .put = alc_cap_vol_put, \
1604                 .tlv = { .c = alc_cap_vol_tlv }, \
1605         }, \
1606         { \
1607                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1608                 /* .name = "Capture Source", */ \
1609                 .name = "Input Source", \
1610                 .count = num, \
1611                 .info = alc_mux_enum_info, \
1612                 .get = alc_mux_enum_get, \
1613                 .put = alc_mux_enum_put, \
1614         }, \
1615         { } /* end */ \
1616 }
1617
1618 /* up to three ADCs */
1619 DEFINE_CAPMIX(1);
1620 DEFINE_CAPMIX(2);
1621 DEFINE_CAPMIX(3);
1622
1623
1624 /*
1625  * ALC880 5-stack model
1626  *
1627  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
1628  *      Side = 0x02 (0xd)
1629  * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
1630  *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
1631  */
1632
1633 /* additional mixers to alc880_three_stack_mixer */
1634 static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
1635         HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1636         HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
1637         { } /* end */
1638 };
1639
1640 /* channel source setting (6/8 channel selection for 5-stack) */
1641 /* 6ch mode */
1642 static struct hda_verb alc880_fivestack_ch6_init[] = {
1643         /* set line-in to input, mute it */
1644         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1645         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1646         { } /* end */
1647 };
1648
1649 /* 8ch mode */
1650 static struct hda_verb alc880_fivestack_ch8_init[] = {
1651         /* set line-in to output, unmute it */
1652         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1653         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1654         { } /* end */
1655 };
1656
1657 static struct hda_channel_mode alc880_fivestack_modes[2] = {
1658         { 6, alc880_fivestack_ch6_init },
1659         { 8, alc880_fivestack_ch8_init },
1660 };
1661
1662
1663 /*
1664  * ALC880 6-stack model
1665  *
1666  * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
1667  *      Side = 0x05 (0x0f)
1668  * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
1669  *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
1670  */
1671
1672 static hda_nid_t alc880_6st_dac_nids[4] = {
1673         /* front, rear, clfe, rear_surr */
1674         0x02, 0x03, 0x04, 0x05
1675 };
1676
1677 static struct hda_input_mux alc880_6stack_capture_source = {
1678         .num_items = 4,
1679         .items = {
1680                 { "Mic", 0x0 },
1681                 { "Front Mic", 0x1 },
1682                 { "Line", 0x2 },
1683                 { "CD", 0x4 },
1684         },
1685 };
1686
1687 /* fixed 8-channels */
1688 static struct hda_channel_mode alc880_sixstack_modes[1] = {
1689         { 8, NULL },
1690 };
1691
1692 static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
1693         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1694         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1695         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1696         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1697         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1698         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1699         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1700         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1701         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1702         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1703         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1704         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1705         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1706         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1707         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1708         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1709         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1710         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1711         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1712         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1713         {
1714                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1715                 .name = "Channel Mode",
1716                 .info = alc_ch_mode_info,
1717                 .get = alc_ch_mode_get,
1718                 .put = alc_ch_mode_put,
1719         },
1720         { } /* end */
1721 };
1722
1723
1724 /*
1725  * ALC880 W810 model
1726  *
1727  * W810 has rear IO for:
1728  * Front (DAC 02)
1729  * Surround (DAC 03)
1730  * Center/LFE (DAC 04)
1731  * Digital out (06)
1732  *
1733  * The system also has a pair of internal speakers, and a headphone jack.
1734  * These are both connected to Line2 on the codec, hence to DAC 02.
1735  *
1736  * There is a variable resistor to control the speaker or headphone
1737  * volume. This is a hardware-only device without a software API.
1738  *
1739  * Plugging headphones in will disable the internal speakers. This is
1740  * implemented in hardware, not via the driver using jack sense. In
1741  * a similar fashion, plugging into the rear socket marked "front" will
1742  * disable both the speakers and headphones.
1743  *
1744  * For input, there's a microphone jack, and an "audio in" jack.
1745  * These may not do anything useful with this driver yet, because I
1746  * haven't setup any initialization verbs for these yet...
1747  */
1748
1749 static hda_nid_t alc880_w810_dac_nids[3] = {
1750         /* front, rear/surround, clfe */
1751         0x02, 0x03, 0x04
1752 };
1753
1754 /* fixed 6 channels */
1755 static struct hda_channel_mode alc880_w810_modes[1] = {
1756         { 6, NULL }
1757 };
1758
1759 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
1760 static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
1761         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1762         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1763         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1764         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1765         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1766         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1767         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1768         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1769         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1770         { } /* end */
1771 };
1772
1773
1774 /*
1775  * Z710V model
1776  *
1777  * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
1778  * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
1779  *                 Line = 0x1a
1780  */
1781
1782 static hda_nid_t alc880_z71v_dac_nids[1] = {
1783         0x02
1784 };
1785 #define ALC880_Z71V_HP_DAC      0x03
1786
1787 /* fixed 2 channels */
1788 static struct hda_channel_mode alc880_2_jack_modes[1] = {
1789         { 2, NULL }
1790 };
1791
1792 static struct snd_kcontrol_new alc880_z71v_mixer[] = {
1793         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1794         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1795         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1796         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
1797         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1798         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1799         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1800         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1801         { } /* end */
1802 };
1803
1804
1805 /*
1806  * ALC880 F1734 model
1807  *
1808  * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
1809  * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
1810  */
1811
1812 static hda_nid_t alc880_f1734_dac_nids[1] = {
1813         0x03
1814 };
1815 #define ALC880_F1734_HP_DAC     0x02
1816
1817 static struct snd_kcontrol_new alc880_f1734_mixer[] = {
1818         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1819         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1820         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1821         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1822         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1823         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1824         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1825         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1826         { } /* end */
1827 };
1828
1829 static struct hda_input_mux alc880_f1734_capture_source = {
1830         .num_items = 2,
1831         .items = {
1832                 { "Mic", 0x1 },
1833                 { "CD", 0x4 },
1834         },
1835 };
1836
1837
1838 /*
1839  * ALC880 ASUS model
1840  *
1841  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1842  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1843  *  Mic = 0x18, Line = 0x1a
1844  */
1845
1846 #define alc880_asus_dac_nids    alc880_w810_dac_nids    /* identical with w810 */
1847 #define alc880_asus_modes       alc880_threestack_modes /* 2/6 channel mode */
1848
1849 static struct snd_kcontrol_new alc880_asus_mixer[] = {
1850         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1851         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1852         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1853         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1854         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1855         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1856         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1857         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1858         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1859         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1860         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1861         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1862         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1863         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1864         {
1865                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1866                 .name = "Channel Mode",
1867                 .info = alc_ch_mode_info,
1868                 .get = alc_ch_mode_get,
1869                 .put = alc_ch_mode_put,
1870         },
1871         { } /* end */
1872 };
1873
1874 /*
1875  * ALC880 ASUS W1V model
1876  *
1877  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1878  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1879  *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
1880  */
1881
1882 /* additional mixers to alc880_asus_mixer */
1883 static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
1884         HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
1885         HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
1886         { } /* end */
1887 };
1888
1889 /* additional mixers to alc880_asus_mixer */
1890 static struct snd_kcontrol_new alc880_pcbeep_mixer[] = {
1891         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1892         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1893         { } /* end */
1894 };
1895
1896 /* TCL S700 */
1897 static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
1898         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1899         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1900         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1901         HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
1902         HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
1903         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
1904         HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
1905         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1906         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1907         { } /* end */
1908 };
1909
1910 /* Uniwill */
1911 static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
1912         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1913         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1914         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1915         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1916         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1917         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1918         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1919         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1920         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1921         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1922         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1923         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1924         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1925         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1926         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1927         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1928         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1929         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1930         {
1931                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1932                 .name = "Channel Mode",
1933                 .info = alc_ch_mode_info,
1934                 .get = alc_ch_mode_get,
1935                 .put = alc_ch_mode_put,
1936         },
1937         { } /* end */
1938 };
1939
1940 static struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
1941         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1942         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1943         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1944         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1945         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1946         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1947         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1948         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1949         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1950         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1951         { } /* end */
1952 };
1953
1954 static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
1955         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1956         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1957         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1958         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1959         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1960         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1961         { } /* end */
1962 };
1963
1964 /*
1965  * virtual master controls
1966  */
1967
1968 /*
1969  * slave controls for virtual master
1970  */
1971 static const char *alc_slave_vols[] = {
1972         "Front Playback Volume",
1973         "Surround Playback Volume",
1974         "Center Playback Volume",
1975         "LFE Playback Volume",
1976         "Side Playback Volume",
1977         "Headphone Playback Volume",
1978         "Speaker Playback Volume",
1979         "Mono Playback Volume",
1980         "Line-Out Playback Volume",
1981         "PCM Playback Volume",
1982         NULL,
1983 };
1984
1985 static const char *alc_slave_sws[] = {
1986         "Front Playback Switch",
1987         "Surround Playback Switch",
1988         "Center Playback Switch",
1989         "LFE Playback Switch",
1990         "Side Playback Switch",
1991         "Headphone Playback Switch",
1992         "Speaker Playback Switch",
1993         "Mono Playback Switch",
1994         "IEC958 Playback Switch",
1995         NULL,
1996 };
1997
1998 /*
1999  * build control elements
2000  */
2001
2002 static void alc_free_kctls(struct hda_codec *codec);
2003
2004 static int alc_build_controls(struct hda_codec *codec)
2005 {
2006         struct alc_spec *spec = codec->spec;
2007         int err;
2008         int i;
2009
2010         for (i = 0; i < spec->num_mixers; i++) {
2011                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
2012                 if (err < 0)
2013                         return err;
2014         }
2015         if (spec->cap_mixer) {
2016                 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
2017                 if (err < 0)
2018                         return err;
2019         }
2020         if (spec->multiout.dig_out_nid) {
2021                 err = snd_hda_create_spdif_out_ctls(codec,
2022                                                     spec->multiout.dig_out_nid);
2023                 if (err < 0)
2024                         return err;
2025                 if (!spec->no_analog) {
2026                         err = snd_hda_create_spdif_share_sw(codec,
2027                                                             &spec->multiout);
2028                         if (err < 0)
2029                                 return err;
2030                         spec->multiout.share_spdif = 1;
2031                 }
2032         }
2033         if (spec->dig_in_nid) {
2034                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
2035                 if (err < 0)
2036                         return err;
2037         }
2038
2039         /* if we have no master control, let's create it */
2040         if (!spec->no_analog &&
2041             !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
2042                 unsigned int vmaster_tlv[4];
2043                 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
2044                                         HDA_OUTPUT, vmaster_tlv);
2045                 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
2046                                           vmaster_tlv, alc_slave_vols);
2047                 if (err < 0)
2048                         return err;
2049         }
2050         if (!spec->no_analog &&
2051             !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
2052                 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
2053                                           NULL, alc_slave_sws);
2054                 if (err < 0)
2055                         return err;
2056         }
2057
2058         alc_free_kctls(codec); /* no longer needed */
2059         return 0;
2060 }
2061
2062
2063 /*
2064  * initialize the codec volumes, etc
2065  */
2066
2067 /*
2068  * generic initialization of ADC, input mixers and output mixers
2069  */
2070 static struct hda_verb alc880_volume_init_verbs[] = {
2071         /*
2072          * Unmute ADC0-2 and set the default input to mic-in
2073          */
2074         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
2075         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2076         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
2077         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2078         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
2079         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2080
2081         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2082          * mixer widget
2083          * Note: PASD motherboards uses the Line In 2 as the input for front
2084          * panel mic (mic 2)
2085          */
2086         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
2087         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2088         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2089         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2090         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2091         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2092         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2093         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2094
2095         /*
2096          * Set up output mixers (0x0c - 0x0f)
2097          */
2098         /* set vol=0 to output mixers */
2099         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2100         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2101         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2102         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2103         /* set up input amps for analog loopback */
2104         /* Amp Indices: DAC = 0, mixer = 1 */
2105         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2106         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2107         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2108         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2109         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2110         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2111         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2112         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2113
2114         { }
2115 };
2116
2117 /*
2118  * 3-stack pin configuration:
2119  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
2120  */
2121 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
2122         /*
2123          * preset connection lists of input pins
2124          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2125          */
2126         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2127         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2128         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2129
2130         /*
2131          * Set pin mode and muting
2132          */
2133         /* set front pin widgets 0x14 for output */
2134         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2135         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2136         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2137         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2138         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2139         /* Mic2 (as headphone out) for HP output */
2140         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2141         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2142         /* Line In pin widget for input */
2143         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2144         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2145         /* Line2 (as front mic) pin widget for input and vref at 80% */
2146         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2147         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2148         /* CD pin widget for input */
2149         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2150
2151         { }
2152 };
2153
2154 /*
2155  * 5-stack pin configuration:
2156  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
2157  * line-in/side = 0x1a, f-mic = 0x1b
2158  */
2159 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
2160         /*
2161          * preset connection lists of input pins
2162          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2163          */
2164         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2165         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
2166
2167         /*
2168          * Set pin mode and muting
2169          */
2170         /* set pin widgets 0x14-0x17 for output */
2171         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2172         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2173         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2174         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2175         /* unmute pins for output (no gain on this amp) */
2176         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2177         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2178         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2179         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2180
2181         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2182         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2183         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2184         /* Mic2 (as headphone out) for HP output */
2185         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2186         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2187         /* Line In pin widget for input */
2188         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2189         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2190         /* Line2 (as front mic) pin widget for input and vref at 80% */
2191         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2192         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2193         /* CD pin widget for input */
2194         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2195
2196         { }
2197 };
2198
2199 /*
2200  * W810 pin configuration:
2201  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
2202  */
2203 static struct hda_verb alc880_pin_w810_init_verbs[] = {
2204         /* hphone/speaker input selector: front DAC */
2205         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
2206
2207         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2208         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2209         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2210         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2211         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2212         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2213
2214         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2215         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2216
2217         { }
2218 };
2219
2220 /*
2221  * Z71V pin configuration:
2222  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
2223  */
2224 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
2225         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2226         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2227         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2228         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2229
2230         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2231         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2232         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2233         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2234
2235         { }
2236 };
2237
2238 /*
2239  * 6-stack pin configuration:
2240  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
2241  * f-mic = 0x19, line = 0x1a, HP = 0x1b
2242  */
2243 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
2244         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2245
2246         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2247         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2248         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2249         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2250         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2251         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2252         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2253         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2254
2255         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2256         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2257         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2258         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2259         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2260         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2261         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2262         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2263         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2264
2265         { }
2266 };
2267
2268 /*
2269  * Uniwill pin configuration:
2270  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
2271  * line = 0x1a
2272  */
2273 static struct hda_verb alc880_uniwill_init_verbs[] = {
2274         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2275
2276         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2277         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2278         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2279         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2280         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2281         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2282         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2283         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2284         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2285         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2286         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2287         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2288         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2289         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2290
2291         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2292         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2293         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2294         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2295         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2296         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2297         /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
2298         /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
2299         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2300
2301         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2302         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
2303
2304         { }
2305 };
2306
2307 /*
2308 * Uniwill P53
2309 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19,
2310  */
2311 static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
2312         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2313
2314         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2315         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2316         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2317         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2318         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2319         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2320         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2321         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2322         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2323         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2324         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2325         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2326
2327         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2328         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2329         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2330         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2331         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2332         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2333
2334         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2335         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
2336
2337         { }
2338 };
2339
2340 static struct hda_verb alc880_beep_init_verbs[] = {
2341         { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
2342         { }
2343 };
2344
2345 /* toggle speaker-output according to the hp-jack state */
2346 static void alc880_uniwill_hp_automute(struct hda_codec *codec)
2347 {
2348         unsigned int present;
2349         unsigned char bits;
2350
2351         present = snd_hda_codec_read(codec, 0x14, 0,
2352                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2353         bits = present ? HDA_AMP_MUTE : 0;
2354         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
2355                                  HDA_AMP_MUTE, bits);
2356         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
2357                                  HDA_AMP_MUTE, bits);
2358 }
2359
2360 /* auto-toggle front mic */
2361 static void alc880_uniwill_mic_automute(struct hda_codec *codec)
2362 {
2363         unsigned int present;
2364         unsigned char bits;
2365
2366         present = snd_hda_codec_read(codec, 0x18, 0,
2367                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2368         bits = present ? HDA_AMP_MUTE : 0;
2369         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
2370 }
2371
2372 static void alc880_uniwill_automute(struct hda_codec *codec)
2373 {
2374         alc880_uniwill_hp_automute(codec);
2375         alc880_uniwill_mic_automute(codec);
2376 }
2377
2378 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
2379                                        unsigned int res)
2380 {
2381         /* Looks like the unsol event is incompatible with the standard
2382          * definition.  4bit tag is placed at 28 bit!
2383          */
2384         switch (res >> 28) {
2385         case ALC880_HP_EVENT:
2386                 alc880_uniwill_hp_automute(codec);
2387                 break;
2388         case ALC880_MIC_EVENT:
2389                 alc880_uniwill_mic_automute(codec);
2390                 break;
2391         }
2392 }
2393
2394 static void alc880_uniwill_p53_hp_automute(struct hda_codec *codec)
2395 {
2396         unsigned int present;
2397         unsigned char bits;
2398
2399         present = snd_hda_codec_read(codec, 0x14, 0,
2400                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2401         bits = present ? HDA_AMP_MUTE : 0;
2402         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, HDA_AMP_MUTE, bits);
2403 }
2404
2405 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
2406 {
2407         unsigned int present;
2408
2409         present = snd_hda_codec_read(codec, 0x21, 0,
2410                                      AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
2411         present &= HDA_AMP_VOLMASK;
2412         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
2413                                  HDA_AMP_VOLMASK, present);
2414         snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
2415                                  HDA_AMP_VOLMASK, present);
2416 }
2417
2418 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
2419                                            unsigned int res)
2420 {
2421         /* Looks like the unsol event is incompatible with the standard
2422          * definition.  4bit tag is placed at 28 bit!
2423          */
2424         if ((res >> 28) == ALC880_HP_EVENT)
2425                 alc880_uniwill_p53_hp_automute(codec);
2426         if ((res >> 28) == ALC880_DCVOL_EVENT)
2427                 alc880_uniwill_p53_dcvol_automute(codec);
2428 }
2429
2430 /*
2431  * F1734 pin configuration:
2432  * HP = 0x14, speaker-out = 0x15, mic = 0x18
2433  */
2434 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
2435         {0x07, AC_VERB_SET_CONNECT_SEL, 0x01},
2436         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2437         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2438         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2439         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2440
2441         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2442         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2443         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2444         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2445
2446         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2447         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2448         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
2449         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2450         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2451         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2452         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2453         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2454         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2455
2456         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
2457         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_DCVOL_EVENT},
2458
2459         { }
2460 };
2461
2462 /*
2463  * ASUS pin configuration:
2464  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
2465  */
2466 static struct hda_verb alc880_pin_asus_init_verbs[] = {
2467         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2468         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2469         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2470         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2471
2472         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2473         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2474         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2475         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2476         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2477         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2478         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2479         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2480
2481         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2482         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2483         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2484         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2485         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2486         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2487         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2488         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2489         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2490
2491         { }
2492 };
2493
2494 /* Enable GPIO mask and set output */
2495 #define alc880_gpio1_init_verbs alc_gpio1_init_verbs
2496 #define alc880_gpio2_init_verbs alc_gpio2_init_verbs
2497
2498 /* Clevo m520g init */
2499 static struct hda_verb alc880_pin_clevo_init_verbs[] = {
2500         /* headphone output */
2501         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2502         /* line-out */
2503         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2504         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2505         /* Line-in */
2506         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2507         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2508         /* CD */
2509         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2510         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2511         /* Mic1 (rear panel) */
2512         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2513         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2514         /* Mic2 (front panel) */
2515         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2516         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2517         /* headphone */
2518         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2519         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2520         /* change to EAPD mode */
2521         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2522         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2523
2524         { }
2525 };
2526
2527 static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
2528         /* change to EAPD mode */
2529         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2530         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2531
2532         /* Headphone output */
2533         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2534         /* Front output*/
2535         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2536         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
2537
2538         /* Line In pin widget for input */
2539         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2540         /* CD pin widget for input */
2541         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2542         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2543         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2544
2545         /* change to EAPD mode */
2546         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2547         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
2548
2549         { }
2550 };
2551
2552 /*
2553  * LG m1 express dual
2554  *
2555  * Pin assignment:
2556  *   Rear Line-In/Out (blue): 0x14
2557  *   Build-in Mic-In: 0x15
2558  *   Speaker-out: 0x17
2559  *   HP-Out (green): 0x1b
2560  *   Mic-In/Out (red): 0x19
2561  *   SPDIF-Out: 0x1e
2562  */
2563
2564 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
2565 static hda_nid_t alc880_lg_dac_nids[3] = {
2566         0x05, 0x02, 0x03
2567 };
2568
2569 /* seems analog CD is not working */
2570 static struct hda_input_mux alc880_lg_capture_source = {
2571         .num_items = 3,
2572         .items = {
2573                 { "Mic", 0x1 },
2574                 { "Line", 0x5 },
2575                 { "Internal Mic", 0x6 },
2576         },
2577 };
2578
2579 /* 2,4,6 channel modes */
2580 static struct hda_verb alc880_lg_ch2_init[] = {
2581         /* set line-in and mic-in to input */
2582         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2583         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2584         { }
2585 };
2586
2587 static struct hda_verb alc880_lg_ch4_init[] = {
2588         /* set line-in to out and mic-in to input */
2589         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2590         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2591         { }
2592 };
2593
2594 static struct hda_verb alc880_lg_ch6_init[] = {
2595         /* set line-in and mic-in to output */
2596         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2597         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2598         { }
2599 };
2600
2601 static struct hda_channel_mode alc880_lg_ch_modes[3] = {
2602         { 2, alc880_lg_ch2_init },
2603         { 4, alc880_lg_ch4_init },
2604         { 6, alc880_lg_ch6_init },
2605 };
2606
2607 static struct snd_kcontrol_new alc880_lg_mixer[] = {
2608         HDA_CODEC_VOLUME("Front Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2609         HDA_BIND_MUTE("Front Playback Switch", 0x0f, 2, HDA_INPUT),
2610         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2611         HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
2612         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
2613         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
2614         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
2615         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
2616         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2617         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2618         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
2619         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
2620         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
2621         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
2622         {
2623                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2624                 .name = "Channel Mode",
2625                 .info = alc_ch_mode_info,
2626                 .get = alc_ch_mode_get,
2627                 .put = alc_ch_mode_put,
2628         },
2629         { } /* end */
2630 };
2631
2632 static struct hda_verb alc880_lg_init_verbs[] = {
2633         /* set capture source to mic-in */
2634         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2635         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2636         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2637         /* mute all amp mixer inputs */
2638         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
2639         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2640         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2641         /* line-in to input */
2642         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2643         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2644         /* built-in mic */
2645         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2646         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2647         /* speaker-out */
2648         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2649         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2650         /* mic-in to input */
2651         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2652         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2653         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2654         /* HP-out */
2655         {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
2656         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2657         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2658         /* jack sense */
2659         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2660         { }
2661 };
2662
2663 /* toggle speaker-output according to the hp-jack state */
2664 static void alc880_lg_automute(struct hda_codec *codec)
2665 {
2666         unsigned int present;
2667         unsigned char bits;
2668
2669         present = snd_hda_codec_read(codec, 0x1b, 0,
2670                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2671         bits = present ? HDA_AMP_MUTE : 0;
2672         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
2673                                  HDA_AMP_MUTE, bits);
2674 }
2675
2676 static void alc880_lg_unsol_event(struct hda_codec *codec, unsigned int res)
2677 {
2678         /* Looks like the unsol event is incompatible with the standard
2679          * definition.  4bit tag is placed at 28 bit!
2680          */
2681         if ((res >> 28) == 0x01)
2682                 alc880_lg_automute(codec);
2683 }
2684
2685 /*
2686  * LG LW20
2687  *
2688  * Pin assignment:
2689  *   Speaker-out: 0x14
2690  *   Mic-In: 0x18
2691  *   Built-in Mic-In: 0x19
2692  *   Line-In: 0x1b
2693  *   HP-Out: 0x1a
2694  *   SPDIF-Out: 0x1e
2695  */
2696
2697 static struct hda_input_mux alc880_lg_lw_capture_source = {
2698         .num_items = 3,
2699         .items = {
2700                 { "Mic", 0x0 },
2701                 { "Internal Mic", 0x1 },
2702                 { "Line In", 0x2 },
2703         },
2704 };
2705
2706 #define alc880_lg_lw_modes alc880_threestack_modes
2707
2708 static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
2709         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2710         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2711         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2712         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
2713         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2714         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2715         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2716         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2717         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2718         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2719         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2720         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2721         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
2722         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
2723         {
2724                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2725                 .name = "Channel Mode",
2726                 .info = alc_ch_mode_info,
2727                 .get = alc_ch_mode_get,
2728                 .put = alc_ch_mode_put,
2729         },
2730         { } /* end */
2731 };
2732
2733 static struct hda_verb alc880_lg_lw_init_verbs[] = {
2734         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2735         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2736         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2737
2738         /* set capture source to mic-in */
2739         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2740         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2741         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2742         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2743         /* speaker-out */
2744         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2745         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2746         /* HP-out */
2747         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2748         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2749         /* mic-in to input */
2750         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2751         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2752         /* built-in mic */
2753         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2754         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2755         /* jack sense */
2756         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2757         { }
2758 };
2759
2760 /* toggle speaker-output according to the hp-jack state */
2761 static void alc880_lg_lw_automute(struct hda_codec *codec)
2762 {
2763         unsigned int present;
2764         unsigned char bits;
2765
2766         present = snd_hda_codec_read(codec, 0x1b, 0,
2767                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2768         bits = present ? HDA_AMP_MUTE : 0;
2769         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
2770                                  HDA_AMP_MUTE, bits);
2771 }
2772
2773 static void alc880_lg_lw_unsol_event(struct hda_codec *codec, unsigned int res)
2774 {
2775         /* Looks like the unsol event is incompatible with the standard
2776          * definition.  4bit tag is placed at 28 bit!
2777          */
2778         if ((res >> 28) == 0x01)
2779                 alc880_lg_lw_automute(codec);
2780 }
2781
2782 static struct snd_kcontrol_new alc880_medion_rim_mixer[] = {
2783         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2784         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
2785         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2786         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2787         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2788         HDA_CODEC_MUTE("Internal Playback Switch", 0x0b, 0x1, HDA_INPUT),
2789         { } /* end */
2790 };
2791
2792 static struct hda_input_mux alc880_medion_rim_capture_source = {
2793         .num_items = 2,
2794         .items = {
2795                 { "Mic", 0x0 },
2796                 { "Internal Mic", 0x1 },
2797         },
2798 };
2799
2800 static struct hda_verb alc880_medion_rim_init_verbs[] = {
2801         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2802
2803         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2804         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2805
2806         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2807         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2808         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2809         /* Mic2 (as headphone out) for HP output */
2810         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2811         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2812         /* Internal Speaker */
2813         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2814         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2815
2816         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2817         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2818
2819         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2820         { }
2821 };
2822
2823 /* toggle speaker-output according to the hp-jack state */
2824 static void alc880_medion_rim_automute(struct hda_codec *codec)
2825 {
2826         unsigned int present;
2827         unsigned char bits;
2828
2829         present = snd_hda_codec_read(codec, 0x14, 0,
2830                                      AC_VERB_GET_PIN_SENSE, 0)
2831                 & AC_PINSENSE_PRESENCE;
2832         bits = present ? HDA_AMP_MUTE : 0;
2833         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
2834                                  HDA_AMP_MUTE, bits);
2835         if (present)
2836                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0);
2837         else
2838                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 2);
2839 }
2840
2841 static void alc880_medion_rim_unsol_event(struct hda_codec *codec,
2842                                           unsigned int res)
2843 {
2844         /* Looks like the unsol event is incompatible with the standard
2845          * definition.  4bit tag is placed at 28 bit!
2846          */
2847         if ((res >> 28) == ALC880_HP_EVENT)
2848                 alc880_medion_rim_automute(codec);
2849 }
2850
2851 #ifdef CONFIG_SND_HDA_POWER_SAVE
2852 static struct hda_amp_list alc880_loopbacks[] = {
2853         { 0x0b, HDA_INPUT, 0 },
2854         { 0x0b, HDA_INPUT, 1 },
2855         { 0x0b, HDA_INPUT, 2 },
2856         { 0x0b, HDA_INPUT, 3 },
2857         { 0x0b, HDA_INPUT, 4 },
2858         { } /* end */
2859 };
2860
2861 static struct hda_amp_list alc880_lg_loopbacks[] = {
2862         { 0x0b, HDA_INPUT, 1 },
2863         { 0x0b, HDA_INPUT, 6 },
2864         { 0x0b, HDA_INPUT, 7 },
2865         { } /* end */
2866 };
2867 #endif
2868
2869 /*
2870  * Common callbacks
2871  */
2872
2873 static int alc_init(struct hda_codec *codec)
2874 {
2875         struct alc_spec *spec = codec->spec;
2876         unsigned int i;
2877
2878         alc_fix_pll(codec);
2879         if (codec->vendor_id == 0x10ec0888)
2880                 alc888_coef_init(codec);
2881
2882         for (i = 0; i < spec->num_init_verbs; i++)
2883                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2884
2885         if (spec->init_hook)
2886                 spec->init_hook(codec);
2887
2888         return 0;
2889 }
2890
2891 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2892 {
2893         struct alc_spec *spec = codec->spec;
2894
2895         if (spec->unsol_event)
2896                 spec->unsol_event(codec, res);
2897 }
2898
2899 #ifdef CONFIG_SND_HDA_POWER_SAVE
2900 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2901 {
2902         struct alc_spec *spec = codec->spec;
2903         return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2904 }
2905 #endif
2906
2907 /*
2908  * Analog playback callbacks
2909  */
2910 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
2911                                     struct hda_codec *codec,
2912                                     struct snd_pcm_substream *substream)
2913 {
2914         struct alc_spec *spec = codec->spec;
2915         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2916                                              hinfo);
2917 }
2918
2919 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2920                                        struct hda_codec *codec,
2921                                        unsigned int stream_tag,
2922                                        unsigned int format,
2923                                        struct snd_pcm_substream *substream)
2924 {
2925         struct alc_spec *spec = codec->spec;
2926         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2927                                                 stream_tag, format, substream);
2928 }
2929
2930 static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2931                                        struct hda_codec *codec,
2932                                        struct snd_pcm_substream *substream)
2933 {
2934         struct alc_spec *spec = codec->spec;
2935         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2936 }
2937
2938 /*
2939  * Digital out
2940  */
2941 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2942                                         struct hda_codec *codec,
2943                                         struct snd_pcm_substream *substream)
2944 {
2945         struct alc_spec *spec = codec->spec;
2946         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2947 }
2948
2949 static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2950                                            struct hda_codec *codec,
2951                                            unsigned int stream_tag,
2952                                            unsigned int format,
2953                                            struct snd_pcm_substream *substream)
2954 {
2955         struct alc_spec *spec = codec->spec;
2956         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2957                                              stream_tag, format, substream);
2958 }
2959
2960 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2961                                          struct hda_codec *codec,
2962                                          struct snd_pcm_substream *substream)
2963 {
2964         struct alc_spec *spec = codec->spec;
2965         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2966 }
2967
2968 /*
2969  * Analog capture
2970  */
2971 static int alc880_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2972                                       struct hda_codec *codec,
2973                                       unsigned int stream_tag,
2974                                       unsigned int format,
2975                                       struct snd_pcm_substream *substream)
2976 {
2977         struct alc_spec *spec = codec->spec;
2978
2979         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
2980                                    stream_tag, 0, format);
2981         return 0;
2982 }
2983
2984 static int alc880_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2985                                       struct hda_codec *codec,
2986                                       struct snd_pcm_substream *substream)
2987 {
2988         struct alc_spec *spec = codec->spec;
2989
2990         snd_hda_codec_cleanup_stream(codec,
2991                                      spec->adc_nids[substream->number + 1]);
2992         return 0;
2993 }
2994
2995
2996 /*
2997  */
2998 static struct hda_pcm_stream alc880_pcm_analog_playback = {
2999         .substreams = 1,
3000         .channels_min = 2,
3001         .channels_max = 8,
3002         /* NID is set in alc_build_pcms */
3003         .ops = {
3004                 .open = alc880_playback_pcm_open,
3005                 .prepare = alc880_playback_pcm_prepare,
3006                 .cleanup = alc880_playback_pcm_cleanup
3007         },
3008 };
3009
3010 static struct hda_pcm_stream alc880_pcm_analog_capture = {
3011         .substreams = 1,
3012         .channels_min = 2,
3013         .channels_max = 2,
3014         /* NID is set in alc_build_pcms */
3015 };
3016
3017 static struct hda_pcm_stream alc880_pcm_analog_alt_playback = {
3018         .substreams = 1,
3019         .channels_min = 2,
3020         .channels_max = 2,
3021         /* NID is set in alc_build_pcms */
3022 };
3023
3024 static struct hda_pcm_stream alc880_pcm_analog_alt_capture = {
3025         .substreams = 2, /* can be overridden */
3026         .channels_min = 2,
3027         .channels_max = 2,
3028         /* NID is set in alc_build_pcms */
3029         .ops = {
3030                 .prepare = alc880_alt_capture_pcm_prepare,
3031                 .cleanup = alc880_alt_capture_pcm_cleanup
3032         },
3033 };
3034
3035 static struct hda_pcm_stream alc880_pcm_digital_playback = {
3036         .substreams = 1,
3037         .channels_min = 2,
3038         .channels_max = 2,
3039         /* NID is set in alc_build_pcms */
3040         .ops = {
3041                 .open = alc880_dig_playback_pcm_open,
3042                 .close = alc880_dig_playback_pcm_close,
3043                 .prepare = alc880_dig_playback_pcm_prepare
3044         },
3045 };
3046
3047 static struct hda_pcm_stream alc880_pcm_digital_capture = {
3048         .substreams = 1,
3049         .channels_min = 2,
3050         .channels_max = 2,
3051         /* NID is set in alc_build_pcms */
3052 };
3053
3054 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
3055 static struct hda_pcm_stream alc_pcm_null_stream = {
3056         .substreams = 0,
3057         .channels_min = 0,
3058         .channels_max = 0,
3059 };
3060
3061 static int alc_build_pcms(struct hda_codec *codec)
3062 {
3063         struct alc_spec *spec = codec->spec;
3064         struct hda_pcm *info = spec->pcm_rec;
3065         int i;
3066
3067         codec->num_pcms = 1;
3068         codec->pcm_info = info;
3069
3070         if (spec->no_analog)
3071                 goto skip_analog;
3072
3073         info->name = spec->stream_name_analog;
3074         if (spec->stream_analog_playback) {
3075                 if (snd_BUG_ON(!spec->multiout.dac_nids))
3076                         return -EINVAL;
3077                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
3078                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
3079         }
3080         if (spec->stream_analog_capture) {
3081                 if (snd_BUG_ON(!spec->adc_nids))
3082                         return -EINVAL;
3083                 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
3084                 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
3085         }
3086
3087         if (spec->channel_mode) {
3088                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
3089                 for (i = 0; i < spec->num_channel_mode; i++) {
3090                         if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
3091                                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
3092                         }
3093                 }
3094         }
3095
3096  skip_analog:
3097         /* SPDIF for stream index #1 */
3098         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
3099                 codec->num_pcms = 2;
3100                 info = spec->pcm_rec + 1;
3101                 info->name = spec->stream_name_digital;
3102                 if (spec->dig_out_type)
3103                         info->pcm_type = spec->dig_out_type;
3104                 else
3105                         info->pcm_type = HDA_PCM_TYPE_SPDIF;
3106                 if (spec->multiout.dig_out_nid &&
3107                     spec->stream_digital_playback) {
3108                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
3109                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
3110                 }
3111                 if (spec->dig_in_nid &&
3112                     spec->stream_digital_capture) {
3113                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
3114                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
3115                 }
3116                 /* FIXME: do we need this for all Realtek codec models? */
3117                 codec->spdif_status_reset = 1;
3118         }
3119
3120         if (spec->no_analog)
3121                 return 0;
3122
3123         /* If the use of more than one ADC is requested for the current
3124          * model, configure a second analog capture-only PCM.
3125          */
3126         /* Additional Analaog capture for index #2 */
3127         if ((spec->alt_dac_nid && spec->stream_analog_alt_playback) ||
3128             (spec->num_adc_nids > 1 && spec->stream_analog_alt_capture)) {
3129                 codec->num_pcms = 3;
3130                 info = spec->pcm_rec + 2;
3131                 info->name = spec->stream_name_analog;
3132                 if (spec->alt_dac_nid) {
3133                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
3134                                 *spec->stream_analog_alt_playback;
3135                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
3136                                 spec->alt_dac_nid;
3137                 } else {
3138                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
3139                                 alc_pcm_null_stream;
3140                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
3141                 }
3142                 if (spec->num_adc_nids > 1) {
3143                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
3144                                 *spec->stream_analog_alt_capture;
3145                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
3146                                 spec->adc_nids[1];
3147                         info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
3148                                 spec->num_adc_nids - 1;
3149                 } else {
3150                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
3151                                 alc_pcm_null_stream;
3152                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
3153                 }
3154         }
3155
3156         return 0;
3157 }
3158
3159 static void alc_free_kctls(struct hda_codec *codec)
3160 {
3161         struct alc_spec *spec = codec->spec;
3162
3163         if (spec->kctls.list) {
3164                 struct snd_kcontrol_new *kctl = spec->kctls.list;
3165                 int i;
3166                 for (i = 0; i < spec->kctls.used; i++)
3167                         kfree(kctl[i].name);
3168         }
3169         snd_array_free(&spec->kctls);
3170 }
3171
3172 static void alc_free(struct hda_codec *codec)
3173 {
3174         struct alc_spec *spec = codec->spec;
3175
3176         if (!spec)
3177                 return;
3178
3179         alc_free_kctls(codec);
3180         kfree(spec);
3181         codec->spec = NULL; /* to be sure */
3182 }
3183
3184 #ifdef SND_HDA_NEEDS_RESUME
3185 static void store_pin_configs(struct hda_codec *codec)
3186 {
3187         struct alc_spec *spec = codec->spec;
3188         hda_nid_t nid, end_nid;
3189
3190         end_nid = codec->start_nid + codec->num_nodes;
3191         for (nid = codec->start_nid; nid < end_nid; nid++) {
3192                 unsigned int wid_caps = get_wcaps(codec, nid);
3193                 unsigned int wid_type =
3194                         (wid_caps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
3195                 if (wid_type != AC_WID_PIN)
3196                         continue;
3197                 if (spec->num_pins >= ARRAY_SIZE(spec->pin_nids))
3198                         break;
3199                 spec->pin_nids[spec->num_pins] = nid;
3200                 spec->pin_cfgs[spec->num_pins] =
3201                         snd_hda_codec_read(codec, nid, 0,
3202                                            AC_VERB_GET_CONFIG_DEFAULT, 0);
3203                 spec->num_pins++;
3204         }
3205 }
3206
3207 static void resume_pin_configs(struct hda_codec *codec)
3208 {
3209         struct alc_spec *spec = codec->spec;
3210         int i;
3211
3212         for (i = 0; i < spec->num_pins; i++) {
3213                 hda_nid_t pin_nid = spec->pin_nids[i];
3214                 unsigned int pin_config = spec->pin_cfgs[i];
3215                 snd_hda_codec_write(codec, pin_nid, 0,
3216                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
3217                                     pin_config & 0x000000ff);
3218                 snd_hda_codec_write(codec, pin_nid, 0,
3219                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
3220                                     (pin_config & 0x0000ff00) >> 8);
3221                 snd_hda_codec_write(codec, pin_nid, 0,
3222                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
3223                                     (pin_config & 0x00ff0000) >> 16);
3224                 snd_hda_codec_write(codec, pin_nid, 0,
3225                                     AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
3226                                     pin_config >> 24);
3227         }
3228 }
3229
3230 static int alc_resume(struct hda_codec *codec)
3231 {
3232         resume_pin_configs(codec);
3233         codec->patch_ops.init(codec);
3234         snd_hda_codec_resume_amp(codec);
3235         snd_hda_codec_resume_cache(codec);
3236         return 0;
3237 }
3238 #else
3239 #define store_pin_configs(codec)
3240 #endif
3241
3242 /*
3243  */
3244 static struct hda_codec_ops alc_patch_ops = {
3245         .build_controls = alc_build_controls,
3246         .build_pcms = alc_build_pcms,
3247         .init = alc_init,
3248         .free = alc_free,
3249         .unsol_event = alc_unsol_event,
3250 #ifdef SND_HDA_NEEDS_RESUME
3251         .resume = alc_resume,
3252 #endif
3253 #ifdef CONFIG_SND_HDA_POWER_SAVE
3254         .check_power_status = alc_check_power_status,
3255 #endif
3256 };
3257
3258
3259 /*
3260  * Test configuration for debugging
3261  *
3262  * Almost all inputs/outputs are enabled.  I/O pins can be configured via
3263  * enum controls.
3264  */
3265 #ifdef CONFIG_SND_DEBUG
3266 static hda_nid_t alc880_test_dac_nids[4] = {
3267         0x02, 0x03, 0x04, 0x05
3268 };
3269
3270 static struct hda_input_mux alc880_test_capture_source = {
3271         .num_items = 7,
3272         .items = {
3273                 { "In-1", 0x0 },
3274                 { "In-2", 0x1 },
3275                 { "In-3", 0x2 },
3276                 { "In-4", 0x3 },
3277                 { "CD", 0x4 },
3278                 { "Front", 0x5 },
3279                 { "Surround", 0x6 },
3280         },
3281 };
3282
3283 static struct hda_channel_mode alc880_test_modes[4] = {
3284         { 2, NULL },
3285         { 4, NULL },
3286         { 6, NULL },
3287         { 8, NULL },
3288 };
3289
3290 static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
3291                                  struct snd_ctl_elem_info *uinfo)
3292 {
3293         static char *texts[] = {
3294                 "N/A", "Line Out", "HP Out",
3295                 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
3296         };
3297         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3298         uinfo->count = 1;
3299         uinfo->value.enumerated.items = 8;
3300         if (uinfo->value.enumerated.item >= 8)
3301                 uinfo->value.enumerated.item = 7;
3302         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3303         return 0;
3304 }
3305
3306 static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
3307                                 struct snd_ctl_elem_value *ucontrol)
3308 {
3309         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3310         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3311         unsigned int pin_ctl, item = 0;
3312
3313         pin_ctl = snd_hda_codec_read(codec, nid, 0,
3314                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3315         if (pin_ctl & AC_PINCTL_OUT_EN) {
3316                 if (pin_ctl & AC_PINCTL_HP_EN)
3317                         item = 2;
3318                 else
3319                         item = 1;
3320         } else if (pin_ctl & AC_PINCTL_IN_EN) {
3321                 switch (pin_ctl & AC_PINCTL_VREFEN) {
3322                 case AC_PINCTL_VREF_HIZ: item = 3; break;
3323                 case AC_PINCTL_VREF_50:  item = 4; break;
3324                 case AC_PINCTL_VREF_GRD: item = 5; break;
3325                 case AC_PINCTL_VREF_80:  item = 6; break;
3326                 case AC_PINCTL_VREF_100: item = 7; break;
3327                 }
3328         }
3329         ucontrol->value.enumerated.item[0] = item;
3330         return 0;
3331 }
3332
3333 static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
3334                                 struct snd_ctl_elem_value *ucontrol)
3335 {
3336         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3337         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3338         static unsigned int ctls[] = {
3339                 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
3340                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
3341                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
3342                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
3343                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
3344                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
3345         };
3346         unsigned int old_ctl, new_ctl;
3347
3348         old_ctl = snd_hda_codec_read(codec, nid, 0,
3349                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3350         new_ctl = ctls[ucontrol->value.enumerated.item[0]];
3351         if (old_ctl != new_ctl) {
3352                 int val;
3353                 snd_hda_codec_write_cache(codec, nid, 0,
3354                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
3355                                           new_ctl);
3356                 val = ucontrol->value.enumerated.item[0] >= 3 ?
3357                         HDA_AMP_MUTE : 0;
3358                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3359                                          HDA_AMP_MUTE, val);
3360                 return 1;
3361         }
3362         return 0;
3363 }
3364
3365 static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
3366                                  struct snd_ctl_elem_info *uinfo)
3367 {
3368         static char *texts[] = {
3369                 "Front", "Surround", "CLFE", "Side"
3370         };
3371         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3372         uinfo->count = 1;
3373         uinfo->value.enumerated.items = 4;
3374         if (uinfo->value.enumerated.item >= 4)
3375                 uinfo->value.enumerated.item = 3;
3376         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3377         return 0;
3378 }
3379
3380 static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
3381                                 struct snd_ctl_elem_value *ucontrol)
3382 {
3383         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3384         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3385         unsigned int sel;
3386
3387         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
3388         ucontrol->value.enumerated.item[0] = sel & 3;
3389         return 0;
3390 }
3391
3392 static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
3393                                 struct snd_ctl_elem_value *ucontrol)
3394 {
3395         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3396         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3397         unsigned int sel;
3398
3399         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
3400         if (ucontrol->value.enumerated.item[0] != sel) {
3401                 sel = ucontrol->value.enumerated.item[0] & 3;
3402                 snd_hda_codec_write_cache(codec, nid, 0,
3403                                           AC_VERB_SET_CONNECT_SEL, sel);
3404                 return 1;
3405         }
3406         return 0;
3407 }
3408
3409 #define PIN_CTL_TEST(xname,nid) {                       \
3410                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3411                         .name = xname,                 \
3412                         .info = alc_test_pin_ctl_info, \
3413                         .get = alc_test_pin_ctl_get,   \
3414                         .put = alc_test_pin_ctl_put,   \
3415                         .private_value = nid           \
3416                         }
3417
3418 #define PIN_SRC_TEST(xname,nid) {                       \
3419                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3420                         .name = xname,                 \
3421                         .info = alc_test_pin_src_info, \
3422                         .get = alc_test_pin_src_get,   \
3423                         .put = alc_test_pin_src_put,   \
3424                         .private_value = nid           \
3425                         }
3426
3427 static struct snd_kcontrol_new alc880_test_mixer[] = {
3428         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3429         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
3430         HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
3431         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3432         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
3433         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
3434         HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
3435         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
3436         PIN_CTL_TEST("Front Pin Mode", 0x14),
3437         PIN_CTL_TEST("Surround Pin Mode", 0x15),
3438         PIN_CTL_TEST("CLFE Pin Mode", 0x16),
3439         PIN_CTL_TEST("Side Pin Mode", 0x17),
3440         PIN_CTL_TEST("In-1 Pin Mode", 0x18),
3441         PIN_CTL_TEST("In-2 Pin Mode", 0x19),
3442         PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
3443         PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
3444         PIN_SRC_TEST("In-1 Pin Source", 0x18),
3445         PIN_SRC_TEST("In-2 Pin Source", 0x19),
3446         PIN_SRC_TEST("In-3 Pin Source", 0x1a),
3447         PIN_SRC_TEST("In-4 Pin Source", 0x1b),
3448         HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
3449         HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
3450         HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
3451         HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
3452         HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
3453         HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
3454         HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
3455         HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
3456         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
3457         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
3458         {
3459                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3460                 .name = "Channel Mode",
3461                 .info = alc_ch_mode_info,
3462                 .get = alc_ch_mode_get,
3463                 .put = alc_ch_mode_put,
3464         },
3465         { } /* end */
3466 };
3467
3468 static struct hda_verb alc880_test_init_verbs[] = {
3469         /* Unmute inputs of 0x0c - 0x0f */
3470         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3471         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3472         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3473         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3474         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3475         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3476         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3477         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3478         /* Vol output for 0x0c-0x0f */
3479         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3480         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3481         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3482         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3483         /* Set output pins 0x14-0x17 */
3484         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3485         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3486         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3487         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3488         /* Unmute output pins 0x14-0x17 */
3489         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3490         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3491         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3492         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3493         /* Set input pins 0x18-0x1c */
3494         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3495         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3496         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3497         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3498         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3499         /* Mute input pins 0x18-0x1b */
3500         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3501         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3502         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3503         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3504         /* ADC set up */
3505         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3506         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
3507         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3508         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
3509         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3510         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
3511         /* Analog input/passthru */
3512         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3513         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3514         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3515         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3516         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3517         { }
3518 };
3519 #endif
3520
3521 /*
3522  */
3523
3524 static const char *alc880_models[ALC880_MODEL_LAST] = {
3525         [ALC880_3ST]            = "3stack",
3526         [ALC880_TCL_S700]       = "tcl",
3527         [ALC880_3ST_DIG]        = "3stack-digout",
3528         [ALC880_CLEVO]          = "clevo",
3529         [ALC880_5ST]            = "5stack",
3530         [ALC880_5ST_DIG]        = "5stack-digout",
3531         [ALC880_W810]           = "w810",
3532         [ALC880_Z71V]           = "z71v",
3533         [ALC880_6ST]            = "6stack",
3534         [ALC880_6ST_DIG]        = "6stack-digout",
3535         [ALC880_ASUS]           = "asus",
3536         [ALC880_ASUS_W1V]       = "asus-w1v",
3537         [ALC880_ASUS_DIG]       = "asus-dig",
3538         [ALC880_ASUS_DIG2]      = "asus-dig2",
3539         [ALC880_UNIWILL_DIG]    = "uniwill",
3540         [ALC880_UNIWILL_P53]    = "uniwill-p53",
3541         [ALC880_FUJITSU]        = "fujitsu",
3542         [ALC880_F1734]          = "F1734",
3543         [ALC880_LG]             = "lg",
3544         [ALC880_LG_LW]          = "lg-lw",
3545         [ALC880_MEDION_RIM]     = "medion",
3546 #ifdef CONFIG_SND_DEBUG
3547         [ALC880_TEST]           = "test",
3548 #endif
3549         [ALC880_AUTO]           = "auto",
3550 };
3551
3552 static struct snd_pci_quirk alc880_cfg_tbl[] = {
3553         SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
3554         SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
3555         SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
3556         SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
3557         SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
3558         SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
3559         SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
3560         SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
3561         SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
3562         SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
3563         SND_PCI_QUIRK(0x103c, 0x2a09, "HP", ALC880_5ST),
3564         SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
3565         SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
3566         SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
3567         SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
3568         SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
3569         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
3570         SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
3571         /* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
3572         SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
3573         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
3574         SND_PCI_QUIRK(0x1043, 0x814e, "ASUS P5GD1 w/SPDIF", ALC880_6ST_DIG),
3575         SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
3576         SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
3577         SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
3578         SND_PCI_QUIRK(0x1043, 0, "ASUS", ALC880_ASUS), /* default ASUS */
3579         SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
3580         SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
3581         SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
3582         SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
3583         SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
3584         SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
3585         SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
3586         SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
3587         SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
3588         SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
3589         SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
3590         SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
3591         SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
3592         SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
3593         SND_PCI_QUIRK(0x1584, 0x9054, "Uniwlll", ALC880_F1734),
3594         SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
3595         SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
3596         SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
3597         SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_MEDION_RIM),
3598         SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
3599         SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
3600         SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
3601         SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FUJITSU),
3602         SND_PCI_QUIRK(0x1734, 0x10ac, "FSC", ALC880_UNIWILL),
3603         SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
3604         SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
3605         SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
3606         SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
3607         SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
3608         SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
3609         SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG), /* broken BIOS */
3610         SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
3611         SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
3612         SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
3613         SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
3614         SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
3615         SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
3616         SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
3617         SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
3618         SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
3619         SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
3620         SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
3621         SND_PCI_QUIRK(0x8086, 0, "Intel mobo", ALC880_3ST), /* default Intel */
3622         SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
3623         SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
3624         {}
3625 };
3626
3627 /*
3628  * ALC880 codec presets
3629  */
3630 static struct alc_config_preset alc880_presets[] = {
3631         [ALC880_3ST] = {
3632                 .mixers = { alc880_three_stack_mixer },
3633                 .init_verbs = { alc880_volume_init_verbs,
3634                                 alc880_pin_3stack_init_verbs },
3635                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3636                 .dac_nids = alc880_dac_nids,
3637                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3638                 .channel_mode = alc880_threestack_modes,
3639                 .need_dac_fix = 1,
3640                 .input_mux = &alc880_capture_source,
3641         },
3642         [ALC880_3ST_DIG] = {
3643                 .mixers = { alc880_three_stack_mixer },
3644                 .init_verbs = { alc880_volume_init_verbs,
3645                                 alc880_pin_3stack_init_verbs },
3646                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3647                 .dac_nids = alc880_dac_nids,
3648                 .dig_out_nid = ALC880_DIGOUT_NID,
3649                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3650                 .channel_mode = alc880_threestack_modes,
3651                 .need_dac_fix = 1,
3652                 .input_mux = &alc880_capture_source,
3653         },
3654         [ALC880_TCL_S700] = {
3655                 .mixers = { alc880_tcl_s700_mixer },
3656                 .init_verbs = { alc880_volume_init_verbs,
3657                                 alc880_pin_tcl_S700_init_verbs,
3658                                 alc880_gpio2_init_verbs },
3659                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3660                 .dac_nids = alc880_dac_nids,
3661                 .adc_nids = alc880_adc_nids_alt, /* FIXME: correct? */
3662                 .num_adc_nids = 1, /* single ADC */
3663                 .hp_nid = 0x03,
3664                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3665                 .channel_mode = alc880_2_jack_modes,
3666                 .input_mux = &alc880_capture_source,
3667         },
3668         [ALC880_5ST] = {
3669                 .mixers = { alc880_three_stack_mixer,
3670                             alc880_five_stack_mixer},
3671                 .init_verbs = { alc880_volume_init_verbs,
3672                                 alc880_pin_5stack_init_verbs },
3673                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3674                 .dac_nids = alc880_dac_nids,
3675                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3676                 .channel_mode = alc880_fivestack_modes,
3677                 .input_mux = &alc880_capture_source,
3678         },
3679         [ALC880_5ST_DIG] = {
3680                 .mixers = { alc880_three_stack_mixer,
3681                             alc880_five_stack_mixer },
3682                 .init_verbs = { alc880_volume_init_verbs,
3683                                 alc880_pin_5stack_init_verbs },
3684                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3685                 .dac_nids = alc880_dac_nids,
3686                 .dig_out_nid = ALC880_DIGOUT_NID,
3687                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3688                 .channel_mode = alc880_fivestack_modes,
3689                 .input_mux = &alc880_capture_source,
3690         },
3691         [ALC880_6ST] = {
3692                 .mixers = { alc880_six_stack_mixer },
3693                 .init_verbs = { alc880_volume_init_verbs,
3694                                 alc880_pin_6stack_init_verbs },
3695                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3696                 .dac_nids = alc880_6st_dac_nids,
3697                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3698                 .channel_mode = alc880_sixstack_modes,
3699                 .input_mux = &alc880_6stack_capture_source,
3700         },
3701         [ALC880_6ST_DIG] = {
3702                 .mixers = { alc880_six_stack_mixer },
3703                 .init_verbs = { alc880_volume_init_verbs,
3704                                 alc880_pin_6stack_init_verbs },
3705                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3706                 .dac_nids = alc880_6st_dac_nids,
3707                 .dig_out_nid = ALC880_DIGOUT_NID,
3708                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3709                 .channel_mode = alc880_sixstack_modes,
3710                 .input_mux = &alc880_6stack_capture_source,
3711         },
3712         [ALC880_W810] = {
3713                 .mixers = { alc880_w810_base_mixer },
3714                 .init_verbs = { alc880_volume_init_verbs,
3715                                 alc880_pin_w810_init_verbs,
3716                                 alc880_gpio2_init_verbs },
3717                 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
3718                 .dac_nids = alc880_w810_dac_nids,
3719                 .dig_out_nid = ALC880_DIGOUT_NID,
3720                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3721                 .channel_mode = alc880_w810_modes,
3722                 .input_mux = &alc880_capture_source,
3723         },
3724         [ALC880_Z71V] = {
3725                 .mixers = { alc880_z71v_mixer },
3726                 .init_verbs = { alc880_volume_init_verbs,
3727                                 alc880_pin_z71v_init_verbs },
3728                 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
3729                 .dac_nids = alc880_z71v_dac_nids,
3730                 .dig_out_nid = ALC880_DIGOUT_NID,
3731                 .hp_nid = 0x03,
3732                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3733                 .channel_mode = alc880_2_jack_modes,
3734                 .input_mux = &alc880_capture_source,
3735         },
3736         [ALC880_F1734] = {
3737                 .mixers = { alc880_f1734_mixer },
3738                 .init_verbs = { alc880_volume_init_verbs,
3739                                 alc880_pin_f1734_init_verbs },
3740                 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
3741                 .dac_nids = alc880_f1734_dac_nids,
3742                 .hp_nid = 0x02,
3743                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3744                 .channel_mode = alc880_2_jack_modes,
3745                 .input_mux = &alc880_f1734_capture_source,
3746                 .unsol_event = alc880_uniwill_p53_unsol_event,
3747                 .init_hook = alc880_uniwill_p53_hp_automute,
3748         },
3749         [ALC880_ASUS] = {
3750                 .mixers = { alc880_asus_mixer },
3751                 .init_verbs = { alc880_volume_init_verbs,
3752                                 alc880_pin_asus_init_verbs,
3753                                 alc880_gpio1_init_verbs },
3754                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3755                 .dac_nids = alc880_asus_dac_nids,
3756                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3757                 .channel_mode = alc880_asus_modes,
3758                 .need_dac_fix = 1,
3759                 .input_mux = &alc880_capture_source,
3760         },
3761         [ALC880_ASUS_DIG] = {
3762                 .mixers = { alc880_asus_mixer },
3763                 .init_verbs = { alc880_volume_init_verbs,
3764                                 alc880_pin_asus_init_verbs,
3765                                 alc880_gpio1_init_verbs },
3766                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3767                 .dac_nids = alc880_asus_dac_nids,
3768                 .dig_out_nid = ALC880_DIGOUT_NID,
3769                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3770                 .channel_mode = alc880_asus_modes,
3771                 .need_dac_fix = 1,
3772                 .input_mux = &alc880_capture_source,
3773         },
3774         [ALC880_ASUS_DIG2] = {
3775                 .mixers = { alc880_asus_mixer },
3776                 .init_verbs = { alc880_volume_init_verbs,
3777                                 alc880_pin_asus_init_verbs,
3778                                 alc880_gpio2_init_verbs }, /* use GPIO2 */
3779                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3780                 .dac_nids = alc880_asus_dac_nids,
3781                 .dig_out_nid = ALC880_DIGOUT_NID,
3782                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3783                 .channel_mode = alc880_asus_modes,
3784                 .need_dac_fix = 1,
3785                 .input_mux = &alc880_capture_source,
3786         },
3787         [ALC880_ASUS_W1V] = {
3788                 .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
3789                 .init_verbs = { alc880_volume_init_verbs,
3790                                 alc880_pin_asus_init_verbs,
3791                                 alc880_gpio1_init_verbs },
3792                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3793                 .dac_nids = alc880_asus_dac_nids,
3794                 .dig_out_nid = ALC880_DIGOUT_NID,
3795                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3796                 .channel_mode = alc880_asus_modes,
3797                 .need_dac_fix = 1,
3798                 .input_mux = &alc880_capture_source,
3799         },
3800         [ALC880_UNIWILL_DIG] = {
3801                 .mixers = { alc880_asus_mixer, alc880_pcbeep_mixer },
3802                 .init_verbs = { alc880_volume_init_verbs,
3803                                 alc880_pin_asus_init_verbs },
3804                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3805                 .dac_nids = alc880_asus_dac_nids,
3806                 .dig_out_nid = ALC880_DIGOUT_NID,
3807                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3808                 .channel_mode = alc880_asus_modes,
3809                 .need_dac_fix = 1,
3810                 .input_mux = &alc880_capture_source,
3811         },
3812         [ALC880_UNIWILL] = {
3813                 .mixers = { alc880_uniwill_mixer },
3814                 .init_verbs = { alc880_volume_init_verbs,
3815                                 alc880_uniwill_init_verbs },
3816                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3817                 .dac_nids = alc880_asus_dac_nids,
3818                 .dig_out_nid = ALC880_DIGOUT_NID,
3819                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3820                 .channel_mode = alc880_threestack_modes,
3821                 .need_dac_fix = 1,
3822                 .input_mux = &alc880_capture_source,
3823                 .unsol_event = alc880_uniwill_unsol_event,
3824                 .init_hook = alc880_uniwill_automute,
3825         },
3826         [ALC880_UNIWILL_P53] = {
3827                 .mixers = { alc880_uniwill_p53_mixer },
3828                 .init_verbs = { alc880_volume_init_verbs,
3829                                 alc880_uniwill_p53_init_verbs },
3830                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3831                 .dac_nids = alc880_asus_dac_nids,
3832                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3833                 .channel_mode = alc880_threestack_modes,
3834                 .input_mux = &alc880_capture_source,
3835                 .unsol_event = alc880_uniwill_p53_unsol_event,
3836                 .init_hook = alc880_uniwill_p53_hp_automute,
3837         },
3838         [ALC880_FUJITSU] = {
3839                 .mixers = { alc880_fujitsu_mixer,
3840                             alc880_pcbeep_mixer, },
3841                 .init_verbs = { alc880_volume_init_verbs,
3842                                 alc880_uniwill_p53_init_verbs,
3843                                 alc880_beep_init_verbs },
3844                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3845                 .dac_nids = alc880_dac_nids,
3846                 .dig_out_nid = ALC880_DIGOUT_NID,
3847                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3848                 .channel_mode = alc880_2_jack_modes,
3849                 .input_mux = &alc880_capture_source,
3850                 .unsol_event = alc880_uniwill_p53_unsol_event,
3851                 .init_hook = alc880_uniwill_p53_hp_automute,
3852         },
3853         [ALC880_CLEVO] = {
3854                 .mixers = { alc880_three_stack_mixer },
3855                 .init_verbs = { alc880_volume_init_verbs,
3856                                 alc880_pin_clevo_init_verbs },
3857                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3858                 .dac_nids = alc880_dac_nids,
3859                 .hp_nid = 0x03,
3860                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3861                 .channel_mode = alc880_threestack_modes,
3862                 .need_dac_fix = 1,
3863                 .input_mux = &alc880_capture_source,
3864         },
3865         [ALC880_LG] = {
3866                 .mixers = { alc880_lg_mixer },
3867                 .init_verbs = { alc880_volume_init_verbs,
3868                                 alc880_lg_init_verbs },
3869                 .num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
3870                 .dac_nids = alc880_lg_dac_nids,
3871                 .dig_out_nid = ALC880_DIGOUT_NID,
3872                 .num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
3873                 .channel_mode = alc880_lg_ch_modes,
3874                 .need_dac_fix = 1,
3875                 .input_mux = &alc880_lg_capture_source,
3876                 .unsol_event = alc880_lg_unsol_event,
3877                 .init_hook = alc880_lg_automute,
3878 #ifdef CONFIG_SND_HDA_POWER_SAVE
3879                 .loopbacks = alc880_lg_loopbacks,
3880 #endif
3881         },
3882         [ALC880_LG_LW] = {
3883                 .mixers = { alc880_lg_lw_mixer },
3884                 .init_verbs = { alc880_volume_init_verbs,
3885                                 alc880_lg_lw_init_verbs },
3886                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3887                 .dac_nids = alc880_dac_nids,
3888                 .dig_out_nid = ALC880_DIGOUT_NID,
3889                 .num_channel_mode = ARRAY_SIZE(alc880_lg_lw_modes),
3890                 .channel_mode = alc880_lg_lw_modes,
3891                 .input_mux = &alc880_lg_lw_capture_source,
3892                 .unsol_event = alc880_lg_lw_unsol_event,
3893                 .init_hook = alc880_lg_lw_automute,
3894         },
3895         [ALC880_MEDION_RIM] = {
3896                 .mixers = { alc880_medion_rim_mixer },
3897                 .init_verbs = { alc880_volume_init_verbs,
3898                                 alc880_medion_rim_init_verbs,
3899                                 alc_gpio2_init_verbs },
3900                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3901                 .dac_nids = alc880_dac_nids,
3902                 .dig_out_nid = ALC880_DIGOUT_NID,
3903                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3904                 .channel_mode = alc880_2_jack_modes,
3905                 .input_mux = &alc880_medion_rim_capture_source,
3906                 .unsol_event = alc880_medion_rim_unsol_event,
3907                 .init_hook = alc880_medion_rim_automute,
3908         },
3909 #ifdef CONFIG_SND_DEBUG
3910         [ALC880_TEST] = {
3911                 .mixers = { alc880_test_mixer },
3912                 .init_verbs = { alc880_test_init_verbs },
3913                 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
3914                 .dac_nids = alc880_test_dac_nids,
3915                 .dig_out_nid = ALC880_DIGOUT_NID,
3916                 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
3917                 .channel_mode = alc880_test_modes,
3918                 .input_mux = &alc880_test_capture_source,
3919         },
3920 #endif
3921 };
3922
3923 /*
3924  * Automatic parse of I/O pins from the BIOS configuration
3925  */
3926
3927 enum {
3928         ALC_CTL_WIDGET_VOL,
3929         ALC_CTL_WIDGET_MUTE,
3930         ALC_CTL_BIND_MUTE,
3931 };
3932 static struct snd_kcontrol_new alc880_control_templates[] = {
3933         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
3934         HDA_CODEC_MUTE(NULL, 0, 0, 0),
3935         HDA_BIND_MUTE(NULL, 0, 0, 0),
3936 };
3937
3938 /* add dynamic controls */
3939 static int add_control(struct alc_spec *spec, int type, const char *name,
3940                        unsigned long val)
3941 {
3942         struct snd_kcontrol_new *knew;
3943
3944         snd_array_init(&spec->kctls, sizeof(*knew), 32);
3945         knew = snd_array_new(&spec->kctls);
3946         if (!knew)
3947                 return -ENOMEM;
3948         *knew = alc880_control_templates[type];
3949         knew->name = kstrdup(name, GFP_KERNEL);
3950         if (!knew->name)
3951                 return -ENOMEM;
3952         knew->private_value = val;
3953         return 0;
3954 }
3955
3956 #define alc880_is_fixed_pin(nid)        ((nid) >= 0x14 && (nid) <= 0x17)
3957 #define alc880_fixed_pin_idx(nid)       ((nid) - 0x14)
3958 #define alc880_is_multi_pin(nid)        ((nid) >= 0x18)
3959 #define alc880_multi_pin_idx(nid)       ((nid) - 0x18)
3960 #define alc880_is_input_pin(nid)        ((nid) >= 0x18)
3961 #define alc880_input_pin_idx(nid)       ((nid) - 0x18)
3962 #define alc880_idx_to_dac(nid)          ((nid) + 0x02)
3963 #define alc880_dac_to_idx(nid)          ((nid) - 0x02)
3964 #define alc880_idx_to_mixer(nid)        ((nid) + 0x0c)
3965 #define alc880_idx_to_selector(nid)     ((nid) + 0x10)
3966 #define ALC880_PIN_CD_NID               0x1c
3967
3968 /* fill in the dac_nids table from the parsed pin configuration */
3969 static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
3970                                      const struct auto_pin_cfg *cfg)
3971 {
3972         hda_nid_t nid;
3973         int assigned[4];
3974         int i, j;
3975
3976         memset(assigned, 0, sizeof(assigned));
3977         spec->multiout.dac_nids = spec->private_dac_nids;
3978
3979         /* check the pins hardwired to audio widget */
3980         for (i = 0; i < cfg->line_outs; i++) {
3981                 nid = cfg->line_out_pins[i];
3982                 if (alc880_is_fixed_pin(nid)) {
3983                         int idx = alc880_fixed_pin_idx(nid);
3984                         spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
3985                         assigned[idx] = 1;
3986                 }
3987         }
3988         /* left pins can be connect to any audio widget */
3989         for (i = 0; i < cfg->line_outs; i++) {
3990                 nid = cfg->line_out_pins[i];
3991                 if (alc880_is_fixed_pin(nid))
3992                         continue;
3993                 /* search for an empty channel */
3994                 for (j = 0; j < cfg->line_outs; j++) {
3995                         if (!assigned[j]) {
3996                                 spec->multiout.dac_nids[i] =
3997                                         alc880_idx_to_dac(j);
3998                                 assigned[j] = 1;
3999                                 break;
4000                         }
4001                 }
4002         }
4003         spec->multiout.num_dacs = cfg->line_outs;
4004         return 0;
4005 }
4006
4007 /* add playback controls from the parsed DAC table */
4008 static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
4009                                              const struct auto_pin_cfg *cfg)
4010 {
4011         char name[32];
4012         static const char *chname[4] = {
4013                 "Front", "Surround", NULL /*CLFE*/, "Side"
4014         };
4015         hda_nid_t nid;
4016         int i, err;
4017
4018         for (i = 0; i < cfg->line_outs; i++) {
4019                 if (!spec->multiout.dac_nids[i])
4020                         continue;
4021                 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
4022                 if (i == 2) {
4023                         /* Center/LFE */
4024                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
4025                                           "Center Playback Volume",
4026                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
4027                                                               HDA_OUTPUT));
4028                         if (err < 0)
4029                                 return err;
4030                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
4031                                           "LFE Playback Volume",
4032                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
4033                                                               HDA_OUTPUT));
4034                         if (err < 0)
4035                                 return err;
4036                         err = add_control(spec, ALC_CTL_BIND_MUTE,
4037                                           "Center Playback Switch",
4038                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
4039                                                               HDA_INPUT));
4040                         if (err < 0)
4041                                 return err;
4042                         err = add_control(spec, ALC_CTL_BIND_MUTE,
4043                                           "LFE Playback Switch",
4044                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
4045                                                               HDA_INPUT));
4046                         if (err < 0)
4047                                 return err;
4048                 } else {
4049                         sprintf(name, "%s Playback Volume", chname[i]);
4050                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4051                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
4052                                                               HDA_OUTPUT));
4053                         if (err < 0)
4054                                 return err;
4055                         sprintf(name, "%s Playback Switch", chname[i]);
4056                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
4057                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
4058                                                               HDA_INPUT));
4059                         if (err < 0)
4060                                 return err;
4061                 }
4062         }
4063         return 0;
4064 }
4065
4066 /* add playback controls for speaker and HP outputs */
4067 static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
4068                                         const char *pfx)
4069 {
4070         hda_nid_t nid;
4071         int err;
4072         char name[32];
4073
4074         if (!pin)
4075                 return 0;
4076
4077         if (alc880_is_fixed_pin(pin)) {
4078                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
4079                 /* specify the DAC as the extra output */
4080                 if (!spec->multiout.hp_nid)
4081                         spec->multiout.hp_nid = nid;
4082                 else
4083                         spec->multiout.extra_out_nid[0] = nid;
4084                 /* control HP volume/switch on the output mixer amp */
4085                 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
4086                 sprintf(name, "%s Playback Volume", pfx);
4087                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4088                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
4089                 if (err < 0)
4090                         return err;
4091                 sprintf(name, "%s Playback Switch", pfx);
4092                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
4093                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
4094                 if (err < 0)
4095                         return err;
4096         } else if (alc880_is_multi_pin(pin)) {
4097                 /* set manual connection */
4098                 /* we have only a switch on HP-out PIN */
4099                 sprintf(name, "%s Playback Switch", pfx);
4100                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
4101                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4102                 if (err < 0)
4103                         return err;
4104         }
4105         return 0;
4106 }
4107
4108 /* create input playback/capture controls for the given pin */
4109 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
4110                             const char *ctlname,
4111                             int idx, hda_nid_t mix_nid)
4112 {
4113         char name[32];
4114         int err;
4115
4116         sprintf(name, "%s Playback Volume", ctlname);
4117         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4118                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
4119         if (err < 0)
4120                 return err;
4121         sprintf(name, "%s Playback Switch", ctlname);
4122         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
4123                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
4124         if (err < 0)
4125                 return err;
4126         return 0;
4127 }
4128
4129 /* create playback/capture controls for input pins */
4130 static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec,
4131                                                 const struct auto_pin_cfg *cfg)
4132 {
4133         struct hda_input_mux *imux = &spec->private_imux;
4134         int i, err, idx;
4135
4136         for (i = 0; i < AUTO_PIN_LAST; i++) {
4137                 if (alc880_is_input_pin(cfg->input_pins[i])) {
4138                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
4139                         err = new_analog_input(spec, cfg->input_pins[i],
4140                                                auto_pin_cfg_labels[i],
4141                                                idx, 0x0b);
4142                         if (err < 0)
4143                                 return err;
4144                         imux->items[imux->num_items].label =
4145                                 auto_pin_cfg_labels[i];
4146                         imux->items[imux->num_items].index =
4147                                 alc880_input_pin_idx(cfg->input_pins[i]);
4148                         imux->num_items++;
4149                 }
4150         }
4151         return 0;
4152 }
4153
4154 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
4155                                unsigned int pin_type)
4156 {
4157         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4158                             pin_type);
4159         /* unmute pin */
4160         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4161                             AMP_OUT_UNMUTE);
4162 }
4163
4164 static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
4165                                               hda_nid_t nid, int pin_type,
4166                                               int dac_idx)
4167 {
4168         alc_set_pin_output(codec, nid, pin_type);
4169         /* need the manual connection? */
4170         if (alc880_is_multi_pin(nid)) {
4171                 struct alc_spec *spec = codec->spec;
4172                 int idx = alc880_multi_pin_idx(nid);
4173                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
4174                                     AC_VERB_SET_CONNECT_SEL,
4175                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
4176         }
4177 }
4178
4179 static int get_pin_type(int line_out_type)
4180 {
4181         if (line_out_type == AUTO_PIN_HP_OUT)
4182                 return PIN_HP;
4183         else
4184                 return PIN_OUT;
4185 }
4186
4187 static void alc880_auto_init_multi_out(struct hda_codec *codec)
4188 {
4189         struct alc_spec *spec = codec->spec;
4190         int i;
4191
4192         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
4193         for (i = 0; i < spec->autocfg.line_outs; i++) {
4194                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
4195                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
4196                 alc880_auto_set_output_and_unmute(codec, nid, pin_type, i);
4197         }
4198 }
4199
4200 static void alc880_auto_init_extra_out(struct hda_codec *codec)
4201 {
4202         struct alc_spec *spec = codec->spec;
4203         hda_nid_t pin;
4204
4205         pin = spec->autocfg.speaker_pins[0];
4206         if (pin) /* connect to front */
4207                 alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
4208         pin = spec->autocfg.hp_pins[0];
4209         if (pin) /* connect to front */
4210                 alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
4211 }
4212
4213 static void alc880_auto_init_analog_input(struct hda_codec *codec)
4214 {
4215         struct alc_spec *spec = codec->spec;
4216         int i;
4217
4218         for (i = 0; i < AUTO_PIN_LAST; i++) {
4219                 hda_nid_t nid = spec->autocfg.input_pins[i];
4220                 if (alc880_is_input_pin(nid)) {
4221                         snd_hda_codec_write(codec, nid, 0,
4222                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
4223                                             i <= AUTO_PIN_FRONT_MIC ?
4224                                             PIN_VREF80 : PIN_IN);
4225                         if (nid != ALC880_PIN_CD_NID)
4226                                 snd_hda_codec_write(codec, nid, 0,
4227                                                     AC_VERB_SET_AMP_GAIN_MUTE,
4228                                                     AMP_OUT_MUTE);
4229                 }
4230         }
4231 }
4232
4233 /* parse the BIOS configuration and set up the alc_spec */
4234 /* return 1 if successful, 0 if the proper config is not found,
4235  * or a negative error code
4236  */
4237 static int alc880_parse_auto_config(struct hda_codec *codec)
4238 {
4239         struct alc_spec *spec = codec->spec;
4240         int err;
4241         static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4242
4243         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
4244                                            alc880_ignore);
4245         if (err < 0)
4246                 return err;
4247         if (!spec->autocfg.line_outs)
4248                 return 0; /* can't find valid BIOS pin config */
4249
4250         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
4251         if (err < 0)
4252                 return err;
4253         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
4254         if (err < 0)
4255                 return err;
4256         err = alc880_auto_create_extra_out(spec,
4257                                            spec->autocfg.speaker_pins[0],
4258                                            "Speaker");
4259         if (err < 0)
4260                 return err;
4261         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
4262                                            "Headphone");
4263         if (err < 0)
4264                 return err;
4265         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
4266         if (err < 0)
4267                 return err;
4268
4269         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4270
4271         if (spec->autocfg.dig_out_pin)
4272                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
4273         if (spec->autocfg.dig_in_pin)
4274                 spec->dig_in_nid = ALC880_DIGIN_NID;
4275
4276         if (spec->kctls.list)
4277                 add_mixer(spec, spec->kctls.list);
4278
4279         add_verb(spec, alc880_volume_init_verbs);
4280
4281         spec->num_mux_defs = 1;
4282         spec->input_mux = &spec->private_imux;
4283
4284         store_pin_configs(codec);
4285         return 1;
4286 }
4287
4288 /* additional initialization for auto-configuration model */
4289 static void alc880_auto_init(struct hda_codec *codec)
4290 {
4291         struct alc_spec *spec = codec->spec;
4292         alc880_auto_init_multi_out(codec);
4293         alc880_auto_init_extra_out(codec);
4294         alc880_auto_init_analog_input(codec);
4295         if (spec->unsol_event)
4296                 alc_inithook(codec);
4297 }
4298
4299 /*
4300  * OK, here we have finally the patch for ALC880
4301  */
4302
4303 static void set_capture_mixer(struct alc_spec *spec)
4304 {
4305         static struct snd_kcontrol_new *caps[3] = {
4306                 alc_capture_mixer1,
4307                 alc_capture_mixer2,
4308                 alc_capture_mixer3,
4309         };
4310         if (spec->num_adc_nids > 0 && spec->num_adc_nids <= 3)
4311                 spec->cap_mixer = caps[spec->num_adc_nids - 1];
4312 }
4313
4314 static int patch_alc880(struct hda_codec *codec)
4315 {
4316         struct alc_spec *spec;
4317         int board_config;
4318         int err;
4319
4320         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4321         if (spec == NULL)
4322                 return -ENOMEM;
4323
4324         codec->spec = spec;
4325
4326         board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
4327                                                   alc880_models,
4328                                                   alc880_cfg_tbl);
4329         if (board_config < 0) {
4330                 printk(KERN_INFO "hda_codec: Unknown model for ALC880, "
4331                        "trying auto-probe from BIOS...\n");
4332                 board_config = ALC880_AUTO;
4333         }
4334
4335         if (board_config == ALC880_AUTO) {
4336                 /* automatic parse from the BIOS config */
4337                 err = alc880_parse_auto_config(codec);
4338                 if (err < 0) {
4339                         alc_free(codec);
4340                         return err;
4341                 } else if (!err) {
4342                         printk(KERN_INFO
4343                                "hda_codec: Cannot set up configuration "
4344                                "from BIOS.  Using 3-stack mode...\n");
4345                         board_config = ALC880_3ST;
4346                 }
4347         }
4348
4349         if (board_config != ALC880_AUTO)
4350                 setup_preset(spec, &alc880_presets[board_config]);
4351
4352         spec->stream_name_analog = "ALC880 Analog";
4353         spec->stream_analog_playback = &alc880_pcm_analog_playback;
4354         spec->stream_analog_capture = &alc880_pcm_analog_capture;
4355         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
4356
4357         spec->stream_name_digital = "ALC880 Digital";
4358         spec->stream_digital_playback = &alc880_pcm_digital_playback;
4359         spec->stream_digital_capture = &alc880_pcm_digital_capture;
4360
4361         if (!spec->adc_nids && spec->input_mux) {
4362                 /* check whether NID 0x07 is valid */
4363                 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
4364                 /* get type */
4365                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
4366                 if (wcap != AC_WID_AUD_IN) {
4367                         spec->adc_nids = alc880_adc_nids_alt;
4368                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
4369                 } else {
4370                         spec->adc_nids = alc880_adc_nids;
4371                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
4372                 }
4373         }
4374         set_capture_mixer(spec);
4375
4376         spec->vmaster_nid = 0x0c;
4377
4378         codec->patch_ops = alc_patch_ops;
4379         if (board_config == ALC880_AUTO)
4380                 spec->init_hook = alc880_auto_init;
4381 #ifdef CONFIG_SND_HDA_POWER_SAVE
4382         if (!spec->loopback.amplist)
4383                 spec->loopback.amplist = alc880_loopbacks;
4384 #endif
4385         codec->proc_widget_hook = print_realtek_coef;
4386
4387         return 0;
4388 }
4389
4390
4391 /*
4392  * ALC260 support
4393  */
4394
4395 static hda_nid_t alc260_dac_nids[1] = {
4396         /* front */
4397         0x02,
4398 };
4399
4400 static hda_nid_t alc260_adc_nids[1] = {
4401         /* ADC0 */
4402         0x04,
4403 };
4404
4405 static hda_nid_t alc260_adc_nids_alt[1] = {
4406         /* ADC1 */
4407         0x05,
4408 };
4409
4410 /* NIDs used when simultaneous access to both ADCs makes sense.  Note that
4411  * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
4412  */
4413 static hda_nid_t alc260_dual_adc_nids[2] = {
4414         /* ADC0, ADC1 */
4415         0x04, 0x05
4416 };
4417
4418 #define ALC260_DIGOUT_NID       0x03
4419 #define ALC260_DIGIN_NID        0x06
4420
4421 static struct hda_input_mux alc260_capture_source = {
4422         .num_items = 4,
4423         .items = {
4424                 { "Mic", 0x0 },
4425                 { "Front Mic", 0x1 },
4426                 { "Line", 0x2 },
4427                 { "CD", 0x4 },
4428         },
4429 };
4430
4431 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
4432  * headphone jack and the internal CD lines since these are the only pins at
4433  * which audio can appear.  For flexibility, also allow the option of
4434  * recording the mixer output on the second ADC (ADC0 doesn't have a
4435  * connection to the mixer output).
4436  */
4437 static struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
4438         {
4439                 .num_items = 3,
4440                 .items = {
4441                         { "Mic/Line", 0x0 },
4442                         { "CD", 0x4 },
4443                         { "Headphone", 0x2 },
4444                 },
4445         },
4446         {
4447                 .num_items = 4,
4448                 .items = {
4449                         { "Mic/Line", 0x0 },
4450                         { "CD", 0x4 },
4451                         { "Headphone", 0x2 },
4452                         { "Mixer", 0x5 },
4453                 },
4454         },
4455
4456 };
4457
4458 /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
4459  * the Fujitsu S702x, but jacks are marked differently.
4460  */
4461 static struct hda_input_mux alc260_acer_capture_sources[2] = {
4462         {
4463                 .num_items = 4,
4464                 .items = {
4465                         { "Mic", 0x0 },
4466                         { "Line", 0x2 },
4467                         { "CD", 0x4 },
4468                         { "Headphone", 0x5 },
4469                 },
4470         },
4471         {
4472                 .num_items = 5,
4473                 .items = {
4474                         { "Mic", 0x0 },
4475                         { "Line", 0x2 },
4476                         { "CD", 0x4 },
4477                         { "Headphone", 0x6 },
4478                         { "Mixer", 0x5 },
4479                 },
4480         },
4481 };
4482 /*
4483  * This is just place-holder, so there's something for alc_build_pcms to look
4484  * at when it calculates the maximum number of channels. ALC260 has no mixer
4485  * element which allows changing the channel mode, so the verb list is
4486  * never used.
4487  */
4488 static struct hda_channel_mode alc260_modes[1] = {
4489         { 2, NULL },
4490 };
4491
4492
4493 /* Mixer combinations
4494  *
4495  * basic: base_output + input + pc_beep + capture
4496  * HP: base_output + input + capture_alt
4497  * HP_3013: hp_3013 + input + capture
4498  * fujitsu: fujitsu + capture
4499  * acer: acer + capture
4500  */
4501
4502 static struct snd_kcontrol_new alc260_base_output_mixer[] = {
4503         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4504         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
4505         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4506         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
4507         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4508         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4509         { } /* end */
4510 };
4511
4512 static struct snd_kcontrol_new alc260_input_mixer[] = {
4513         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4514         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4515         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4516         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4517         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4518         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4519         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
4520         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
4521         { } /* end */
4522 };
4523
4524 static struct snd_kcontrol_new alc260_pc_beep_mixer[] = {
4525         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x07, 0x05, HDA_INPUT),
4526         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x07, 0x05, HDA_INPUT),
4527         { } /* end */
4528 };
4529
4530 /* update HP, line and mono out pins according to the master switch */
4531 static void alc260_hp_master_update(struct hda_codec *codec,
4532                                     hda_nid_t hp, hda_nid_t line,
4533                                     hda_nid_t mono)
4534 {
4535         struct alc_spec *spec = codec->spec;
4536         unsigned int val = spec->master_sw ? PIN_HP : 0;
4537         /* change HP and line-out pins */
4538         snd_hda_codec_write(codec, hp, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4539                             val);
4540         snd_hda_codec_write(codec, line, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4541                             val);
4542         /* mono (speaker) depending on the HP jack sense */
4543         val = (val && !spec->jack_present) ? PIN_OUT : 0;
4544         snd_hda_codec_write(codec, mono, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4545                             val);
4546 }
4547
4548 static int alc260_hp_master_sw_get(struct snd_kcontrol *kcontrol,
4549                                    struct snd_ctl_elem_value *ucontrol)
4550 {
4551         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4552         struct alc_spec *spec = codec->spec;
4553         *ucontrol->value.integer.value = spec->master_sw;
4554         return 0;
4555 }
4556
4557 static int alc260_hp_master_sw_put(struct snd_kcontrol *kcontrol,
4558                                    struct snd_ctl_elem_value *ucontrol)
4559 {
4560         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4561         struct alc_spec *spec = codec->spec;
4562         int val = !!*ucontrol->value.integer.value;
4563         hda_nid_t hp, line, mono;
4564
4565         if (val == spec->master_sw)
4566                 return 0;
4567         spec->master_sw = val;
4568         hp = (kcontrol->private_value >> 16) & 0xff;
4569         line = (kcontrol->private_value >> 8) & 0xff;
4570         mono = kcontrol->private_value & 0xff;
4571         alc260_hp_master_update(codec, hp, line, mono);
4572         return 1;
4573 }
4574
4575 static struct snd_kcontrol_new alc260_hp_output_mixer[] = {
4576         {
4577                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4578                 .name = "Master Playback Switch",
4579                 .info = snd_ctl_boolean_mono_info,
4580                 .get = alc260_hp_master_sw_get,
4581                 .put = alc260_hp_master_sw_put,
4582                 .private_value = (0x0f << 16) | (0x10 << 8) | 0x11
4583         },
4584         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4585         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
4586         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4587         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
4588         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4589                               HDA_OUTPUT),
4590         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4591         { } /* end */
4592 };
4593
4594 static struct hda_verb alc260_hp_unsol_verbs[] = {
4595         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4596         {},
4597 };
4598
4599 static void alc260_hp_automute(struct hda_codec *codec)
4600 {
4601         struct alc_spec *spec = codec->spec;
4602         unsigned int present;
4603
4604         present = snd_hda_codec_read(codec, 0x10, 0,
4605                                      AC_VERB_GET_PIN_SENSE, 0);
4606         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4607         alc260_hp_master_update(codec, 0x0f, 0x10, 0x11);
4608 }
4609
4610 static void alc260_hp_unsol_event(struct hda_codec *codec, unsigned int res)
4611 {
4612         if ((res >> 26) == ALC880_HP_EVENT)
4613                 alc260_hp_automute(codec);
4614 }
4615
4616 static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
4617         {
4618                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4619                 .name = "Master Playback Switch",
4620                 .info = snd_ctl_boolean_mono_info,
4621                 .get = alc260_hp_master_sw_get,
4622                 .put = alc260_hp_master_sw_put,
4623                 .private_value = (0x15 << 16) | (0x10 << 8) | 0x11
4624         },
4625         HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4626         HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
4627         HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
4628         HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
4629         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4630         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
4631         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4632         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
4633         { } /* end */
4634 };
4635
4636 static struct hda_bind_ctls alc260_dc7600_bind_master_vol = {
4637         .ops = &snd_hda_bind_vol,
4638         .values = {
4639                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_OUTPUT),
4640                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
4641                 HDA_COMPOSE_AMP_VAL(0x0a, 3, 0, HDA_OUTPUT),
4642                 0
4643         },
4644 };
4645
4646 static struct hda_bind_ctls alc260_dc7600_bind_switch = {
4647         .ops = &snd_hda_bind_sw,
4648         .values = {
4649                 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
4650                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
4651                 0
4652         },
4653 };
4654
4655 static struct snd_kcontrol_new alc260_hp_dc7600_mixer[] = {
4656         HDA_BIND_VOL("Master Playback Volume", &alc260_dc7600_bind_master_vol),
4657         HDA_BIND_SW("LineOut Playback Switch", &alc260_dc7600_bind_switch),
4658         HDA_CODEC_MUTE("Speaker Playback Switch", 0x0f, 0x0, HDA_OUTPUT),
4659         HDA_CODEC_MUTE("Headphone Playback Switch", 0x10, 0x0, HDA_OUTPUT),
4660         { } /* end */
4661 };
4662
4663 static struct hda_verb alc260_hp_3013_unsol_verbs[] = {
4664         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4665         {},
4666 };
4667
4668 static void alc260_hp_3013_automute(struct hda_codec *codec)
4669 {
4670         struct alc_spec *spec = codec->spec;
4671         unsigned int present;
4672
4673         present = snd_hda_codec_read(codec, 0x15, 0,
4674                                      AC_VERB_GET_PIN_SENSE, 0);
4675         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4676         alc260_hp_master_update(codec, 0x15, 0x10, 0x11);
4677 }
4678
4679 static void alc260_hp_3013_unsol_event(struct hda_codec *codec,
4680                                        unsigned int res)
4681 {
4682         if ((res >> 26) == ALC880_HP_EVENT)
4683                 alc260_hp_3013_automute(codec);
4684 }
4685
4686 static void alc260_hp_3012_automute(struct hda_codec *codec)
4687 {
4688         unsigned int present, bits;
4689
4690         present = snd_hda_codec_read(codec, 0x10, 0,
4691                         AC_VERB_GET_PIN_SENSE, 0) & AC_PINSENSE_PRESENCE;
4692
4693         bits = present ? 0 : PIN_OUT;
4694         snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4695                             bits);
4696         snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4697                             bits);
4698         snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4699                             bits);
4700 }
4701
4702 static void alc260_hp_3012_unsol_event(struct hda_codec *codec,
4703                                        unsigned int res)
4704 {
4705         if ((res >> 26) == ALC880_HP_EVENT)
4706                 alc260_hp_3012_automute(codec);
4707 }
4708
4709 /* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12,
4710  * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
4711  */
4712 static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
4713         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4714         HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
4715         ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4716         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4717         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4718         HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
4719         HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
4720         ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
4721         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4722         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4723         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4724         HDA_BIND_MUTE("Speaker Playback Switch", 0x09, 2, HDA_INPUT),
4725         { } /* end */
4726 };
4727
4728 /* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks.  Note that current
4729  * versions of the ALC260 don't act on requests to enable mic bias from NID
4730  * 0x0f (used to drive the headphone jack in these laptops).  The ALC260
4731  * datasheet doesn't mention this restriction.  At this stage it's not clear
4732  * whether this behaviour is intentional or is a hardware bug in chip
4733  * revisions available in early 2006.  Therefore for now allow the
4734  * "Headphone Jack Mode" control to span all choices, but if it turns out
4735  * that the lack of mic bias for this NID is intentional we could change the
4736  * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
4737  *
4738  * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
4739  * don't appear to make the mic bias available from the "line" jack, even
4740  * though the NID used for this jack (0x14) can supply it.  The theory is
4741  * that perhaps Acer have included blocking capacitors between the ALC260
4742  * and the output jack.  If this turns out to be the case for all such
4743  * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
4744  * to ALC_PIN_DIR_INOUT_NOMICBIAS.
4745  *
4746  * The C20x Tablet series have a mono internal speaker which is controlled
4747  * via the chip's Mono sum widget and pin complex, so include the necessary
4748  * controls for such models.  On models without a "mono speaker" the control
4749  * won't do anything.
4750  */
4751 static struct snd_kcontrol_new alc260_acer_mixer[] = {
4752         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4753         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
4754         ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
4755         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4756                               HDA_OUTPUT),
4757         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2,
4758                            HDA_INPUT),
4759         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4760         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4761         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4762         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4763         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4764         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4765         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4766         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4767         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4768         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4769         { } /* end */
4770 };
4771
4772 /* Packard bell V7900  ALC260 pin usage: HP = 0x0f, Mic jack = 0x12,
4773  * Line In jack = 0x14, CD audio =  0x16, pc beep = 0x17.
4774  */
4775 static struct snd_kcontrol_new alc260_will_mixer[] = {
4776         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4777         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
4778         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4779         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4780         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4781         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4782         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4783         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4784         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4785         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4786         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4787         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4788         { } /* end */
4789 };
4790
4791 /* Replacer 672V ALC260 pin usage: Mic jack = 0x12,
4792  * Line In jack = 0x14, ATAPI Mic = 0x13, speaker = 0x0f.
4793  */
4794 static struct snd_kcontrol_new alc260_replacer_672v_mixer[] = {
4795         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4796         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
4797         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4798         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4799         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4800         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x07, 0x1, HDA_INPUT),
4801         HDA_CODEC_MUTE("ATATI Mic Playback Switch", 0x07, 0x1, HDA_INPUT),
4802         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4803         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4804         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4805         { } /* end */
4806 };
4807
4808 /*
4809  * initialization verbs
4810  */
4811 static struct hda_verb alc260_init_verbs[] = {
4812         /* Line In pin widget for input */
4813         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4814         /* CD pin widget for input */
4815         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4816         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4817         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4818         /* Mic2 (front panel) pin widget for input and vref at 80% */
4819         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4820         /* LINE-2 is used for line-out in rear */
4821         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4822         /* select line-out */
4823         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
4824         /* LINE-OUT pin */
4825         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4826         /* enable HP */
4827         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4828         /* enable Mono */
4829         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4830         /* mute capture amp left and right */
4831         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4832         /* set connection select to line in (default select for this ADC) */
4833         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4834         /* mute capture amp left and right */
4835         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4836         /* set connection select to line in (default select for this ADC) */
4837         {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
4838         /* set vol=0 Line-Out mixer amp left and right */
4839         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4840         /* unmute pin widget amp left and right (no gain on this amp) */
4841         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4842         /* set vol=0 HP mixer amp left and right */
4843         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4844         /* unmute pin widget amp left and right (no gain on this amp) */
4845         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4846         /* set vol=0 Mono mixer amp left and right */
4847         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4848         /* unmute pin widget amp left and right (no gain on this amp) */
4849         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4850         /* unmute LINE-2 out pin */
4851         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4852         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4853          * Line In 2 = 0x03
4854          */
4855         /* mute analog inputs */
4856         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4857         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4858         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4859         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4860         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4861         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4862         /* mute Front out path */
4863         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4864         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4865         /* mute Headphone out path */
4866         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4867         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4868         /* mute Mono out path */
4869         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4870         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4871         { }
4872 };
4873
4874 #if 0 /* should be identical with alc260_init_verbs? */
4875 static struct hda_verb alc260_hp_init_verbs[] = {
4876         /* Headphone and output */
4877         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4878         /* mono output */
4879         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4880         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4881         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4882         /* Mic2 (front panel) pin widget for input and vref at 80% */
4883         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4884         /* Line In pin widget for input */
4885         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4886         /* Line-2 pin widget for output */
4887         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4888         /* CD pin widget for input */
4889         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4890         /* unmute amp left and right */
4891         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4892         /* set connection select to line in (default select for this ADC) */
4893         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4894         /* unmute Line-Out mixer amp left and right (volume = 0) */
4895         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4896         /* mute pin widget amp left and right (no gain on this amp) */
4897         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4898         /* unmute HP mixer amp left and right (volume = 0) */
4899         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4900         /* mute pin widget amp left and right (no gain on this amp) */
4901         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4902         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4903          * Line In 2 = 0x03
4904          */
4905         /* mute analog inputs */
4906         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4907         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4908         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4909         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4910         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4911         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4912         /* Unmute Front out path */
4913         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4914         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4915         /* Unmute Headphone out path */
4916         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4917         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4918         /* Unmute Mono out path */
4919         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4920         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4921         { }
4922 };
4923 #endif
4924
4925 static struct hda_verb alc260_hp_3013_init_verbs[] = {
4926         /* Line out and output */
4927         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4928         /* mono output */
4929         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4930         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4931         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4932         /* Mic2 (front panel) pin widget for input and vref at 80% */
4933         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4934         /* Line In pin widget for input */
4935         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4936         /* Headphone pin widget for output */
4937         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4938         /* CD pin widget for input */
4939         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4940         /* unmute amp left and right */
4941         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4942         /* set connection select to line in (default select for this ADC) */
4943         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4944         /* unmute Line-Out mixer amp left and right (volume = 0) */
4945         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4946         /* mute pin widget amp left and right (no gain on this amp) */
4947         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4948         /* unmute HP mixer amp left and right (volume = 0) */
4949         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4950         /* mute pin widget amp left and right (no gain on this amp) */
4951         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4952         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4953          * Line In 2 = 0x03
4954          */
4955         /* mute analog inputs */
4956         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4957         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4958         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4959         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4960         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4961         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4962         /* Unmute Front out path */
4963         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4964         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4965         /* Unmute Headphone out path */
4966         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4967         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4968         /* Unmute Mono out path */
4969         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4970         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4971         { }
4972 };
4973
4974 /* Initialisation sequence for ALC260 as configured in Fujitsu S702x
4975  * laptops.  ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
4976  * audio = 0x16, internal speaker = 0x10.
4977  */
4978 static struct hda_verb alc260_fujitsu_init_verbs[] = {
4979         /* Disable all GPIOs */
4980         {0x01, AC_VERB_SET_GPIO_MASK, 0},
4981         /* Internal speaker is connected to headphone pin */
4982         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4983         /* Headphone/Line-out jack connects to Line1 pin; make it an output */
4984         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4985         /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
4986         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4987         /* Ensure all other unused pins are disabled and muted. */
4988         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4989         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4990         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4991         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4992         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4993         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4994         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
4995         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4996
4997         /* Disable digital (SPDIF) pins */
4998         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
4999         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5000
5001         /* Ensure Line1 pin widget takes its input from the OUT1 sum bus
5002          * when acting as an output.
5003          */
5004         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5005
5006         /* Start with output sum widgets muted and their output gains at min */
5007         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5008         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5009         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5010         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5011         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5012         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5013         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5014         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5015         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5016
5017         /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
5018         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5019         /* Unmute Line1 pin widget output buffer since it starts as an output.
5020          * If the pin mode is changed by the user the pin mode control will
5021          * take care of enabling the pin's input/output buffers as needed.
5022          * Therefore there's no need to enable the input buffer at this
5023          * stage.
5024          */
5025         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5026         /* Unmute input buffer of pin widget used for Line-in (no equiv
5027          * mixer ctrl)
5028          */
5029         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5030
5031         /* Mute capture amp left and right */
5032         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5033         /* Set ADC connection select to match default mixer setting - line
5034          * in (on mic1 pin)
5035          */
5036         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5037
5038         /* Do the same for the second ADC: mute capture input amp and
5039          * set ADC connection to line in (on mic1 pin)
5040          */
5041         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5042         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5043
5044         /* Mute all inputs to mixer widget (even unconnected ones) */
5045         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5046         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5047         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5048         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5049         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5050         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5051         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5052         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5053
5054         { }
5055 };
5056
5057 /* Initialisation sequence for ALC260 as configured in Acer TravelMate and
5058  * similar laptops (adapted from Fujitsu init verbs).
5059  */
5060 static struct hda_verb alc260_acer_init_verbs[] = {
5061         /* On TravelMate laptops, GPIO 0 enables the internal speaker and
5062          * the headphone jack.  Turn this on and rely on the standard mute
5063          * methods whenever the user wants to turn these outputs off.
5064          */
5065         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5066         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5067         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5068         /* Internal speaker/Headphone jack is connected to Line-out pin */
5069         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5070         /* Internal microphone/Mic jack is connected to Mic1 pin */
5071         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
5072         /* Line In jack is connected to Line1 pin */
5073         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5074         /* Some Acers (eg: C20x Tablets) use Mono pin for internal speaker */
5075         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5076         /* Ensure all other unused pins are disabled and muted. */
5077         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5078         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5079         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5080         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5081         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5082         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5083         /* Disable digital (SPDIF) pins */
5084         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5085         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5086
5087         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
5088          * bus when acting as outputs.
5089          */
5090         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5091         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5092
5093         /* Start with output sum widgets muted and their output gains at min */
5094         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5095         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5096         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5097         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5098         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5099         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5100         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5101         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5102         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5103
5104         /* Unmute Line-out pin widget amp left and right
5105          * (no equiv mixer ctrl)
5106          */
5107         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5108         /* Unmute mono pin widget amp output (no equiv mixer ctrl) */
5109         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5110         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
5111          * inputs. If the pin mode is changed by the user the pin mode control
5112          * will take care of enabling the pin's input/output buffers as needed.
5113          * Therefore there's no need to enable the input buffer at this
5114          * stage.
5115          */
5116         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5117         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5118
5119         /* Mute capture amp left and right */
5120         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5121         /* Set ADC connection select to match default mixer setting - mic
5122          * (on mic1 pin)
5123          */
5124         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5125
5126         /* Do similar with the second ADC: mute capture input amp and
5127          * set ADC connection to mic to match ALSA's default state.
5128          */
5129         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5130         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5131
5132         /* Mute all inputs to mixer widget (even unconnected ones) */
5133         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5134         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5135         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5136         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5137         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5138         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5139         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5140         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5141
5142         { }
5143 };
5144
5145 static struct hda_verb alc260_will_verbs[] = {
5146         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5147         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x00},
5148         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
5149         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
5150         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
5151         {0x1a, AC_VERB_SET_PROC_COEF, 0x3040},
5152         {}
5153 };
5154
5155 static struct hda_verb alc260_replacer_672v_verbs[] = {
5156         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
5157         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
5158         {0x1a, AC_VERB_SET_PROC_COEF, 0x3050},
5159
5160         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5161         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5162         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5163
5164         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5165         {}
5166 };
5167
5168 /* toggle speaker-output according to the hp-jack state */
5169 static void alc260_replacer_672v_automute(struct hda_codec *codec)
5170 {
5171         unsigned int present;
5172
5173         /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
5174         present = snd_hda_codec_read(codec, 0x0f, 0,
5175                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5176         if (present) {
5177                 snd_hda_codec_write_cache(codec, 0x01, 0,
5178                                           AC_VERB_SET_GPIO_DATA, 1);
5179                 snd_hda_codec_write_cache(codec, 0x0f, 0,
5180                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
5181                                           PIN_HP);
5182         } else {
5183                 snd_hda_codec_write_cache(codec, 0x01, 0,
5184                                           AC_VERB_SET_GPIO_DATA, 0);
5185                 snd_hda_codec_write_cache(codec, 0x0f, 0,
5186                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
5187                                           PIN_OUT);
5188         }
5189 }
5190
5191 static void alc260_replacer_672v_unsol_event(struct hda_codec *codec,
5192                                        unsigned int res)
5193 {
5194         if ((res >> 26) == ALC880_HP_EVENT)
5195                 alc260_replacer_672v_automute(codec);
5196 }
5197
5198 static struct hda_verb alc260_hp_dc7600_verbs[] = {
5199         {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
5200         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
5201         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5202         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5203         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5204         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5205         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5206         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5207         {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5208         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5209         {}
5210 };
5211
5212 /* Test configuration for debugging, modelled after the ALC880 test
5213  * configuration.
5214  */
5215 #ifdef CONFIG_SND_DEBUG
5216 static hda_nid_t alc260_test_dac_nids[1] = {
5217         0x02,
5218 };
5219 static hda_nid_t alc260_test_adc_nids[2] = {
5220         0x04, 0x05,
5221 };
5222 /* For testing the ALC260, each input MUX needs its own definition since
5223  * the signal assignments are different.  This assumes that the first ADC
5224  * is NID 0x04.
5225  */
5226 static struct hda_input_mux alc260_test_capture_sources[2] = {
5227         {
5228                 .num_items = 7,
5229                 .items = {
5230                         { "MIC1 pin", 0x0 },
5231                         { "MIC2 pin", 0x1 },
5232                         { "LINE1 pin", 0x2 },
5233                         { "LINE2 pin", 0x3 },
5234                         { "CD pin", 0x4 },
5235                         { "LINE-OUT pin", 0x5 },
5236                         { "HP-OUT pin", 0x6 },
5237                 },
5238         },
5239         {
5240                 .num_items = 8,
5241                 .items = {
5242                         { "MIC1 pin", 0x0 },
5243                         { "MIC2 pin", 0x1 },
5244                         { "LINE1 pin", 0x2 },
5245                         { "LINE2 pin", 0x3 },
5246                         { "CD pin", 0x4 },
5247                         { "Mixer", 0x5 },
5248                         { "LINE-OUT pin", 0x6 },
5249                         { "HP-OUT pin", 0x7 },
5250                 },
5251         },
5252 };
5253 static struct snd_kcontrol_new alc260_test_mixer[] = {
5254         /* Output driver widgets */
5255         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
5256         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
5257         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5258         HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
5259         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5260         HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),
5261
5262         /* Modes for retasking pin widgets
5263          * Note: the ALC260 doesn't seem to act on requests to enable mic
5264          * bias from NIDs 0x0f and 0x10.  The ALC260 datasheet doesn't
5265          * mention this restriction.  At this stage it's not clear whether
5266          * this behaviour is intentional or is a hardware bug in chip
5267          * revisions available at least up until early 2006.  Therefore for
5268          * now allow the "HP-OUT" and "LINE-OUT" Mode controls to span all
5269          * choices, but if it turns out that the lack of mic bias for these
5270          * NIDs is intentional we could change their modes from
5271          * ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
5272          */
5273         ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
5274         ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
5275         ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
5276         ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
5277         ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
5278         ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),
5279
5280         /* Loopback mixer controls */
5281         HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
5282         HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
5283         HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
5284         HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
5285         HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
5286         HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
5287         HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
5288         HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
5289         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5290         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5291         HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
5292         HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
5293         HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
5294         HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
5295         HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
5296         HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
5297
5298         /* Controls for GPIO pins, assuming they are configured as outputs */
5299         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
5300         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
5301         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
5302         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
5303
5304         /* Switches to allow the digital IO pins to be enabled.  The datasheet
5305          * is ambigious as to which NID is which; testing on laptops which
5306          * make this output available should provide clarification.
5307          */
5308         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
5309         ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),
5310
5311         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
5312          * this output to turn on an external amplifier.
5313          */
5314         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
5315         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
5316
5317         { } /* end */
5318 };
5319 static struct hda_verb alc260_test_init_verbs[] = {
5320         /* Enable all GPIOs as outputs with an initial value of 0 */
5321         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
5322         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5323         {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
5324
5325         /* Enable retasking pins as output, initially without power amp */
5326         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5327         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5328         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5329         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5330         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5331         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5332
5333         /* Disable digital (SPDIF) pins initially, but users can enable
5334          * them via a mixer switch.  In the case of SPDIF-out, this initverb
5335          * payload also sets the generation to 0, output to be in "consumer"
5336          * PCM format, copyright asserted, no pre-emphasis and no validity
5337          * control.
5338          */
5339         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5340         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5341
5342         /* Ensure mic1, mic2, line1 and line2 pin widgets take input from the
5343          * OUT1 sum bus when acting as an output.
5344          */
5345         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5346         {0x0c, AC_VERB_SET_CONNECT_SEL, 0},
5347         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5348         {0x0e, AC_VERB_SET_CONNECT_SEL, 0},
5349
5350         /* Start with output sum widgets muted and their output gains at min */
5351         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5352         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5353         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5354         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5355         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5356         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5357         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5358         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5359         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5360
5361         /* Unmute retasking pin widget output buffers since the default
5362          * state appears to be output.  As the pin mode is changed by the
5363          * user the pin mode control will take care of enabling the pin's
5364          * input/output buffers as needed.
5365          */
5366         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5367         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5368         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5369         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5370         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5371         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5372         /* Also unmute the mono-out pin widget */
5373         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5374
5375         /* Mute capture amp left and right */
5376         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5377         /* Set ADC connection select to match default mixer setting (mic1
5378          * pin)
5379          */
5380         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5381
5382         /* Do the same for the second ADC: mute capture input amp and
5383          * set ADC connection to mic1 pin
5384          */
5385         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5386         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5387
5388         /* Mute all inputs to mixer widget (even unconnected ones) */
5389         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5390         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5391         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5392         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5393         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5394         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5395         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5396         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5397
5398         { }
5399 };
5400 #endif
5401
5402 #define alc260_pcm_analog_playback      alc880_pcm_analog_alt_playback
5403 #define alc260_pcm_analog_capture       alc880_pcm_analog_capture
5404
5405 #define alc260_pcm_digital_playback     alc880_pcm_digital_playback
5406 #define alc260_pcm_digital_capture      alc880_pcm_digital_capture
5407
5408 /*
5409  * for BIOS auto-configuration
5410  */
5411
5412 static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
5413                                         const char *pfx, int *vol_bits)
5414 {
5415         hda_nid_t nid_vol;
5416         unsigned long vol_val, sw_val;
5417         char name[32];
5418         int err;
5419
5420         if (nid >= 0x0f && nid < 0x11) {
5421                 nid_vol = nid - 0x7;
5422                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
5423                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
5424         } else if (nid == 0x11) {
5425                 nid_vol = nid - 0x7;
5426                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT);
5427                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
5428         } else if (nid >= 0x12 && nid <= 0x15) {
5429                 nid_vol = 0x08;
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
5433                 return 0; /* N/A */
5434
5435         if (!(*vol_bits & (1 << nid_vol))) {
5436                 /* first control for the volume widget */
5437                 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
5438                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name, vol_val);
5439                 if (err < 0)
5440                         return err;
5441                 *vol_bits |= (1 << nid_vol);
5442         }
5443         snprintf(name, sizeof(name), "%s Playback Switch", pfx);
5444         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, sw_val);
5445         if (err < 0)
5446                 return err;
5447         return 1;
5448 }
5449
5450 /* add playback controls from the parsed DAC table */
5451 static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
5452                                              const struct auto_pin_cfg *cfg)
5453 {
5454         hda_nid_t nid;
5455         int err;
5456         int vols = 0;
5457
5458         spec->multiout.num_dacs = 1;
5459         spec->multiout.dac_nids = spec->private_dac_nids;
5460         spec->multiout.dac_nids[0] = 0x02;
5461
5462         nid = cfg->line_out_pins[0];
5463         if (nid) {
5464                 err = alc260_add_playback_controls(spec, nid, "Front", &vols);
5465                 if (err < 0)
5466                         return err;
5467         }
5468
5469         nid = cfg->speaker_pins[0];
5470         if (nid) {
5471                 err = alc260_add_playback_controls(spec, nid, "Speaker", &vols);
5472                 if (err < 0)
5473                         return err;
5474         }
5475
5476         nid = cfg->hp_pins[0];
5477         if (nid) {
5478                 err = alc260_add_playback_controls(spec, nid, "Headphone",
5479                                                    &vols);
5480                 if (err < 0)
5481                         return err;
5482         }
5483         return 0;
5484 }
5485
5486 /* create playback/capture controls for input pins */
5487 static int alc260_auto_create_analog_input_ctls(struct alc_spec *spec,
5488                                                 const struct auto_pin_cfg *cfg)
5489 {
5490         struct hda_input_mux *imux = &spec->private_imux;
5491         int i, err, idx;
5492
5493         for (i = 0; i < AUTO_PIN_LAST; i++) {
5494                 if (cfg->input_pins[i] >= 0x12) {
5495                         idx = cfg->input_pins[i] - 0x12;
5496                         err = new_analog_input(spec, cfg->input_pins[i],
5497                                                auto_pin_cfg_labels[i], idx,
5498                                                0x07);
5499                         if (err < 0)
5500                                 return err;
5501                         imux->items[imux->num_items].label =
5502                                 auto_pin_cfg_labels[i];
5503                         imux->items[imux->num_items].index = idx;
5504                         imux->num_items++;
5505                 }
5506                 if (cfg->input_pins[i] >= 0x0f && cfg->input_pins[i] <= 0x10){
5507                         idx = cfg->input_pins[i] - 0x09;
5508                         err = new_analog_input(spec, cfg->input_pins[i],
5509                                                auto_pin_cfg_labels[i], idx,
5510                                                0x07);
5511                         if (err < 0)
5512                                 return err;
5513                         imux->items[imux->num_items].label =
5514                                 auto_pin_cfg_labels[i];
5515                         imux->items[imux->num_items].index = idx;
5516                         imux->num_items++;
5517                 }
5518         }
5519         return 0;
5520 }
5521
5522 static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
5523                                               hda_nid_t nid, int pin_type,
5524                                               int sel_idx)
5525 {
5526         alc_set_pin_output(codec, nid, pin_type);
5527         /* need the manual connection? */
5528         if (nid >= 0x12) {
5529                 int idx = nid - 0x12;
5530                 snd_hda_codec_write(codec, idx + 0x0b, 0,
5531                                     AC_VERB_SET_CONNECT_SEL, sel_idx);
5532         }
5533 }
5534
5535 static void alc260_auto_init_multi_out(struct hda_codec *codec)
5536 {
5537         struct alc_spec *spec = codec->spec;
5538         hda_nid_t nid;
5539
5540         alc_subsystem_id(codec, 0x10, 0x15, 0x0f);
5541         nid = spec->autocfg.line_out_pins[0];
5542         if (nid) {
5543                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
5544                 alc260_auto_set_output_and_unmute(codec, nid, pin_type, 0);
5545         }
5546
5547         nid = spec->autocfg.speaker_pins[0];
5548         if (nid)
5549                 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
5550
5551         nid = spec->autocfg.hp_pins[0];
5552         if (nid)
5553                 alc260_auto_set_output_and_unmute(codec, nid, PIN_HP, 0);
5554 }
5555
5556 #define ALC260_PIN_CD_NID               0x16
5557 static void alc260_auto_init_analog_input(struct hda_codec *codec)
5558 {
5559         struct alc_spec *spec = codec->spec;
5560         int i;
5561
5562         for (i = 0; i < AUTO_PIN_LAST; i++) {
5563                 hda_nid_t nid = spec->autocfg.input_pins[i];
5564                 if (nid >= 0x12) {
5565                         snd_hda_codec_write(codec, nid, 0,
5566                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
5567                                             i <= AUTO_PIN_FRONT_MIC ?
5568                                             PIN_VREF80 : PIN_IN);
5569                         if (nid != ALC260_PIN_CD_NID)
5570                                 snd_hda_codec_write(codec, nid, 0,
5571                                                     AC_VERB_SET_AMP_GAIN_MUTE,
5572                                                     AMP_OUT_MUTE);
5573                 }
5574         }
5575 }
5576
5577 /*
5578  * generic initialization of ADC, input mixers and output mixers
5579  */
5580 static struct hda_verb alc260_volume_init_verbs[] = {
5581         /*
5582          * Unmute ADC0-1 and set the default input to mic-in
5583          */
5584         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5585         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5586         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5587         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5588
5589         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5590          * mixer widget
5591          * Note: PASD motherboards uses the Line In 2 as the input for
5592          * front panel mic (mic 2)
5593          */
5594         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
5595         /* mute analog inputs */
5596         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5597         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5598         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5599         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5600         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5601
5602         /*
5603          * Set up output mixers (0x08 - 0x0a)
5604          */
5605         /* set vol=0 to output mixers */
5606         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5607         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5608         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5609         /* set up input amps for analog loopback */
5610         /* Amp Indices: DAC = 0, mixer = 1 */
5611         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5612         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5613         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5614         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5615         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5616         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5617
5618         { }
5619 };
5620
5621 static int alc260_parse_auto_config(struct hda_codec *codec)
5622 {
5623         struct alc_spec *spec = codec->spec;
5624         int err;
5625         static hda_nid_t alc260_ignore[] = { 0x17, 0 };
5626
5627         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
5628                                            alc260_ignore);
5629         if (err < 0)
5630                 return err;
5631         err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg);
5632         if (err < 0)
5633                 return err;
5634         if (!spec->kctls.list)
5635                 return 0; /* can't find valid BIOS pin config */
5636         err = alc260_auto_create_analog_input_ctls(spec, &spec->autocfg);
5637         if (err < 0)
5638                 return err;
5639
5640         spec->multiout.max_channels = 2;
5641
5642         if (spec->autocfg.dig_out_pin)
5643                 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
5644         if (spec->kctls.list)
5645                 add_mixer(spec, spec->kctls.list);
5646
5647         add_verb(spec, alc260_volume_init_verbs);
5648
5649         spec->num_mux_defs = 1;
5650         spec->input_mux = &spec->private_imux;
5651
5652         store_pin_configs(codec);
5653         return 1;
5654 }
5655
5656 /* additional initialization for auto-configuration model */
5657 static void alc260_auto_init(struct hda_codec *codec)
5658 {
5659         struct alc_spec *spec = codec->spec;
5660         alc260_auto_init_multi_out(codec);
5661         alc260_auto_init_analog_input(codec);
5662         if (spec->unsol_event)
5663                 alc_inithook(codec);
5664 }
5665
5666 #ifdef CONFIG_SND_HDA_POWER_SAVE
5667 static struct hda_amp_list alc260_loopbacks[] = {
5668         { 0x07, HDA_INPUT, 0 },
5669         { 0x07, HDA_INPUT, 1 },
5670         { 0x07, HDA_INPUT, 2 },
5671         { 0x07, HDA_INPUT, 3 },
5672         { 0x07, HDA_INPUT, 4 },
5673         { } /* end */
5674 };
5675 #endif
5676
5677 /*
5678  * ALC260 configurations
5679  */
5680 static const char *alc260_models[ALC260_MODEL_LAST] = {
5681         [ALC260_BASIC]          = "basic",
5682         [ALC260_HP]             = "hp",
5683         [ALC260_HP_3013]        = "hp-3013",
5684         [ALC260_HP_DC7600]      = "hp-dc7600",
5685         [ALC260_FUJITSU_S702X]  = "fujitsu",
5686         [ALC260_ACER]           = "acer",
5687         [ALC260_WILL]           = "will",
5688         [ALC260_REPLACER_672V]  = "replacer",
5689 #ifdef CONFIG_SND_DEBUG
5690         [ALC260_TEST]           = "test",
5691 #endif
5692         [ALC260_AUTO]           = "auto",
5693 };
5694
5695 static struct snd_pci_quirk alc260_cfg_tbl[] = {
5696         SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER),
5697         SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
5698         SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
5699         SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_HP_3013),
5700         SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
5701         SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP_3013),
5702         SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_DC7600),
5703         SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
5704         SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
5705         SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP),
5706         SND_PCI_QUIRK(0x103c, 0x3016, "HP", ALC260_HP),
5707         SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_BASIC),
5708         SND_PCI_QUIRK(0x104d, 0x81cc, "Sony VAIO", ALC260_BASIC),
5709         SND_PCI_QUIRK(0x104d, 0x81cd, "Sony VAIO", ALC260_BASIC),
5710         SND_PCI_QUIRK(0x10cf, 0x1326, "Fujitsu S702X", ALC260_FUJITSU_S702X),
5711         SND_PCI_QUIRK(0x152d, 0x0729, "CTL U553W", ALC260_BASIC),
5712         SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_REPLACER_672V),
5713         SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_WILL),
5714         {}
5715 };
5716
5717 static struct alc_config_preset alc260_presets[] = {
5718         [ALC260_BASIC] = {
5719                 .mixers = { alc260_base_output_mixer,
5720                             alc260_input_mixer,
5721                             alc260_pc_beep_mixer },
5722                 .init_verbs = { alc260_init_verbs },
5723                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5724                 .dac_nids = alc260_dac_nids,
5725                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5726                 .adc_nids = alc260_adc_nids,
5727                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5728                 .channel_mode = alc260_modes,
5729                 .input_mux = &alc260_capture_source,
5730         },
5731         [ALC260_HP] = {
5732                 .mixers = { alc260_hp_output_mixer,
5733                             alc260_input_mixer },
5734                 .init_verbs = { alc260_init_verbs,
5735                                 alc260_hp_unsol_verbs },
5736                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5737                 .dac_nids = alc260_dac_nids,
5738                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
5739                 .adc_nids = alc260_adc_nids_alt,
5740                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5741                 .channel_mode = alc260_modes,
5742                 .input_mux = &alc260_capture_source,
5743                 .unsol_event = alc260_hp_unsol_event,
5744                 .init_hook = alc260_hp_automute,
5745         },
5746         [ALC260_HP_DC7600] = {
5747                 .mixers = { alc260_hp_dc7600_mixer,
5748                             alc260_input_mixer },
5749                 .init_verbs = { alc260_init_verbs,
5750                                 alc260_hp_dc7600_verbs },
5751                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5752                 .dac_nids = alc260_dac_nids,
5753                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
5754                 .adc_nids = alc260_adc_nids_alt,
5755                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5756                 .channel_mode = alc260_modes,
5757                 .input_mux = &alc260_capture_source,
5758                 .unsol_event = alc260_hp_3012_unsol_event,
5759                 .init_hook = alc260_hp_3012_automute,
5760         },
5761         [ALC260_HP_3013] = {
5762                 .mixers = { alc260_hp_3013_mixer,
5763                             alc260_input_mixer },
5764                 .init_verbs = { alc260_hp_3013_init_verbs,
5765                                 alc260_hp_3013_unsol_verbs },
5766                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5767                 .dac_nids = alc260_dac_nids,
5768                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
5769                 .adc_nids = alc260_adc_nids_alt,
5770                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5771                 .channel_mode = alc260_modes,
5772                 .input_mux = &alc260_capture_source,
5773                 .unsol_event = alc260_hp_3013_unsol_event,
5774                 .init_hook = alc260_hp_3013_automute,
5775         },
5776         [ALC260_FUJITSU_S702X] = {
5777                 .mixers = { alc260_fujitsu_mixer },
5778                 .init_verbs = { alc260_fujitsu_init_verbs },
5779                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5780                 .dac_nids = alc260_dac_nids,
5781                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5782                 .adc_nids = alc260_dual_adc_nids,
5783                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5784                 .channel_mode = alc260_modes,
5785                 .num_mux_defs = ARRAY_SIZE(alc260_fujitsu_capture_sources),
5786                 .input_mux = alc260_fujitsu_capture_sources,
5787         },
5788         [ALC260_ACER] = {
5789                 .mixers = { alc260_acer_mixer },
5790                 .init_verbs = { alc260_acer_init_verbs },
5791                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5792                 .dac_nids = alc260_dac_nids,
5793                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5794                 .adc_nids = alc260_dual_adc_nids,
5795                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5796                 .channel_mode = alc260_modes,
5797                 .num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources),
5798                 .input_mux = alc260_acer_capture_sources,
5799         },
5800         [ALC260_WILL] = {
5801                 .mixers = { alc260_will_mixer },
5802                 .init_verbs = { alc260_init_verbs, alc260_will_verbs },
5803                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5804                 .dac_nids = alc260_dac_nids,
5805                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5806                 .adc_nids = alc260_adc_nids,
5807                 .dig_out_nid = ALC260_DIGOUT_NID,
5808                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5809                 .channel_mode = alc260_modes,
5810                 .input_mux = &alc260_capture_source,
5811         },
5812         [ALC260_REPLACER_672V] = {
5813                 .mixers = { alc260_replacer_672v_mixer },
5814                 .init_verbs = { alc260_init_verbs, alc260_replacer_672v_verbs },
5815                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5816                 .dac_nids = alc260_dac_nids,
5817                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5818                 .adc_nids = alc260_adc_nids,
5819                 .dig_out_nid = ALC260_DIGOUT_NID,
5820                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5821                 .channel_mode = alc260_modes,
5822                 .input_mux = &alc260_capture_source,
5823                 .unsol_event = alc260_replacer_672v_unsol_event,
5824                 .init_hook = alc260_replacer_672v_automute,
5825         },
5826 #ifdef CONFIG_SND_DEBUG
5827         [ALC260_TEST] = {
5828                 .mixers = { alc260_test_mixer },
5829                 .init_verbs = { alc260_test_init_verbs },
5830                 .num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
5831                 .dac_nids = alc260_test_dac_nids,
5832                 .num_adc_nids = ARRAY_SIZE(alc260_test_adc_nids),
5833                 .adc_nids = alc260_test_adc_nids,
5834                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5835                 .channel_mode = alc260_modes,
5836                 .num_mux_defs = ARRAY_SIZE(alc260_test_capture_sources),
5837                 .input_mux = alc260_test_capture_sources,
5838         },
5839 #endif
5840 };
5841
5842 static int patch_alc260(struct hda_codec *codec)
5843 {
5844         struct alc_spec *spec;
5845         int err, board_config;
5846
5847         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5848         if (spec == NULL)
5849                 return -ENOMEM;
5850
5851         codec->spec = spec;
5852
5853         board_config = snd_hda_check_board_config(codec, ALC260_MODEL_LAST,
5854                                                   alc260_models,
5855                                                   alc260_cfg_tbl);
5856         if (board_config < 0) {
5857                 snd_printd(KERN_INFO "hda_codec: Unknown model for ALC260, "
5858                            "trying auto-probe from BIOS...\n");
5859                 board_config = ALC260_AUTO;
5860         }
5861
5862         if (board_config == ALC260_AUTO) {
5863                 /* automatic parse from the BIOS config */
5864                 err = alc260_parse_auto_config(codec);
5865                 if (err < 0) {
5866                         alc_free(codec);
5867                         return err;
5868                 } else if (!err) {
5869                         printk(KERN_INFO
5870                                "hda_codec: Cannot set up configuration "
5871                                "from BIOS.  Using base mode...\n");
5872                         board_config = ALC260_BASIC;
5873                 }
5874         }
5875
5876         if (board_config != ALC260_AUTO)
5877                 setup_preset(spec, &alc260_presets[board_config]);
5878
5879         spec->stream_name_analog = "ALC260 Analog";
5880         spec->stream_analog_playback = &alc260_pcm_analog_playback;
5881         spec->stream_analog_capture = &alc260_pcm_analog_capture;
5882
5883         spec->stream_name_digital = "ALC260 Digital";
5884         spec->stream_digital_playback = &alc260_pcm_digital_playback;
5885         spec->stream_digital_capture = &alc260_pcm_digital_capture;
5886
5887         if (!spec->adc_nids && spec->input_mux) {
5888                 /* check whether NID 0x04 is valid */
5889                 unsigned int wcap = get_wcaps(codec, 0x04);
5890                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
5891                 /* get type */
5892                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
5893                         spec->adc_nids = alc260_adc_nids_alt;
5894                         spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
5895                 } else {
5896                         spec->adc_nids = alc260_adc_nids;
5897                         spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
5898                 }
5899         }
5900         set_capture_mixer(spec);
5901
5902         spec->vmaster_nid = 0x08;
5903
5904         codec->patch_ops = alc_patch_ops;
5905         if (board_config == ALC260_AUTO)
5906                 spec->init_hook = alc260_auto_init;
5907 #ifdef CONFIG_SND_HDA_POWER_SAVE
5908         if (!spec->loopback.amplist)
5909                 spec->loopback.amplist = alc260_loopbacks;
5910 #endif
5911         codec->proc_widget_hook = print_realtek_coef;
5912
5913         return 0;
5914 }
5915
5916
5917 /*
5918  * ALC882 support
5919  *
5920  * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5921  * configuration.  Each pin widget can choose any input DACs and a mixer.
5922  * Each ADC is connected from a mixer of all inputs.  This makes possible
5923  * 6-channel independent captures.
5924  *
5925  * In addition, an independent DAC for the multi-playback (not used in this
5926  * driver yet).
5927  */
5928 #define ALC882_DIGOUT_NID       0x06
5929 #define ALC882_DIGIN_NID        0x0a
5930
5931 static struct hda_channel_mode alc882_ch_modes[1] = {
5932         { 8, NULL }
5933 };
5934
5935 static hda_nid_t alc882_dac_nids[4] = {
5936         /* front, rear, clfe, rear_surr */
5937         0x02, 0x03, 0x04, 0x05
5938 };
5939
5940 /* identical with ALC880 */
5941 #define alc882_adc_nids         alc880_adc_nids
5942 #define alc882_adc_nids_alt     alc880_adc_nids_alt
5943
5944 static hda_nid_t alc882_capsrc_nids[3] = { 0x24, 0x23, 0x22 };
5945 static hda_nid_t alc882_capsrc_nids_alt[2] = { 0x23, 0x22 };
5946
5947 /* input MUX */
5948 /* FIXME: should be a matrix-type input source selection */
5949
5950 static struct hda_input_mux alc882_capture_source = {
5951         .num_items = 4,
5952         .items = {
5953                 { "Mic", 0x0 },
5954                 { "Front Mic", 0x1 },
5955                 { "Line", 0x2 },
5956                 { "CD", 0x4 },
5957         },
5958 };
5959 /*
5960  * 2ch mode
5961  */
5962 static struct hda_verb alc882_3ST_ch2_init[] = {
5963         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
5964         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5965         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
5966         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
5967         { } /* end */
5968 };
5969
5970 /*
5971  * 6ch mode
5972  */
5973 static struct hda_verb alc882_3ST_ch6_init[] = {
5974         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5975         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5976         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
5977         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5978         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
5979         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
5980         { } /* end */
5981 };
5982
5983 static struct hda_channel_mode alc882_3ST_6ch_modes[2] = {
5984         { 2, alc882_3ST_ch2_init },
5985         { 6, alc882_3ST_ch6_init },
5986 };
5987
5988 /*
5989  * 6ch mode
5990  */
5991 static struct hda_verb alc882_sixstack_ch6_init[] = {
5992         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
5993         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5994         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5995         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
5996         { } /* end */
5997 };
5998
5999 /*
6000  * 8ch mode
6001  */
6002 static struct hda_verb alc882_sixstack_ch8_init[] = {
6003         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6004         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6005         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6006         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6007         { } /* end */
6008 };
6009
6010 static struct hda_channel_mode alc882_sixstack_modes[2] = {
6011         { 6, alc882_sixstack_ch6_init },
6012         { 8, alc882_sixstack_ch8_init },
6013 };
6014
6015 /*
6016  * macbook pro ALC885 can switch LineIn to LineOut without loosing Mic
6017  */
6018
6019 /*
6020  * 2ch mode
6021  */
6022 static struct hda_verb alc885_mbp_ch2_init[] = {
6023         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6024         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6025         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6026         { } /* end */
6027 };
6028
6029 /*
6030  * 6ch mode
6031  */
6032 static struct hda_verb alc885_mbp_ch6_init[] = {
6033         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6034         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6035         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6036         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6037         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6038         { } /* end */
6039 };
6040
6041 static struct hda_channel_mode alc885_mbp_6ch_modes[2] = {
6042         { 2, alc885_mbp_ch2_init },
6043         { 6, alc885_mbp_ch6_init },
6044 };
6045
6046
6047 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
6048  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
6049  */
6050 static struct snd_kcontrol_new alc882_base_mixer[] = {
6051         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6052         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6053         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6054         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6055         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6056         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6057         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6058         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6059         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
6060         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
6061         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6062         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6063         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6064         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6065         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6066         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6067         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6068         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6069         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6070         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6071         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6072         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6073         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6074         { } /* end */
6075 };
6076
6077 static struct snd_kcontrol_new alc885_mbp3_mixer[] = {
6078         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
6079         HDA_BIND_MUTE   ("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
6080         HDA_CODEC_MUTE  ("Speaker Playback Switch", 0x14, 0x00, HDA_OUTPUT),
6081         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
6082         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6083         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6084         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
6085         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
6086         HDA_CODEC_VOLUME("Line Boost", 0x1a, 0x00, HDA_INPUT),
6087         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
6088         { } /* end */
6089 };
6090 static struct snd_kcontrol_new alc882_w2jc_mixer[] = {
6091         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6092         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6093         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6094         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6095         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6096         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6097         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6098         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6099         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6100         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6101         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6102         { } /* end */
6103 };
6104
6105 static struct snd_kcontrol_new alc882_targa_mixer[] = {
6106         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6107         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6108         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6109         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6110         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6111         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6112         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6113         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6114         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6115         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6116         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6117         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6118         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6119         { } /* end */
6120 };
6121
6122 /* Pin assignment: Front=0x14, HP = 0x15, Front = 0x16, ???
6123  *                 Front Mic=0x18, Line In = 0x1a, Line In = 0x1b, CD = 0x1c
6124  */
6125 static struct snd_kcontrol_new alc882_asus_a7j_mixer[] = {
6126         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6127         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6128         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6129         HDA_CODEC_MUTE("Mobile Front Playback Switch", 0x16, 0x0, HDA_OUTPUT),
6130         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6131         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6132         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6133         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6134         HDA_CODEC_VOLUME("Mobile Line Playback Volume", 0x0b, 0x03, HDA_INPUT),
6135         HDA_CODEC_MUTE("Mobile Line Playback Switch", 0x0b, 0x03, HDA_INPUT),
6136         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6137         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6138         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6139         { } /* end */
6140 };
6141
6142 static struct snd_kcontrol_new alc882_asus_a7m_mixer[] = {
6143         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6144         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6145         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6146         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6147         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6148         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6149         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6150         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6151         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6152         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6153         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6154         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6155         { } /* end */
6156 };
6157
6158 static struct snd_kcontrol_new alc882_chmode_mixer[] = {
6159         {
6160                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6161                 .name = "Channel Mode",
6162                 .info = alc_ch_mode_info,
6163                 .get = alc_ch_mode_get,
6164                 .put = alc_ch_mode_put,
6165         },
6166         { } /* end */
6167 };
6168
6169 static struct hda_verb alc882_init_verbs[] = {
6170         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6171         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6172         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6173         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6174         /* Rear mixer */
6175         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6176         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6177         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6178         /* CLFE mixer */
6179         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6180         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6181         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6182         /* Side mixer */
6183         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6184         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6185         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6186
6187         /* Front Pin: output 0 (0x0c) */
6188         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6189         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6190         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6191         /* Rear Pin: output 1 (0x0d) */
6192         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6193         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6194         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
6195         /* CLFE Pin: output 2 (0x0e) */
6196         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6197         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6198         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
6199         /* Side Pin: output 3 (0x0f) */
6200         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6201         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6202         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
6203         /* Mic (rear) pin: input vref at 80% */
6204         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6205         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6206         /* Front Mic pin: input vref at 80% */
6207         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6208         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6209         /* Line In pin: input */
6210         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6211         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6212         /* Line-2 In: Headphone output (output 0 - 0x0c) */
6213         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6214         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6215         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
6216         /* CD pin widget for input */
6217         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6218
6219         /* FIXME: use matrix-type input source selection */
6220         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6221         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6222         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6223         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6224         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6225         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6226         /* Input mixer2 */
6227         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6228         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6229         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6230         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6231         /* Input mixer3 */
6232         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6233         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6234         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6235         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6236         /* ADC1: mute amp left and right */
6237         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6238         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6239         /* ADC2: mute amp left and right */
6240         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6241         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6242         /* ADC3: mute amp left and right */
6243         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6244         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6245
6246         { }
6247 };
6248
6249 static struct hda_verb alc882_eapd_verbs[] = {
6250         /* change to EAPD mode */
6251         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
6252         {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
6253         { }
6254 };
6255
6256 /* Mac Pro test */
6257 static struct snd_kcontrol_new alc882_macpro_mixer[] = {
6258         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6259         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6260         HDA_CODEC_MUTE("Headphone Playback Switch", 0x18, 0x0, HDA_OUTPUT),
6261         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
6262         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
6263         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x02, HDA_INPUT),
6264         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x02, HDA_INPUT),
6265         { } /* end */
6266 };
6267
6268 static struct hda_verb alc882_macpro_init_verbs[] = {
6269         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6270         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6271         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6272         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6273         /* Front Pin: output 0 (0x0c) */
6274         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6275         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6276         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6277         /* Front Mic pin: input vref at 80% */
6278         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6279         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6280         /* Speaker:  output */
6281         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6282         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6283         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x04},
6284         /* Headphone output (output 0 - 0x0c) */
6285         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6286         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6287         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
6288
6289         /* FIXME: use matrix-type input source selection */
6290         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6291         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6292         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6293         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6294         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6295         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6296         /* Input mixer2 */
6297         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6298         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6299         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6300         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6301         /* Input mixer3 */
6302         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6303         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6304         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6305         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6306         /* ADC1: mute amp left and right */
6307         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6308         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6309         /* ADC2: mute amp left and right */
6310         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6311         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6312         /* ADC3: mute amp left and right */
6313         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6314         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6315
6316         { }
6317 };
6318
6319 /* Macbook Pro rev3 */
6320 static struct hda_verb alc885_mbp3_init_verbs[] = {
6321         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6322         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6323         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6324         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6325         /* Rear mixer */
6326         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6327         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6328         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6329         /* Front Pin: output 0 (0x0c) */
6330         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6331         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6332         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6333         /* HP Pin: output 0 (0x0d) */
6334         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},
6335         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6336         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6337         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6338         /* Mic (rear) pin: input vref at 80% */
6339         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6340         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6341         /* Front Mic pin: input vref at 80% */
6342         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6343         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6344         /* Line In pin: use output 1 when in LineOut mode */
6345         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6346         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6347         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
6348
6349         /* FIXME: use matrix-type input source selection */
6350         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6351         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6352         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6353         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6354         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6355         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6356         /* Input mixer2 */
6357         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6358         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6359         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6360         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6361         /* Input mixer3 */
6362         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6363         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6364         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6365         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6366         /* ADC1: mute amp left and right */
6367         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6368         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6369         /* ADC2: mute amp left and right */
6370         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6371         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6372         /* ADC3: mute amp left and right */
6373         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6374         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6375
6376         { }
6377 };
6378
6379 /* iMac 24 mixer. */
6380 static struct snd_kcontrol_new alc885_imac24_mixer[] = {
6381         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
6382         HDA_CODEC_MUTE("Master Playback Switch", 0x0c, 0x00, HDA_INPUT),
6383         { } /* end */
6384 };
6385
6386 /* iMac 24 init verbs. */
6387 static struct hda_verb alc885_imac24_init_verbs[] = {
6388         /* Internal speakers: output 0 (0x0c) */
6389         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6390         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6391         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
6392         /* Internal speakers: output 0 (0x0c) */
6393         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6394         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6395         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
6396         /* Headphone: output 0 (0x0c) */
6397         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6398         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6399         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6400         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6401         /* Front Mic: input vref at 80% */
6402         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6403         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6404         { }
6405 };
6406
6407 /* Toggle speaker-output according to the hp-jack state */
6408 static void alc885_imac24_automute(struct hda_codec *codec)
6409 {
6410         unsigned int present;
6411
6412         present = snd_hda_codec_read(codec, 0x14, 0,
6413                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6414         snd_hda_codec_amp_stereo(codec, 0x18, HDA_OUTPUT, 0,
6415                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6416         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
6417                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6418 }
6419
6420 /* Processes unsolicited events. */
6421 static void alc885_imac24_unsol_event(struct hda_codec *codec,
6422                                       unsigned int res)
6423 {
6424         /* Headphone insertion or removal. */
6425         if ((res >> 26) == ALC880_HP_EVENT)
6426                 alc885_imac24_automute(codec);
6427 }
6428
6429 static void alc885_mbp3_automute(struct hda_codec *codec)
6430 {
6431         unsigned int present;
6432
6433         present = snd_hda_codec_read(codec, 0x15, 0,
6434                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6435         snd_hda_codec_amp_stereo(codec, 0x14,  HDA_OUTPUT, 0,
6436                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6437         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
6438                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
6439
6440 }
6441 static void alc885_mbp3_unsol_event(struct hda_codec *codec,
6442                                     unsigned int res)
6443 {
6444         /* Headphone insertion or removal. */
6445         if ((res >> 26) == ALC880_HP_EVENT)
6446                 alc885_mbp3_automute(codec);
6447 }
6448
6449
6450 static struct hda_verb alc882_targa_verbs[] = {
6451         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6452         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6453
6454         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6455         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6456
6457         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6458         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6459         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6460
6461         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6462         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6463         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
6464         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
6465         { } /* end */
6466 };
6467
6468 /* toggle speaker-output according to the hp-jack state */
6469 static void alc882_targa_automute(struct hda_codec *codec)
6470 {
6471         unsigned int present;
6472
6473         present = snd_hda_codec_read(codec, 0x14, 0,
6474                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6475         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
6476                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6477         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
6478                                   present ? 1 : 3);
6479 }
6480
6481 static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res)
6482 {
6483         /* Looks like the unsol event is incompatible with the standard
6484          * definition.  4bit tag is placed at 26 bit!
6485          */
6486         if (((res >> 26) == ALC880_HP_EVENT)) {
6487                 alc882_targa_automute(codec);
6488         }
6489 }
6490
6491 static struct hda_verb alc882_asus_a7j_verbs[] = {
6492         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6493         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6494
6495         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6496         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6497         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6498
6499         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6500         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6501         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6502
6503         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6504         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6505         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6506         { } /* end */
6507 };
6508
6509 static struct hda_verb alc882_asus_a7m_verbs[] = {
6510         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6511         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6512
6513         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6514         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6515         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6516
6517         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6518         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6519         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6520
6521         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6522         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6523         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6524         { } /* end */
6525 };
6526
6527 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
6528 {
6529         unsigned int gpiostate, gpiomask, gpiodir;
6530
6531         gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
6532                                        AC_VERB_GET_GPIO_DATA, 0);
6533
6534         if (!muted)
6535                 gpiostate |= (1 << pin);
6536         else
6537                 gpiostate &= ~(1 << pin);
6538
6539         gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
6540                                       AC_VERB_GET_GPIO_MASK, 0);
6541         gpiomask |= (1 << pin);
6542
6543         gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
6544                                      AC_VERB_GET_GPIO_DIRECTION, 0);
6545         gpiodir |= (1 << pin);
6546
6547
6548         snd_hda_codec_write(codec, codec->afg, 0,
6549                             AC_VERB_SET_GPIO_MASK, gpiomask);
6550         snd_hda_codec_write(codec, codec->afg, 0,
6551                             AC_VERB_SET_GPIO_DIRECTION, gpiodir);
6552
6553         msleep(1);
6554
6555         snd_hda_codec_write(codec, codec->afg, 0,
6556                             AC_VERB_SET_GPIO_DATA, gpiostate);
6557 }
6558
6559 /* set up GPIO at initialization */
6560 static void alc885_macpro_init_hook(struct hda_codec *codec)
6561 {
6562         alc882_gpio_mute(codec, 0, 0);
6563         alc882_gpio_mute(codec, 1, 0);
6564 }
6565
6566 /* set up GPIO and update auto-muting at initialization */
6567 static void alc885_imac24_init_hook(struct hda_codec *codec)
6568 {
6569         alc885_macpro_init_hook(codec);
6570         alc885_imac24_automute(codec);
6571 }
6572
6573 /*
6574  * generic initialization of ADC, input mixers and output mixers
6575  */
6576 static struct hda_verb alc882_auto_init_verbs[] = {
6577         /*
6578          * Unmute ADC0-2 and set the default input to mic-in
6579          */
6580         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6581         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6582         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6583         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6584         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6585         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6586
6587         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
6588          * mixer widget
6589          * Note: PASD motherboards uses the Line In 2 as the input for
6590          * front panel mic (mic 2)
6591          */
6592         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
6593         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6594         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6595         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6596         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6597         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6598
6599         /*
6600          * Set up output mixers (0x0c - 0x0f)
6601          */
6602         /* set vol=0 to output mixers */
6603         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6604         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6605         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6606         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6607         /* set up input amps for analog loopback */
6608         /* Amp Indices: DAC = 0, mixer = 1 */
6609         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6610         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6611         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6612         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6613         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6614         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6615         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6616         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6617         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6618         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6619
6620         /* FIXME: use matrix-type input source selection */
6621         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6622         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6623         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6624         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6625         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6626         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6627         /* Input mixer2 */
6628         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6629         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6630         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6631         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6632         /* Input mixer3 */
6633         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6634         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6635         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6636         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6637
6638         { }
6639 };
6640
6641 #ifdef CONFIG_SND_HDA_POWER_SAVE
6642 #define alc882_loopbacks        alc880_loopbacks
6643 #endif
6644
6645 /* pcm configuration: identiacal with ALC880 */
6646 #define alc882_pcm_analog_playback      alc880_pcm_analog_playback
6647 #define alc882_pcm_analog_capture       alc880_pcm_analog_capture
6648 #define alc882_pcm_digital_playback     alc880_pcm_digital_playback
6649 #define alc882_pcm_digital_capture      alc880_pcm_digital_capture
6650
6651 /*
6652  * configuration and preset
6653  */
6654 static const char *alc882_models[ALC882_MODEL_LAST] = {
6655         [ALC882_3ST_DIG]        = "3stack-dig",
6656         [ALC882_6ST_DIG]        = "6stack-dig",
6657         [ALC882_ARIMA]          = "arima",
6658         [ALC882_W2JC]           = "w2jc",
6659         [ALC882_TARGA]          = "targa",
6660         [ALC882_ASUS_A7J]       = "asus-a7j",
6661         [ALC882_ASUS_A7M]       = "asus-a7m",
6662         [ALC885_MACPRO]         = "macpro",
6663         [ALC885_MBP3]           = "mbp3",
6664         [ALC885_IMAC24]         = "imac24",
6665         [ALC882_AUTO]           = "auto",
6666 };
6667
6668 static struct snd_pci_quirk alc882_cfg_tbl[] = {
6669         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),
6670         SND_PCI_QUIRK(0x1043, 0x060d, "Asus A7J", ALC882_ASUS_A7J),
6671         SND_PCI_QUIRK(0x1043, 0x1243, "Asus A7J", ALC882_ASUS_A7J),
6672         SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_ASUS_A7M),
6673         SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_W2JC),
6674         SND_PCI_QUIRK(0x1043, 0x817f, "Asus P5LD2", ALC882_6ST_DIG),
6675         SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
6676         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
6677         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte P35 DS3R", ALC882_6ST_DIG),
6678         SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8  */
6679         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
6680         SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA),
6681         {}
6682 };
6683
6684 static struct alc_config_preset alc882_presets[] = {
6685         [ALC882_3ST_DIG] = {
6686                 .mixers = { alc882_base_mixer },
6687                 .init_verbs = { alc882_init_verbs },
6688                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6689                 .dac_nids = alc882_dac_nids,
6690                 .dig_out_nid = ALC882_DIGOUT_NID,
6691                 .dig_in_nid = ALC882_DIGIN_NID,
6692                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6693                 .channel_mode = alc882_ch_modes,
6694                 .need_dac_fix = 1,
6695                 .input_mux = &alc882_capture_source,
6696         },
6697         [ALC882_6ST_DIG] = {
6698                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
6699                 .init_verbs = { alc882_init_verbs },
6700                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6701                 .dac_nids = alc882_dac_nids,
6702                 .dig_out_nid = ALC882_DIGOUT_NID,
6703                 .dig_in_nid = ALC882_DIGIN_NID,
6704                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
6705                 .channel_mode = alc882_sixstack_modes,
6706                 .input_mux = &alc882_capture_source,
6707         },
6708         [ALC882_ARIMA] = {
6709                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
6710                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs },
6711                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6712                 .dac_nids = alc882_dac_nids,
6713                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
6714                 .channel_mode = alc882_sixstack_modes,
6715                 .input_mux = &alc882_capture_source,
6716         },
6717         [ALC882_W2JC] = {
6718                 .mixers = { alc882_w2jc_mixer, alc882_chmode_mixer },
6719                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
6720                                 alc880_gpio1_init_verbs },
6721                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6722                 .dac_nids = alc882_dac_nids,
6723                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
6724                 .channel_mode = alc880_threestack_modes,
6725                 .need_dac_fix = 1,
6726                 .input_mux = &alc882_capture_source,
6727                 .dig_out_nid = ALC882_DIGOUT_NID,
6728         },
6729         [ALC885_MBP3] = {
6730                 .mixers = { alc885_mbp3_mixer, alc882_chmode_mixer },
6731                 .init_verbs = { alc885_mbp3_init_verbs,
6732                                 alc880_gpio1_init_verbs },
6733                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6734                 .dac_nids = alc882_dac_nids,
6735                 .channel_mode = alc885_mbp_6ch_modes,
6736                 .num_channel_mode = ARRAY_SIZE(alc885_mbp_6ch_modes),
6737                 .input_mux = &alc882_capture_source,
6738                 .dig_out_nid = ALC882_DIGOUT_NID,
6739                 .dig_in_nid = ALC882_DIGIN_NID,
6740                 .unsol_event = alc885_mbp3_unsol_event,
6741                 .init_hook = alc885_mbp3_automute,
6742         },
6743         [ALC885_MACPRO] = {
6744                 .mixers = { alc882_macpro_mixer },
6745                 .init_verbs = { alc882_macpro_init_verbs },
6746                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6747                 .dac_nids = alc882_dac_nids,
6748                 .dig_out_nid = ALC882_DIGOUT_NID,
6749                 .dig_in_nid = ALC882_DIGIN_NID,
6750                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6751                 .channel_mode = alc882_ch_modes,
6752                 .input_mux = &alc882_capture_source,
6753                 .init_hook = alc885_macpro_init_hook,
6754         },
6755         [ALC885_IMAC24] = {
6756                 .mixers = { alc885_imac24_mixer },
6757                 .init_verbs = { alc885_imac24_init_verbs },
6758                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6759                 .dac_nids = alc882_dac_nids,
6760                 .dig_out_nid = ALC882_DIGOUT_NID,
6761                 .dig_in_nid = ALC882_DIGIN_NID,
6762                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6763                 .channel_mode = alc882_ch_modes,
6764                 .input_mux = &alc882_capture_source,
6765                 .unsol_event = alc885_imac24_unsol_event,
6766                 .init_hook = alc885_imac24_init_hook,
6767         },
6768         [ALC882_TARGA] = {
6769                 .mixers = { alc882_targa_mixer, alc882_chmode_mixer },
6770                 .init_verbs = { alc882_init_verbs, alc882_targa_verbs},
6771                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6772                 .dac_nids = alc882_dac_nids,
6773                 .dig_out_nid = ALC882_DIGOUT_NID,
6774                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6775                 .adc_nids = alc882_adc_nids,
6776                 .capsrc_nids = alc882_capsrc_nids,
6777                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6778                 .channel_mode = alc882_3ST_6ch_modes,
6779                 .need_dac_fix = 1,
6780                 .input_mux = &alc882_capture_source,
6781                 .unsol_event = alc882_targa_unsol_event,
6782                 .init_hook = alc882_targa_automute,
6783         },
6784         [ALC882_ASUS_A7J] = {
6785                 .mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer },
6786                 .init_verbs = { alc882_init_verbs, alc882_asus_a7j_verbs},
6787                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6788                 .dac_nids = alc882_dac_nids,
6789                 .dig_out_nid = ALC882_DIGOUT_NID,
6790                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6791                 .adc_nids = alc882_adc_nids,
6792                 .capsrc_nids = alc882_capsrc_nids,
6793                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6794                 .channel_mode = alc882_3ST_6ch_modes,
6795                 .need_dac_fix = 1,
6796                 .input_mux = &alc882_capture_source,
6797         },
6798         [ALC882_ASUS_A7M] = {
6799                 .mixers = { alc882_asus_a7m_mixer, alc882_chmode_mixer },
6800                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
6801                                 alc880_gpio1_init_verbs,
6802                                 alc882_asus_a7m_verbs },
6803                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6804                 .dac_nids = alc882_dac_nids,
6805                 .dig_out_nid = ALC882_DIGOUT_NID,
6806                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
6807                 .channel_mode = alc880_threestack_modes,
6808                 .need_dac_fix = 1,
6809                 .input_mux = &alc882_capture_source,
6810         },
6811 };
6812
6813
6814 /*
6815  * Pin config fixes
6816  */
6817 enum {
6818         PINFIX_ABIT_AW9D_MAX
6819 };
6820
6821 static struct alc_pincfg alc882_abit_aw9d_pinfix[] = {
6822         { 0x15, 0x01080104 }, /* side */
6823         { 0x16, 0x01011012 }, /* rear */
6824         { 0x17, 0x01016011 }, /* clfe */
6825         { }
6826 };
6827
6828 static const struct alc_pincfg *alc882_pin_fixes[] = {
6829         [PINFIX_ABIT_AW9D_MAX] = alc882_abit_aw9d_pinfix,
6830 };
6831
6832 static struct snd_pci_quirk alc882_pinfix_tbl[] = {
6833         SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
6834         {}
6835 };
6836
6837 /*
6838  * BIOS auto configuration
6839  */
6840 static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
6841                                               hda_nid_t nid, int pin_type,
6842                                               int dac_idx)
6843 {
6844         /* set as output */
6845         struct alc_spec *spec = codec->spec;
6846         int idx;
6847
6848         alc_set_pin_output(codec, nid, pin_type);
6849         if (spec->multiout.dac_nids[dac_idx] == 0x25)
6850                 idx = 4;
6851         else
6852                 idx = spec->multiout.dac_nids[dac_idx] - 2;
6853         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
6854
6855 }
6856
6857 static void alc882_auto_init_multi_out(struct hda_codec *codec)
6858 {
6859         struct alc_spec *spec = codec->spec;
6860         int i;
6861
6862         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
6863         for (i = 0; i <= HDA_SIDE; i++) {
6864                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
6865                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
6866                 if (nid)
6867                         alc882_auto_set_output_and_unmute(codec, nid, pin_type,
6868                                                           i);
6869         }
6870 }
6871
6872 static void alc882_auto_init_hp_out(struct hda_codec *codec)
6873 {
6874         struct alc_spec *spec = codec->spec;
6875         hda_nid_t pin;
6876
6877         pin = spec->autocfg.hp_pins[0];
6878         if (pin) /* connect to front */
6879                 /* use dac 0 */
6880                 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
6881         pin = spec->autocfg.speaker_pins[0];
6882         if (pin)
6883                 alc882_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
6884 }
6885
6886 #define alc882_is_input_pin(nid)        alc880_is_input_pin(nid)
6887 #define ALC882_PIN_CD_NID               ALC880_PIN_CD_NID
6888
6889 static void alc882_auto_init_analog_input(struct hda_codec *codec)
6890 {
6891         struct alc_spec *spec = codec->spec;
6892         int i;
6893
6894         for (i = 0; i < AUTO_PIN_LAST; i++) {
6895                 hda_nid_t nid = spec->autocfg.input_pins[i];
6896                 unsigned int vref;
6897                 if (!nid)
6898                         continue;
6899                 vref = PIN_IN;
6900                 if (1 /*i <= AUTO_PIN_FRONT_MIC*/) {
6901                         unsigned int pincap;
6902                         pincap = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
6903                         if ((pincap >> AC_PINCAP_VREF_SHIFT) &
6904                             AC_PINCAP_VREF_80)
6905                                 vref = PIN_VREF80;
6906                 }
6907                 snd_hda_codec_write(codec, nid, 0,
6908                                     AC_VERB_SET_PIN_WIDGET_CONTROL, vref);
6909                 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
6910                         snd_hda_codec_write(codec, nid, 0,
6911                                             AC_VERB_SET_AMP_GAIN_MUTE,
6912                                             AMP_OUT_MUTE);
6913         }
6914 }
6915
6916 static void alc882_auto_init_input_src(struct hda_codec *codec)
6917 {
6918         struct alc_spec *spec = codec->spec;
6919         const struct hda_input_mux *imux = spec->input_mux;
6920         int c;
6921
6922         for (c = 0; c < spec->num_adc_nids; c++) {
6923                 hda_nid_t conn_list[HDA_MAX_NUM_INPUTS];
6924                 hda_nid_t nid = spec->capsrc_nids[c];
6925                 int conns, mute, idx, item;
6926
6927                 conns = snd_hda_get_connections(codec, nid, conn_list,
6928                                                 ARRAY_SIZE(conn_list));
6929                 if (conns < 0)
6930                         continue;
6931                 for (idx = 0; idx < conns; idx++) {
6932                         /* if the current connection is the selected one,
6933                          * unmute it as default - otherwise mute it
6934                          */
6935                         mute = AMP_IN_MUTE(idx);
6936                         for (item = 0; item < imux->num_items; item++) {
6937                                 if (imux->items[item].index == idx) {
6938                                         if (spec->cur_mux[c] == item)
6939                                                 mute = AMP_IN_UNMUTE(idx);
6940                                         break;
6941                                 }
6942                         }
6943                         snd_hda_codec_write(codec, nid, 0,
6944                                             AC_VERB_SET_AMP_GAIN_MUTE, mute);
6945                 }
6946         }
6947 }
6948
6949 /* add mic boosts if needed */
6950 static int alc_auto_add_mic_boost(struct hda_codec *codec)
6951 {
6952         struct alc_spec *spec = codec->spec;
6953         int err;
6954         hda_nid_t nid;
6955
6956         nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
6957         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
6958                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6959                                   "Mic Boost",
6960                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6961                 if (err < 0)
6962                         return err;
6963         }
6964         nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
6965         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
6966                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
6967                                   "Front Mic Boost",
6968                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
6969                 if (err < 0)
6970                         return err;
6971         }
6972         return 0;
6973 }
6974
6975 /* almost identical with ALC880 parser... */
6976 static int alc882_parse_auto_config(struct hda_codec *codec)
6977 {
6978         struct alc_spec *spec = codec->spec;
6979         int err = alc880_parse_auto_config(codec);
6980
6981         if (err < 0)
6982                 return err;
6983         else if (!err)
6984                 return 0; /* no config found */
6985
6986         err = alc_auto_add_mic_boost(codec);
6987         if (err < 0)
6988                 return err;
6989
6990         /* hack - override the init verbs */
6991         spec->init_verbs[0] = alc882_auto_init_verbs;
6992
6993         return 1; /* config found */
6994 }
6995
6996 /* additional initialization for auto-configuration model */
6997 static void alc882_auto_init(struct hda_codec *codec)
6998 {
6999         struct alc_spec *spec = codec->spec;
7000         alc882_auto_init_multi_out(codec);
7001         alc882_auto_init_hp_out(codec);
7002         alc882_auto_init_analog_input(codec);
7003         alc882_auto_init_input_src(codec);
7004         if (spec->unsol_event)
7005                 alc_inithook(codec);
7006 }
7007
7008 static int patch_alc883(struct hda_codec *codec); /* called in patch_alc882() */
7009
7010 static int patch_alc882(struct hda_codec *codec)
7011 {
7012         struct alc_spec *spec;
7013         int err, board_config;
7014
7015         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
7016         if (spec == NULL)
7017                 return -ENOMEM;
7018
7019         codec->spec = spec;
7020
7021         board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
7022                                                   alc882_models,
7023                                                   alc882_cfg_tbl);
7024
7025         if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
7026                 /* Pick up systems that don't supply PCI SSID */
7027                 switch (codec->subsystem_id) {
7028                 case 0x106b0c00: /* Mac Pro */
7029                         board_config = ALC885_MACPRO;
7030                         break;
7031                 case 0x106b1000: /* iMac 24 */
7032                 case 0x106b2800: /* AppleTV */
7033                         board_config = ALC885_IMAC24;
7034                         break;
7035                 case 0x106b00a1: /* Macbook (might be wrong - PCI SSID?) */
7036                 case 0x106b00a4: /* MacbookPro4,1 */
7037                 case 0x106b2c00: /* Macbook Pro rev3 */
7038                 case 0x106b3600: /* Macbook 3.1 */
7039                         board_config = ALC885_MBP3;
7040                         break;
7041                 default:
7042                         /* ALC889A is handled better as ALC888-compatible */
7043                         if (codec->revision_id == 0x100101 ||
7044                             codec->revision_id == 0x100103) {
7045                                 alc_free(codec);
7046                                 return patch_alc883(codec);
7047                         }
7048                         printk(KERN_INFO "hda_codec: Unknown model for ALC882, "
7049                                          "trying auto-probe from BIOS...\n");
7050                         board_config = ALC882_AUTO;
7051                 }
7052         }
7053
7054         alc_fix_pincfg(codec, alc882_pinfix_tbl, alc882_pin_fixes);
7055
7056         if (board_config == ALC882_AUTO) {
7057                 /* automatic parse from the BIOS config */
7058                 err = alc882_parse_auto_config(codec);
7059                 if (err < 0) {
7060                         alc_free(codec);
7061                         return err;
7062                 } else if (!err) {
7063                         printk(KERN_INFO
7064                                "hda_codec: Cannot set up configuration "
7065                                "from BIOS.  Using base mode...\n");
7066                         board_config = ALC882_3ST_DIG;
7067                 }
7068         }
7069
7070         if (board_config != ALC882_AUTO)
7071                 setup_preset(spec, &alc882_presets[board_config]);
7072
7073         if (codec->vendor_id == 0x10ec0885) {
7074                 spec->stream_name_analog = "ALC885 Analog";
7075                 spec->stream_name_digital = "ALC885 Digital";
7076         } else {
7077                 spec->stream_name_analog = "ALC882 Analog";
7078                 spec->stream_name_digital = "ALC882 Digital";
7079         }
7080
7081         spec->stream_analog_playback = &alc882_pcm_analog_playback;
7082         spec->stream_analog_capture = &alc882_pcm_analog_capture;
7083         /* FIXME: setup DAC5 */
7084         /*spec->stream_analog_alt_playback = &alc880_pcm_analog_alt_playback;*/
7085         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
7086
7087         spec->stream_digital_playback = &alc882_pcm_digital_playback;
7088         spec->stream_digital_capture = &alc882_pcm_digital_capture;
7089
7090         spec->is_mix_capture = 1; /* matrix-style capture */
7091         if (!spec->adc_nids && spec->input_mux) {
7092                 /* check whether NID 0x07 is valid */
7093                 unsigned int wcap = get_wcaps(codec, 0x07);
7094                 /* get type */
7095                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
7096                 if (wcap != AC_WID_AUD_IN) {
7097                         spec->adc_nids = alc882_adc_nids_alt;
7098                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt);
7099                         spec->capsrc_nids = alc882_capsrc_nids_alt;
7100                 } else {
7101                         spec->adc_nids = alc882_adc_nids;
7102                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
7103                         spec->capsrc_nids = alc882_capsrc_nids;
7104                 }
7105         }
7106         set_capture_mixer(spec);
7107
7108         spec->vmaster_nid = 0x0c;
7109
7110         codec->patch_ops = alc_patch_ops;
7111         if (board_config == ALC882_AUTO)
7112                 spec->init_hook = alc882_auto_init;
7113 #ifdef CONFIG_SND_HDA_POWER_SAVE
7114         if (!spec->loopback.amplist)
7115                 spec->loopback.amplist = alc882_loopbacks;
7116 #endif
7117         codec->proc_widget_hook = print_realtek_coef;
7118
7119         return 0;
7120 }
7121
7122 /*
7123  * ALC883 support
7124  *
7125  * ALC883 is almost identical with ALC880 but has cleaner and more flexible
7126  * configuration.  Each pin widget can choose any input DACs and a mixer.
7127  * Each ADC is connected from a mixer of all inputs.  This makes possible
7128  * 6-channel independent captures.
7129  *
7130  * In addition, an independent DAC for the multi-playback (not used in this
7131  * driver yet).
7132  */
7133 #define ALC883_DIGOUT_NID       0x06
7134 #define ALC883_DIGIN_NID        0x0a
7135
7136 #define ALC1200_DIGOUT_NID      0x10
7137
7138 static hda_nid_t alc883_dac_nids[4] = {
7139         /* front, rear, clfe, rear_surr */
7140         0x02, 0x03, 0x04, 0x05
7141 };
7142
7143 static hda_nid_t alc883_adc_nids[2] = {
7144         /* ADC1-2 */
7145         0x08, 0x09,
7146 };
7147
7148 static hda_nid_t alc883_adc_nids_alt[1] = {
7149         /* ADC1 */
7150         0x08,
7151 };
7152
7153 static hda_nid_t alc883_adc_nids_rev[2] = {
7154         /* ADC2-1 */
7155         0x09, 0x08
7156 };
7157
7158 static hda_nid_t alc883_capsrc_nids[2] = { 0x23, 0x22 };
7159
7160 static hda_nid_t alc883_capsrc_nids_rev[2] = { 0x22, 0x23 };
7161
7162 /* input MUX */
7163 /* FIXME: should be a matrix-type input source selection */
7164
7165 static struct hda_input_mux alc883_capture_source = {
7166         .num_items = 4,
7167         .items = {
7168                 { "Mic", 0x0 },
7169                 { "Front Mic", 0x1 },
7170                 { "Line", 0x2 },
7171                 { "CD", 0x4 },
7172         },
7173 };
7174
7175 static struct hda_input_mux alc883_3stack_6ch_intel = {
7176         .num_items = 4,
7177         .items = {
7178                 { "Mic", 0x1 },
7179                 { "Front Mic", 0x0 },
7180                 { "Line", 0x2 },
7181                 { "CD", 0x4 },
7182         },
7183 };
7184
7185 static struct hda_input_mux alc883_lenovo_101e_capture_source = {
7186         .num_items = 2,
7187         .items = {
7188                 { "Mic", 0x1 },
7189                 { "Line", 0x2 },
7190         },
7191 };
7192
7193 static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
7194         .num_items = 4,
7195         .items = {
7196                 { "Mic", 0x0 },
7197                 { "iMic", 0x1 },
7198                 { "Line", 0x2 },
7199                 { "CD", 0x4 },
7200         },
7201 };
7202
7203 static struct hda_input_mux alc883_fujitsu_pi2515_capture_source = {
7204         .num_items = 2,
7205         .items = {
7206                 { "Mic", 0x0 },
7207                 { "Int Mic", 0x1 },
7208         },
7209 };
7210
7211 static struct hda_input_mux alc883_lenovo_sky_capture_source = {
7212         .num_items = 3,
7213         .items = {
7214                 { "Mic", 0x0 },
7215                 { "Front Mic", 0x1 },
7216                 { "Line", 0x4 },
7217         },
7218 };
7219
7220 static struct hda_input_mux alc883_asus_eee1601_capture_source = {
7221         .num_items = 2,
7222         .items = {
7223                 { "Mic", 0x0 },
7224                 { "Line", 0x2 },
7225         },
7226 };
7227
7228 /*
7229  * 2ch mode
7230  */
7231 static struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
7232         { 2, NULL }
7233 };
7234
7235 /*
7236  * 2ch mode
7237  */
7238 static struct hda_verb alc883_3ST_ch2_init[] = {
7239         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7240         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7241         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7242         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7243         { } /* end */
7244 };
7245
7246 /*
7247  * 4ch mode
7248  */
7249 static struct hda_verb alc883_3ST_ch4_init[] = {
7250         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7251         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7252         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7253         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7254         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7255         { } /* end */
7256 };
7257
7258 /*
7259  * 6ch mode
7260  */
7261 static struct hda_verb alc883_3ST_ch6_init[] = {
7262         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7263         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7264         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
7265         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7266         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7267         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7268         { } /* end */
7269 };
7270
7271 static struct hda_channel_mode alc883_3ST_6ch_modes[3] = {
7272         { 2, alc883_3ST_ch2_init },
7273         { 4, alc883_3ST_ch4_init },
7274         { 6, alc883_3ST_ch6_init },
7275 };
7276
7277 /*
7278  * 2ch mode
7279  */
7280 static struct hda_verb alc883_3ST_ch2_intel_init[] = {
7281         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7282         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7283         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7284         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7285         { } /* end */
7286 };
7287
7288 /*
7289  * 4ch mode
7290  */
7291 static struct hda_verb alc883_3ST_ch4_intel_init[] = {
7292         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7293         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7294         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7295         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7296         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7297         { } /* end */
7298 };
7299
7300 /*
7301  * 6ch mode
7302  */
7303 static struct hda_verb alc883_3ST_ch6_intel_init[] = {
7304         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7305         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7306         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x02 },
7307         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7308         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7309         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7310         { } /* end */
7311 };
7312
7313 static struct hda_channel_mode alc883_3ST_6ch_intel_modes[3] = {
7314         { 2, alc883_3ST_ch2_intel_init },
7315         { 4, alc883_3ST_ch4_intel_init },
7316         { 6, alc883_3ST_ch6_intel_init },
7317 };
7318
7319 /*
7320  * 6ch mode
7321  */
7322 static struct hda_verb alc883_sixstack_ch6_init[] = {
7323         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
7324         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7325         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7326         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7327         { } /* end */
7328 };
7329
7330 /*
7331  * 8ch mode
7332  */
7333 static struct hda_verb alc883_sixstack_ch8_init[] = {
7334         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7335         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7336         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7337         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7338         { } /* end */
7339 };
7340
7341 static struct hda_channel_mode alc883_sixstack_modes[2] = {
7342         { 6, alc883_sixstack_ch6_init },
7343         { 8, alc883_sixstack_ch8_init },
7344 };
7345
7346 static struct hda_verb alc883_medion_eapd_verbs[] = {
7347         /* eanable EAPD on medion laptop */
7348         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7349         {0x20, AC_VERB_SET_PROC_COEF, 0x3070},
7350         { }
7351 };
7352
7353 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
7354  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
7355  */
7356
7357 static struct snd_kcontrol_new alc883_base_mixer[] = {
7358         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7359         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7360         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7361         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7362         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7363         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7364         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7365         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7366         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7367         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7368         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7369         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7370         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7371         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7372         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7373         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7374         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7375         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7376         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7377         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7378         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7379         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7380         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7381         { } /* end */
7382 };
7383
7384 static struct snd_kcontrol_new alc883_mitac_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_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7388         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7389         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7390         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7391         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7392         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7393         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7394         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7395         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7396         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7397         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7398         { } /* end */
7399 };
7400
7401 static struct snd_kcontrol_new alc883_clevo_m720_mixer[] = {
7402         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7403         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7404         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7405         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7406         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7407         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7408         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7409         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7410         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7411         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7412         { } /* end */
7413 };
7414
7415 static struct snd_kcontrol_new alc883_2ch_fujitsu_pi2515_mixer[] = {
7416         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7417         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7418         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7419         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7420         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7421         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7422         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7423         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7424         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7425         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7426         { } /* end */
7427 };
7428
7429 static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
7430         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7431         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7432         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7433         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7434         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7435         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7436         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7437         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7438         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7439         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7440         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7441         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7442         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7443         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7444         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7445         { } /* end */
7446 };
7447
7448 static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
7449         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7450         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7451         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7452         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7453         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7454         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7455         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7456         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7457         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7458         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7459         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7460         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7461         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7462         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7463         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7464         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7465         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7466         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7467         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7468         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7469         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7470         { } /* end */
7471 };
7472
7473 static struct snd_kcontrol_new alc883_3ST_6ch_intel_mixer[] = {
7474         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7475         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7476         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7477         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7478         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
7479                               HDA_OUTPUT),
7480         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7481         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7482         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7483         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7484         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7485         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7486         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7487         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7488         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7489         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
7490         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7491         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7492         HDA_CODEC_VOLUME("Front Mic Boost", 0x18, 0, HDA_INPUT),
7493         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7494         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7495         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7496         { } /* end */
7497 };
7498
7499 static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
7500         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7501         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7502         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7503         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7504         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7505         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7506         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7507         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7508         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7509         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7510         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7511         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7512         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7513         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7514         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7515         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7516         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7517         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7518         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7519         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7520         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7521         { } /* end */
7522 };
7523
7524 static struct snd_kcontrol_new alc883_tagra_mixer[] = {
7525         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7526         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7527         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7528         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7529         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7530         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7531         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7532         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7533         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7534         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7535         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7536         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7537         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7538         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7539         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7540         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7541         { } /* end */
7542 };
7543
7544 static struct snd_kcontrol_new alc883_tagra_2ch_mixer[] = {
7545         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7546         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7547         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7548         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7549         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7550         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7551         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7552         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7553         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7554         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7555         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7556         { } /* end */
7557 };
7558
7559 static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
7560         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7561         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7562         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7563         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7564         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7565         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7566         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7567         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7568         { } /* end */
7569 };
7570
7571 static struct snd_kcontrol_new alc883_lenovo_nb0763_mixer[] = {
7572         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7573         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
7574         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 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_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7579         HDA_CODEC_VOLUME("iMic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7580         HDA_CODEC_MUTE("iMic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7581         { } /* end */
7582 };
7583
7584 static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
7585         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7586         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7587         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7588         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7589         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7590         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7591         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7592         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7593         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7594         { } /* end */
7595 };
7596
7597 static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
7598         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7599         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7600         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7601         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7602         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7603         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7604         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7605         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7606         { } /* end */
7607 };
7608
7609 static struct snd_kcontrol_new alc888_lenovo_sky_mixer[] = {
7610         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7611         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7612         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
7613         HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
7614         HDA_CODEC_VOLUME_MONO("Center Playback Volume",
7615                                                 0x0d, 1, 0x0, HDA_OUTPUT),
7616         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
7617         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
7618         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
7619         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7620         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7621         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7622         HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
7623         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7624         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7625         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7626         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7627         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7628         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7629         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7630         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7631         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7632         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7633         { } /* end */
7634 };
7635
7636 static struct hda_bind_ctls alc883_bind_cap_vol = {
7637         .ops = &snd_hda_bind_vol,
7638         .values = {
7639                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
7640                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
7641                 0
7642         },
7643 };
7644
7645 static struct hda_bind_ctls alc883_bind_cap_switch = {
7646         .ops = &snd_hda_bind_sw,
7647         .values = {
7648                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
7649                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
7650                 0
7651         },
7652 };
7653
7654 static struct snd_kcontrol_new alc883_asus_eee1601_mixer[] = {
7655         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7656         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7657         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7658         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7659         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7660         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7661         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7662         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7663         { } /* end */
7664 };
7665
7666 static struct snd_kcontrol_new alc883_asus_eee1601_cap_mixer[] = {
7667         HDA_BIND_VOL("Capture Volume", &alc883_bind_cap_vol),
7668         HDA_BIND_SW("Capture Switch", &alc883_bind_cap_switch),
7669         {
7670                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7671                 /* .name = "Capture Source", */
7672                 .name = "Input Source",
7673                 .count = 1,
7674                 .info = alc_mux_enum_info,
7675                 .get = alc_mux_enum_get,
7676                 .put = alc_mux_enum_put,
7677         },
7678         { } /* end */
7679 };
7680
7681 static struct snd_kcontrol_new alc883_chmode_mixer[] = {
7682         {
7683                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7684                 .name = "Channel Mode",
7685                 .info = alc_ch_mode_info,
7686                 .get = alc_ch_mode_get,
7687                 .put = alc_ch_mode_put,
7688         },
7689         { } /* end */
7690 };
7691
7692 static struct hda_verb alc883_init_verbs[] = {
7693         /* ADC1: mute amp left and right */
7694         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7695         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7696         /* ADC2: mute amp left and right */
7697         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7698         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7699         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7700         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7701         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7702         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7703         /* Rear mixer */
7704         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7705         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7706         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7707         /* CLFE mixer */
7708         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7709         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7710         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7711         /* Side mixer */
7712         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7713         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7714         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7715
7716         /* mute analog input loopbacks */
7717         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7718         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7719         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7720         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7721         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7722
7723         /* Front Pin: output 0 (0x0c) */
7724         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7725         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7726         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7727         /* Rear Pin: output 1 (0x0d) */
7728         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7729         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7730         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7731         /* CLFE Pin: output 2 (0x0e) */
7732         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7733         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7734         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
7735         /* Side Pin: output 3 (0x0f) */
7736         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7737         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7738         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
7739         /* Mic (rear) pin: input vref at 80% */
7740         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7741         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7742         /* Front Mic pin: input vref at 80% */
7743         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7744         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7745         /* Line In pin: input */
7746         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7747         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7748         /* Line-2 In: Headphone output (output 0 - 0x0c) */
7749         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7750         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7751         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7752         /* CD pin widget for input */
7753         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7754
7755         /* FIXME: use matrix-type input source selection */
7756         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7757         /* Input mixer2 */
7758         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7759         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7760         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7761         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7762         /* Input mixer3 */
7763         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7764         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7765         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7766         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7767         { }
7768 };
7769
7770 /* toggle speaker-output according to the hp-jack state */
7771 static void alc883_mitac_hp_automute(struct hda_codec *codec)
7772 {
7773         unsigned int present;
7774
7775         present = snd_hda_codec_read(codec, 0x15, 0,
7776                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7777         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7778                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7779         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
7780                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7781 }
7782
7783 /* auto-toggle front mic */
7784 /*
7785 static void alc883_mitac_mic_automute(struct hda_codec *codec)
7786 {
7787         unsigned int present;
7788         unsigned char bits;
7789
7790         present = snd_hda_codec_read(codec, 0x18, 0,
7791                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7792         bits = present ? HDA_AMP_MUTE : 0;
7793         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
7794 }
7795 */
7796
7797 static void alc883_mitac_automute(struct hda_codec *codec)
7798 {
7799         alc883_mitac_hp_automute(codec);
7800         /* alc883_mitac_mic_automute(codec); */
7801 }
7802
7803 static void alc883_mitac_unsol_event(struct hda_codec *codec,
7804                                            unsigned int res)
7805 {
7806         switch (res >> 26) {
7807         case ALC880_HP_EVENT:
7808                 alc883_mitac_hp_automute(codec);
7809                 break;
7810         case ALC880_MIC_EVENT:
7811                 /* alc883_mitac_mic_automute(codec); */
7812                 break;
7813         }
7814 }
7815
7816 static struct hda_verb alc883_mitac_verbs[] = {
7817         /* HP */
7818         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7819         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7820         /* Subwoofer */
7821         {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
7822         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7823
7824         /* enable unsolicited event */
7825         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7826         /* {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN}, */
7827
7828         { } /* end */
7829 };
7830
7831 static struct hda_verb alc883_clevo_m720_verbs[] = {
7832         /* HP */
7833         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7834         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7835         /* Int speaker */
7836         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
7837         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7838
7839         /* enable unsolicited event */
7840         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7841         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
7842
7843         { } /* end */
7844 };
7845
7846 static struct hda_verb alc883_2ch_fujitsu_pi2515_verbs[] = {
7847         /* HP */
7848         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7849         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7850         /* Subwoofer */
7851         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7852         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7853
7854         /* enable unsolicited event */
7855         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7856
7857         { } /* end */
7858 };
7859
7860 static struct hda_verb alc883_tagra_verbs[] = {
7861         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7862         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7863
7864         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7865         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7866
7867         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
7868         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
7869         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
7870
7871         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7872         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
7873         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
7874         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
7875
7876         { } /* end */
7877 };
7878
7879 static struct hda_verb alc883_lenovo_101e_verbs[] = {
7880         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7881         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT|AC_USRSP_EN},
7882         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT|AC_USRSP_EN},
7883         { } /* end */
7884 };
7885
7886 static struct hda_verb alc883_lenovo_nb0763_verbs[] = {
7887         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7888         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7889         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7890         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7891         { } /* end */
7892 };
7893
7894 static struct hda_verb alc888_lenovo_ms7195_verbs[] = {
7895         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7896         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7897         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7898         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT | AC_USRSP_EN},
7899         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT    | AC_USRSP_EN},
7900         { } /* end */
7901 };
7902
7903 static struct hda_verb alc883_haier_w66_verbs[] = {
7904         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7905         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7906
7907         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7908
7909         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7910         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7911         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7912         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7913         { } /* end */
7914 };
7915
7916 static struct hda_verb alc888_lenovo_sky_verbs[] = {
7917         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7918         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7919         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7920         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7921         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7922         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7923         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
7924         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7925         { } /* end */
7926 };
7927
7928 static struct hda_verb alc888_3st_hp_verbs[] = {
7929         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
7930         {0x16, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Rear : output 1 (0x0d) */
7931         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},  /* CLFE : output 2 (0x0e) */
7932         { }
7933 };
7934
7935 static struct hda_verb alc888_6st_dell_verbs[] = {
7936         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7937         { }
7938 };
7939
7940 static struct hda_verb alc888_3st_hp_2ch_init[] = {
7941         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7942         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7943         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7944         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7945         { }
7946 };
7947
7948 static struct hda_verb alc888_3st_hp_6ch_init[] = {
7949         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7950         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7951         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7952         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7953         { }
7954 };
7955
7956 static struct hda_channel_mode alc888_3st_hp_modes[2] = {
7957         { 2, alc888_3st_hp_2ch_init },
7958         { 6, alc888_3st_hp_6ch_init },
7959 };
7960
7961 /* toggle front-jack and RCA according to the hp-jack state */
7962 static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
7963 {
7964         unsigned int present;
7965
7966         present = snd_hda_codec_read(codec, 0x1b, 0,
7967                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7968         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7969                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7970         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7971                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7972 }
7973
7974 /* toggle RCA according to the front-jack state */
7975 static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
7976 {
7977         unsigned int present;
7978
7979         present = snd_hda_codec_read(codec, 0x14, 0,
7980                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7981         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7982                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7983 }
7984
7985 static void alc883_lenovo_ms7195_unsol_event(struct hda_codec *codec,
7986                                              unsigned int res)
7987 {
7988         if ((res >> 26) == ALC880_HP_EVENT)
7989                 alc888_lenovo_ms7195_front_automute(codec);
7990         if ((res >> 26) == ALC880_FRONT_EVENT)
7991                 alc888_lenovo_ms7195_rca_automute(codec);
7992 }
7993
7994 static struct hda_verb alc883_medion_md2_verbs[] = {
7995         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7996         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7997
7998         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7999
8000         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8001         { } /* end */
8002 };
8003
8004 /* toggle speaker-output according to the hp-jack state */
8005 static void alc883_medion_md2_automute(struct hda_codec *codec)
8006 {
8007         unsigned int present;
8008
8009         present = snd_hda_codec_read(codec, 0x14, 0,
8010                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8011         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8012                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8013 }
8014
8015 static void alc883_medion_md2_unsol_event(struct hda_codec *codec,
8016                                           unsigned int res)
8017 {
8018         if ((res >> 26) == ALC880_HP_EVENT)
8019                 alc883_medion_md2_automute(codec);
8020 }
8021
8022 /* toggle speaker-output according to the hp-jack state */
8023 static void alc883_tagra_automute(struct hda_codec *codec)
8024 {
8025         unsigned int present;
8026         unsigned char bits;
8027
8028         present = snd_hda_codec_read(codec, 0x14, 0,
8029                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8030         bits = present ? HDA_AMP_MUTE : 0;
8031         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
8032                                  HDA_AMP_MUTE, bits);
8033         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
8034                                   present ? 1 : 3);
8035 }
8036
8037 static void alc883_tagra_unsol_event(struct hda_codec *codec, unsigned int res)
8038 {
8039         if ((res >> 26) == ALC880_HP_EVENT)
8040                 alc883_tagra_automute(codec);
8041 }
8042
8043 /* toggle speaker-output according to the hp-jack state */
8044 static void alc883_clevo_m720_hp_automute(struct hda_codec *codec)
8045 {
8046         unsigned int present;
8047         unsigned char bits;
8048
8049         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
8050                 & AC_PINSENSE_PRESENCE;
8051         bits = present ? HDA_AMP_MUTE : 0;
8052         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8053                                  HDA_AMP_MUTE, bits);
8054 }
8055
8056 static void alc883_clevo_m720_mic_automute(struct hda_codec *codec)
8057 {
8058         unsigned int present;
8059
8060         present = snd_hda_codec_read(codec, 0x18, 0,
8061                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8062         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
8063                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8064 }
8065
8066 static void alc883_clevo_m720_automute(struct hda_codec *codec)
8067 {
8068         alc883_clevo_m720_hp_automute(codec);
8069         alc883_clevo_m720_mic_automute(codec);
8070 }
8071
8072 static void alc883_clevo_m720_unsol_event(struct hda_codec *codec,
8073                                            unsigned int res)
8074 {
8075         switch (res >> 26) {
8076         case ALC880_HP_EVENT:
8077                 alc883_clevo_m720_hp_automute(codec);
8078                 break;
8079         case ALC880_MIC_EVENT:
8080                 alc883_clevo_m720_mic_automute(codec);
8081                 break;
8082         }
8083 }
8084
8085 /* toggle speaker-output according to the hp-jack state */
8086 static void alc883_2ch_fujitsu_pi2515_automute(struct hda_codec *codec)
8087 {
8088         unsigned int present;
8089         unsigned char bits;
8090
8091         present = snd_hda_codec_read(codec, 0x14, 0, AC_VERB_GET_PIN_SENSE, 0)
8092                 & AC_PINSENSE_PRESENCE;
8093         bits = present ? HDA_AMP_MUTE : 0;
8094         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8095                                  HDA_AMP_MUTE, bits);
8096 }
8097
8098 static void alc883_2ch_fujitsu_pi2515_unsol_event(struct hda_codec *codec,
8099                                                   unsigned int res)
8100 {
8101         if ((res >> 26) == ALC880_HP_EVENT)
8102                 alc883_2ch_fujitsu_pi2515_automute(codec);
8103 }
8104
8105 static void alc883_haier_w66_automute(struct hda_codec *codec)
8106 {
8107         unsigned int present;
8108         unsigned char bits;
8109
8110         present = snd_hda_codec_read(codec, 0x1b, 0,
8111                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8112         bits = present ? 0x80 : 0;
8113         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8114                                  0x80, bits);
8115 }
8116
8117 static void alc883_haier_w66_unsol_event(struct hda_codec *codec,
8118                                          unsigned int res)
8119 {
8120         if ((res >> 26) == ALC880_HP_EVENT)
8121                 alc883_haier_w66_automute(codec);
8122 }
8123
8124 static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
8125 {
8126         unsigned int present;
8127         unsigned char bits;
8128
8129         present = snd_hda_codec_read(codec, 0x14, 0,
8130                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8131         bits = present ? HDA_AMP_MUTE : 0;
8132         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8133                                  HDA_AMP_MUTE, bits);
8134 }
8135
8136 static void alc883_lenovo_101e_all_automute(struct hda_codec *codec)
8137 {
8138         unsigned int present;
8139         unsigned char bits;
8140
8141         present = snd_hda_codec_read(codec, 0x1b, 0,
8142                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8143         bits = present ? HDA_AMP_MUTE : 0;
8144         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8145                                  HDA_AMP_MUTE, bits);
8146         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8147                                  HDA_AMP_MUTE, bits);
8148 }
8149
8150 static void alc883_lenovo_101e_unsol_event(struct hda_codec *codec,
8151                                            unsigned int res)
8152 {
8153         if ((res >> 26) == ALC880_HP_EVENT)
8154                 alc883_lenovo_101e_all_automute(codec);
8155         if ((res >> 26) == ALC880_FRONT_EVENT)
8156                 alc883_lenovo_101e_ispeaker_automute(codec);
8157 }
8158
8159 /* toggle speaker-output according to the hp-jack state */
8160 static void alc883_acer_aspire_automute(struct hda_codec *codec)
8161 {
8162         unsigned int present;
8163
8164         present = snd_hda_codec_read(codec, 0x14, 0,
8165                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8166         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8167                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8168         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8169                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8170 }
8171
8172 static void alc883_acer_aspire_unsol_event(struct hda_codec *codec,
8173                                            unsigned int res)
8174 {
8175         if ((res >> 26) == ALC880_HP_EVENT)
8176                 alc883_acer_aspire_automute(codec);
8177 }
8178
8179 static struct hda_verb alc883_acer_eapd_verbs[] = {
8180         /* HP Pin: output 0 (0x0c) */
8181         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8182         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8183         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8184         /* Front Pin: output 0 (0x0c) */
8185         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8186         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8187         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8188         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
8189         /* eanable EAPD on medion laptop */
8190         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
8191         {0x20, AC_VERB_SET_PROC_COEF, 0x3050},
8192         /* enable unsolicited event */
8193         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8194         { }
8195 };
8196
8197 static void alc888_6st_dell_front_automute(struct hda_codec *codec)
8198 {
8199         unsigned int present;
8200
8201         present = snd_hda_codec_read(codec, 0x1b, 0,
8202                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8203         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8204                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8205         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8206                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8207         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8208                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8209         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
8210                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8211 }
8212
8213 static void alc888_6st_dell_unsol_event(struct hda_codec *codec,
8214                                              unsigned int res)
8215 {
8216         switch (res >> 26) {
8217         case ALC880_HP_EVENT:
8218                 printk("hp_event\n");
8219                 alc888_6st_dell_front_automute(codec);
8220                 break;
8221         }
8222 }
8223
8224 static void alc888_lenovo_sky_front_automute(struct hda_codec *codec)
8225 {
8226         unsigned int mute;
8227         unsigned int present;
8228
8229         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
8230         present = snd_hda_codec_read(codec, 0x1b, 0,
8231                                      AC_VERB_GET_PIN_SENSE, 0);
8232         present = (present & 0x80000000) != 0;
8233         if (present) {
8234                 /* mute internal speaker */
8235                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8236                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8237                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8238                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8239                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8240                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8241                 snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
8242                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8243                 snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
8244                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8245         } else {
8246                 /* unmute internal speaker if necessary */
8247                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
8248                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8249                                          HDA_AMP_MUTE, mute);
8250                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8251                                          HDA_AMP_MUTE, mute);
8252                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8253                                          HDA_AMP_MUTE, mute);
8254                 snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
8255                                          HDA_AMP_MUTE, mute);
8256                 snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
8257                                          HDA_AMP_MUTE, mute);
8258         }
8259 }
8260
8261 static void alc883_lenovo_sky_unsol_event(struct hda_codec *codec,
8262                                              unsigned int res)
8263 {
8264         if ((res >> 26) == ALC880_HP_EVENT)
8265                 alc888_lenovo_sky_front_automute(codec);
8266 }
8267
8268 /*
8269  * generic initialization of ADC, input mixers and output mixers
8270  */
8271 static struct hda_verb alc883_auto_init_verbs[] = {
8272         /*
8273          * Unmute ADC0-2 and set the default input to mic-in
8274          */
8275         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8276         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8277         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8278         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8279
8280         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
8281          * mixer widget
8282          * Note: PASD motherboards uses the Line In 2 as the input for
8283          * front panel mic (mic 2)
8284          */
8285         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
8286         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8287         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8288         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8289         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8290         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8291
8292         /*
8293          * Set up output mixers (0x0c - 0x0f)
8294          */
8295         /* set vol=0 to output mixers */
8296         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8297         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8298         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8299         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8300         /* set up input amps for analog loopback */
8301         /* Amp Indices: DAC = 0, mixer = 1 */
8302         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8303         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8304         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8305         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8306         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8307         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8308         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8309         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8310         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8311         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8312
8313         /* FIXME: use matrix-type input source selection */
8314         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8315         /* Input mixer1 */
8316         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8317         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8318         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8319         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
8320         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
8321         /* Input mixer2 */
8322         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8323         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8324         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8325         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
8326         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
8327
8328         { }
8329 };
8330
8331 static struct hda_verb alc888_asus_m90v_verbs[] = {
8332         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8333         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8334         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8335         /* enable unsolicited event */
8336         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8337         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
8338         { } /* end */
8339 };
8340
8341 static void alc883_nb_mic_automute(struct hda_codec *codec)
8342 {
8343         unsigned int present;
8344
8345         present = snd_hda_codec_read(codec, 0x18, 0,
8346                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8347         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
8348                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
8349         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
8350                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
8351 }
8352
8353 static void alc883_M90V_speaker_automute(struct hda_codec *codec)
8354 {
8355         unsigned int present;
8356         unsigned char bits;
8357
8358         present = snd_hda_codec_read(codec, 0x1b, 0,
8359                                      AC_VERB_GET_PIN_SENSE, 0)
8360                 & AC_PINSENSE_PRESENCE;
8361         bits = present ? 0 : PIN_OUT;
8362         snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8363                             bits);
8364         snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8365                             bits);
8366         snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8367                             bits);
8368 }
8369
8370 static void alc883_mode2_unsol_event(struct hda_codec *codec,
8371                                            unsigned int res)
8372 {
8373         switch (res >> 26) {
8374         case ALC880_HP_EVENT:
8375                 alc883_M90V_speaker_automute(codec);
8376                 break;
8377         case ALC880_MIC_EVENT:
8378                 alc883_nb_mic_automute(codec);
8379                 break;
8380         }
8381 }
8382
8383 static void alc883_mode2_inithook(struct hda_codec *codec)
8384 {
8385         alc883_M90V_speaker_automute(codec);
8386         alc883_nb_mic_automute(codec);
8387 }
8388
8389 static struct hda_verb alc888_asus_eee1601_verbs[] = {
8390         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8391         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8392         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8393         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8394         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8395         {0x20, AC_VERB_SET_COEF_INDEX, 0x0b},
8396         {0x20, AC_VERB_SET_PROC_COEF,  0x0838},
8397         /* enable unsolicited event */
8398         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8399         { } /* end */
8400 };
8401
8402 static void alc883_eee1601_speaker_automute(struct hda_codec *codec)
8403 {
8404         unsigned int present;
8405         unsigned char bits;
8406
8407         present = snd_hda_codec_read(codec, 0x14, 0,
8408                                      AC_VERB_GET_PIN_SENSE, 0)
8409                 & AC_PINSENSE_PRESENCE;
8410         bits = present ? 0 : PIN_OUT;
8411         snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8412                             bits);
8413 }
8414
8415 static void alc883_eee1601_unsol_event(struct hda_codec *codec,
8416                                            unsigned int res)
8417 {
8418         switch (res >> 26) {
8419         case ALC880_HP_EVENT:
8420                 alc883_eee1601_speaker_automute(codec);
8421                 break;
8422         }
8423 }
8424
8425 static void alc883_eee1601_inithook(struct hda_codec *codec)
8426 {
8427         alc883_eee1601_speaker_automute(codec);
8428 }
8429
8430 #ifdef CONFIG_SND_HDA_POWER_SAVE
8431 #define alc883_loopbacks        alc880_loopbacks
8432 #endif
8433
8434 /* pcm configuration: identiacal with ALC880 */
8435 #define alc883_pcm_analog_playback      alc880_pcm_analog_playback
8436 #define alc883_pcm_analog_capture       alc880_pcm_analog_capture
8437 #define alc883_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
8438 #define alc883_pcm_digital_playback     alc880_pcm_digital_playback
8439 #define alc883_pcm_digital_capture      alc880_pcm_digital_capture
8440
8441 /*
8442  * configuration and preset
8443  */
8444 static const char *alc883_models[ALC883_MODEL_LAST] = {
8445         [ALC883_3ST_2ch_DIG]    = "3stack-dig",
8446         [ALC883_3ST_6ch_DIG]    = "3stack-6ch-dig",
8447         [ALC883_3ST_6ch]        = "3stack-6ch",
8448         [ALC883_6ST_DIG]        = "6stack-dig",
8449         [ALC883_TARGA_DIG]      = "targa-dig",
8450         [ALC883_TARGA_2ch_DIG]  = "targa-2ch-dig",
8451         [ALC883_ACER]           = "acer",
8452         [ALC883_ACER_ASPIRE]    = "acer-aspire",
8453         [ALC888_ACER_ASPIRE_4930G]      = "acer-aspire-4930g",
8454         [ALC883_MEDION]         = "medion",
8455         [ALC883_MEDION_MD2]     = "medion-md2",
8456         [ALC883_LAPTOP_EAPD]    = "laptop-eapd",
8457         [ALC883_LENOVO_101E_2ch] = "lenovo-101e",
8458         [ALC883_LENOVO_NB0763]  = "lenovo-nb0763",
8459         [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
8460         [ALC888_LENOVO_SKY] = "lenovo-sky",
8461         [ALC883_HAIER_W66]      = "haier-w66",
8462         [ALC888_3ST_HP]         = "3stack-hp",
8463         [ALC888_6ST_DELL]       = "6stack-dell",
8464         [ALC883_MITAC]          = "mitac",
8465         [ALC883_CLEVO_M720]     = "clevo-m720",
8466         [ALC883_FUJITSU_PI2515] = "fujitsu-pi2515",
8467         [ALC888_FUJITSU_XA3530] = "fujitsu-xa3530",
8468         [ALC883_3ST_6ch_INTEL]  = "3stack-6ch-intel",
8469         [ALC1200_ASUS_P5Q]      = "asus-p5q",
8470         [ALC883_AUTO]           = "auto",
8471 };
8472
8473 static struct snd_pci_quirk alc883_cfg_tbl[] = {
8474         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC883_3ST_6ch_DIG),
8475         SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE),
8476         SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_ACER_ASPIRE),
8477         SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE),
8478         SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE),
8479         SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_ACER_ASPIRE),
8480         SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
8481                 ALC888_ACER_ASPIRE_4930G),
8482         SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
8483                 ALC888_ACER_ASPIRE_4930G),
8484         SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
8485                 ALC888_ACER_ASPIRE_4930G),
8486         SND_PCI_QUIRK(0x1025, 0, "Acer laptop", ALC883_ACER), /* default Acer */
8487         SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL),
8488         SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
8489         SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
8490         SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
8491         SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG),
8492         SND_PCI_QUIRK(0x103c, 0x2a66, "HP Acacia", ALC888_3ST_HP),
8493         SND_PCI_QUIRK(0x1043, 0x1873, "Asus M90V", ALC888_ASUS_M90V),
8494         SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG),
8495         SND_PCI_QUIRK(0x1043, 0x82fe, "Asus P5Q-EM HDMI", ALC1200_ASUS_P5Q),
8496         SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_ASUS_EEE1601),
8497         SND_PCI_QUIRK(0x105b, 0x0ce8, "Foxconn P35AX-S", ALC883_6ST_DIG),
8498         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG),
8499         SND_PCI_QUIRK(0x1071, 0x8227, "Mitac 82801H", ALC883_MITAC),
8500         SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC),
8501         SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
8502         SND_PCI_QUIRK(0x10f1, 0x2350, "TYAN-S2350", ALC888_6ST_DELL),
8503         SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
8504         SND_PCI_QUIRK(0x1458, 0xa002, "MSI", ALC883_6ST_DIG),
8505         SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
8506         SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG),
8507         SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
8508         SND_PCI_QUIRK(0x1462, 0x2fb3, "MSI", ALC883_TARGA_2ch_DIG),
8509         SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
8510         SND_PCI_QUIRK(0x1462, 0x3783, "NEC S970", ALC883_TARGA_DIG),
8511         SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
8512         SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
8513         SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
8514         SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG),
8515         SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG),
8516         SND_PCI_QUIRK(0x1462, 0x3fdf, "MSI", ALC883_TARGA_DIG),
8517         SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
8518         SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
8519         SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
8520         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
8521         SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
8522         SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
8523         SND_PCI_QUIRK(0x1462, 0x7260, "MSI 7260", ALC883_TARGA_DIG),
8524         SND_PCI_QUIRK(0x1462, 0x7267, "MSI", ALC883_3ST_6ch_DIG),
8525         SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
8526         SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
8527         SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
8528         SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG),
8529         SND_PCI_QUIRK(0x1558, 0x0721, "Clevo laptop M720R", ALC883_CLEVO_M720),
8530         SND_PCI_QUIRK(0x1558, 0x0722, "Clevo laptop M720SR", ALC883_CLEVO_M720),
8531         SND_PCI_QUIRK(0x1558, 0, "Clevo laptop", ALC883_LAPTOP_EAPD),
8532         SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
8533         SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
8534         SND_PCI_QUIRK(0x1734, 0x1108, "Fujitsu AMILO Pi2515", ALC883_FUJITSU_PI2515),
8535         SND_PCI_QUIRK(0x1734, 0x113d, "Fujitsu AMILO Xa3530",
8536                 ALC888_FUJITSU_XA3530),
8537         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
8538         SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8539         SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8540         SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8541         SND_PCI_QUIRK(0x17aa, 0x101d, "Lenovo Sky", ALC888_LENOVO_SKY),
8542         SND_PCI_QUIRK(0x17c0, 0x4071, "MEDION MD2", ALC883_MEDION_MD2),
8543         SND_PCI_QUIRK(0x17c0, 0x4085, "MEDION MD96630", ALC888_LENOVO_MS7195_DIG),
8544         SND_PCI_QUIRK(0x17f2, 0x5000, "Albatron KI690-AM2", ALC883_6ST_DIG),
8545         SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66),
8546         SND_PCI_QUIRK(0x8086, 0x0001, "DG33BUC", ALC883_3ST_6ch_INTEL),
8547         SND_PCI_QUIRK(0x8086, 0x0002, "DG33FBC", ALC883_3ST_6ch_INTEL),
8548         SND_PCI_QUIRK(0x8086, 0x2503, "82801H", ALC883_MITAC),
8549         SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC883_3ST_6ch_INTEL),
8550         SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch),
8551         {}
8552 };
8553
8554 static struct alc_config_preset alc883_presets[] = {
8555         [ALC883_3ST_2ch_DIG] = {
8556                 .mixers = { alc883_3ST_2ch_mixer },
8557                 .init_verbs = { alc883_init_verbs },
8558                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8559                 .dac_nids = alc883_dac_nids,
8560                 .dig_out_nid = ALC883_DIGOUT_NID,
8561                 .dig_in_nid = ALC883_DIGIN_NID,
8562                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8563                 .channel_mode = alc883_3ST_2ch_modes,
8564                 .input_mux = &alc883_capture_source,
8565         },
8566         [ALC883_3ST_6ch_DIG] = {
8567                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8568                 .init_verbs = { alc883_init_verbs },
8569                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8570                 .dac_nids = alc883_dac_nids,
8571                 .dig_out_nid = ALC883_DIGOUT_NID,
8572                 .dig_in_nid = ALC883_DIGIN_NID,
8573                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8574                 .channel_mode = alc883_3ST_6ch_modes,
8575                 .need_dac_fix = 1,
8576                 .input_mux = &alc883_capture_source,
8577         },
8578         [ALC883_3ST_6ch] = {
8579                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8580                 .init_verbs = { alc883_init_verbs },
8581                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8582                 .dac_nids = alc883_dac_nids,
8583                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8584                 .channel_mode = alc883_3ST_6ch_modes,
8585                 .need_dac_fix = 1,
8586                 .input_mux = &alc883_capture_source,
8587         },
8588         [ALC883_3ST_6ch_INTEL] = {
8589                 .mixers = { alc883_3ST_6ch_intel_mixer, alc883_chmode_mixer },
8590                 .init_verbs = { alc883_init_verbs },
8591                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8592                 .dac_nids = alc883_dac_nids,
8593                 .dig_out_nid = ALC883_DIGOUT_NID,
8594                 .dig_in_nid = ALC883_DIGIN_NID,
8595                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_intel_modes),
8596                 .channel_mode = alc883_3ST_6ch_intel_modes,
8597                 .need_dac_fix = 1,
8598                 .input_mux = &alc883_3stack_6ch_intel,
8599         },
8600         [ALC883_6ST_DIG] = {
8601                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8602                 .init_verbs = { alc883_init_verbs },
8603                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8604                 .dac_nids = alc883_dac_nids,
8605                 .dig_out_nid = ALC883_DIGOUT_NID,
8606                 .dig_in_nid = ALC883_DIGIN_NID,
8607                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8608                 .channel_mode = alc883_sixstack_modes,
8609                 .input_mux = &alc883_capture_source,
8610         },
8611         [ALC883_TARGA_DIG] = {
8612                 .mixers = { alc883_tagra_mixer, alc883_chmode_mixer },
8613                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
8614                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8615                 .dac_nids = alc883_dac_nids,
8616                 .dig_out_nid = ALC883_DIGOUT_NID,
8617                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8618                 .channel_mode = alc883_3ST_6ch_modes,
8619                 .need_dac_fix = 1,
8620                 .input_mux = &alc883_capture_source,
8621                 .unsol_event = alc883_tagra_unsol_event,
8622                 .init_hook = alc883_tagra_automute,
8623         },
8624         [ALC883_TARGA_2ch_DIG] = {
8625                 .mixers = { alc883_tagra_2ch_mixer},
8626                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
8627                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8628                 .dac_nids = alc883_dac_nids,
8629                 .adc_nids = alc883_adc_nids_alt,
8630                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
8631                 .dig_out_nid = ALC883_DIGOUT_NID,
8632                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8633                 .channel_mode = alc883_3ST_2ch_modes,
8634                 .input_mux = &alc883_capture_source,
8635                 .unsol_event = alc883_tagra_unsol_event,
8636                 .init_hook = alc883_tagra_automute,
8637         },
8638         [ALC883_ACER] = {
8639                 .mixers = { alc883_base_mixer },
8640                 /* On TravelMate laptops, GPIO 0 enables the internal speaker
8641                  * and the headphone jack.  Turn this on and rely on the
8642                  * standard mute methods whenever the user wants to turn
8643                  * these outputs off.
8644                  */
8645                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
8646                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8647                 .dac_nids = alc883_dac_nids,
8648                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8649                 .channel_mode = alc883_3ST_2ch_modes,
8650                 .input_mux = &alc883_capture_source,
8651         },
8652         [ALC883_ACER_ASPIRE] = {
8653                 .mixers = { alc883_acer_aspire_mixer },
8654                 .init_verbs = { alc883_init_verbs, alc883_acer_eapd_verbs },
8655                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8656                 .dac_nids = alc883_dac_nids,
8657                 .dig_out_nid = ALC883_DIGOUT_NID,
8658                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8659                 .channel_mode = alc883_3ST_2ch_modes,
8660                 .input_mux = &alc883_capture_source,
8661                 .unsol_event = alc883_acer_aspire_unsol_event,
8662                 .init_hook = alc883_acer_aspire_automute,
8663         },
8664         [ALC888_ACER_ASPIRE_4930G] = {
8665                 .mixers = { alc888_base_mixer,
8666                                 alc883_chmode_mixer },
8667                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
8668                                 alc888_acer_aspire_4930g_verbs },
8669                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8670                 .dac_nids = alc883_dac_nids,
8671                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
8672                 .adc_nids = alc883_adc_nids_rev,
8673                 .capsrc_nids = alc883_capsrc_nids_rev,
8674                 .dig_out_nid = ALC883_DIGOUT_NID,
8675                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8676                 .channel_mode = alc883_3ST_6ch_modes,
8677                 .need_dac_fix = 1,
8678                 .num_mux_defs =
8679                         ARRAY_SIZE(alc888_2_capture_sources),
8680                 .input_mux = alc888_2_capture_sources,
8681                 .unsol_event = alc888_acer_aspire_4930g_unsol_event,
8682                 .init_hook = alc888_acer_aspire_4930g_automute,
8683         },
8684         [ALC883_MEDION] = {
8685                 .mixers = { alc883_fivestack_mixer,
8686                             alc883_chmode_mixer },
8687                 .init_verbs = { alc883_init_verbs,
8688                                 alc883_medion_eapd_verbs },
8689                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8690                 .dac_nids = alc883_dac_nids,
8691                 .adc_nids = alc883_adc_nids_alt,
8692                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
8693                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8694                 .channel_mode = alc883_sixstack_modes,
8695                 .input_mux = &alc883_capture_source,
8696         },
8697         [ALC883_MEDION_MD2] = {
8698                 .mixers = { alc883_medion_md2_mixer},
8699                 .init_verbs = { alc883_init_verbs, alc883_medion_md2_verbs},
8700                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8701                 .dac_nids = alc883_dac_nids,
8702                 .dig_out_nid = ALC883_DIGOUT_NID,
8703                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8704                 .channel_mode = alc883_3ST_2ch_modes,
8705                 .input_mux = &alc883_capture_source,
8706                 .unsol_event = alc883_medion_md2_unsol_event,
8707                 .init_hook = alc883_medion_md2_automute,
8708         },
8709         [ALC883_LAPTOP_EAPD] = {
8710                 .mixers = { alc883_base_mixer },
8711                 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
8712                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8713                 .dac_nids = alc883_dac_nids,
8714                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8715                 .channel_mode = alc883_3ST_2ch_modes,
8716                 .input_mux = &alc883_capture_source,
8717         },
8718         [ALC883_CLEVO_M720] = {
8719                 .mixers = { alc883_clevo_m720_mixer },
8720                 .init_verbs = { alc883_init_verbs, alc883_clevo_m720_verbs },
8721                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8722                 .dac_nids = alc883_dac_nids,
8723                 .dig_out_nid = ALC883_DIGOUT_NID,
8724                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8725                 .channel_mode = alc883_3ST_2ch_modes,
8726                 .input_mux = &alc883_capture_source,
8727                 .unsol_event = alc883_clevo_m720_unsol_event,
8728                 .init_hook = alc883_clevo_m720_automute,
8729         },
8730         [ALC883_LENOVO_101E_2ch] = {
8731                 .mixers = { alc883_lenovo_101e_2ch_mixer},
8732                 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
8733                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8734                 .dac_nids = alc883_dac_nids,
8735                 .adc_nids = alc883_adc_nids_alt,
8736                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
8737                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8738                 .channel_mode = alc883_3ST_2ch_modes,
8739                 .input_mux = &alc883_lenovo_101e_capture_source,
8740                 .unsol_event = alc883_lenovo_101e_unsol_event,
8741                 .init_hook = alc883_lenovo_101e_all_automute,
8742         },
8743         [ALC883_LENOVO_NB0763] = {
8744                 .mixers = { alc883_lenovo_nb0763_mixer },
8745                 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs},
8746                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8747                 .dac_nids = alc883_dac_nids,
8748                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8749                 .channel_mode = alc883_3ST_2ch_modes,
8750                 .need_dac_fix = 1,
8751                 .input_mux = &alc883_lenovo_nb0763_capture_source,
8752                 .unsol_event = alc883_medion_md2_unsol_event,
8753                 .init_hook = alc883_medion_md2_automute,
8754         },
8755         [ALC888_LENOVO_MS7195_DIG] = {
8756                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8757                 .init_verbs = { alc883_init_verbs, alc888_lenovo_ms7195_verbs},
8758                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8759                 .dac_nids = alc883_dac_nids,
8760                 .dig_out_nid = ALC883_DIGOUT_NID,
8761                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8762                 .channel_mode = alc883_3ST_6ch_modes,
8763                 .need_dac_fix = 1,
8764                 .input_mux = &alc883_capture_source,
8765                 .unsol_event = alc883_lenovo_ms7195_unsol_event,
8766                 .init_hook = alc888_lenovo_ms7195_front_automute,
8767         },
8768         [ALC883_HAIER_W66] = {
8769                 .mixers = { alc883_tagra_2ch_mixer},
8770                 .init_verbs = { alc883_init_verbs, alc883_haier_w66_verbs},
8771                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8772                 .dac_nids = alc883_dac_nids,
8773                 .dig_out_nid = ALC883_DIGOUT_NID,
8774                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8775                 .channel_mode = alc883_3ST_2ch_modes,
8776                 .input_mux = &alc883_capture_source,
8777                 .unsol_event = alc883_haier_w66_unsol_event,
8778                 .init_hook = alc883_haier_w66_automute,
8779         },
8780         [ALC888_3ST_HP] = {
8781                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8782                 .init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs },
8783                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8784                 .dac_nids = alc883_dac_nids,
8785                 .num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes),
8786                 .channel_mode = alc888_3st_hp_modes,
8787                 .need_dac_fix = 1,
8788                 .input_mux = &alc883_capture_source,
8789         },
8790         [ALC888_6ST_DELL] = {
8791                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8792                 .init_verbs = { alc883_init_verbs, alc888_6st_dell_verbs },
8793                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8794                 .dac_nids = alc883_dac_nids,
8795                 .dig_out_nid = ALC883_DIGOUT_NID,
8796                 .dig_in_nid = ALC883_DIGIN_NID,
8797                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8798                 .channel_mode = alc883_sixstack_modes,
8799                 .input_mux = &alc883_capture_source,
8800                 .unsol_event = alc888_6st_dell_unsol_event,
8801                 .init_hook = alc888_6st_dell_front_automute,
8802         },
8803         [ALC883_MITAC] = {
8804                 .mixers = { alc883_mitac_mixer },
8805                 .init_verbs = { alc883_init_verbs, alc883_mitac_verbs },
8806                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8807                 .dac_nids = alc883_dac_nids,
8808                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8809                 .channel_mode = alc883_3ST_2ch_modes,
8810                 .input_mux = &alc883_capture_source,
8811                 .unsol_event = alc883_mitac_unsol_event,
8812                 .init_hook = alc883_mitac_automute,
8813         },
8814         [ALC883_FUJITSU_PI2515] = {
8815                 .mixers = { alc883_2ch_fujitsu_pi2515_mixer },
8816                 .init_verbs = { alc883_init_verbs,
8817                                 alc883_2ch_fujitsu_pi2515_verbs},
8818                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8819                 .dac_nids = alc883_dac_nids,
8820                 .dig_out_nid = ALC883_DIGOUT_NID,
8821                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8822                 .channel_mode = alc883_3ST_2ch_modes,
8823                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
8824                 .unsol_event = alc883_2ch_fujitsu_pi2515_unsol_event,
8825                 .init_hook = alc883_2ch_fujitsu_pi2515_automute,
8826         },
8827         [ALC888_FUJITSU_XA3530] = {
8828                 .mixers = { alc888_base_mixer, alc883_chmode_mixer },
8829                 .init_verbs = { alc883_init_verbs,
8830                         alc888_fujitsu_xa3530_verbs },
8831                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8832                 .dac_nids = alc883_dac_nids,
8833                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
8834                 .adc_nids = alc883_adc_nids_rev,
8835                 .capsrc_nids = alc883_capsrc_nids_rev,
8836                 .dig_out_nid = ALC883_DIGOUT_NID,
8837                 .num_channel_mode = ARRAY_SIZE(alc888_4ST_8ch_intel_modes),
8838                 .channel_mode = alc888_4ST_8ch_intel_modes,
8839                 .num_mux_defs =
8840                         ARRAY_SIZE(alc888_2_capture_sources),
8841                 .input_mux = alc888_2_capture_sources,
8842                 .unsol_event = alc888_fujitsu_xa3530_unsol_event,
8843                 .init_hook = alc888_fujitsu_xa3530_automute,
8844         },
8845         [ALC888_LENOVO_SKY] = {
8846                 .mixers = { alc888_lenovo_sky_mixer, alc883_chmode_mixer },
8847                 .init_verbs = { alc883_init_verbs, alc888_lenovo_sky_verbs},
8848                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8849                 .dac_nids = alc883_dac_nids,
8850                 .dig_out_nid = ALC883_DIGOUT_NID,
8851                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8852                 .channel_mode = alc883_sixstack_modes,
8853                 .need_dac_fix = 1,
8854                 .input_mux = &alc883_lenovo_sky_capture_source,
8855                 .unsol_event = alc883_lenovo_sky_unsol_event,
8856                 .init_hook = alc888_lenovo_sky_front_automute,
8857         },
8858         [ALC888_ASUS_M90V] = {
8859                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8860                 .init_verbs = { alc883_init_verbs, alc888_asus_m90v_verbs },
8861                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8862                 .dac_nids = alc883_dac_nids,
8863                 .dig_out_nid = ALC883_DIGOUT_NID,
8864                 .dig_in_nid = ALC883_DIGIN_NID,
8865                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8866                 .channel_mode = alc883_3ST_6ch_modes,
8867                 .need_dac_fix = 1,
8868                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
8869                 .unsol_event = alc883_mode2_unsol_event,
8870                 .init_hook = alc883_mode2_inithook,
8871         },
8872         [ALC888_ASUS_EEE1601] = {
8873                 .mixers = { alc883_asus_eee1601_mixer },
8874                 .cap_mixer = alc883_asus_eee1601_cap_mixer,
8875                 .init_verbs = { alc883_init_verbs, alc888_asus_eee1601_verbs },
8876                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8877                 .dac_nids = alc883_dac_nids,
8878                 .dig_out_nid = ALC883_DIGOUT_NID,
8879                 .dig_in_nid = ALC883_DIGIN_NID,
8880                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8881                 .channel_mode = alc883_3ST_2ch_modes,
8882                 .need_dac_fix = 1,
8883                 .input_mux = &alc883_asus_eee1601_capture_source,
8884                 .unsol_event = alc883_eee1601_unsol_event,
8885                 .init_hook = alc883_eee1601_inithook,
8886         },
8887         [ALC1200_ASUS_P5Q] = {
8888                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8889                 .init_verbs = { alc883_init_verbs },
8890                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8891                 .dac_nids = alc883_dac_nids,
8892                 .dig_out_nid = ALC1200_DIGOUT_NID,
8893                 .dig_in_nid = ALC883_DIGIN_NID,
8894                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8895                 .channel_mode = alc883_sixstack_modes,
8896                 .input_mux = &alc883_capture_source,
8897         },
8898 };
8899
8900
8901 /*
8902  * BIOS auto configuration
8903  */
8904 static void alc883_auto_set_output_and_unmute(struct hda_codec *codec,
8905                                               hda_nid_t nid, int pin_type,
8906                                               int dac_idx)
8907 {
8908         /* set as output */
8909         struct alc_spec *spec = codec->spec;
8910         int idx;
8911
8912         alc_set_pin_output(codec, nid, pin_type);
8913         if (spec->multiout.dac_nids[dac_idx] == 0x25)
8914                 idx = 4;
8915         else
8916                 idx = spec->multiout.dac_nids[dac_idx] - 2;
8917         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
8918
8919 }
8920
8921 static void alc883_auto_init_multi_out(struct hda_codec *codec)
8922 {
8923         struct alc_spec *spec = codec->spec;
8924         int i;
8925
8926         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
8927         for (i = 0; i <= HDA_SIDE; i++) {
8928                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
8929                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
8930                 if (nid)
8931                         alc883_auto_set_output_and_unmute(codec, nid, pin_type,
8932                                                           i);
8933         }
8934 }
8935
8936 static void alc883_auto_init_hp_out(struct hda_codec *codec)
8937 {
8938         struct alc_spec *spec = codec->spec;
8939         hda_nid_t pin;
8940
8941         pin = spec->autocfg.hp_pins[0];
8942         if (pin) /* connect to front */
8943                 /* use dac 0 */
8944                 alc883_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
8945         pin = spec->autocfg.speaker_pins[0];
8946         if (pin)
8947                 alc883_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
8948 }
8949
8950 #define alc883_is_input_pin(nid)        alc880_is_input_pin(nid)
8951 #define ALC883_PIN_CD_NID               ALC880_PIN_CD_NID
8952
8953 static void alc883_auto_init_analog_input(struct hda_codec *codec)
8954 {
8955         struct alc_spec *spec = codec->spec;
8956         int i;
8957
8958         for (i = 0; i < AUTO_PIN_LAST; i++) {
8959                 hda_nid_t nid = spec->autocfg.input_pins[i];
8960                 if (alc883_is_input_pin(nid)) {
8961                         snd_hda_codec_write(codec, nid, 0,
8962                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
8963                                             (i <= AUTO_PIN_FRONT_MIC ?
8964                                              PIN_VREF80 : PIN_IN));
8965                         if (nid != ALC883_PIN_CD_NID)
8966                                 snd_hda_codec_write(codec, nid, 0,
8967                                                     AC_VERB_SET_AMP_GAIN_MUTE,
8968                                                     AMP_OUT_MUTE);
8969                 }
8970         }
8971 }
8972
8973 #define alc883_auto_init_input_src      alc882_auto_init_input_src
8974
8975 /* almost identical with ALC880 parser... */
8976 static int alc883_parse_auto_config(struct hda_codec *codec)
8977 {
8978         struct alc_spec *spec = codec->spec;
8979         int err = alc880_parse_auto_config(codec);
8980
8981         if (err < 0)
8982                 return err;
8983         else if (!err)
8984                 return 0; /* no config found */
8985
8986         err = alc_auto_add_mic_boost(codec);
8987         if (err < 0)
8988                 return err;
8989
8990         /* hack - override the init verbs */
8991         spec->init_verbs[0] = alc883_auto_init_verbs;
8992
8993         return 1; /* config found */
8994 }
8995
8996 /* additional initialization for auto-configuration model */
8997 static void alc883_auto_init(struct hda_codec *codec)
8998 {
8999         struct alc_spec *spec = codec->spec;
9000         alc883_auto_init_multi_out(codec);
9001         alc883_auto_init_hp_out(codec);
9002         alc883_auto_init_analog_input(codec);
9003         alc883_auto_init_input_src(codec);
9004         if (spec->unsol_event)
9005                 alc_inithook(codec);
9006 }
9007
9008 static int patch_alc883(struct hda_codec *codec)
9009 {
9010         struct alc_spec *spec;
9011         int err, board_config;
9012
9013         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
9014         if (spec == NULL)
9015                 return -ENOMEM;
9016
9017         codec->spec = spec;
9018
9019         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
9020
9021         board_config = snd_hda_check_board_config(codec, ALC883_MODEL_LAST,
9022                                                   alc883_models,
9023                                                   alc883_cfg_tbl);
9024         if (board_config < 0) {
9025                 printk(KERN_INFO "hda_codec: Unknown model for ALC883, "
9026                        "trying auto-probe from BIOS...\n");
9027                 board_config = ALC883_AUTO;
9028         }
9029
9030         if (board_config == ALC883_AUTO) {
9031                 /* automatic parse from the BIOS config */
9032                 err = alc883_parse_auto_config(codec);
9033                 if (err < 0) {
9034                         alc_free(codec);
9035                         return err;
9036                 } else if (!err) {
9037                         printk(KERN_INFO
9038                                "hda_codec: Cannot set up configuration "
9039                                "from BIOS.  Using base mode...\n");
9040                         board_config = ALC883_3ST_2ch_DIG;
9041                 }
9042         }
9043
9044         if (board_config != ALC883_AUTO)
9045                 setup_preset(spec, &alc883_presets[board_config]);
9046
9047         switch (codec->vendor_id) {
9048         case 0x10ec0888:
9049                 if (codec->revision_id == 0x100101) {
9050                         spec->stream_name_analog = "ALC1200 Analog";
9051                         spec->stream_name_digital = "ALC1200 Digital";
9052                 } else {
9053                         spec->stream_name_analog = "ALC888 Analog";
9054                         spec->stream_name_digital = "ALC888 Digital";
9055                 }
9056                 break;
9057         case 0x10ec0889:
9058                 spec->stream_name_analog = "ALC889 Analog";
9059                 spec->stream_name_digital = "ALC889 Digital";
9060                 break;
9061         default:
9062                 spec->stream_name_analog = "ALC883 Analog";
9063                 spec->stream_name_digital = "ALC883 Digital";
9064                 break;
9065         }
9066
9067         spec->stream_analog_playback = &alc883_pcm_analog_playback;
9068         spec->stream_analog_capture = &alc883_pcm_analog_capture;
9069         spec->stream_analog_alt_capture = &alc883_pcm_analog_alt_capture;
9070
9071         spec->stream_digital_playback = &alc883_pcm_digital_playback;
9072         spec->stream_digital_capture = &alc883_pcm_digital_capture;
9073
9074         if (!spec->num_adc_nids) {
9075                 spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
9076                 spec->adc_nids = alc883_adc_nids;
9077         }
9078         if (!spec->capsrc_nids)
9079                 spec->capsrc_nids = alc883_capsrc_nids;
9080         spec->is_mix_capture = 1; /* matrix-style capture */
9081         if (!spec->cap_mixer)
9082                 set_capture_mixer(spec);
9083
9084         spec->vmaster_nid = 0x0c;
9085
9086         codec->patch_ops = alc_patch_ops;
9087         if (board_config == ALC883_AUTO)
9088                 spec->init_hook = alc883_auto_init;
9089
9090 #ifdef CONFIG_SND_HDA_POWER_SAVE
9091         if (!spec->loopback.amplist)
9092                 spec->loopback.amplist = alc883_loopbacks;
9093 #endif
9094         codec->proc_widget_hook = print_realtek_coef;
9095
9096         return 0;
9097 }
9098
9099 /*
9100  * ALC262 support
9101  */
9102
9103 #define ALC262_DIGOUT_NID       ALC880_DIGOUT_NID
9104 #define ALC262_DIGIN_NID        ALC880_DIGIN_NID
9105
9106 #define alc262_dac_nids         alc260_dac_nids
9107 #define alc262_adc_nids         alc882_adc_nids
9108 #define alc262_adc_nids_alt     alc882_adc_nids_alt
9109 #define alc262_capsrc_nids      alc882_capsrc_nids
9110 #define alc262_capsrc_nids_alt  alc882_capsrc_nids_alt
9111
9112 #define alc262_modes            alc260_modes
9113 #define alc262_capture_source   alc882_capture_source
9114
9115 static hda_nid_t alc262_dmic_adc_nids[1] = {
9116         /* ADC0 */
9117         0x09
9118 };
9119
9120 static hda_nid_t alc262_dmic_capsrc_nids[1] = { 0x22 };
9121
9122 static struct snd_kcontrol_new alc262_base_mixer[] = {
9123         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9124         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9125         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9126         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9127         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9128         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9129         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9130         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9131         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9132         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9133         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9134         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9135         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
9136            HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT), */
9137         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
9138         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9139         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
9140         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
9141         { } /* end */
9142 };
9143
9144 static struct snd_kcontrol_new alc262_hippo1_mixer[] = {
9145         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9146         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9147         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9148         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9149         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9150         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9151         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9152         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9153         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9154         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9155         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9156         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9157         /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
9158            HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT), */
9159         /*HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),*/
9160         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9161         { } /* end */
9162 };
9163
9164 /* update HP, line and mono-out pins according to the master switch */
9165 static void alc262_hp_master_update(struct hda_codec *codec)
9166 {
9167         struct alc_spec *spec = codec->spec;
9168         int val = spec->master_sw;
9169
9170         /* HP & line-out */
9171         snd_hda_codec_write_cache(codec, 0x1b, 0,
9172                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9173                                   val ? PIN_HP : 0);
9174         snd_hda_codec_write_cache(codec, 0x15, 0,
9175                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9176                                   val ? PIN_HP : 0);
9177         /* mono (speaker) depending on the HP jack sense */
9178         val = val && !spec->jack_present;
9179         snd_hda_codec_write_cache(codec, 0x16, 0,
9180                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9181                                   val ? PIN_OUT : 0);
9182 }
9183
9184 static void alc262_hp_bpc_automute(struct hda_codec *codec)
9185 {
9186         struct alc_spec *spec = codec->spec;
9187         unsigned int presence;
9188         presence = snd_hda_codec_read(codec, 0x1b, 0,
9189                                       AC_VERB_GET_PIN_SENSE, 0);
9190         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
9191         alc262_hp_master_update(codec);
9192 }
9193
9194 static void alc262_hp_bpc_unsol_event(struct hda_codec *codec, unsigned int res)
9195 {
9196         if ((res >> 26) != ALC880_HP_EVENT)
9197                 return;
9198         alc262_hp_bpc_automute(codec);
9199 }
9200
9201 static void alc262_hp_wildwest_automute(struct hda_codec *codec)
9202 {
9203         struct alc_spec *spec = codec->spec;
9204         unsigned int presence;
9205         presence = snd_hda_codec_read(codec, 0x15, 0,
9206                                       AC_VERB_GET_PIN_SENSE, 0);
9207         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
9208         alc262_hp_master_update(codec);
9209 }
9210
9211 static void alc262_hp_wildwest_unsol_event(struct hda_codec *codec,
9212                                            unsigned int res)
9213 {
9214         if ((res >> 26) != ALC880_HP_EVENT)
9215                 return;
9216         alc262_hp_wildwest_automute(codec);
9217 }
9218
9219 static int alc262_hp_master_sw_get(struct snd_kcontrol *kcontrol,
9220                                    struct snd_ctl_elem_value *ucontrol)
9221 {
9222         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9223         struct alc_spec *spec = codec->spec;
9224         *ucontrol->value.integer.value = spec->master_sw;
9225         return 0;
9226 }
9227
9228 static int alc262_hp_master_sw_put(struct snd_kcontrol *kcontrol,
9229                                    struct snd_ctl_elem_value *ucontrol)
9230 {
9231         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9232         struct alc_spec *spec = codec->spec;
9233         int val = !!*ucontrol->value.integer.value;
9234
9235         if (val == spec->master_sw)
9236                 return 0;
9237         spec->master_sw = val;
9238         alc262_hp_master_update(codec);
9239         return 1;
9240 }
9241
9242 static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
9243         {
9244                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9245                 .name = "Master Playback Switch",
9246                 .info = snd_ctl_boolean_mono_info,
9247                 .get = alc262_hp_master_sw_get,
9248                 .put = alc262_hp_master_sw_put,
9249         },
9250         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9251         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9252         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9253         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
9254                               HDA_OUTPUT),
9255         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
9256                             HDA_OUTPUT),
9257         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9258         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9259         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9260         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9261         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9262         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9263         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9264         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9265         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9266         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9267         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
9268         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
9269         HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
9270         HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
9271         { } /* end */
9272 };
9273
9274 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
9275         {
9276                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9277                 .name = "Master Playback Switch",
9278                 .info = snd_ctl_boolean_mono_info,
9279                 .get = alc262_hp_master_sw_get,
9280                 .put = alc262_hp_master_sw_put,
9281         },
9282         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9283         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9284         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9285         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9286         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
9287                               HDA_OUTPUT),
9288         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
9289                             HDA_OUTPUT),
9290         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
9291         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
9292         HDA_CODEC_VOLUME("Front Mic Boost", 0x1a, 0, HDA_INPUT),
9293         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
9294         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
9295         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9296         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9297         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
9298         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
9299         { } /* end */
9300 };
9301
9302 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
9303         HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9304         HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9305         HDA_CODEC_VOLUME("Rear Mic Boost", 0x18, 0, HDA_INPUT),
9306         { } /* end */
9307 };
9308
9309 /* mute/unmute internal speaker according to the hp jack and mute state */
9310 static void alc262_hp_t5735_automute(struct hda_codec *codec, int force)
9311 {
9312         struct alc_spec *spec = codec->spec;
9313
9314         if (force || !spec->sense_updated) {
9315                 unsigned int present;
9316                 present = snd_hda_codec_read(codec, 0x15, 0,
9317                                              AC_VERB_GET_PIN_SENSE, 0);
9318                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
9319                 spec->sense_updated = 1;
9320         }
9321         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0, HDA_AMP_MUTE,
9322                                  spec->jack_present ? HDA_AMP_MUTE : 0);
9323 }
9324
9325 static void alc262_hp_t5735_unsol_event(struct hda_codec *codec,
9326                                         unsigned int res)
9327 {
9328         if ((res >> 26) != ALC880_HP_EVENT)
9329                 return;
9330         alc262_hp_t5735_automute(codec, 1);
9331 }
9332
9333 static void alc262_hp_t5735_init_hook(struct hda_codec *codec)
9334 {
9335         alc262_hp_t5735_automute(codec, 1);
9336 }
9337
9338 static struct snd_kcontrol_new alc262_hp_t5735_mixer[] = {
9339         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9340         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9341         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9342         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9343         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9344         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9345         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9346         { } /* end */
9347 };
9348
9349 static struct hda_verb alc262_hp_t5735_verbs[] = {
9350         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9351         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9352
9353         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9354         { }
9355 };
9356
9357 static struct snd_kcontrol_new alc262_hp_rp5700_mixer[] = {
9358         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9359         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9360         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
9361         HDA_CODEC_MUTE("Speaker Playback Switch", 0x16, 0x0, HDA_OUTPUT),
9362         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
9363         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
9364         { } /* end */
9365 };
9366
9367 static struct hda_verb alc262_hp_rp5700_verbs[] = {
9368         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9369         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9370         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9371         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9372         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9373         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9374         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9375         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9376         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
9377         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
9378         {}
9379 };
9380
9381 static struct hda_input_mux alc262_hp_rp5700_capture_source = {
9382         .num_items = 1,
9383         .items = {
9384                 { "Line", 0x1 },
9385         },
9386 };
9387
9388 /* bind hp and internal speaker mute (with plug check) */
9389 static int alc262_sony_master_sw_put(struct snd_kcontrol *kcontrol,
9390                                      struct snd_ctl_elem_value *ucontrol)
9391 {
9392         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9393         long *valp = ucontrol->value.integer.value;
9394         int change;
9395
9396         /* change hp mute */
9397         change = snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
9398                                           HDA_AMP_MUTE,
9399                                           valp[0] ? 0 : HDA_AMP_MUTE);
9400         change |= snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
9401                                            HDA_AMP_MUTE,
9402                                            valp[1] ? 0 : HDA_AMP_MUTE);
9403         if (change) {
9404                 /* change speaker according to HP jack state */
9405                 struct alc_spec *spec = codec->spec;
9406                 unsigned int mute;
9407                 if (spec->jack_present)
9408                         mute = HDA_AMP_MUTE;
9409                 else
9410                         mute = snd_hda_codec_amp_read(codec, 0x15, 0,
9411                                                       HDA_OUTPUT, 0);
9412                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9413                                          HDA_AMP_MUTE, mute);
9414         }
9415         return change;
9416 }
9417
9418 static struct snd_kcontrol_new alc262_sony_mixer[] = {
9419         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9420         {
9421                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9422                 .name = "Master Playback Switch",
9423                 .info = snd_hda_mixer_amp_switch_info,
9424                 .get = snd_hda_mixer_amp_switch_get,
9425                 .put = alc262_sony_master_sw_put,
9426                 .private_value = HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
9427         },
9428         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9429         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9430         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9431         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9432         { } /* end */
9433 };
9434
9435 static struct snd_kcontrol_new alc262_benq_t31_mixer[] = {
9436         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9437         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9438         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9439         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9440         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9441         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9442         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9443         { } /* end */
9444 };
9445
9446 #define alc262_capture_mixer            alc882_capture_mixer
9447 #define alc262_capture_alt_mixer        alc882_capture_alt_mixer
9448
9449 /*
9450  * generic initialization of ADC, input mixers and output mixers
9451  */
9452 static struct hda_verb alc262_init_verbs[] = {
9453         /*
9454          * Unmute ADC0-2 and set the default input to mic-in
9455          */
9456         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
9457         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9458         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9459         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9460         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9461         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9462
9463         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
9464          * mixer widget
9465          * Note: PASD motherboards uses the Line In 2 as the input for
9466          * front panel mic (mic 2)
9467          */
9468         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9469         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9470         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9471         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9472         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9473         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9474
9475         /*
9476          * Set up output mixers (0x0c - 0x0e)
9477          */
9478         /* set vol=0 to output mixers */
9479         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9480         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9481         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9482         /* set up input amps for analog loopback */
9483         /* Amp Indices: DAC = 0, mixer = 1 */
9484         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9485         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9486         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9487         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9488         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9489         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9490
9491         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
9492         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9493         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
9494         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9495         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9496         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9497
9498         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9499         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9500         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9501         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9502         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9503
9504         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
9505         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
9506
9507         /* FIXME: use matrix-type input source selection */
9508         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
9509         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9510         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9511         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9512         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9513         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9514         /* Input mixer2 */
9515         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9516         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9517         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9518         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9519         /* Input mixer3 */
9520         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9521         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9522         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9523         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9524
9525         { }
9526 };
9527
9528 static struct hda_verb alc262_eapd_verbs[] = {
9529         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
9530         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
9531         { }
9532 };
9533
9534 static struct hda_verb alc262_hippo_unsol_verbs[] = {
9535         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9536         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9537         {}
9538 };
9539
9540 static struct hda_verb alc262_hippo1_unsol_verbs[] = {
9541         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9542         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9543         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9544
9545         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9546         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9547         {}
9548 };
9549
9550 static struct hda_verb alc262_sony_unsol_verbs[] = {
9551         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9552         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9553         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},   // Front Mic
9554
9555         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9556         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9557         {}
9558 };
9559
9560 static struct hda_input_mux alc262_dmic_capture_source = {
9561         .num_items = 2,
9562         .items = {
9563                 { "Int DMic", 0x9 },
9564                 { "Mic", 0x0 },
9565         },
9566 };
9567
9568 static struct snd_kcontrol_new alc262_toshiba_s06_mixer[] = {
9569         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9570         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9571         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9572         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9573         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9574         { } /* end */
9575 };
9576
9577 static struct hda_verb alc262_toshiba_s06_verbs[] = {
9578         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9579         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9580         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9581         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9582         {0x22, AC_VERB_SET_CONNECT_SEL, 0x09},
9583         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9584         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
9585         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9586         {}
9587 };
9588
9589 static void alc262_dmic_automute(struct hda_codec *codec)
9590 {
9591         unsigned int present;
9592
9593         present = snd_hda_codec_read(codec, 0x18, 0,
9594                                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
9595         snd_hda_codec_write(codec, 0x22, 0,
9596                                 AC_VERB_SET_CONNECT_SEL, present ? 0x0 : 0x09);
9597 }
9598
9599 /* toggle speaker-output according to the hp-jack state */
9600 static void alc262_toshiba_s06_speaker_automute(struct hda_codec *codec)
9601 {
9602         unsigned int present;
9603         unsigned char bits;
9604
9605         present = snd_hda_codec_read(codec, 0x15, 0,
9606                                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
9607         bits = present ? 0 : PIN_OUT;
9608         snd_hda_codec_write(codec, 0x14, 0,
9609                                         AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
9610 }
9611
9612
9613
9614 /* unsolicited event for HP jack sensing */
9615 static void alc262_toshiba_s06_unsol_event(struct hda_codec *codec,
9616                                        unsigned int res)
9617 {
9618         if ((res >> 26) == ALC880_HP_EVENT)
9619                 alc262_toshiba_s06_speaker_automute(codec);
9620         if ((res >> 26) == ALC880_MIC_EVENT)
9621                 alc262_dmic_automute(codec);
9622
9623 }
9624
9625 static void alc262_toshiba_s06_init_hook(struct hda_codec *codec)
9626 {
9627         alc262_toshiba_s06_speaker_automute(codec);
9628         alc262_dmic_automute(codec);
9629 }
9630
9631 /* mute/unmute internal speaker according to the hp jack and mute state */
9632 static void alc262_hippo_automute(struct hda_codec *codec)
9633 {
9634         struct alc_spec *spec = codec->spec;
9635         unsigned int mute;
9636         unsigned int present;
9637
9638         /* need to execute and sync at first */
9639         snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
9640         present = snd_hda_codec_read(codec, 0x15, 0,
9641                                      AC_VERB_GET_PIN_SENSE, 0);
9642         spec->jack_present = (present & 0x80000000) != 0;
9643         if (spec->jack_present) {
9644                 /* mute internal speaker */
9645                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9646                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9647         } else {
9648                 /* unmute internal speaker if necessary */
9649                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
9650                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9651                                          HDA_AMP_MUTE, mute);
9652         }
9653 }
9654
9655 /* unsolicited event for HP jack sensing */
9656 static void alc262_hippo_unsol_event(struct hda_codec *codec,
9657                                        unsigned int res)
9658 {
9659         if ((res >> 26) != ALC880_HP_EVENT)
9660                 return;
9661         alc262_hippo_automute(codec);
9662 }
9663
9664 static void alc262_hippo1_automute(struct hda_codec *codec)
9665 {
9666         unsigned int mute;
9667         unsigned int present;
9668
9669         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9670         present = snd_hda_codec_read(codec, 0x1b, 0,
9671                                      AC_VERB_GET_PIN_SENSE, 0);
9672         present = (present & 0x80000000) != 0;
9673         if (present) {
9674                 /* mute internal speaker */
9675                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9676                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9677         } else {
9678                 /* unmute internal speaker if necessary */
9679                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
9680                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9681                                          HDA_AMP_MUTE, mute);
9682         }
9683 }
9684
9685 /* unsolicited event for HP jack sensing */
9686 static void alc262_hippo1_unsol_event(struct hda_codec *codec,
9687                                        unsigned int res)
9688 {
9689         if ((res >> 26) != ALC880_HP_EVENT)
9690                 return;
9691         alc262_hippo1_automute(codec);
9692 }
9693
9694 /*
9695  * nec model
9696  *  0x15 = headphone
9697  *  0x16 = internal speaker
9698  *  0x18 = external mic
9699  */
9700
9701 static struct snd_kcontrol_new alc262_nec_mixer[] = {
9702         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
9703         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 0, 0x0, HDA_OUTPUT),
9704
9705         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9706         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9707         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9708
9709         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9710         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9711         { } /* end */
9712 };
9713
9714 static struct hda_verb alc262_nec_verbs[] = {
9715         /* Unmute Speaker */
9716         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9717
9718         /* Headphone */
9719         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9720         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9721
9722         /* External mic to headphone */
9723         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9724         /* External mic to speaker */
9725         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9726         {}
9727 };
9728
9729 /*
9730  * fujitsu model
9731  *  0x14 = headphone/spdif-out, 0x15 = internal speaker,
9732  *  0x1b = port replicator headphone out
9733  */
9734
9735 #define ALC_HP_EVENT    0x37
9736
9737 static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
9738         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9739         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9740         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9741         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9742         {}
9743 };
9744
9745 static struct hda_verb alc262_lenovo_3000_unsol_verbs[] = {
9746         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
9747         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9748         {}
9749 };
9750
9751 static struct hda_input_mux alc262_fujitsu_capture_source = {
9752         .num_items = 3,
9753         .items = {
9754                 { "Mic", 0x0 },
9755                 { "Int Mic", 0x1 },
9756                 { "CD", 0x4 },
9757         },
9758 };
9759
9760 static struct hda_input_mux alc262_HP_capture_source = {
9761         .num_items = 5,
9762         .items = {
9763                 { "Mic", 0x0 },
9764                 { "Front Mic", 0x1 },
9765                 { "Line", 0x2 },
9766                 { "CD", 0x4 },
9767                 { "AUX IN", 0x6 },
9768         },
9769 };
9770
9771 static struct hda_input_mux alc262_HP_D7000_capture_source = {
9772         .num_items = 4,
9773         .items = {
9774                 { "Mic", 0x0 },
9775                 { "Front Mic", 0x2 },
9776                 { "Line", 0x1 },
9777                 { "CD", 0x4 },
9778         },
9779 };
9780
9781 /* mute/unmute internal speaker according to the hp jacks and mute state */
9782 static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
9783 {
9784         struct alc_spec *spec = codec->spec;
9785         unsigned int mute;
9786
9787         if (force || !spec->sense_updated) {
9788                 unsigned int present;
9789                 /* need to execute and sync at first */
9790                 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
9791                 /* check laptop HP jack */
9792                 present = snd_hda_codec_read(codec, 0x14, 0,
9793                                              AC_VERB_GET_PIN_SENSE, 0);
9794                 /* need to execute and sync at first */
9795                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9796                 /* check docking HP jack */
9797                 present |= snd_hda_codec_read(codec, 0x1b, 0,
9798                                               AC_VERB_GET_PIN_SENSE, 0);
9799                 if (present & AC_PINSENSE_PRESENCE)
9800                         spec->jack_present = 1;
9801                 else
9802                         spec->jack_present = 0;
9803                 spec->sense_updated = 1;
9804         }
9805         /* unmute internal speaker only if both HPs are unplugged and
9806          * master switch is on
9807          */
9808         if (spec->jack_present)
9809                 mute = HDA_AMP_MUTE;
9810         else
9811                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
9812         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
9813                                  HDA_AMP_MUTE, mute);
9814 }
9815
9816 /* unsolicited event for HP jack sensing */
9817 static void alc262_fujitsu_unsol_event(struct hda_codec *codec,
9818                                        unsigned int res)
9819 {
9820         if ((res >> 26) != ALC_HP_EVENT)
9821                 return;
9822         alc262_fujitsu_automute(codec, 1);
9823 }
9824
9825 static void alc262_fujitsu_init_hook(struct hda_codec *codec)
9826 {
9827         alc262_fujitsu_automute(codec, 1);
9828 }
9829
9830 /* bind volumes of both NID 0x0c and 0x0d */
9831 static struct hda_bind_ctls alc262_fujitsu_bind_master_vol = {
9832         .ops = &snd_hda_bind_vol,
9833         .values = {
9834                 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
9835                 HDA_COMPOSE_AMP_VAL(0x0d, 3, 0, HDA_OUTPUT),
9836                 0
9837         },
9838 };
9839
9840 /* mute/unmute internal speaker according to the hp jack and mute state */
9841 static void alc262_lenovo_3000_automute(struct hda_codec *codec, int force)
9842 {
9843         struct alc_spec *spec = codec->spec;
9844         unsigned int mute;
9845
9846         if (force || !spec->sense_updated) {
9847                 unsigned int present_int_hp;
9848                 /* need to execute and sync at first */
9849                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9850                 present_int_hp = snd_hda_codec_read(codec, 0x1b, 0,
9851                                         AC_VERB_GET_PIN_SENSE, 0);
9852                 spec->jack_present = (present_int_hp & 0x80000000) != 0;
9853                 spec->sense_updated = 1;
9854         }
9855         if (spec->jack_present) {
9856                 /* mute internal speaker */
9857                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9858                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9859                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
9860                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9861         } else {
9862                 /* unmute internal speaker if necessary */
9863                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
9864                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9865                                          HDA_AMP_MUTE, mute);
9866                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
9867                                          HDA_AMP_MUTE, mute);
9868         }
9869 }
9870
9871 /* unsolicited event for HP jack sensing */
9872 static void alc262_lenovo_3000_unsol_event(struct hda_codec *codec,
9873                                        unsigned int res)
9874 {
9875         if ((res >> 26) != ALC_HP_EVENT)
9876                 return;
9877         alc262_lenovo_3000_automute(codec, 1);
9878 }
9879
9880 /* bind hp and internal speaker mute (with plug check) */
9881 static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
9882                                          struct snd_ctl_elem_value *ucontrol)
9883 {
9884         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9885         long *valp = ucontrol->value.integer.value;
9886         int change;
9887
9888         change = snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9889                                                  HDA_AMP_MUTE,
9890                                                  valp ? 0 : HDA_AMP_MUTE);
9891         change |= snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
9892                                                  HDA_AMP_MUTE,
9893                                                  valp ? 0 : HDA_AMP_MUTE);
9894
9895         if (change)
9896                 alc262_fujitsu_automute(codec, 0);
9897         return change;
9898 }
9899
9900 static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
9901         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9902         {
9903                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9904                 .name = "Master Playback Switch",
9905                 .info = snd_hda_mixer_amp_switch_info,
9906                 .get = snd_hda_mixer_amp_switch_get,
9907                 .put = alc262_fujitsu_master_sw_put,
9908                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
9909         },
9910         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9911         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9912         HDA_CODEC_VOLUME("PC Speaker Volume", 0x0b, 0x05, HDA_INPUT),
9913         HDA_CODEC_MUTE("PC Speaker Switch", 0x0b, 0x05, HDA_INPUT),
9914         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9915         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9916         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9917         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
9918         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9919         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9920         { } /* end */
9921 };
9922
9923 /* bind hp and internal speaker mute (with plug check) */
9924 static int alc262_lenovo_3000_master_sw_put(struct snd_kcontrol *kcontrol,
9925                                          struct snd_ctl_elem_value *ucontrol)
9926 {
9927         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9928         long *valp = ucontrol->value.integer.value;
9929         int change;
9930
9931         change = snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
9932                                                  HDA_AMP_MUTE,
9933                                                  valp ? 0 : HDA_AMP_MUTE);
9934
9935         if (change)
9936                 alc262_lenovo_3000_automute(codec, 0);
9937         return change;
9938 }
9939
9940 static struct snd_kcontrol_new alc262_lenovo_3000_mixer[] = {
9941         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9942         {
9943                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9944                 .name = "Master Playback Switch",
9945                 .info = snd_hda_mixer_amp_switch_info,
9946                 .get = snd_hda_mixer_amp_switch_get,
9947                 .put = alc262_lenovo_3000_master_sw_put,
9948                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
9949         },
9950         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9951         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9952         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9953         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9954         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9955         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
9956         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
9957         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
9958         { } /* end */
9959 };
9960
9961 static struct snd_kcontrol_new alc262_toshiba_rx1_mixer[] = {
9962         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
9963         {
9964                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9965                 .name = "Master Playback Switch",
9966                 .info = snd_hda_mixer_amp_switch_info,
9967                 .get = snd_hda_mixer_amp_switch_get,
9968                 .put = alc262_sony_master_sw_put,
9969                 .private_value = HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
9970         },
9971         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9972         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9973         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9974         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9975         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9976         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9977         { } /* end */
9978 };
9979
9980 /* additional init verbs for Benq laptops */
9981 static struct hda_verb alc262_EAPD_verbs[] = {
9982         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
9983         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
9984         {}
9985 };
9986
9987 static struct hda_verb alc262_benq_t31_EAPD_verbs[] = {
9988         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9989         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9990
9991         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
9992         {0x20, AC_VERB_SET_PROC_COEF,  0x3050},
9993         {}
9994 };
9995
9996 /* Samsung Q1 Ultra Vista model setup */
9997 static struct snd_kcontrol_new alc262_ultra_mixer[] = {
9998         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9999         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
10000         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10001         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10002         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
10003         HDA_CODEC_VOLUME("Headphone Mic Boost", 0x15, 0, HDA_INPUT),
10004         { } /* end */
10005 };
10006
10007 static struct hda_verb alc262_ultra_verbs[] = {
10008         /* output mixer */
10009         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10010         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10011         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10012         /* speaker */
10013         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10014         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10015         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10016         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
10017         /* HP */
10018         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10019         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10020         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10021         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10022         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10023         /* internal mic */
10024         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10025         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10026         /* ADC, choose mic */
10027         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10028         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10029         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10030         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10031         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10032         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10033         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10034         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10035         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
10036         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(8)},
10037         {}
10038 };
10039
10040 /* mute/unmute internal speaker according to the hp jack and mute state */
10041 static void alc262_ultra_automute(struct hda_codec *codec)
10042 {
10043         struct alc_spec *spec = codec->spec;
10044         unsigned int mute;
10045
10046         mute = 0;
10047         /* auto-mute only when HP is used as HP */
10048         if (!spec->cur_mux[0]) {
10049                 unsigned int present;
10050                 /* need to execute and sync at first */
10051                 snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
10052                 present = snd_hda_codec_read(codec, 0x15, 0,
10053                                              AC_VERB_GET_PIN_SENSE, 0);
10054                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
10055                 if (spec->jack_present)
10056                         mute = HDA_AMP_MUTE;
10057         }
10058         /* mute/unmute internal speaker */
10059         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10060                                  HDA_AMP_MUTE, mute);
10061         /* mute/unmute HP */
10062         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
10063                                  HDA_AMP_MUTE, mute ? 0 : HDA_AMP_MUTE);
10064 }
10065
10066 /* unsolicited event for HP jack sensing */
10067 static void alc262_ultra_unsol_event(struct hda_codec *codec,
10068                                        unsigned int res)
10069 {
10070         if ((res >> 26) != ALC880_HP_EVENT)
10071                 return;
10072         alc262_ultra_automute(codec);
10073 }
10074
10075 static struct hda_input_mux alc262_ultra_capture_source = {
10076         .num_items = 2,
10077         .items = {
10078                 { "Mic", 0x1 },
10079                 { "Headphone", 0x7 },
10080         },
10081 };
10082
10083 static int alc262_ultra_mux_enum_put(struct snd_kcontrol *kcontrol,
10084                                      struct snd_ctl_elem_value *ucontrol)
10085 {
10086         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10087         struct alc_spec *spec = codec->spec;
10088         int ret;
10089
10090         ret = alc_mux_enum_put(kcontrol, ucontrol);
10091         if (!ret)
10092                 return 0;
10093         /* reprogram the HP pin as mic or HP according to the input source */
10094         snd_hda_codec_write_cache(codec, 0x15, 0,
10095                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
10096                                   spec->cur_mux[0] ? PIN_VREF80 : PIN_HP);
10097         alc262_ultra_automute(codec); /* mute/unmute HP */
10098         return ret;
10099 }
10100
10101 static struct snd_kcontrol_new alc262_ultra_capture_mixer[] = {
10102         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
10103         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
10104         {
10105                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10106                 .name = "Capture Source",
10107                 .info = alc_mux_enum_info,
10108                 .get = alc_mux_enum_get,
10109                 .put = alc262_ultra_mux_enum_put,
10110         },
10111         { } /* end */
10112 };
10113
10114 /* add playback controls from the parsed DAC table */
10115 static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
10116                                              const struct auto_pin_cfg *cfg)
10117 {
10118         hda_nid_t nid;
10119         int err;
10120
10121         spec->multiout.num_dacs = 1;    /* only use one dac */
10122         spec->multiout.dac_nids = spec->private_dac_nids;
10123         spec->multiout.dac_nids[0] = 2;
10124
10125         nid = cfg->line_out_pins[0];
10126         if (nid) {
10127                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
10128                                   "Front Playback Volume",
10129                                   HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT));
10130                 if (err < 0)
10131                         return err;
10132                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10133                                   "Front Playback Switch",
10134                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
10135                 if (err < 0)
10136                         return err;
10137         }
10138
10139         nid = cfg->speaker_pins[0];
10140         if (nid) {
10141                 if (nid == 0x16) {
10142                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
10143                                           "Speaker Playback Volume",
10144                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
10145                                                               HDA_OUTPUT));
10146                         if (err < 0)
10147                                 return err;
10148                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10149                                           "Speaker Playback Switch",
10150                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
10151                                                               HDA_OUTPUT));
10152                         if (err < 0)
10153                                 return err;
10154                 } else {
10155                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10156                                           "Speaker Playback Switch",
10157                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
10158                                                               HDA_OUTPUT));
10159                         if (err < 0)
10160                                 return err;
10161                 }
10162         }
10163         nid = cfg->hp_pins[0];
10164         if (nid) {
10165                 /* spec->multiout.hp_nid = 2; */
10166                 if (nid == 0x16) {
10167                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
10168                                           "Headphone Playback Volume",
10169                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
10170                                                               HDA_OUTPUT));
10171                         if (err < 0)
10172                                 return err;
10173                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10174                                           "Headphone Playback Switch",
10175                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
10176                                                               HDA_OUTPUT));
10177                         if (err < 0)
10178                                 return err;
10179                 } else {
10180                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10181                                           "Headphone Playback Switch",
10182                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
10183                                                               HDA_OUTPUT));
10184                         if (err < 0)
10185                                 return err;
10186                 }
10187         }
10188         return 0;
10189 }
10190
10191 /* identical with ALC880 */
10192 #define alc262_auto_create_analog_input_ctls \
10193         alc880_auto_create_analog_input_ctls
10194
10195 /*
10196  * generic initialization of ADC, input mixers and output mixers
10197  */
10198 static struct hda_verb alc262_volume_init_verbs[] = {
10199         /*
10200          * Unmute ADC0-2 and set the default input to mic-in
10201          */
10202         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10203         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10204         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10205         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10206         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10207         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10208
10209         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10210          * mixer widget
10211          * Note: PASD motherboards uses the Line In 2 as the input for
10212          * front panel mic (mic 2)
10213          */
10214         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10215         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10216         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10217         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10218         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10219         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10220
10221         /*
10222          * Set up output mixers (0x0c - 0x0f)
10223          */
10224         /* set vol=0 to output mixers */
10225         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10226         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10227         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10228
10229         /* set up input amps for analog loopback */
10230         /* Amp Indices: DAC = 0, mixer = 1 */
10231         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10232         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10233         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10234         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10235         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10236         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10237
10238         /* FIXME: use matrix-type input source selection */
10239         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10240         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10241         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10242         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10243         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10244         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10245         /* Input mixer2 */
10246         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10247         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10248         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10249         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10250         /* Input mixer3 */
10251         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10252         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10253         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10254         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10255
10256         { }
10257 };
10258
10259 static struct hda_verb alc262_HP_BPC_init_verbs[] = {
10260         /*
10261          * Unmute ADC0-2 and set the default input to mic-in
10262          */
10263         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10264         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10265         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10266         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10267         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10268         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10269
10270         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10271          * mixer widget
10272          * Note: PASD motherboards uses the Line In 2 as the input for
10273          * front panel mic (mic 2)
10274          */
10275         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10276         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10277         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10278         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10279         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10280         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10281         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10282         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10283
10284         /*
10285          * Set up output mixers (0x0c - 0x0e)
10286          */
10287         /* set vol=0 to output mixers */
10288         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10289         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10290         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10291
10292         /* set up input amps for analog loopback */
10293         /* Amp Indices: DAC = 0, mixer = 1 */
10294         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10295         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10296         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10297         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10298         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10299         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10300
10301         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10302         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10303         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10304
10305         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10306         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10307
10308         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10309         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10310
10311         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10312         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10313         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10314         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10315         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10316
10317         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
10318         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10319         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10320         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
10321         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10322         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10323
10324
10325         /* FIXME: use matrix-type input source selection */
10326         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10327         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10328         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10329         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10330         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10331         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10332         /* Input mixer2 */
10333         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10334         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10335         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10336         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10337         /* Input mixer3 */
10338         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10339         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10340         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10341         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10342
10343         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10344
10345         { }
10346 };
10347
10348 static struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
10349         /*
10350          * Unmute ADC0-2 and set the default input to mic-in
10351          */
10352         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10353         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10354         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10355         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10356         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10357         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10358
10359         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10360          * mixer widget
10361          * Note: PASD motherboards uses the Line In 2 as the input for front
10362          * panel mic (mic 2)
10363          */
10364         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10365         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10366         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10367         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10368         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10369         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10370         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10371         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10372         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
10373         /*
10374          * Set up output mixers (0x0c - 0x0e)
10375          */
10376         /* set vol=0 to output mixers */
10377         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10378         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10379         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10380
10381         /* set up input amps for analog loopback */
10382         /* Amp Indices: DAC = 0, mixer = 1 */
10383         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10384         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10385         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10386         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10387         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10388         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10389
10390
10391         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP */
10392         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Mono */
10393         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* rear MIC */
10394         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* Line in */
10395         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
10396         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Line out */
10397         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* CD in */
10398
10399         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10400         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10401
10402         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10403         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
10404
10405         /* {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 }, */
10406         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10407         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10408         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
10409         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10410         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10411
10412         /* FIXME: use matrix-type input source selection */
10413         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10414         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10415         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, /*rear MIC*/
10416         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, /*Line in*/
10417         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))}, /*F MIC*/
10418         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))}, /*Front*/
10419         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))}, /*CD*/
10420         /* {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))},  */
10421         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))}, /*HP*/
10422         /* Input mixer2 */
10423         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10424         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10425         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10426         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10427         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10428         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
10429         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
10430         /* Input mixer3 */
10431         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10432         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10433         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10434         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10435         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10436         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
10437         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
10438
10439         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10440
10441         { }
10442 };
10443
10444 static struct hda_verb alc262_toshiba_rx1_unsol_verbs[] = {
10445
10446         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Front Speaker */
10447         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10448         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
10449
10450         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* MIC jack */
10451         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
10452         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
10453         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
10454
10455         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP  jack */
10456         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10457         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10458         {}
10459 };
10460
10461
10462 #ifdef CONFIG_SND_HDA_POWER_SAVE
10463 #define alc262_loopbacks        alc880_loopbacks
10464 #endif
10465
10466 /* pcm configuration: identiacal with ALC880 */
10467 #define alc262_pcm_analog_playback      alc880_pcm_analog_playback
10468 #define alc262_pcm_analog_capture       alc880_pcm_analog_capture
10469 #define alc262_pcm_digital_playback     alc880_pcm_digital_playback
10470 #define alc262_pcm_digital_capture      alc880_pcm_digital_capture
10471
10472 /*
10473  * BIOS auto configuration
10474  */
10475 static int alc262_parse_auto_config(struct hda_codec *codec)
10476 {
10477         struct alc_spec *spec = codec->spec;
10478         int err;
10479         static hda_nid_t alc262_ignore[] = { 0x1d, 0 };
10480
10481         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
10482                                            alc262_ignore);
10483         if (err < 0)
10484                 return err;
10485         if (!spec->autocfg.line_outs) {
10486                 if (spec->autocfg.dig_out_pin || spec->autocfg.dig_in_pin) {
10487                         spec->multiout.max_channels = 2;
10488                         spec->no_analog = 1;
10489                         goto dig_only;
10490                 }
10491                 return 0; /* can't find valid BIOS pin config */
10492         }
10493         err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
10494         if (err < 0)
10495                 return err;
10496         err = alc262_auto_create_analog_input_ctls(spec, &spec->autocfg);
10497         if (err < 0)
10498                 return err;
10499
10500         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
10501
10502  dig_only:
10503         if (spec->autocfg.dig_out_pin) {
10504                 spec->multiout.dig_out_nid = ALC262_DIGOUT_NID;
10505                 spec->dig_out_type = spec->autocfg.dig_out_type;
10506         }
10507         if (spec->autocfg.dig_in_pin)
10508                 spec->dig_in_nid = ALC262_DIGIN_NID;
10509
10510         if (spec->kctls.list)
10511                 add_mixer(spec, spec->kctls.list);
10512
10513         add_verb(spec, alc262_volume_init_verbs);
10514         spec->num_mux_defs = 1;
10515         spec->input_mux = &spec->private_imux;
10516
10517         err = alc_auto_add_mic_boost(codec);
10518         if (err < 0)
10519                 return err;
10520
10521         store_pin_configs(codec);
10522         return 1;
10523 }
10524
10525 #define alc262_auto_init_multi_out      alc882_auto_init_multi_out
10526 #define alc262_auto_init_hp_out         alc882_auto_init_hp_out
10527 #define alc262_auto_init_analog_input   alc882_auto_init_analog_input
10528 #define alc262_auto_init_input_src      alc882_auto_init_input_src
10529
10530
10531 /* init callback for auto-configuration model -- overriding the default init */
10532 static void alc262_auto_init(struct hda_codec *codec)
10533 {
10534         struct alc_spec *spec = codec->spec;
10535         alc262_auto_init_multi_out(codec);
10536         alc262_auto_init_hp_out(codec);
10537         alc262_auto_init_analog_input(codec);
10538         alc262_auto_init_input_src(codec);
10539         if (spec->unsol_event)
10540                 alc_inithook(codec);
10541 }
10542
10543 /*
10544  * configuration and preset
10545  */
10546 static const char *alc262_models[ALC262_MODEL_LAST] = {
10547         [ALC262_BASIC]          = "basic",
10548         [ALC262_HIPPO]          = "hippo",
10549         [ALC262_HIPPO_1]        = "hippo_1",
10550         [ALC262_FUJITSU]        = "fujitsu",
10551         [ALC262_HP_BPC]         = "hp-bpc",
10552         [ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000",
10553         [ALC262_HP_TC_T5735]    = "hp-tc-t5735",
10554         [ALC262_HP_RP5700]      = "hp-rp5700",
10555         [ALC262_BENQ_ED8]       = "benq",
10556         [ALC262_BENQ_T31]       = "benq-t31",
10557         [ALC262_SONY_ASSAMD]    = "sony-assamd",
10558         [ALC262_TOSHIBA_S06]    = "toshiba-s06",
10559         [ALC262_TOSHIBA_RX1]    = "toshiba-rx1",
10560         [ALC262_ULTRA]          = "ultra",
10561         [ALC262_LENOVO_3000]    = "lenovo-3000",
10562         [ALC262_NEC]            = "nec",
10563         [ALC262_AUTO]           = "auto",
10564 };
10565
10566 static struct snd_pci_quirk alc262_cfg_tbl[] = {
10567         SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
10568         SND_PCI_QUIRK(0x1033, 0x8895, "NEC Versa S9100", ALC262_NEC),
10569         SND_PCI_QUIRK(0x103c, 0x12fe, "HP xw9400", ALC262_HP_BPC),
10570         SND_PCI_QUIRK(0x103c, 0x12ff, "HP xw4550", ALC262_HP_BPC),
10571         SND_PCI_QUIRK(0x103c, 0x1306, "HP xw8600", ALC262_HP_BPC),
10572         SND_PCI_QUIRK(0x103c, 0x1307, "HP xw6600", ALC262_HP_BPC),
10573         SND_PCI_QUIRK(0x103c, 0x1308, "HP xw4600", ALC262_HP_BPC),
10574         SND_PCI_QUIRK(0x103c, 0x1309, "HP xw4*00", ALC262_HP_BPC),
10575         SND_PCI_QUIRK(0x103c, 0x130a, "HP xw6*00", ALC262_HP_BPC),
10576         SND_PCI_QUIRK(0x103c, 0x130b, "HP xw8*00", ALC262_HP_BPC),
10577         SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
10578         SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
10579         SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
10580         SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF),
10581         SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL),
10582         SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF),
10583         SND_PCI_QUIRK(0x103c, 0x2806, "HP D7000", ALC262_HP_BPC_D7000_WL),
10584         SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF),
10585         SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC),
10586         SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC),
10587         SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC),
10588         SND_PCI_QUIRK(0x103c, 0x302f, "HP Thin Client T5735",
10589                       ALC262_HP_TC_T5735),
10590         SND_PCI_QUIRK(0x103c, 0x2817, "HP RP5700", ALC262_HP_RP5700),
10591         SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10592         SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
10593         SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10594         SND_PCI_QUIRK(0x104d, 0x900e, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10595         SND_PCI_QUIRK(0x104d, 0x9015, "Sony 0x9015", ALC262_SONY_ASSAMD),
10596         SND_PCI_QUIRK(0x104d, 0x9033, "Sony VAIO VGN-SR19XN",
10597                       ALC262_SONY_ASSAMD),
10598         SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
10599                       ALC262_TOSHIBA_RX1),
10600         SND_PCI_QUIRK(0x1179, 0xff7b, "Toshiba S06", ALC262_TOSHIBA_S06),
10601         SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
10602         SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU),
10603         SND_PCI_QUIRK(0x144d, 0xc032, "Samsung Q1 Ultra", ALC262_ULTRA),
10604         SND_PCI_QUIRK(0x144d, 0xc039, "Samsung Q1U EL", ALC262_ULTRA),
10605         SND_PCI_QUIRK(0x144d, 0xc510, "Samsung Q45", ALC262_HIPPO),
10606         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 y410", ALC262_LENOVO_3000),
10607         SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
10608         SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
10609         SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
10610         {}
10611 };
10612
10613 static struct alc_config_preset alc262_presets[] = {
10614         [ALC262_BASIC] = {
10615                 .mixers = { alc262_base_mixer },
10616                 .init_verbs = { alc262_init_verbs },
10617                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10618                 .dac_nids = alc262_dac_nids,
10619                 .hp_nid = 0x03,
10620                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10621                 .channel_mode = alc262_modes,
10622                 .input_mux = &alc262_capture_source,
10623         },
10624         [ALC262_HIPPO] = {
10625                 .mixers = { alc262_base_mixer },
10626                 .init_verbs = { alc262_init_verbs, alc262_hippo_unsol_verbs},
10627                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10628                 .dac_nids = alc262_dac_nids,
10629                 .hp_nid = 0x03,
10630                 .dig_out_nid = ALC262_DIGOUT_NID,
10631                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10632                 .channel_mode = alc262_modes,
10633                 .input_mux = &alc262_capture_source,
10634                 .unsol_event = alc262_hippo_unsol_event,
10635                 .init_hook = alc262_hippo_automute,
10636         },
10637         [ALC262_HIPPO_1] = {
10638                 .mixers = { alc262_hippo1_mixer },
10639                 .init_verbs = { alc262_init_verbs, alc262_hippo1_unsol_verbs},
10640                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10641                 .dac_nids = alc262_dac_nids,
10642                 .hp_nid = 0x02,
10643                 .dig_out_nid = ALC262_DIGOUT_NID,
10644                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10645                 .channel_mode = alc262_modes,
10646                 .input_mux = &alc262_capture_source,
10647                 .unsol_event = alc262_hippo1_unsol_event,
10648                 .init_hook = alc262_hippo1_automute,
10649         },
10650         [ALC262_FUJITSU] = {
10651                 .mixers = { alc262_fujitsu_mixer },
10652                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
10653                                 alc262_fujitsu_unsol_verbs },
10654                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10655                 .dac_nids = alc262_dac_nids,
10656                 .hp_nid = 0x03,
10657                 .dig_out_nid = ALC262_DIGOUT_NID,
10658                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10659                 .channel_mode = alc262_modes,
10660                 .input_mux = &alc262_fujitsu_capture_source,
10661                 .unsol_event = alc262_fujitsu_unsol_event,
10662                 .init_hook = alc262_fujitsu_init_hook,
10663         },
10664         [ALC262_HP_BPC] = {
10665                 .mixers = { alc262_HP_BPC_mixer },
10666                 .init_verbs = { alc262_HP_BPC_init_verbs },
10667                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10668                 .dac_nids = alc262_dac_nids,
10669                 .hp_nid = 0x03,
10670                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10671                 .channel_mode = alc262_modes,
10672                 .input_mux = &alc262_HP_capture_source,
10673                 .unsol_event = alc262_hp_bpc_unsol_event,
10674                 .init_hook = alc262_hp_bpc_automute,
10675         },
10676         [ALC262_HP_BPC_D7000_WF] = {
10677                 .mixers = { alc262_HP_BPC_WildWest_mixer },
10678                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
10679                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10680                 .dac_nids = alc262_dac_nids,
10681                 .hp_nid = 0x03,
10682                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10683                 .channel_mode = alc262_modes,
10684                 .input_mux = &alc262_HP_D7000_capture_source,
10685                 .unsol_event = alc262_hp_wildwest_unsol_event,
10686                 .init_hook = alc262_hp_wildwest_automute,
10687         },
10688         [ALC262_HP_BPC_D7000_WL] = {
10689                 .mixers = { alc262_HP_BPC_WildWest_mixer,
10690                             alc262_HP_BPC_WildWest_option_mixer },
10691                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
10692                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10693                 .dac_nids = alc262_dac_nids,
10694                 .hp_nid = 0x03,
10695                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10696                 .channel_mode = alc262_modes,
10697                 .input_mux = &alc262_HP_D7000_capture_source,
10698                 .unsol_event = alc262_hp_wildwest_unsol_event,
10699                 .init_hook = alc262_hp_wildwest_automute,
10700         },
10701         [ALC262_HP_TC_T5735] = {
10702                 .mixers = { alc262_hp_t5735_mixer },
10703                 .init_verbs = { alc262_init_verbs, alc262_hp_t5735_verbs },
10704                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10705                 .dac_nids = alc262_dac_nids,
10706                 .hp_nid = 0x03,
10707                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10708                 .channel_mode = alc262_modes,
10709                 .input_mux = &alc262_capture_source,
10710                 .unsol_event = alc262_hp_t5735_unsol_event,
10711                 .init_hook = alc262_hp_t5735_init_hook,
10712         },
10713         [ALC262_HP_RP5700] = {
10714                 .mixers = { alc262_hp_rp5700_mixer },
10715                 .init_verbs = { alc262_init_verbs, alc262_hp_rp5700_verbs },
10716                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10717                 .dac_nids = alc262_dac_nids,
10718                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10719                 .channel_mode = alc262_modes,
10720                 .input_mux = &alc262_hp_rp5700_capture_source,
10721         },
10722         [ALC262_BENQ_ED8] = {
10723                 .mixers = { alc262_base_mixer },
10724                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs },
10725                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10726                 .dac_nids = alc262_dac_nids,
10727                 .hp_nid = 0x03,
10728                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10729                 .channel_mode = alc262_modes,
10730                 .input_mux = &alc262_capture_source,
10731         },
10732         [ALC262_SONY_ASSAMD] = {
10733                 .mixers = { alc262_sony_mixer },
10734                 .init_verbs = { alc262_init_verbs, alc262_sony_unsol_verbs},
10735                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10736                 .dac_nids = alc262_dac_nids,
10737                 .hp_nid = 0x02,
10738                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10739                 .channel_mode = alc262_modes,
10740                 .input_mux = &alc262_capture_source,
10741                 .unsol_event = alc262_hippo_unsol_event,
10742                 .init_hook = alc262_hippo_automute,
10743         },
10744         [ALC262_BENQ_T31] = {
10745                 .mixers = { alc262_benq_t31_mixer },
10746                 .init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs, alc262_hippo_unsol_verbs },
10747                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10748                 .dac_nids = alc262_dac_nids,
10749                 .hp_nid = 0x03,
10750                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10751                 .channel_mode = alc262_modes,
10752                 .input_mux = &alc262_capture_source,
10753                 .unsol_event = alc262_hippo_unsol_event,
10754                 .init_hook = alc262_hippo_automute,
10755         },
10756         [ALC262_ULTRA] = {
10757                 .mixers = { alc262_ultra_mixer },
10758                 .cap_mixer = alc262_ultra_capture_mixer,
10759                 .init_verbs = { alc262_ultra_verbs },
10760                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10761                 .dac_nids = alc262_dac_nids,
10762                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10763                 .channel_mode = alc262_modes,
10764                 .input_mux = &alc262_ultra_capture_source,
10765                 .adc_nids = alc262_adc_nids, /* ADC0 */
10766                 .capsrc_nids = alc262_capsrc_nids,
10767                 .num_adc_nids = 1, /* single ADC */
10768                 .unsol_event = alc262_ultra_unsol_event,
10769                 .init_hook = alc262_ultra_automute,
10770         },
10771         [ALC262_LENOVO_3000] = {
10772                 .mixers = { alc262_lenovo_3000_mixer },
10773                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
10774                                 alc262_lenovo_3000_unsol_verbs },
10775                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10776                 .dac_nids = alc262_dac_nids,
10777                 .hp_nid = 0x03,
10778                 .dig_out_nid = ALC262_DIGOUT_NID,
10779                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10780                 .channel_mode = alc262_modes,
10781                 .input_mux = &alc262_fujitsu_capture_source,
10782                 .unsol_event = alc262_lenovo_3000_unsol_event,
10783         },
10784         [ALC262_NEC] = {
10785                 .mixers = { alc262_nec_mixer },
10786                 .init_verbs = { alc262_nec_verbs },
10787                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10788                 .dac_nids = alc262_dac_nids,
10789                 .hp_nid = 0x03,
10790                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10791                 .channel_mode = alc262_modes,
10792                 .input_mux = &alc262_capture_source,
10793         },
10794         [ALC262_TOSHIBA_S06] = {
10795                 .mixers = { alc262_toshiba_s06_mixer },
10796                 .init_verbs = { alc262_init_verbs, alc262_toshiba_s06_verbs,
10797                                                         alc262_eapd_verbs },
10798                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10799                 .capsrc_nids = alc262_dmic_capsrc_nids,
10800                 .dac_nids = alc262_dac_nids,
10801                 .adc_nids = alc262_dmic_adc_nids, /* ADC0 */
10802                 .dig_out_nid = ALC262_DIGOUT_NID,
10803                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10804                 .channel_mode = alc262_modes,
10805                 .input_mux = &alc262_dmic_capture_source,
10806                 .unsol_event = alc262_toshiba_s06_unsol_event,
10807                 .init_hook = alc262_toshiba_s06_init_hook,
10808         },
10809         [ALC262_TOSHIBA_RX1] = {
10810                 .mixers = { alc262_toshiba_rx1_mixer },
10811                 .init_verbs = { alc262_init_verbs, alc262_toshiba_rx1_unsol_verbs },
10812                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10813                 .dac_nids = alc262_dac_nids,
10814                 .hp_nid = 0x03,
10815                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10816                 .channel_mode = alc262_modes,
10817                 .input_mux = &alc262_capture_source,
10818                 .unsol_event = alc262_hippo_unsol_event,
10819                 .init_hook = alc262_hippo_automute,
10820         },
10821 };
10822
10823 static int patch_alc262(struct hda_codec *codec)
10824 {
10825         struct alc_spec *spec;
10826         int board_config;
10827         int err;
10828
10829         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
10830         if (spec == NULL)
10831                 return -ENOMEM;
10832
10833         codec->spec = spec;
10834 #if 0
10835         /* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is
10836          * under-run
10837          */
10838         {
10839         int tmp;
10840         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
10841         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
10842         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
10843         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
10844         }
10845 #endif
10846
10847         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
10848
10849         board_config = snd_hda_check_board_config(codec, ALC262_MODEL_LAST,
10850                                                   alc262_models,
10851                                                   alc262_cfg_tbl);
10852
10853         if (board_config < 0) {
10854                 printk(KERN_INFO "hda_codec: Unknown model for ALC262, "
10855                        "trying auto-probe from BIOS...\n");
10856                 board_config = ALC262_AUTO;
10857         }
10858
10859         if (board_config == ALC262_AUTO) {
10860                 /* automatic parse from the BIOS config */
10861                 err = alc262_parse_auto_config(codec);
10862                 if (err < 0) {
10863                         alc_free(codec);
10864                         return err;
10865                 } else if (!err) {
10866                         printk(KERN_INFO
10867                                "hda_codec: Cannot set up configuration "
10868                                "from BIOS.  Using base mode...\n");
10869                         board_config = ALC262_BASIC;
10870                 }
10871         }
10872
10873         if (board_config != ALC262_AUTO)
10874                 setup_preset(spec, &alc262_presets[board_config]);
10875
10876         spec->stream_name_analog = "ALC262 Analog";
10877         spec->stream_analog_playback = &alc262_pcm_analog_playback;
10878         spec->stream_analog_capture = &alc262_pcm_analog_capture;
10879
10880         spec->stream_name_digital = "ALC262 Digital";
10881         spec->stream_digital_playback = &alc262_pcm_digital_playback;
10882         spec->stream_digital_capture = &alc262_pcm_digital_capture;
10883
10884         spec->is_mix_capture = 1;
10885         if (!spec->adc_nids && spec->input_mux) {
10886                 /* check whether NID 0x07 is valid */
10887                 unsigned int wcap = get_wcaps(codec, 0x07);
10888
10889                 /* get type */
10890                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
10891                 if (wcap != AC_WID_AUD_IN) {
10892                         spec->adc_nids = alc262_adc_nids_alt;
10893                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids_alt);
10894                         spec->capsrc_nids = alc262_capsrc_nids_alt;
10895                 } else {
10896                         spec->adc_nids = alc262_adc_nids;
10897                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids);
10898                         spec->capsrc_nids = alc262_capsrc_nids;
10899                 }
10900         }
10901         if (!spec->cap_mixer && !spec->no_analog)
10902                 set_capture_mixer(spec);
10903
10904         spec->vmaster_nid = 0x0c;
10905
10906         codec->patch_ops = alc_patch_ops;
10907         if (board_config == ALC262_AUTO)
10908                 spec->init_hook = alc262_auto_init;
10909 #ifdef CONFIG_SND_HDA_POWER_SAVE
10910         if (!spec->loopback.amplist)
10911                 spec->loopback.amplist = alc262_loopbacks;
10912 #endif
10913         codec->proc_widget_hook = print_realtek_coef;
10914
10915         return 0;
10916 }
10917
10918 /*
10919  *  ALC268 channel source setting (2 channel)
10920  */
10921 #define ALC268_DIGOUT_NID       ALC880_DIGOUT_NID
10922 #define alc268_modes            alc260_modes
10923
10924 static hda_nid_t alc268_dac_nids[2] = {
10925         /* front, hp */
10926         0x02, 0x03
10927 };
10928
10929 static hda_nid_t alc268_adc_nids[2] = {
10930         /* ADC0-1 */
10931         0x08, 0x07
10932 };
10933
10934 static hda_nid_t alc268_adc_nids_alt[1] = {
10935         /* ADC0 */
10936         0x08
10937 };
10938
10939 static hda_nid_t alc268_capsrc_nids[2] = { 0x23, 0x24 };
10940
10941 static struct snd_kcontrol_new alc268_base_mixer[] = {
10942         /* output mixer control */
10943         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
10944         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10945         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
10946         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10947         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10948         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10949         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
10950         { }
10951 };
10952
10953 /* bind Beep switches of both NID 0x0f and 0x10 */
10954 static struct hda_bind_ctls alc268_bind_beep_sw = {
10955         .ops = &snd_hda_bind_sw,
10956         .values = {
10957                 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
10958                 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
10959                 0
10960         },
10961 };
10962
10963 static struct snd_kcontrol_new alc268_beep_mixer[] = {
10964         HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
10965         HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
10966         { }
10967 };
10968
10969 static struct hda_verb alc268_eapd_verbs[] = {
10970         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
10971         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
10972         { }
10973 };
10974
10975 /* Toshiba specific */
10976 #define alc268_toshiba_automute alc262_hippo_automute
10977
10978 static struct hda_verb alc268_toshiba_verbs[] = {
10979         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10980         { } /* end */
10981 };
10982
10983 static struct hda_input_mux alc268_acer_lc_capture_source = {
10984         .num_items = 2,
10985         .items = {
10986                 { "i-Mic", 0x6 },
10987                 { "E-Mic", 0x0 },
10988         },
10989 };
10990
10991 /* Acer specific */
10992 /* bind volumes of both NID 0x02 and 0x03 */
10993 static struct hda_bind_ctls alc268_acer_bind_master_vol = {
10994         .ops = &snd_hda_bind_vol,
10995         .values = {
10996                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
10997                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
10998                 0
10999         },
11000 };
11001
11002 /* mute/unmute internal speaker according to the hp jack and mute state */
11003 static void alc268_acer_automute(struct hda_codec *codec, int force)
11004 {
11005         struct alc_spec *spec = codec->spec;
11006         unsigned int mute;
11007
11008         if (force || !spec->sense_updated) {
11009                 unsigned int present;
11010                 present = snd_hda_codec_read(codec, 0x14, 0,
11011                                          AC_VERB_GET_PIN_SENSE, 0);
11012                 spec->jack_present = (present & 0x80000000) != 0;
11013                 spec->sense_updated = 1;
11014         }
11015         if (spec->jack_present)
11016                 mute = HDA_AMP_MUTE; /* mute internal speaker */
11017         else /* unmute internal speaker if necessary */
11018                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
11019         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
11020                                  HDA_AMP_MUTE, mute);
11021 }
11022
11023
11024 /* bind hp and internal speaker mute (with plug check) */
11025 static int alc268_acer_master_sw_put(struct snd_kcontrol *kcontrol,
11026                                      struct snd_ctl_elem_value *ucontrol)
11027 {
11028         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
11029         long *valp = ucontrol->value.integer.value;
11030         int change;
11031
11032         change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
11033                                           HDA_AMP_MUTE,
11034                                           valp[0] ? 0 : HDA_AMP_MUTE);
11035         change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
11036                                            HDA_AMP_MUTE,
11037                                            valp[1] ? 0 : HDA_AMP_MUTE);
11038         if (change)
11039                 alc268_acer_automute(codec, 0);
11040         return change;
11041 }
11042
11043 static struct snd_kcontrol_new alc268_acer_aspire_one_mixer[] = {
11044         /* output mixer control */
11045         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11046         {
11047                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11048                 .name = "Master Playback Switch",
11049                 .info = snd_hda_mixer_amp_switch_info,
11050                 .get = snd_hda_mixer_amp_switch_get,
11051                 .put = alc268_acer_master_sw_put,
11052                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11053         },
11054         HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x18, 0, HDA_INPUT),
11055         { }
11056 };
11057
11058 static struct snd_kcontrol_new alc268_acer_mixer[] = {
11059         /* output mixer control */
11060         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11061         {
11062                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11063                 .name = "Master Playback Switch",
11064                 .info = snd_hda_mixer_amp_switch_info,
11065                 .get = snd_hda_mixer_amp_switch_get,
11066                 .put = alc268_acer_master_sw_put,
11067                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11068         },
11069         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11070         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
11071         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11072         { }
11073 };
11074
11075 static struct snd_kcontrol_new alc268_acer_dmic_mixer[] = {
11076         /* output mixer control */
11077         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11078         {
11079                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11080                 .name = "Master Playback Switch",
11081                 .info = snd_hda_mixer_amp_switch_info,
11082                 .get = snd_hda_mixer_amp_switch_get,
11083                 .put = alc268_acer_master_sw_put,
11084                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11085         },
11086         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11087         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11088         { }
11089 };
11090
11091 static struct hda_verb alc268_acer_aspire_one_verbs[] = {
11092         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11093         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11094         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11095         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
11096         {0x23, AC_VERB_SET_CONNECT_SEL, 0x06},
11097         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, 0xa017},
11098         { }
11099 };
11100
11101 static struct hda_verb alc268_acer_verbs[] = {
11102         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* internal dmic? */
11103         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11104         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11105         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11106         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11107         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11108         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11109         { }
11110 };
11111
11112 /* unsolicited event for HP jack sensing */
11113 static void alc268_toshiba_unsol_event(struct hda_codec *codec,
11114                                        unsigned int res)
11115 {
11116         if ((res >> 26) != ALC880_HP_EVENT)
11117                 return;
11118         alc268_toshiba_automute(codec);
11119 }
11120
11121 static void alc268_acer_unsol_event(struct hda_codec *codec,
11122                                        unsigned int res)
11123 {
11124         if ((res >> 26) != ALC880_HP_EVENT)
11125                 return;
11126         alc268_acer_automute(codec, 1);
11127 }
11128
11129 static void alc268_acer_init_hook(struct hda_codec *codec)
11130 {
11131         alc268_acer_automute(codec, 1);
11132 }
11133
11134 /* toggle speaker-output according to the hp-jack state */
11135 static void alc268_aspire_one_speaker_automute(struct hda_codec *codec)
11136 {
11137         unsigned int present;
11138         unsigned char bits;
11139
11140         present = snd_hda_codec_read(codec, 0x15, 0,
11141                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11142         bits = present ? AMP_IN_MUTE(0) : 0;
11143         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 0,
11144                                 AMP_IN_MUTE(0), bits);
11145         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 1,
11146                                 AMP_IN_MUTE(0), bits);
11147 }
11148
11149
11150 static void alc268_acer_mic_automute(struct hda_codec *codec)
11151 {
11152         unsigned int present;
11153
11154         present = snd_hda_codec_read(codec, 0x18, 0,
11155                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11156         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_CONNECT_SEL,
11157                             present ? 0x0 : 0x6);
11158 }
11159
11160 static void alc268_acer_lc_unsol_event(struct hda_codec *codec,
11161                                     unsigned int res)
11162 {
11163         if ((res >> 26) == ALC880_HP_EVENT)
11164                 alc268_aspire_one_speaker_automute(codec);
11165         if ((res >> 26) == ALC880_MIC_EVENT)
11166                 alc268_acer_mic_automute(codec);
11167 }
11168
11169 static void alc268_acer_lc_init_hook(struct hda_codec *codec)
11170 {
11171         alc268_aspire_one_speaker_automute(codec);
11172         alc268_acer_mic_automute(codec);
11173 }
11174
11175 static struct snd_kcontrol_new alc268_dell_mixer[] = {
11176         /* output mixer control */
11177         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11178         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11179         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
11180         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11181         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11182         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
11183         { }
11184 };
11185
11186 static struct hda_verb alc268_dell_verbs[] = {
11187         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11188         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11189         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11190         { }
11191 };
11192
11193 /* mute/unmute internal speaker according to the hp jack and mute state */
11194 static void alc268_dell_automute(struct hda_codec *codec)
11195 {
11196         unsigned int present;
11197         unsigned int mute;
11198
11199         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0);
11200         if (present & 0x80000000)
11201                 mute = HDA_AMP_MUTE;
11202         else
11203                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
11204         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
11205                                  HDA_AMP_MUTE, mute);
11206 }
11207
11208 static void alc268_dell_unsol_event(struct hda_codec *codec,
11209                                     unsigned int res)
11210 {
11211         if ((res >> 26) != ALC880_HP_EVENT)
11212                 return;
11213         alc268_dell_automute(codec);
11214 }
11215
11216 #define alc268_dell_init_hook   alc268_dell_automute
11217
11218 static struct snd_kcontrol_new alc267_quanta_il1_mixer[] = {
11219         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x2, 0x0, HDA_OUTPUT),
11220         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11221         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
11222         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11223         HDA_CODEC_VOLUME("Mic Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11224         HDA_BIND_MUTE("Mic Capture Switch", 0x23, 2, HDA_OUTPUT),
11225         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
11226         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
11227         { }
11228 };
11229
11230 static struct hda_verb alc267_quanta_il1_verbs[] = {
11231         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11232         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
11233         { }
11234 };
11235
11236 static void alc267_quanta_il1_hp_automute(struct hda_codec *codec)
11237 {
11238         unsigned int present;
11239
11240         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
11241                 & AC_PINSENSE_PRESENCE;
11242         snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
11243                             present ? 0 : PIN_OUT);
11244 }
11245
11246 static void alc267_quanta_il1_mic_automute(struct hda_codec *codec)
11247 {
11248         unsigned int present;
11249
11250         present = snd_hda_codec_read(codec, 0x18, 0,
11251                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11252         snd_hda_codec_write(codec, 0x23, 0,
11253                             AC_VERB_SET_CONNECT_SEL,
11254                             present ? 0x00 : 0x01);
11255 }
11256
11257 static void alc267_quanta_il1_automute(struct hda_codec *codec)
11258 {
11259         alc267_quanta_il1_hp_automute(codec);
11260         alc267_quanta_il1_mic_automute(codec);
11261 }
11262
11263 static void alc267_quanta_il1_unsol_event(struct hda_codec *codec,
11264                                            unsigned int res)
11265 {
11266         switch (res >> 26) {
11267         case ALC880_HP_EVENT:
11268                 alc267_quanta_il1_hp_automute(codec);
11269                 break;
11270         case ALC880_MIC_EVENT:
11271                 alc267_quanta_il1_mic_automute(codec);
11272                 break;
11273         }
11274 }
11275
11276 /*
11277  * generic initialization of ADC, input mixers and output mixers
11278  */
11279 static struct hda_verb alc268_base_init_verbs[] = {
11280         /* Unmute DAC0-1 and set vol = 0 */
11281         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11282         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11283
11284         /*
11285          * Set up output mixers (0x0c - 0x0e)
11286          */
11287         /* set vol=0 to output mixers */
11288         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11289         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
11290
11291         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11292         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11293
11294         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
11295         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
11296         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
11297         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11298         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11299         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11300         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11301         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11302
11303         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11304         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11305         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11306         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11307         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11308
11309         /* set PCBEEP vol = 0, mute connections */
11310         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11311         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11312         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11313
11314         /* Unmute Selector 23h,24h and set the default input to mic-in */
11315
11316         {0x23, AC_VERB_SET_CONNECT_SEL, 0x00},
11317         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11318         {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
11319         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11320
11321         { }
11322 };
11323
11324 /*
11325  * generic initialization of ADC, input mixers and output mixers
11326  */
11327 static struct hda_verb alc268_volume_init_verbs[] = {
11328         /* set output DAC */
11329         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11330         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11331
11332         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11333         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11334         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11335         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11336         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11337
11338         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11339         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11340         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11341
11342         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11343         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11344
11345         /* set PCBEEP vol = 0, mute connections */
11346         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11347         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11348         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11349
11350         { }
11351 };
11352
11353 static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
11354         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11355         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
11356         {
11357                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11358                 /* The multiple "Capture Source" controls confuse alsamixer
11359                  * So call somewhat different..
11360                  */
11361                 /* .name = "Capture Source", */
11362                 .name = "Input Source",
11363                 .count = 1,
11364                 .info = alc_mux_enum_info,
11365                 .get = alc_mux_enum_get,
11366                 .put = alc_mux_enum_put,
11367         },
11368         { } /* end */
11369 };
11370
11371 static struct snd_kcontrol_new alc268_capture_mixer[] = {
11372         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11373         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
11374         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
11375         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
11376         {
11377                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11378                 /* The multiple "Capture Source" controls confuse alsamixer
11379                  * So call somewhat different..
11380                  */
11381                 /* .name = "Capture Source", */
11382                 .name = "Input Source",
11383                 .count = 2,
11384                 .info = alc_mux_enum_info,
11385                 .get = alc_mux_enum_get,
11386                 .put = alc_mux_enum_put,
11387         },
11388         { } /* end */
11389 };
11390
11391 static struct hda_input_mux alc268_capture_source = {
11392         .num_items = 4,
11393         .items = {
11394                 { "Mic", 0x0 },
11395                 { "Front Mic", 0x1 },
11396                 { "Line", 0x2 },
11397                 { "CD", 0x3 },
11398         },
11399 };
11400
11401 static struct hda_input_mux alc268_acer_capture_source = {
11402         .num_items = 3,
11403         .items = {
11404                 { "Mic", 0x0 },
11405                 { "Internal Mic", 0x1 },
11406                 { "Line", 0x2 },
11407         },
11408 };
11409
11410 static struct hda_input_mux alc268_acer_dmic_capture_source = {
11411         .num_items = 3,
11412         .items = {
11413                 { "Mic", 0x0 },
11414                 { "Internal Mic", 0x6 },
11415                 { "Line", 0x2 },
11416         },
11417 };
11418
11419 #ifdef CONFIG_SND_DEBUG
11420 static struct snd_kcontrol_new alc268_test_mixer[] = {
11421         /* Volume widgets */
11422         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11423         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x03, 0x0, HDA_OUTPUT),
11424         HDA_BIND_MUTE_MONO("Mono sum Playback Switch", 0x0e, 1, 2, HDA_INPUT),
11425         HDA_BIND_MUTE("LINE-OUT sum Playback Switch", 0x0f, 2, HDA_INPUT),
11426         HDA_BIND_MUTE("HP-OUT sum Playback Switch", 0x10, 2, HDA_INPUT),
11427         HDA_BIND_MUTE("LINE-OUT Playback Switch", 0x14, 2, HDA_OUTPUT),
11428         HDA_BIND_MUTE("HP-OUT Playback Switch", 0x15, 2, HDA_OUTPUT),
11429         HDA_BIND_MUTE("Mono Playback Switch", 0x16, 2, HDA_OUTPUT),
11430         HDA_CODEC_VOLUME("MIC1 Capture Volume", 0x18, 0x0, HDA_INPUT),
11431         HDA_BIND_MUTE("MIC1 Capture Switch", 0x18, 2, HDA_OUTPUT),
11432         HDA_CODEC_VOLUME("MIC2 Capture Volume", 0x19, 0x0, HDA_INPUT),
11433         HDA_CODEC_VOLUME("LINE1 Capture Volume", 0x1a, 0x0, HDA_INPUT),
11434         HDA_BIND_MUTE("LINE1 Capture Switch", 0x1a, 2, HDA_OUTPUT),
11435         /* The below appears problematic on some hardwares */
11436         /*HDA_CODEC_VOLUME("PCBEEP Playback Volume", 0x1d, 0x0, HDA_INPUT),*/
11437         HDA_CODEC_VOLUME("PCM-IN1 Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11438         HDA_BIND_MUTE("PCM-IN1 Capture Switch", 0x23, 2, HDA_OUTPUT),
11439         HDA_CODEC_VOLUME("PCM-IN2 Capture Volume", 0x24, 0x0, HDA_OUTPUT),
11440         HDA_BIND_MUTE("PCM-IN2 Capture Switch", 0x24, 2, HDA_OUTPUT),
11441
11442         /* Modes for retasking pin widgets */
11443         ALC_PIN_MODE("LINE-OUT pin mode", 0x14, ALC_PIN_DIR_INOUT),
11444         ALC_PIN_MODE("HP-OUT pin mode", 0x15, ALC_PIN_DIR_INOUT),
11445         ALC_PIN_MODE("MIC1 pin mode", 0x18, ALC_PIN_DIR_INOUT),
11446         ALC_PIN_MODE("LINE1 pin mode", 0x1a, ALC_PIN_DIR_INOUT),
11447
11448         /* Controls for GPIO pins, assuming they are configured as outputs */
11449         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
11450         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
11451         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
11452         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
11453
11454         /* Switches to allow the digital SPDIF output pin to be enabled.
11455          * The ALC268 does not have an SPDIF input.
11456          */
11457         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x06, 0x01),
11458
11459         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
11460          * this output to turn on an external amplifier.
11461          */
11462         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
11463         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
11464
11465         { } /* end */
11466 };
11467 #endif
11468
11469 /* create input playback/capture controls for the given pin */
11470 static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
11471                                     const char *ctlname, int idx)
11472 {
11473         char name[32];
11474         int err;
11475
11476         sprintf(name, "%s Playback Volume", ctlname);
11477         if (nid == 0x14) {
11478                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
11479                                   HDA_COMPOSE_AMP_VAL(0x02, 3, idx,
11480                                                       HDA_OUTPUT));
11481                 if (err < 0)
11482                         return err;
11483         } else if (nid == 0x15) {
11484                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
11485                                   HDA_COMPOSE_AMP_VAL(0x03, 3, idx,
11486                                                       HDA_OUTPUT));
11487                 if (err < 0)
11488                         return err;
11489         } else
11490                 return -1;
11491         sprintf(name, "%s Playback Switch", ctlname);
11492         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
11493                           HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
11494         if (err < 0)
11495                 return err;
11496         return 0;
11497 }
11498
11499 /* add playback controls from the parsed DAC table */
11500 static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
11501                                              const struct auto_pin_cfg *cfg)
11502 {
11503         hda_nid_t nid;
11504         int err;
11505
11506         spec->multiout.num_dacs = 2;    /* only use one dac */
11507         spec->multiout.dac_nids = spec->private_dac_nids;
11508         spec->multiout.dac_nids[0] = 2;
11509         spec->multiout.dac_nids[1] = 3;
11510
11511         nid = cfg->line_out_pins[0];
11512         if (nid)
11513                 alc268_new_analog_output(spec, nid, "Front", 0);
11514
11515         nid = cfg->speaker_pins[0];
11516         if (nid == 0x1d) {
11517                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
11518                                   "Speaker Playback Volume",
11519                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
11520                 if (err < 0)
11521                         return err;
11522         }
11523         nid = cfg->hp_pins[0];
11524         if (nid)
11525                 alc268_new_analog_output(spec, nid, "Headphone", 0);
11526
11527         nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
11528         if (nid == 0x16) {
11529                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11530                                   "Mono Playback Switch",
11531                                   HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_INPUT));
11532                 if (err < 0)
11533                         return err;
11534         }
11535         return 0;
11536 }
11537
11538 /* create playback/capture controls for input pins */
11539 static int alc268_auto_create_analog_input_ctls(struct alc_spec *spec,
11540                                                 const struct auto_pin_cfg *cfg)
11541 {
11542         struct hda_input_mux *imux = &spec->private_imux;
11543         int i, idx1;
11544
11545         for (i = 0; i < AUTO_PIN_LAST; i++) {
11546                 switch(cfg->input_pins[i]) {
11547                 case 0x18:
11548                         idx1 = 0;       /* Mic 1 */
11549                         break;
11550                 case 0x19:
11551                         idx1 = 1;       /* Mic 2 */
11552                         break;
11553                 case 0x1a:
11554                         idx1 = 2;       /* Line In */
11555                         break;
11556                 case 0x1c:
11557                         idx1 = 3;       /* CD */
11558                         break;
11559                 case 0x12:
11560                 case 0x13:
11561                         idx1 = 6;       /* digital mics */
11562                         break;
11563                 default:
11564                         continue;
11565                 }
11566                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
11567                 imux->items[imux->num_items].index = idx1;
11568                 imux->num_items++;
11569         }
11570         return 0;
11571 }
11572
11573 static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
11574 {
11575         struct alc_spec *spec = codec->spec;
11576         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
11577         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
11578         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
11579         unsigned int    dac_vol1, dac_vol2;
11580
11581         if (speaker_nid) {
11582                 snd_hda_codec_write(codec, speaker_nid, 0,
11583                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
11584                 snd_hda_codec_write(codec, 0x0f, 0,
11585                                     AC_VERB_SET_AMP_GAIN_MUTE,
11586                                     AMP_IN_UNMUTE(1));
11587                 snd_hda_codec_write(codec, 0x10, 0,
11588                                     AC_VERB_SET_AMP_GAIN_MUTE,
11589                                     AMP_IN_UNMUTE(1));
11590         } else {
11591                 snd_hda_codec_write(codec, 0x0f, 0,
11592                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
11593                 snd_hda_codec_write(codec, 0x10, 0,
11594                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
11595         }
11596
11597         dac_vol1 = dac_vol2 = 0xb000 | 0x40;    /* set max volume  */
11598         if (line_nid == 0x14)
11599                 dac_vol2 = AMP_OUT_ZERO;
11600         else if (line_nid == 0x15)
11601                 dac_vol1 = AMP_OUT_ZERO;
11602         if (hp_nid == 0x14)
11603                 dac_vol2 = AMP_OUT_ZERO;
11604         else if (hp_nid == 0x15)
11605                 dac_vol1 = AMP_OUT_ZERO;
11606         if (line_nid != 0x16 || hp_nid != 0x16 ||
11607             spec->autocfg.line_out_pins[1] != 0x16 ||
11608             spec->autocfg.line_out_pins[2] != 0x16)
11609                 dac_vol1 = dac_vol2 = AMP_OUT_ZERO;
11610
11611         snd_hda_codec_write(codec, 0x02, 0,
11612                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol1);
11613         snd_hda_codec_write(codec, 0x03, 0,
11614                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol2);
11615 }
11616
11617 /* pcm configuration: identiacal with ALC880 */
11618 #define alc268_pcm_analog_playback      alc880_pcm_analog_playback
11619 #define alc268_pcm_analog_capture       alc880_pcm_analog_capture
11620 #define alc268_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
11621 #define alc268_pcm_digital_playback     alc880_pcm_digital_playback
11622
11623 /*
11624  * BIOS auto configuration
11625  */
11626 static int alc268_parse_auto_config(struct hda_codec *codec)
11627 {
11628         struct alc_spec *spec = codec->spec;
11629         int err;
11630         static hda_nid_t alc268_ignore[] = { 0 };
11631
11632         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
11633                                            alc268_ignore);
11634         if (err < 0)
11635                 return err;
11636         if (!spec->autocfg.line_outs)
11637                 return 0; /* can't find valid BIOS pin config */
11638
11639         err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
11640         if (err < 0)
11641                 return err;
11642         err = alc268_auto_create_analog_input_ctls(spec, &spec->autocfg);
11643         if (err < 0)
11644                 return err;
11645
11646         spec->multiout.max_channels = 2;
11647
11648         /* digital only support output */
11649         if (spec->autocfg.dig_out_pin)
11650                 spec->multiout.dig_out_nid = ALC268_DIGOUT_NID;
11651
11652         if (spec->kctls.list)
11653                 add_mixer(spec, spec->kctls.list);
11654
11655         if (spec->autocfg.speaker_pins[0] != 0x1d)
11656                 add_mixer(spec, alc268_beep_mixer);
11657
11658         add_verb(spec, alc268_volume_init_verbs);
11659         spec->num_mux_defs = 1;
11660         spec->input_mux = &spec->private_imux;
11661
11662         err = alc_auto_add_mic_boost(codec);
11663         if (err < 0)
11664                 return err;
11665
11666         store_pin_configs(codec);
11667         return 1;
11668 }
11669
11670 #define alc268_auto_init_multi_out      alc882_auto_init_multi_out
11671 #define alc268_auto_init_hp_out         alc882_auto_init_hp_out
11672 #define alc268_auto_init_analog_input   alc882_auto_init_analog_input
11673
11674 /* init callback for auto-configuration model -- overriding the default init */
11675 static void alc268_auto_init(struct hda_codec *codec)
11676 {
11677         struct alc_spec *spec = codec->spec;
11678         alc268_auto_init_multi_out(codec);
11679         alc268_auto_init_hp_out(codec);
11680         alc268_auto_init_mono_speaker_out(codec);
11681         alc268_auto_init_analog_input(codec);
11682         if (spec->unsol_event)
11683                 alc_inithook(codec);
11684 }
11685
11686 /*
11687  * configuration and preset
11688  */
11689 static const char *alc268_models[ALC268_MODEL_LAST] = {
11690         [ALC267_QUANTA_IL1]     = "quanta-il1",
11691         [ALC268_3ST]            = "3stack",
11692         [ALC268_TOSHIBA]        = "toshiba",
11693         [ALC268_ACER]           = "acer",
11694         [ALC268_ACER_DMIC]      = "acer-dmic",
11695         [ALC268_ACER_ASPIRE_ONE]        = "acer-aspire",
11696         [ALC268_DELL]           = "dell",
11697         [ALC268_ZEPTO]          = "zepto",
11698 #ifdef CONFIG_SND_DEBUG
11699         [ALC268_TEST]           = "test",
11700 #endif
11701         [ALC268_AUTO]           = "auto",
11702 };
11703
11704 static struct snd_pci_quirk alc268_cfg_tbl[] = {
11705         SND_PCI_QUIRK(0x1025, 0x011e, "Acer Aspire 5720z", ALC268_ACER),
11706         SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
11707         SND_PCI_QUIRK(0x1025, 0x012e, "Acer Aspire 5310", ALC268_ACER),
11708         SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
11709         SND_PCI_QUIRK(0x1025, 0x0136, "Acer Aspire 5315", ALC268_ACER),
11710         SND_PCI_QUIRK(0x1025, 0x015b, "Acer Aspire One",
11711                                                 ALC268_ACER_ASPIRE_ONE),
11712         SND_PCI_QUIRK(0x1028, 0x0253, "Dell OEM", ALC268_DELL),
11713         SND_PCI_QUIRK(0x1028, 0x02b0, "Dell Inspiron Mini9", ALC268_DELL),
11714         SND_PCI_QUIRK(0x103c, 0x30cc, "TOSHIBA", ALC268_TOSHIBA),
11715         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
11716         SND_PCI_QUIRK(0x1179, 0xff10, "TOSHIBA A205", ALC268_TOSHIBA),
11717         SND_PCI_QUIRK(0x1179, 0xff50, "TOSHIBA A305", ALC268_TOSHIBA),
11718         SND_PCI_QUIRK(0x1179, 0xff64, "TOSHIBA L305", ALC268_TOSHIBA),
11719         SND_PCI_QUIRK(0x14c0, 0x0025, "COMPAL IFL90/JFL-92", ALC268_TOSHIBA),
11720         SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER),
11721         SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1),
11722         SND_PCI_QUIRK(0x1170, 0x0040, "ZEPTO", ALC268_ZEPTO),
11723         {}
11724 };
11725
11726 static struct alc_config_preset alc268_presets[] = {
11727         [ALC267_QUANTA_IL1] = {
11728                 .mixers = { alc267_quanta_il1_mixer },
11729                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11730                                 alc267_quanta_il1_verbs },
11731                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11732                 .dac_nids = alc268_dac_nids,
11733                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11734                 .adc_nids = alc268_adc_nids_alt,
11735                 .hp_nid = 0x03,
11736                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11737                 .channel_mode = alc268_modes,
11738                 .input_mux = &alc268_capture_source,
11739                 .unsol_event = alc267_quanta_il1_unsol_event,
11740                 .init_hook = alc267_quanta_il1_automute,
11741         },
11742         [ALC268_3ST] = {
11743                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
11744                             alc268_beep_mixer },
11745                 .init_verbs = { alc268_base_init_verbs },
11746                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11747                 .dac_nids = alc268_dac_nids,
11748                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11749                 .adc_nids = alc268_adc_nids_alt,
11750                 .capsrc_nids = alc268_capsrc_nids,
11751                 .hp_nid = 0x03,
11752                 .dig_out_nid = ALC268_DIGOUT_NID,
11753                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11754                 .channel_mode = alc268_modes,
11755                 .input_mux = &alc268_capture_source,
11756         },
11757         [ALC268_TOSHIBA] = {
11758                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
11759                             alc268_beep_mixer },
11760                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11761                                 alc268_toshiba_verbs },
11762                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11763                 .dac_nids = alc268_dac_nids,
11764                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11765                 .adc_nids = alc268_adc_nids_alt,
11766                 .capsrc_nids = alc268_capsrc_nids,
11767                 .hp_nid = 0x03,
11768                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11769                 .channel_mode = alc268_modes,
11770                 .input_mux = &alc268_capture_source,
11771                 .unsol_event = alc268_toshiba_unsol_event,
11772                 .init_hook = alc268_toshiba_automute,
11773         },
11774         [ALC268_ACER] = {
11775                 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer,
11776                             alc268_beep_mixer },
11777                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11778                                 alc268_acer_verbs },
11779                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11780                 .dac_nids = alc268_dac_nids,
11781                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11782                 .adc_nids = alc268_adc_nids_alt,
11783                 .capsrc_nids = alc268_capsrc_nids,
11784                 .hp_nid = 0x02,
11785                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11786                 .channel_mode = alc268_modes,
11787                 .input_mux = &alc268_acer_capture_source,
11788                 .unsol_event = alc268_acer_unsol_event,
11789                 .init_hook = alc268_acer_init_hook,
11790         },
11791         [ALC268_ACER_DMIC] = {
11792                 .mixers = { alc268_acer_dmic_mixer, alc268_capture_alt_mixer,
11793                             alc268_beep_mixer },
11794                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11795                                 alc268_acer_verbs },
11796                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11797                 .dac_nids = alc268_dac_nids,
11798                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11799                 .adc_nids = alc268_adc_nids_alt,
11800                 .capsrc_nids = alc268_capsrc_nids,
11801                 .hp_nid = 0x02,
11802                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11803                 .channel_mode = alc268_modes,
11804                 .input_mux = &alc268_acer_dmic_capture_source,
11805                 .unsol_event = alc268_acer_unsol_event,
11806                 .init_hook = alc268_acer_init_hook,
11807         },
11808         [ALC268_ACER_ASPIRE_ONE] = {
11809                 .mixers = { alc268_acer_aspire_one_mixer,
11810                                 alc268_capture_alt_mixer },
11811                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11812                                 alc268_acer_aspire_one_verbs },
11813                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11814                 .dac_nids = alc268_dac_nids,
11815                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11816                 .adc_nids = alc268_adc_nids_alt,
11817                 .capsrc_nids = alc268_capsrc_nids,
11818                 .hp_nid = 0x03,
11819                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11820                 .channel_mode = alc268_modes,
11821                 .input_mux = &alc268_acer_lc_capture_source,
11822                 .unsol_event = alc268_acer_lc_unsol_event,
11823                 .init_hook = alc268_acer_lc_init_hook,
11824         },
11825         [ALC268_DELL] = {
11826                 .mixers = { alc268_dell_mixer, alc268_beep_mixer },
11827                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11828                                 alc268_dell_verbs },
11829                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11830                 .dac_nids = alc268_dac_nids,
11831                 .hp_nid = 0x02,
11832                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11833                 .channel_mode = alc268_modes,
11834                 .unsol_event = alc268_dell_unsol_event,
11835                 .init_hook = alc268_dell_init_hook,
11836                 .input_mux = &alc268_capture_source,
11837         },
11838         [ALC268_ZEPTO] = {
11839                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
11840                             alc268_beep_mixer },
11841                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11842                                 alc268_toshiba_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 = 0x03,
11849                 .dig_out_nid = ALC268_DIGOUT_NID,
11850                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11851                 .channel_mode = alc268_modes,
11852                 .input_mux = &alc268_capture_source,
11853                 .unsol_event = alc268_toshiba_unsol_event,
11854                 .init_hook = alc268_toshiba_automute
11855         },
11856 #ifdef CONFIG_SND_DEBUG
11857         [ALC268_TEST] = {
11858                 .mixers = { alc268_test_mixer, alc268_capture_mixer },
11859                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11860                                 alc268_volume_init_verbs },
11861                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
11862                 .dac_nids = alc268_dac_nids,
11863                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
11864                 .adc_nids = alc268_adc_nids_alt,
11865                 .capsrc_nids = alc268_capsrc_nids,
11866                 .hp_nid = 0x03,
11867                 .dig_out_nid = ALC268_DIGOUT_NID,
11868                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
11869                 .channel_mode = alc268_modes,
11870                 .input_mux = &alc268_capture_source,
11871         },
11872 #endif
11873 };
11874
11875 static int patch_alc268(struct hda_codec *codec)
11876 {
11877         struct alc_spec *spec;
11878         int board_config;
11879         int err;
11880
11881         spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
11882         if (spec == NULL)
11883                 return -ENOMEM;
11884
11885         codec->spec = spec;
11886
11887         board_config = snd_hda_check_board_config(codec, ALC268_MODEL_LAST,
11888                                                   alc268_models,
11889                                                   alc268_cfg_tbl);
11890
11891         if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
11892                 printk(KERN_INFO "hda_codec: Unknown model for ALC268, "
11893                        "trying auto-probe from BIOS...\n");
11894                 board_config = ALC268_AUTO;
11895         }
11896
11897         if (board_config == ALC268_AUTO) {
11898                 /* automatic parse from the BIOS config */
11899                 err = alc268_parse_auto_config(codec);
11900                 if (err < 0) {
11901                         alc_free(codec);
11902                         return err;
11903                 } else if (!err) {
11904                         printk(KERN_INFO
11905                                "hda_codec: Cannot set up configuration "
11906                                "from BIOS.  Using base mode...\n");
11907                         board_config = ALC268_3ST;
11908                 }
11909         }
11910
11911         if (board_config != ALC268_AUTO)
11912                 setup_preset(spec, &alc268_presets[board_config]);
11913
11914         if (codec->vendor_id == 0x10ec0267) {
11915                 spec->stream_name_analog = "ALC267 Analog";
11916                 spec->stream_name_digital = "ALC267 Digital";
11917         } else {
11918                 spec->stream_name_analog = "ALC268 Analog";
11919                 spec->stream_name_digital = "ALC268 Digital";
11920         }
11921
11922         spec->stream_analog_playback = &alc268_pcm_analog_playback;
11923         spec->stream_analog_capture = &alc268_pcm_analog_capture;
11924         spec->stream_analog_alt_capture = &alc268_pcm_analog_alt_capture;
11925
11926         spec->stream_digital_playback = &alc268_pcm_digital_playback;
11927
11928         if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
11929                 /* override the amp caps for beep generator */
11930                 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
11931                                           (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
11932                                           (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
11933                                           (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
11934                                           (0 << AC_AMPCAP_MUTE_SHIFT));
11935
11936         if (!spec->adc_nids && spec->input_mux) {
11937                 /* check whether NID 0x07 is valid */
11938                 unsigned int wcap = get_wcaps(codec, 0x07);
11939                 int i;
11940
11941                 /* get type */
11942                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
11943                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
11944                         spec->adc_nids = alc268_adc_nids_alt;
11945                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt);
11946                         add_mixer(spec, alc268_capture_alt_mixer);
11947                 } else {
11948                         spec->adc_nids = alc268_adc_nids;
11949                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids);
11950                         add_mixer(spec, alc268_capture_mixer);
11951                 }
11952                 spec->capsrc_nids = alc268_capsrc_nids;
11953                 /* set default input source */
11954                 for (i = 0; i < spec->num_adc_nids; i++)
11955                         snd_hda_codec_write_cache(codec, alc268_capsrc_nids[i],
11956                                 0, AC_VERB_SET_CONNECT_SEL,
11957                                 spec->input_mux->items[0].index);
11958         }
11959
11960         spec->vmaster_nid = 0x02;
11961
11962         codec->patch_ops = alc_patch_ops;
11963         if (board_config == ALC268_AUTO)
11964                 spec->init_hook = alc268_auto_init;
11965
11966         codec->proc_widget_hook = print_realtek_coef;
11967
11968         return 0;
11969 }
11970
11971 /*
11972  *  ALC269 channel source setting (2 channel)
11973  */
11974 #define ALC269_DIGOUT_NID       ALC880_DIGOUT_NID
11975
11976 #define alc269_dac_nids         alc260_dac_nids
11977
11978 static hda_nid_t alc269_adc_nids[1] = {
11979         /* ADC1 */
11980         0x08,
11981 };
11982
11983 static hda_nid_t alc269_capsrc_nids[1] = {
11984         0x23,
11985 };
11986
11987 /* NOTE: ADC2 (0x07) is connected from a recording *MIXER* (0x24),
11988  *       not a mux!
11989  */
11990
11991 static struct hda_input_mux alc269_eeepc_dmic_capture_source = {
11992         .num_items = 2,
11993         .items = {
11994                 { "i-Mic", 0x5 },
11995                 { "e-Mic", 0x0 },
11996         },
11997 };
11998
11999 static struct hda_input_mux alc269_eeepc_amic_capture_source = {
12000         .num_items = 2,
12001         .items = {
12002                 { "i-Mic", 0x1 },
12003                 { "e-Mic", 0x0 },
12004         },
12005 };
12006
12007 #define alc269_modes            alc260_modes
12008 #define alc269_capture_source   alc880_lg_lw_capture_source
12009
12010 static struct snd_kcontrol_new alc269_base_mixer[] = {
12011         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12012         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12013         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
12014         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
12015         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12016         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12017         HDA_CODEC_VOLUME("Beep Playback Volume", 0x0b, 0x4, HDA_INPUT),
12018         HDA_CODEC_MUTE("Beep Playback Switch", 0x0b, 0x4, HDA_INPUT),
12019         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12020         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12021         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12022         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
12023         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12024         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
12025         { } /* end */
12026 };
12027
12028 static struct snd_kcontrol_new alc269_quanta_fl1_mixer[] = {
12029         /* output mixer control */
12030         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
12031         {
12032                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12033                 .name = "Master Playback Switch",
12034                 .info = snd_hda_mixer_amp_switch_info,
12035                 .get = snd_hda_mixer_amp_switch_get,
12036                 .put = alc268_acer_master_sw_put,
12037                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
12038         },
12039         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12040         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12041         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12042         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12043         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12044         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
12045         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x04, HDA_INPUT),
12046         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x04, HDA_INPUT),
12047         { }
12048 };
12049
12050 static struct snd_kcontrol_new alc269_lifebook_mixer[] = {
12051         /* output mixer control */
12052         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
12053         {
12054                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12055                 .name = "Master Playback Switch",
12056                 .info = snd_hda_mixer_amp_switch_info,
12057                 .get = snd_hda_mixer_amp_switch_get,
12058                 .put = alc268_acer_master_sw_put,
12059                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
12060         },
12061         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12062         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12063         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12064         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12065         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12066         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
12067         HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x0b, 0x03, HDA_INPUT),
12068         HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x0b, 0x03, HDA_INPUT),
12069         HDA_CODEC_VOLUME("Dock Mic Boost", 0x1b, 0, HDA_INPUT),
12070         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x04, HDA_INPUT),
12071         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x04, HDA_INPUT),
12072         { }
12073 };
12074
12075 /* bind volumes of both NID 0x0c and 0x0d */
12076 static struct hda_bind_ctls alc269_epc_bind_vol = {
12077         .ops = &snd_hda_bind_vol,
12078         .values = {
12079                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
12080                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
12081                 0
12082         },
12083 };
12084
12085 static struct snd_kcontrol_new alc269_eeepc_mixer[] = {
12086         HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12087         HDA_BIND_VOL("LineOut Playback Volume", &alc269_epc_bind_vol),
12088         HDA_CODEC_MUTE("LineOut Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12089         { } /* end */
12090 };
12091
12092 /* capture mixer elements */
12093 static struct snd_kcontrol_new alc269_epc_capture_mixer[] = {
12094         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
12095         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
12096         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12097         { } /* end */
12098 };
12099
12100 /* FSC amilo */
12101 static struct snd_kcontrol_new alc269_fujitsu_mixer[] = {
12102         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12103         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12104         HDA_BIND_VOL("PCM Playback Volume", &alc269_epc_bind_vol),
12105         { } /* end */
12106 };
12107
12108 /* beep control */
12109 static struct snd_kcontrol_new alc269_beep_mixer[] = {
12110         HDA_CODEC_VOLUME("Beep Playback Volume", 0x0b, 0x4, HDA_INPUT),
12111         HDA_CODEC_MUTE("Beep Playback Switch", 0x0b, 0x4, HDA_INPUT),
12112         { } /* end */
12113 };
12114
12115 static struct hda_verb alc269_quanta_fl1_verbs[] = {
12116         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12117         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12118         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12119         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12120         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12121         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12122         { }
12123 };
12124
12125 static struct hda_verb alc269_lifebook_verbs[] = {
12126         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12127         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
12128         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12129         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12130         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12131         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12132         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12133         {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12134         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12135         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12136         { }
12137 };
12138
12139 /* toggle speaker-output according to the hp-jack state */
12140 static void alc269_quanta_fl1_speaker_automute(struct hda_codec *codec)
12141 {
12142         unsigned int present;
12143         unsigned char bits;
12144
12145         present = snd_hda_codec_read(codec, 0x15, 0,
12146                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12147         bits = present ? AMP_IN_MUTE(0) : 0;
12148         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
12149                         AMP_IN_MUTE(0), bits);
12150         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
12151                         AMP_IN_MUTE(0), bits);
12152
12153         snd_hda_codec_write(codec, 0x20, 0,
12154                         AC_VERB_SET_COEF_INDEX, 0x0c);
12155         snd_hda_codec_write(codec, 0x20, 0,
12156                         AC_VERB_SET_PROC_COEF, 0x680);
12157
12158         snd_hda_codec_write(codec, 0x20, 0,
12159                         AC_VERB_SET_COEF_INDEX, 0x0c);
12160         snd_hda_codec_write(codec, 0x20, 0,
12161                         AC_VERB_SET_PROC_COEF, 0x480);
12162 }
12163
12164 /* toggle speaker-output according to the hp-jacks state */
12165 static void alc269_lifebook_speaker_automute(struct hda_codec *codec)
12166 {
12167         unsigned int present;
12168         unsigned char bits;
12169
12170         /* Check laptop headphone socket */
12171         present = snd_hda_codec_read(codec, 0x15, 0,
12172                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12173
12174         /* Check port replicator headphone socket */
12175         present |= snd_hda_codec_read(codec, 0x1a, 0,
12176                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12177
12178         bits = present ? AMP_IN_MUTE(0) : 0;
12179         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
12180                         AMP_IN_MUTE(0), bits);
12181         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
12182                         AMP_IN_MUTE(0), bits);
12183
12184         snd_hda_codec_write(codec, 0x20, 0,
12185                         AC_VERB_SET_COEF_INDEX, 0x0c);
12186         snd_hda_codec_write(codec, 0x20, 0,
12187                         AC_VERB_SET_PROC_COEF, 0x680);
12188
12189         snd_hda_codec_write(codec, 0x20, 0,
12190                         AC_VERB_SET_COEF_INDEX, 0x0c);
12191         snd_hda_codec_write(codec, 0x20, 0,
12192                         AC_VERB_SET_PROC_COEF, 0x480);
12193 }
12194
12195 static void alc269_quanta_fl1_mic_automute(struct hda_codec *codec)
12196 {
12197         unsigned int present;
12198
12199         present = snd_hda_codec_read(codec, 0x18, 0,
12200                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12201         snd_hda_codec_write(codec, 0x23, 0,
12202                             AC_VERB_SET_CONNECT_SEL, present ? 0x0 : 0x1);
12203 }
12204
12205 static void alc269_lifebook_mic_autoswitch(struct hda_codec *codec)
12206 {
12207         unsigned int present_laptop;
12208         unsigned int present_dock;
12209
12210         present_laptop = snd_hda_codec_read(codec, 0x18, 0,
12211                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12212
12213         present_dock = snd_hda_codec_read(codec, 0x1b, 0,
12214                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12215
12216         /* Laptop mic port overrides dock mic port, design decision */
12217         if (present_dock)
12218                 snd_hda_codec_write(codec, 0x23, 0,
12219                                 AC_VERB_SET_CONNECT_SEL, 0x3);
12220         if (present_laptop)
12221                 snd_hda_codec_write(codec, 0x23, 0,
12222                                 AC_VERB_SET_CONNECT_SEL, 0x0);
12223         if (!present_dock && !present_laptop)
12224                 snd_hda_codec_write(codec, 0x23, 0,
12225                                 AC_VERB_SET_CONNECT_SEL, 0x1);
12226 }
12227
12228 static void alc269_quanta_fl1_unsol_event(struct hda_codec *codec,
12229                                     unsigned int res)
12230 {
12231         if ((res >> 26) == ALC880_HP_EVENT)
12232                 alc269_quanta_fl1_speaker_automute(codec);
12233         if ((res >> 26) == ALC880_MIC_EVENT)
12234                 alc269_quanta_fl1_mic_automute(codec);
12235 }
12236
12237 static void alc269_lifebook_unsol_event(struct hda_codec *codec,
12238                                         unsigned int res)
12239 {
12240         if ((res >> 26) == ALC880_HP_EVENT)
12241                 alc269_lifebook_speaker_automute(codec);
12242         if ((res >> 26) == ALC880_MIC_EVENT)
12243                 alc269_lifebook_mic_autoswitch(codec);
12244 }
12245
12246 static void alc269_quanta_fl1_init_hook(struct hda_codec *codec)
12247 {
12248         alc269_quanta_fl1_speaker_automute(codec);
12249         alc269_quanta_fl1_mic_automute(codec);
12250 }
12251
12252 static void alc269_lifebook_init_hook(struct hda_codec *codec)
12253 {
12254         alc269_lifebook_speaker_automute(codec);
12255         alc269_lifebook_mic_autoswitch(codec);
12256 }
12257
12258 static struct hda_verb alc269_eeepc_dmic_init_verbs[] = {
12259         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12260         {0x23, AC_VERB_SET_CONNECT_SEL, 0x05},
12261         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
12262         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))},
12263         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12264         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12265         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12266         {}
12267 };
12268
12269 static struct hda_verb alc269_eeepc_amic_init_verbs[] = {
12270         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12271         {0x23, AC_VERB_SET_CONNECT_SEL, 0x01},
12272         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
12273         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x701b | (0x00 << 8))},
12274         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12275         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12276         {}
12277 };
12278
12279 /* toggle speaker-output according to the hp-jack state */
12280 static void alc269_speaker_automute(struct hda_codec *codec)
12281 {
12282         unsigned int present;
12283         unsigned char bits;
12284
12285         present = snd_hda_codec_read(codec, 0x15, 0,
12286                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12287         bits = present ? AMP_IN_MUTE(0) : 0;
12288         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
12289                                 AMP_IN_MUTE(0), bits);
12290         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
12291                                 AMP_IN_MUTE(0), bits);
12292 }
12293
12294 static void alc269_eeepc_dmic_automute(struct hda_codec *codec)
12295 {
12296         unsigned int present;
12297
12298         present = snd_hda_codec_read(codec, 0x18, 0,
12299                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12300         snd_hda_codec_write(codec, 0x23, 0,
12301                                 AC_VERB_SET_CONNECT_SEL,  (present ? 0 : 5));
12302 }
12303
12304 static void alc269_eeepc_amic_automute(struct hda_codec *codec)
12305 {
12306         unsigned int present;
12307
12308         present = snd_hda_codec_read(codec, 0x18, 0,
12309                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12310         snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
12311                                 0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
12312         snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
12313                                 0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
12314 }
12315
12316 /* unsolicited event for HP jack sensing */
12317 static void alc269_eeepc_dmic_unsol_event(struct hda_codec *codec,
12318                                      unsigned int res)
12319 {
12320         if ((res >> 26) == ALC880_HP_EVENT)
12321                 alc269_speaker_automute(codec);
12322
12323         if ((res >> 26) == ALC880_MIC_EVENT)
12324                 alc269_eeepc_dmic_automute(codec);
12325 }
12326
12327 static void alc269_eeepc_dmic_inithook(struct hda_codec *codec)
12328 {
12329         alc269_speaker_automute(codec);
12330         alc269_eeepc_dmic_automute(codec);
12331 }
12332
12333 /* unsolicited event for HP jack sensing */
12334 static void alc269_eeepc_amic_unsol_event(struct hda_codec *codec,
12335                                      unsigned int res)
12336 {
12337         if ((res >> 26) == ALC880_HP_EVENT)
12338                 alc269_speaker_automute(codec);
12339
12340         if ((res >> 26) == ALC880_MIC_EVENT)
12341                 alc269_eeepc_amic_automute(codec);
12342 }
12343
12344 static void alc269_eeepc_amic_inithook(struct hda_codec *codec)
12345 {
12346         alc269_speaker_automute(codec);
12347         alc269_eeepc_amic_automute(codec);
12348 }
12349
12350 /*
12351  * generic initialization of ADC, input mixers and output mixers
12352  */
12353 static struct hda_verb alc269_init_verbs[] = {
12354         /*
12355          * Unmute ADC0 and set the default input to mic-in
12356          */
12357         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12358
12359         /* Mute input amps (PCBeep, Line In, Mic 1 & Mic 2) of the
12360          * analog-loopback mixer widget
12361          * Note: PASD motherboards uses the Line In 2 as the input for
12362          * front panel mic (mic 2)
12363          */
12364         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
12365         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12366         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12367         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12368         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12369         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
12370
12371         /*
12372          * Set up output mixers (0x0c - 0x0e)
12373          */
12374         /* set vol=0 to output mixers */
12375         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12376         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12377
12378         /* set up input amps for analog loopback */
12379         /* Amp Indices: DAC = 0, mixer = 1 */
12380         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12381         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12382         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12383         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12384         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12385         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12386
12387         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12388         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12389         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12390         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12391         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12392         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12393         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12394
12395         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12396         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12397         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12398         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12399         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12400         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12401         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12402
12403         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
12404         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
12405
12406         /* FIXME: use matrix-type input source selection */
12407         /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
12408         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
12409         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12410         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12411         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12412         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12413
12414         /* set EAPD */
12415         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
12416         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
12417         { }
12418 };
12419
12420 /* add playback controls from the parsed DAC table */
12421 static int alc269_auto_create_multi_out_ctls(struct alc_spec *spec,
12422                                              const struct auto_pin_cfg *cfg)
12423 {
12424         hda_nid_t nid;
12425         int err;
12426
12427         spec->multiout.num_dacs = 1;    /* only use one dac */
12428         spec->multiout.dac_nids = spec->private_dac_nids;
12429         spec->multiout.dac_nids[0] = 2;
12430
12431         nid = cfg->line_out_pins[0];
12432         if (nid) {
12433                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
12434                                   "Front Playback Volume",
12435                                   HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT));
12436                 if (err < 0)
12437                         return err;
12438                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12439                                   "Front Playback Switch",
12440                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
12441                 if (err < 0)
12442                         return err;
12443         }
12444
12445         nid = cfg->speaker_pins[0];
12446         if (nid) {
12447                 if (!cfg->line_out_pins[0]) {
12448                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
12449                                           "Speaker Playback Volume",
12450                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
12451                                                               HDA_OUTPUT));
12452                         if (err < 0)
12453                                 return err;
12454                 }
12455                 if (nid == 0x16) {
12456                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12457                                           "Speaker Playback Switch",
12458                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
12459                                                               HDA_OUTPUT));
12460                         if (err < 0)
12461                                 return err;
12462                 } else {
12463                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12464                                           "Speaker Playback Switch",
12465                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
12466                                                               HDA_OUTPUT));
12467                         if (err < 0)
12468                                 return err;
12469                 }
12470         }
12471         nid = cfg->hp_pins[0];
12472         if (nid) {
12473                 /* spec->multiout.hp_nid = 2; */
12474                 if (!cfg->line_out_pins[0] && !cfg->speaker_pins[0]) {
12475                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
12476                                           "Headphone Playback Volume",
12477                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
12478                                                               HDA_OUTPUT));
12479                         if (err < 0)
12480                                 return err;
12481                 }
12482                 if (nid == 0x16) {
12483                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12484                                           "Headphone Playback Switch",
12485                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
12486                                                               HDA_OUTPUT));
12487                         if (err < 0)
12488                                 return err;
12489                 } else {
12490                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12491                                           "Headphone Playback Switch",
12492                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
12493                                                               HDA_OUTPUT));
12494                         if (err < 0)
12495                                 return err;
12496                 }
12497         }
12498         return 0;
12499 }
12500
12501 static int alc269_auto_create_analog_input_ctls(struct alc_spec *spec,
12502                                                 const struct auto_pin_cfg *cfg)
12503 {
12504         int err;
12505
12506         err = alc880_auto_create_analog_input_ctls(spec, cfg);
12507         if (err < 0)
12508                 return err;
12509         /* digital-mic input pin is excluded in alc880_auto_create..()
12510          * because it's under 0x18
12511          */
12512         if (cfg->input_pins[AUTO_PIN_MIC] == 0x12 ||
12513             cfg->input_pins[AUTO_PIN_FRONT_MIC] == 0x12) {
12514                 struct hda_input_mux *imux = &spec->private_imux;
12515                 imux->items[imux->num_items].label = "Int Mic";
12516                 imux->items[imux->num_items].index = 0x05;
12517                 imux->num_items++;
12518         }
12519         return 0;
12520 }
12521
12522 #ifdef CONFIG_SND_HDA_POWER_SAVE
12523 #define alc269_loopbacks        alc880_loopbacks
12524 #endif
12525
12526 /* pcm configuration: identiacal with ALC880 */
12527 #define alc269_pcm_analog_playback      alc880_pcm_analog_playback
12528 #define alc269_pcm_analog_capture       alc880_pcm_analog_capture
12529 #define alc269_pcm_digital_playback     alc880_pcm_digital_playback
12530 #define alc269_pcm_digital_capture      alc880_pcm_digital_capture
12531
12532 /*
12533  * BIOS auto configuration
12534  */
12535 static int alc269_parse_auto_config(struct hda_codec *codec)
12536 {
12537         struct alc_spec *spec = codec->spec;
12538         int i, err;
12539         static hda_nid_t alc269_ignore[] = { 0x1d, 0 };
12540
12541         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
12542                                            alc269_ignore);
12543         if (err < 0)
12544                 return err;
12545
12546         err = alc269_auto_create_multi_out_ctls(spec, &spec->autocfg);
12547         if (err < 0)
12548                 return err;
12549         err = alc269_auto_create_analog_input_ctls(spec, &spec->autocfg);
12550         if (err < 0)
12551                 return err;
12552
12553         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
12554
12555         if (spec->autocfg.dig_out_pin)
12556                 spec->multiout.dig_out_nid = ALC269_DIGOUT_NID;
12557
12558         if (spec->kctls.list)
12559                 add_mixer(spec, spec->kctls.list);
12560
12561         /* create a beep mixer control if the pin 0x1d isn't assigned */
12562         for (i = 0; i < ARRAY_SIZE(spec->autocfg.input_pins); i++)
12563                 if (spec->autocfg.input_pins[i] == 0x1d)
12564                         break;
12565         if (i >= ARRAY_SIZE(spec->autocfg.input_pins))
12566                 add_mixer(spec, alc269_beep_mixer);
12567
12568         add_verb(spec, alc269_init_verbs);
12569         spec->num_mux_defs = 1;
12570         spec->input_mux = &spec->private_imux;
12571         /* set default input source */
12572         snd_hda_codec_write_cache(codec, alc269_capsrc_nids[0],
12573                                   0, AC_VERB_SET_CONNECT_SEL,
12574                                   spec->input_mux->items[0].index);
12575
12576         err = alc_auto_add_mic_boost(codec);
12577         if (err < 0)
12578                 return err;
12579
12580         if (!spec->cap_mixer)
12581                 set_capture_mixer(spec);
12582
12583         store_pin_configs(codec);
12584         return 1;
12585 }
12586
12587 #define alc269_auto_init_multi_out      alc882_auto_init_multi_out
12588 #define alc269_auto_init_hp_out         alc882_auto_init_hp_out
12589 #define alc269_auto_init_analog_input   alc882_auto_init_analog_input
12590
12591
12592 /* init callback for auto-configuration model -- overriding the default init */
12593 static void alc269_auto_init(struct hda_codec *codec)
12594 {
12595         struct alc_spec *spec = codec->spec;
12596         alc269_auto_init_multi_out(codec);
12597         alc269_auto_init_hp_out(codec);
12598         alc269_auto_init_analog_input(codec);
12599         if (spec->unsol_event)
12600                 alc_inithook(codec);
12601 }
12602
12603 /*
12604  * configuration and preset
12605  */
12606 static const char *alc269_models[ALC269_MODEL_LAST] = {
12607         [ALC269_BASIC]                  = "basic",
12608         [ALC269_QUANTA_FL1]             = "quanta",
12609         [ALC269_ASUS_EEEPC_P703]        = "eeepc-p703",
12610         [ALC269_ASUS_EEEPC_P901]        = "eeepc-p901",
12611         [ALC269_FUJITSU]                = "fujitsu",
12612         [ALC269_LIFEBOOK]               = "lifebook"
12613 };
12614
12615 static struct snd_pci_quirk alc269_cfg_tbl[] = {
12616         SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_QUANTA_FL1),
12617         SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
12618                       ALC269_ASUS_EEEPC_P703),
12619         SND_PCI_QUIRK(0x1043, 0x831a, "ASUS Eeepc P901",
12620                       ALC269_ASUS_EEEPC_P901),
12621         SND_PCI_QUIRK(0x1043, 0x834a, "ASUS Eeepc S101",
12622                       ALC269_ASUS_EEEPC_P901),
12623         SND_PCI_QUIRK(0x1734, 0x115d, "FSC Amilo", ALC269_FUJITSU),
12624         SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook ICH9M-based", ALC269_LIFEBOOK),
12625         {}
12626 };
12627
12628 static struct alc_config_preset alc269_presets[] = {
12629         [ALC269_BASIC] = {
12630                 .mixers = { alc269_base_mixer },
12631                 .init_verbs = { alc269_init_verbs },
12632                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12633                 .dac_nids = alc269_dac_nids,
12634                 .hp_nid = 0x03,
12635                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12636                 .channel_mode = alc269_modes,
12637                 .input_mux = &alc269_capture_source,
12638         },
12639         [ALC269_QUANTA_FL1] = {
12640                 .mixers = { alc269_quanta_fl1_mixer },
12641                 .init_verbs = { alc269_init_verbs, alc269_quanta_fl1_verbs },
12642                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12643                 .dac_nids = alc269_dac_nids,
12644                 .hp_nid = 0x03,
12645                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12646                 .channel_mode = alc269_modes,
12647                 .input_mux = &alc269_capture_source,
12648                 .unsol_event = alc269_quanta_fl1_unsol_event,
12649                 .init_hook = alc269_quanta_fl1_init_hook,
12650         },
12651         [ALC269_ASUS_EEEPC_P703] = {
12652                 .mixers = { alc269_eeepc_mixer },
12653                 .cap_mixer = alc269_epc_capture_mixer,
12654                 .init_verbs = { alc269_init_verbs,
12655                                 alc269_eeepc_amic_init_verbs },
12656                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12657                 .dac_nids = alc269_dac_nids,
12658                 .hp_nid = 0x03,
12659                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12660                 .channel_mode = alc269_modes,
12661                 .input_mux = &alc269_eeepc_amic_capture_source,
12662                 .unsol_event = alc269_eeepc_amic_unsol_event,
12663                 .init_hook = alc269_eeepc_amic_inithook,
12664         },
12665         [ALC269_ASUS_EEEPC_P901] = {
12666                 .mixers = { alc269_eeepc_mixer },
12667                 .cap_mixer = alc269_epc_capture_mixer,
12668                 .init_verbs = { alc269_init_verbs,
12669                                 alc269_eeepc_dmic_init_verbs },
12670                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12671                 .dac_nids = alc269_dac_nids,
12672                 .hp_nid = 0x03,
12673                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12674                 .channel_mode = alc269_modes,
12675                 .input_mux = &alc269_eeepc_dmic_capture_source,
12676                 .unsol_event = alc269_eeepc_dmic_unsol_event,
12677                 .init_hook = alc269_eeepc_dmic_inithook,
12678         },
12679         [ALC269_FUJITSU] = {
12680                 .mixers = { alc269_fujitsu_mixer, alc269_beep_mixer },
12681                 .cap_mixer = alc269_epc_capture_mixer,
12682                 .init_verbs = { alc269_init_verbs,
12683                                 alc269_eeepc_dmic_init_verbs },
12684                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12685                 .dac_nids = alc269_dac_nids,
12686                 .hp_nid = 0x03,
12687                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12688                 .channel_mode = alc269_modes,
12689                 .input_mux = &alc269_eeepc_dmic_capture_source,
12690                 .unsol_event = alc269_eeepc_dmic_unsol_event,
12691                 .init_hook = alc269_eeepc_dmic_inithook,
12692         },
12693         [ALC269_LIFEBOOK] = {
12694                 .mixers = { alc269_lifebook_mixer },
12695                 .init_verbs = { alc269_init_verbs, alc269_lifebook_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                 .unsol_event = alc269_lifebook_unsol_event,
12703                 .init_hook = alc269_lifebook_init_hook,
12704         },
12705 };
12706
12707 static int patch_alc269(struct hda_codec *codec)
12708 {
12709         struct alc_spec *spec;
12710         int board_config;
12711         int err;
12712
12713         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
12714         if (spec == NULL)
12715                 return -ENOMEM;
12716
12717         codec->spec = spec;
12718
12719         alc_fix_pll_init(codec, 0x20, 0x04, 15);
12720
12721         board_config = snd_hda_check_board_config(codec, ALC269_MODEL_LAST,
12722                                                   alc269_models,
12723                                                   alc269_cfg_tbl);
12724
12725         if (board_config < 0) {
12726                 printk(KERN_INFO "hda_codec: Unknown model for ALC269, "
12727                        "trying auto-probe from BIOS...\n");
12728                 board_config = ALC269_AUTO;
12729         }
12730
12731         if (board_config == ALC269_AUTO) {
12732                 /* automatic parse from the BIOS config */
12733                 err = alc269_parse_auto_config(codec);
12734                 if (err < 0) {
12735                         alc_free(codec);
12736                         return err;
12737                 } else if (!err) {
12738                         printk(KERN_INFO
12739                                "hda_codec: Cannot set up configuration "
12740                                "from BIOS.  Using base mode...\n");
12741                         board_config = ALC269_BASIC;
12742                 }
12743         }
12744
12745         if (board_config != ALC269_AUTO)
12746                 setup_preset(spec, &alc269_presets[board_config]);
12747
12748         spec->stream_name_analog = "ALC269 Analog";
12749         spec->stream_analog_playback = &alc269_pcm_analog_playback;
12750         spec->stream_analog_capture = &alc269_pcm_analog_capture;
12751
12752         spec->stream_name_digital = "ALC269 Digital";
12753         spec->stream_digital_playback = &alc269_pcm_digital_playback;
12754         spec->stream_digital_capture = &alc269_pcm_digital_capture;
12755
12756         spec->adc_nids = alc269_adc_nids;
12757         spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids);
12758         spec->capsrc_nids = alc269_capsrc_nids;
12759         if (!spec->cap_mixer)
12760                 set_capture_mixer(spec);
12761
12762         codec->patch_ops = alc_patch_ops;
12763         if (board_config == ALC269_AUTO)
12764                 spec->init_hook = alc269_auto_init;
12765 #ifdef CONFIG_SND_HDA_POWER_SAVE
12766         if (!spec->loopback.amplist)
12767                 spec->loopback.amplist = alc269_loopbacks;
12768 #endif
12769         codec->proc_widget_hook = print_realtek_coef;
12770
12771         return 0;
12772 }
12773
12774 /*
12775  *  ALC861 channel source setting (2/6 channel selection for 3-stack)
12776  */
12777
12778 /*
12779  * set the path ways for 2 channel output
12780  * need to set the codec line out and mic 1 pin widgets to inputs
12781  */
12782 static struct hda_verb alc861_threestack_ch2_init[] = {
12783         /* set pin widget 1Ah (line in) for input */
12784         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12785         /* set pin widget 18h (mic1/2) for input, for mic also enable
12786          * the vref
12787          */
12788         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12789
12790         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
12791 #if 0
12792         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
12793         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
12794 #endif
12795         { } /* end */
12796 };
12797 /*
12798  * 6ch mode
12799  * need to set the codec line out and mic 1 pin widgets to outputs
12800  */
12801 static struct hda_verb alc861_threestack_ch6_init[] = {
12802         /* set pin widget 1Ah (line in) for output (Back Surround)*/
12803         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12804         /* set pin widget 18h (mic1) for output (CLFE)*/
12805         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12806
12807         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
12808         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
12809
12810         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
12811 #if 0
12812         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
12813         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
12814 #endif
12815         { } /* end */
12816 };
12817
12818 static struct hda_channel_mode alc861_threestack_modes[2] = {
12819         { 2, alc861_threestack_ch2_init },
12820         { 6, alc861_threestack_ch6_init },
12821 };
12822 /* Set mic1 as input and unmute the mixer */
12823 static struct hda_verb alc861_uniwill_m31_ch2_init[] = {
12824         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12825         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
12826         { } /* end */
12827 };
12828 /* Set mic1 as output and mute mixer */
12829 static struct hda_verb alc861_uniwill_m31_ch4_init[] = {
12830         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12831         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
12832         { } /* end */
12833 };
12834
12835 static struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
12836         { 2, alc861_uniwill_m31_ch2_init },
12837         { 4, alc861_uniwill_m31_ch4_init },
12838 };
12839
12840 /* Set mic1 and line-in as input and unmute the mixer */
12841 static struct hda_verb alc861_asus_ch2_init[] = {
12842         /* set pin widget 1Ah (line in) for input */
12843         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
12844         /* set pin widget 18h (mic1/2) for input, for mic also enable
12845          * the vref
12846          */
12847         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
12848
12849         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
12850 #if 0
12851         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
12852         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
12853 #endif
12854         { } /* end */
12855 };
12856 /* Set mic1 nad line-in as output and mute mixer */
12857 static struct hda_verb alc861_asus_ch6_init[] = {
12858         /* set pin widget 1Ah (line in) for output (Back Surround)*/
12859         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12860         /* { 0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
12861         /* set pin widget 18h (mic1) for output (CLFE)*/
12862         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
12863         /* { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
12864         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
12865         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
12866
12867         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
12868 #if 0
12869         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
12870         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
12871 #endif
12872         { } /* end */
12873 };
12874
12875 static struct hda_channel_mode alc861_asus_modes[2] = {
12876         { 2, alc861_asus_ch2_init },
12877         { 6, alc861_asus_ch6_init },
12878 };
12879
12880 /* patch-ALC861 */
12881
12882 static struct snd_kcontrol_new alc861_base_mixer[] = {
12883         /* output mixer control */
12884         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12885         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12886         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12887         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12888         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
12889
12890         /*Input mixer control */
12891         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12892            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
12893         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12894         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12895         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12896         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12897         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12898         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12899         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12900         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
12901
12902         { } /* end */
12903 };
12904
12905 static struct snd_kcontrol_new alc861_3ST_mixer[] = {
12906         /* output mixer control */
12907         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12908         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12909         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12910         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12911         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
12912
12913         /* Input mixer control */
12914         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12915            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
12916         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12917         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12918         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12919         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12920         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12921         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12922         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12923         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
12924
12925         {
12926                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12927                 .name = "Channel Mode",
12928                 .info = alc_ch_mode_info,
12929                 .get = alc_ch_mode_get,
12930                 .put = alc_ch_mode_put,
12931                 .private_value = ARRAY_SIZE(alc861_threestack_modes),
12932         },
12933         { } /* end */
12934 };
12935
12936 static struct snd_kcontrol_new alc861_toshiba_mixer[] = {
12937         /* output mixer control */
12938         HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12939         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12940         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12941
12942         { } /* end */
12943 };
12944
12945 static struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
12946         /* output mixer control */
12947         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12948         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12949         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12950         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12951         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
12952
12953         /* Input mixer control */
12954         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12955            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
12956         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12957         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12958         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12959         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12960         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12961         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12962         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12963         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
12964
12965         {
12966                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12967                 .name = "Channel Mode",
12968                 .info = alc_ch_mode_info,
12969                 .get = alc_ch_mode_get,
12970                 .put = alc_ch_mode_put,
12971                 .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
12972         },
12973         { } /* end */
12974 };
12975
12976 static struct snd_kcontrol_new alc861_asus_mixer[] = {
12977         /* output mixer control */
12978         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
12979         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
12980         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
12981         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
12982         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
12983
12984         /* Input mixer control */
12985         HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
12986         HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12987         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
12988         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
12989         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
12990         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
12991         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
12992         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
12993         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
12994         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT),
12995
12996         {
12997                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12998                 .name = "Channel Mode",
12999                 .info = alc_ch_mode_info,
13000                 .get = alc_ch_mode_get,
13001                 .put = alc_ch_mode_put,
13002                 .private_value = ARRAY_SIZE(alc861_asus_modes),
13003         },
13004         { }
13005 };
13006
13007 /* additional mixer */
13008 static struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
13009         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13010         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13011         HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x23, 0x0, HDA_OUTPUT),
13012         HDA_CODEC_MUTE("PC Beep Playback Switch", 0x23, 0x0, HDA_OUTPUT),
13013         { }
13014 };
13015
13016 /*
13017  * generic initialization of ADC, input mixers and output mixers
13018  */
13019 static struct hda_verb alc861_base_init_verbs[] = {
13020         /*
13021          * Unmute ADC0 and set the default input to mic-in
13022          */
13023         /* port-A for surround (rear panel) */
13024         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13025         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
13026         /* port-B for mic-in (rear panel) with vref */
13027         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13028         /* port-C for line-in (rear panel) */
13029         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13030         /* port-D for Front */
13031         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13032         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13033         /* port-E for HP out (front panel) */
13034         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
13035         /* route front PCM to HP */
13036         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13037         /* port-F for mic-in (front panel) with vref */
13038         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13039         /* port-G for CLFE (rear panel) */
13040         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13041         { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13042         /* port-H for side (rear panel) */
13043         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13044         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
13045         /* CD-in */
13046         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13047         /* route front mic to ADC1*/
13048         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13049         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13050
13051         /* Unmute DAC0~3 & spdif out*/
13052         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13053         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13054         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13055         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13056         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13057
13058         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13059         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13060         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13061         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13062         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13063
13064         /* Unmute Stereo Mixer 15 */
13065         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13066         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13067         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13068         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13069
13070         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13071         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13072         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13073         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13074         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13075         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13076         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13077         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13078         /* hp used DAC 3 (Front) */
13079         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13080         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13081
13082         { }
13083 };
13084
13085 static struct hda_verb alc861_threestack_init_verbs[] = {
13086         /*
13087          * Unmute ADC0 and set the default input to mic-in
13088          */
13089         /* port-A for surround (rear panel) */
13090         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13091         /* port-B for mic-in (rear panel) with vref */
13092         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13093         /* port-C for line-in (rear panel) */
13094         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13095         /* port-D for Front */
13096         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13097         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13098         /* port-E for HP out (front panel) */
13099         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
13100         /* route front PCM to HP */
13101         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13102         /* port-F for mic-in (front panel) with vref */
13103         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13104         /* port-G for CLFE (rear panel) */
13105         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13106         /* port-H for side (rear panel) */
13107         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13108         /* CD-in */
13109         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13110         /* route front mic to ADC1*/
13111         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13112         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13113         /* Unmute DAC0~3 & spdif out*/
13114         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13115         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13116         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13117         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13118         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13119
13120         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13121         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13122         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13123         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13124         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13125
13126         /* Unmute Stereo Mixer 15 */
13127         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13128         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13129         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13130         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13131
13132         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13133         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13134         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13135         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13136         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13137         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13138         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13139         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13140         /* hp used DAC 3 (Front) */
13141         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13142         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13143         { }
13144 };
13145
13146 static struct hda_verb alc861_uniwill_m31_init_verbs[] = {
13147         /*
13148          * Unmute ADC0 and set the default input to mic-in
13149          */
13150         /* port-A for surround (rear panel) */
13151         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13152         /* port-B for mic-in (rear panel) with vref */
13153         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13154         /* port-C for line-in (rear panel) */
13155         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13156         /* port-D for Front */
13157         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13158         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13159         /* port-E for HP out (front panel) */
13160         /* this has to be set to VREF80 */
13161         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13162         /* route front PCM to HP */
13163         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13164         /* port-F for mic-in (front panel) with vref */
13165         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13166         /* port-G for CLFE (rear panel) */
13167         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13168         /* port-H for side (rear panel) */
13169         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13170         /* CD-in */
13171         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13172         /* route front mic to ADC1*/
13173         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13174         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13175         /* Unmute DAC0~3 & spdif out*/
13176         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13177         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13178         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13179         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13180         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13181
13182         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13183         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13184         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13185         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13186         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13187
13188         /* Unmute Stereo Mixer 15 */
13189         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13190         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13191         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13192         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13193
13194         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13195         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13196         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13197         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13198         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13199         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13200         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13201         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13202         /* hp used DAC 3 (Front) */
13203         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13204         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13205         { }
13206 };
13207
13208 static struct hda_verb alc861_asus_init_verbs[] = {
13209         /*
13210          * Unmute ADC0 and set the default input to mic-in
13211          */
13212         /* port-A for surround (rear panel)
13213          * according to codec#0 this is the HP jack
13214          */
13215         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, /* was 0x00 */
13216         /* route front PCM to HP */
13217         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x01 },
13218         /* port-B for mic-in (rear panel) with vref */
13219         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13220         /* port-C for line-in (rear panel) */
13221         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13222         /* port-D for Front */
13223         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13224         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13225         /* port-E for HP out (front panel) */
13226         /* this has to be set to VREF80 */
13227         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13228         /* route front PCM to HP */
13229         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13230         /* port-F for mic-in (front panel) with vref */
13231         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13232         /* port-G for CLFE (rear panel) */
13233         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13234         /* port-H for side (rear panel) */
13235         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13236         /* CD-in */
13237         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13238         /* route front mic to ADC1*/
13239         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13240         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13241         /* Unmute DAC0~3 & spdif out*/
13242         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13243         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13244         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13245         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13246         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13247         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13248         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13249         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13250         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13251         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13252
13253         /* Unmute Stereo Mixer 15 */
13254         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13255         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13256         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13257         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13258
13259         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13260         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13261         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13262         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13263         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13264         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13265         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13266         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13267         /* hp used DAC 3 (Front) */
13268         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13269         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13270         { }
13271 };
13272
13273 /* additional init verbs for ASUS laptops */
13274 static struct hda_verb alc861_asus_laptop_init_verbs[] = {
13275         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x45 }, /* HP-out */
13276         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2) }, /* mute line-in */
13277         { }
13278 };
13279
13280 /*
13281  * generic initialization of ADC, input mixers and output mixers
13282  */
13283 static struct hda_verb alc861_auto_init_verbs[] = {
13284         /*
13285          * Unmute ADC0 and set the default input to mic-in
13286          */
13287         /* {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, */
13288         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13289
13290         /* Unmute DAC0~3 & spdif out*/
13291         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13292         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13293         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13294         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13295         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13296
13297         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13298         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13299         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13300         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13301         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13302
13303         /* Unmute Stereo Mixer 15 */
13304         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13305         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13306         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13307         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c},
13308
13309         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13310         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13311         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13312         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13313         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13314         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13315         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13316         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13317
13318         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13319         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13320         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13321         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13322         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13323         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13324         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13325         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13326
13327         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},  /* set Mic 1 */
13328
13329         { }
13330 };
13331
13332 static struct hda_verb alc861_toshiba_init_verbs[] = {
13333         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13334
13335         { }
13336 };
13337
13338 /* toggle speaker-output according to the hp-jack state */
13339 static void alc861_toshiba_automute(struct hda_codec *codec)
13340 {
13341         unsigned int present;
13342
13343         present = snd_hda_codec_read(codec, 0x0f, 0,
13344                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13345         snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
13346                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
13347         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
13348                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
13349 }
13350
13351 static void alc861_toshiba_unsol_event(struct hda_codec *codec,
13352                                        unsigned int res)
13353 {
13354         if ((res >> 26) == ALC880_HP_EVENT)
13355                 alc861_toshiba_automute(codec);
13356 }
13357
13358 /* pcm configuration: identiacal with ALC880 */
13359 #define alc861_pcm_analog_playback      alc880_pcm_analog_playback
13360 #define alc861_pcm_analog_capture       alc880_pcm_analog_capture
13361 #define alc861_pcm_digital_playback     alc880_pcm_digital_playback
13362 #define alc861_pcm_digital_capture      alc880_pcm_digital_capture
13363
13364
13365 #define ALC861_DIGOUT_NID       0x07
13366
13367 static struct hda_channel_mode alc861_8ch_modes[1] = {
13368         { 8, NULL }
13369 };
13370
13371 static hda_nid_t alc861_dac_nids[4] = {
13372         /* front, surround, clfe, side */
13373         0x03, 0x06, 0x05, 0x04
13374 };
13375
13376 static hda_nid_t alc660_dac_nids[3] = {
13377         /* front, clfe, surround */
13378         0x03, 0x05, 0x06
13379 };
13380
13381 static hda_nid_t alc861_adc_nids[1] = {
13382         /* ADC0-2 */
13383         0x08,
13384 };
13385
13386 static struct hda_input_mux alc861_capture_source = {
13387         .num_items = 5,
13388         .items = {
13389                 { "Mic", 0x0 },
13390                 { "Front Mic", 0x3 },
13391                 { "Line", 0x1 },
13392                 { "CD", 0x4 },
13393                 { "Mixer", 0x5 },
13394         },
13395 };
13396
13397 /* fill in the dac_nids table from the parsed pin configuration */
13398 static int alc861_auto_fill_dac_nids(struct alc_spec *spec,
13399                                      const struct auto_pin_cfg *cfg)
13400 {
13401         int i;
13402         hda_nid_t nid;
13403
13404         spec->multiout.dac_nids = spec->private_dac_nids;
13405         for (i = 0; i < cfg->line_outs; i++) {
13406                 nid = cfg->line_out_pins[i];
13407                 if (nid) {
13408                         if (i >= ARRAY_SIZE(alc861_dac_nids))
13409                                 continue;
13410                         spec->multiout.dac_nids[i] = alc861_dac_nids[i];
13411                 }
13412         }
13413         spec->multiout.num_dacs = cfg->line_outs;
13414         return 0;
13415 }
13416
13417 /* add playback controls from the parsed DAC table */
13418 static int alc861_auto_create_multi_out_ctls(struct alc_spec *spec,
13419                                              const struct auto_pin_cfg *cfg)
13420 {
13421         char name[32];
13422         static const char *chname[4] = {
13423                 "Front", "Surround", NULL /*CLFE*/, "Side"
13424         };
13425         hda_nid_t nid;
13426         int i, idx, err;
13427
13428         for (i = 0; i < cfg->line_outs; i++) {
13429                 nid = spec->multiout.dac_nids[i];
13430                 if (!nid)
13431                         continue;
13432                 if (nid == 0x05) {
13433                         /* Center/LFE */
13434                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13435                                           "Center Playback Switch",
13436                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
13437                                                               HDA_OUTPUT));
13438                         if (err < 0)
13439                                 return err;
13440                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13441                                           "LFE Playback Switch",
13442                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
13443                                                               HDA_OUTPUT));
13444                         if (err < 0)
13445                                 return err;
13446                 } else {
13447                         for (idx = 0; idx < ARRAY_SIZE(alc861_dac_nids) - 1;
13448                              idx++)
13449                                 if (nid == alc861_dac_nids[idx])
13450                                         break;
13451                         sprintf(name, "%s Playback Switch", chname[idx]);
13452                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
13453                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
13454                                                               HDA_OUTPUT));
13455                         if (err < 0)
13456                                 return err;
13457                 }
13458         }
13459         return 0;
13460 }
13461
13462 static int alc861_auto_create_hp_ctls(struct alc_spec *spec, hda_nid_t pin)
13463 {
13464         int err;
13465         hda_nid_t nid;
13466
13467         if (!pin)
13468                 return 0;
13469
13470         if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
13471                 nid = 0x03;
13472                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
13473                                   "Headphone Playback Switch",
13474                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
13475                 if (err < 0)
13476                         return err;
13477                 spec->multiout.hp_nid = nid;
13478         }
13479         return 0;
13480 }
13481
13482 /* create playback/capture controls for input pins */
13483 static int alc861_auto_create_analog_input_ctls(struct alc_spec *spec,
13484                                                 const struct auto_pin_cfg *cfg)
13485 {
13486         struct hda_input_mux *imux = &spec->private_imux;
13487         int i, err, idx, idx1;
13488
13489         for (i = 0; i < AUTO_PIN_LAST; i++) {
13490                 switch (cfg->input_pins[i]) {
13491                 case 0x0c:
13492                         idx1 = 1;
13493                         idx = 2;        /* Line In */
13494                         break;
13495                 case 0x0f:
13496                         idx1 = 2;
13497                         idx = 2;        /* Line In */
13498                         break;
13499                 case 0x0d:
13500                         idx1 = 0;
13501                         idx = 1;        /* Mic In */
13502                         break;
13503                 case 0x10:
13504                         idx1 = 3;
13505                         idx = 1;        /* Mic In */
13506                         break;
13507                 case 0x11:
13508                         idx1 = 4;
13509                         idx = 0;        /* CD */
13510                         break;
13511                 default:
13512                         continue;
13513                 }
13514
13515                 err = new_analog_input(spec, cfg->input_pins[i],
13516                                        auto_pin_cfg_labels[i], idx, 0x15);
13517                 if (err < 0)
13518                         return err;
13519
13520                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
13521                 imux->items[imux->num_items].index = idx1;
13522                 imux->num_items++;
13523         }
13524         return 0;
13525 }
13526
13527 static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
13528                                               hda_nid_t nid,
13529                                               int pin_type, int dac_idx)
13530 {
13531         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
13532                             pin_type);
13533         snd_hda_codec_write(codec, dac_idx, 0, AC_VERB_SET_AMP_GAIN_MUTE,
13534                             AMP_OUT_UNMUTE);
13535 }
13536
13537 static void alc861_auto_init_multi_out(struct hda_codec *codec)
13538 {
13539         struct alc_spec *spec = codec->spec;
13540         int i;
13541
13542         alc_subsystem_id(codec, 0x0e, 0x0f, 0x0b);
13543         for (i = 0; i < spec->autocfg.line_outs; i++) {
13544                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
13545                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
13546                 if (nid)
13547                         alc861_auto_set_output_and_unmute(codec, nid, pin_type,
13548                                                           spec->multiout.dac_nids[i]);
13549         }
13550 }
13551
13552 static void alc861_auto_init_hp_out(struct hda_codec *codec)
13553 {
13554         struct alc_spec *spec = codec->spec;
13555         hda_nid_t pin;
13556
13557         pin = spec->autocfg.hp_pins[0];
13558         if (pin) /* connect to front */
13559                 alc861_auto_set_output_and_unmute(codec, pin, PIN_HP,
13560                                                   spec->multiout.dac_nids[0]);
13561         pin = spec->autocfg.speaker_pins[0];
13562         if (pin)
13563                 alc861_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
13564 }
13565
13566 static void alc861_auto_init_analog_input(struct hda_codec *codec)
13567 {
13568         struct alc_spec *spec = codec->spec;
13569         int i;
13570
13571         for (i = 0; i < AUTO_PIN_LAST; i++) {
13572                 hda_nid_t nid = spec->autocfg.input_pins[i];
13573                 if (nid >= 0x0c && nid <= 0x11) {
13574                         snd_hda_codec_write(codec, nid, 0,
13575                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
13576                                             i <= AUTO_PIN_FRONT_MIC ?
13577                                             PIN_VREF80 : PIN_IN);
13578                 }
13579         }
13580 }
13581
13582 /* parse the BIOS configuration and set up the alc_spec */
13583 /* return 1 if successful, 0 if the proper config is not found,
13584  * or a negative error code
13585  */
13586 static int alc861_parse_auto_config(struct hda_codec *codec)
13587 {
13588         struct alc_spec *spec = codec->spec;
13589         int err;
13590         static hda_nid_t alc861_ignore[] = { 0x1d, 0 };
13591
13592         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
13593                                            alc861_ignore);
13594         if (err < 0)
13595                 return err;
13596         if (!spec->autocfg.line_outs)
13597                 return 0; /* can't find valid BIOS pin config */
13598
13599         err = alc861_auto_fill_dac_nids(spec, &spec->autocfg);
13600         if (err < 0)
13601                 return err;
13602         err = alc861_auto_create_multi_out_ctls(spec, &spec->autocfg);
13603         if (err < 0)
13604                 return err;
13605         err = alc861_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
13606         if (err < 0)
13607                 return err;
13608         err = alc861_auto_create_analog_input_ctls(spec, &spec->autocfg);
13609         if (err < 0)
13610                 return err;
13611
13612         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
13613
13614         if (spec->autocfg.dig_out_pin)
13615                 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;
13616
13617         if (spec->kctls.list)
13618                 add_mixer(spec, spec->kctls.list);
13619
13620         add_verb(spec, alc861_auto_init_verbs);
13621
13622         spec->num_mux_defs = 1;
13623         spec->input_mux = &spec->private_imux;
13624
13625         spec->adc_nids = alc861_adc_nids;
13626         spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
13627         set_capture_mixer(spec);
13628
13629         store_pin_configs(codec);
13630         return 1;
13631 }
13632
13633 /* additional initialization for auto-configuration model */
13634 static void alc861_auto_init(struct hda_codec *codec)
13635 {
13636         struct alc_spec *spec = codec->spec;
13637         alc861_auto_init_multi_out(codec);
13638         alc861_auto_init_hp_out(codec);
13639         alc861_auto_init_analog_input(codec);
13640         if (spec->unsol_event)
13641                 alc_inithook(codec);
13642 }
13643
13644 #ifdef CONFIG_SND_HDA_POWER_SAVE
13645 static struct hda_amp_list alc861_loopbacks[] = {
13646         { 0x15, HDA_INPUT, 0 },
13647         { 0x15, HDA_INPUT, 1 },
13648         { 0x15, HDA_INPUT, 2 },
13649         { 0x15, HDA_INPUT, 3 },
13650         { } /* end */
13651 };
13652 #endif
13653
13654
13655 /*
13656  * configuration and preset
13657  */
13658 static const char *alc861_models[ALC861_MODEL_LAST] = {
13659         [ALC861_3ST]            = "3stack",
13660         [ALC660_3ST]            = "3stack-660",
13661         [ALC861_3ST_DIG]        = "3stack-dig",
13662         [ALC861_6ST_DIG]        = "6stack-dig",
13663         [ALC861_UNIWILL_M31]    = "uniwill-m31",
13664         [ALC861_TOSHIBA]        = "toshiba",
13665         [ALC861_ASUS]           = "asus",
13666         [ALC861_ASUS_LAPTOP]    = "asus-laptop",
13667         [ALC861_AUTO]           = "auto",
13668 };
13669
13670 static struct snd_pci_quirk alc861_cfg_tbl[] = {
13671         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC861_3ST),
13672         SND_PCI_QUIRK(0x1043, 0x1335, "ASUS F2/3", ALC861_ASUS_LAPTOP),
13673         SND_PCI_QUIRK(0x1043, 0x1338, "ASUS F2/3", ALC861_ASUS_LAPTOP),
13674         SND_PCI_QUIRK(0x1043, 0x1393, "ASUS", ALC861_ASUS),
13675         SND_PCI_QUIRK(0x1043, 0x13d7, "ASUS A9rp", ALC861_ASUS_LAPTOP),
13676         SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS P1-AH2", ALC861_3ST_DIG),
13677         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba", ALC861_TOSHIBA),
13678         /* FIXME: the entry below breaks Toshiba A100 (model=auto works!)
13679          *        Any other models that need this preset?
13680          */
13681         /* SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba", ALC861_TOSHIBA), */
13682         SND_PCI_QUIRK(0x1462, 0x7254, "HP dx2200 (MSI MS-7254)", ALC861_3ST),
13683         SND_PCI_QUIRK(0x1462, 0x7297, "HP dx2250 (MSI MS-7297)", ALC861_3ST),
13684         SND_PCI_QUIRK(0x1584, 0x2b01, "Uniwill X40AIx", ALC861_UNIWILL_M31),
13685         SND_PCI_QUIRK(0x1584, 0x9072, "Uniwill m31", ALC861_UNIWILL_M31),
13686         SND_PCI_QUIRK(0x1584, 0x9075, "Airis Praxis N1212", ALC861_ASUS_LAPTOP),
13687         /* FIXME: the below seems conflict */
13688         /* SND_PCI_QUIRK(0x1584, 0x9075, "Uniwill", ALC861_UNIWILL_M31), */
13689         SND_PCI_QUIRK(0x1849, 0x0660, "Asrock 939SLI32", ALC660_3ST),
13690         SND_PCI_QUIRK(0x8086, 0xd600, "Intel", ALC861_3ST),
13691         {}
13692 };
13693
13694 static struct alc_config_preset alc861_presets[] = {
13695         [ALC861_3ST] = {
13696                 .mixers = { alc861_3ST_mixer },
13697                 .init_verbs = { alc861_threestack_init_verbs },
13698                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13699                 .dac_nids = alc861_dac_nids,
13700                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
13701                 .channel_mode = alc861_threestack_modes,
13702                 .need_dac_fix = 1,
13703                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13704                 .adc_nids = alc861_adc_nids,
13705                 .input_mux = &alc861_capture_source,
13706         },
13707         [ALC861_3ST_DIG] = {
13708                 .mixers = { alc861_base_mixer },
13709                 .init_verbs = { alc861_threestack_init_verbs },
13710                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13711                 .dac_nids = alc861_dac_nids,
13712                 .dig_out_nid = ALC861_DIGOUT_NID,
13713                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
13714                 .channel_mode = alc861_threestack_modes,
13715                 .need_dac_fix = 1,
13716                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13717                 .adc_nids = alc861_adc_nids,
13718                 .input_mux = &alc861_capture_source,
13719         },
13720         [ALC861_6ST_DIG] = {
13721                 .mixers = { alc861_base_mixer },
13722                 .init_verbs = { alc861_base_init_verbs },
13723                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13724                 .dac_nids = alc861_dac_nids,
13725                 .dig_out_nid = ALC861_DIGOUT_NID,
13726                 .num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
13727                 .channel_mode = alc861_8ch_modes,
13728                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13729                 .adc_nids = alc861_adc_nids,
13730                 .input_mux = &alc861_capture_source,
13731         },
13732         [ALC660_3ST] = {
13733                 .mixers = { alc861_3ST_mixer },
13734                 .init_verbs = { alc861_threestack_init_verbs },
13735                 .num_dacs = ARRAY_SIZE(alc660_dac_nids),
13736                 .dac_nids = alc660_dac_nids,
13737                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
13738                 .channel_mode = alc861_threestack_modes,
13739                 .need_dac_fix = 1,
13740                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13741                 .adc_nids = alc861_adc_nids,
13742                 .input_mux = &alc861_capture_source,
13743         },
13744         [ALC861_UNIWILL_M31] = {
13745                 .mixers = { alc861_uniwill_m31_mixer },
13746                 .init_verbs = { alc861_uniwill_m31_init_verbs },
13747                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13748                 .dac_nids = alc861_dac_nids,
13749                 .dig_out_nid = ALC861_DIGOUT_NID,
13750                 .num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
13751                 .channel_mode = alc861_uniwill_m31_modes,
13752                 .need_dac_fix = 1,
13753                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13754                 .adc_nids = alc861_adc_nids,
13755                 .input_mux = &alc861_capture_source,
13756         },
13757         [ALC861_TOSHIBA] = {
13758                 .mixers = { alc861_toshiba_mixer },
13759                 .init_verbs = { alc861_base_init_verbs,
13760                                 alc861_toshiba_init_verbs },
13761                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13762                 .dac_nids = alc861_dac_nids,
13763                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
13764                 .channel_mode = alc883_3ST_2ch_modes,
13765                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13766                 .adc_nids = alc861_adc_nids,
13767                 .input_mux = &alc861_capture_source,
13768                 .unsol_event = alc861_toshiba_unsol_event,
13769                 .init_hook = alc861_toshiba_automute,
13770         },
13771         [ALC861_ASUS] = {
13772                 .mixers = { alc861_asus_mixer },
13773                 .init_verbs = { alc861_asus_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_asus_modes),
13778                 .channel_mode = alc861_asus_modes,
13779                 .need_dac_fix = 1,
13780                 .hp_nid = 0x06,
13781                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13782                 .adc_nids = alc861_adc_nids,
13783                 .input_mux = &alc861_capture_source,
13784         },
13785         [ALC861_ASUS_LAPTOP] = {
13786                 .mixers = { alc861_toshiba_mixer, alc861_asus_laptop_mixer },
13787                 .init_verbs = { alc861_asus_init_verbs,
13788                                 alc861_asus_laptop_init_verbs },
13789                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
13790                 .dac_nids = alc861_dac_nids,
13791                 .dig_out_nid = ALC861_DIGOUT_NID,
13792                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
13793                 .channel_mode = alc883_3ST_2ch_modes,
13794                 .need_dac_fix = 1,
13795                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
13796                 .adc_nids = alc861_adc_nids,
13797                 .input_mux = &alc861_capture_source,
13798         },
13799 };
13800
13801
13802 static int patch_alc861(struct hda_codec *codec)
13803 {
13804         struct alc_spec *spec;
13805         int board_config;
13806         int err;
13807
13808         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
13809         if (spec == NULL)
13810                 return -ENOMEM;
13811
13812         codec->spec = spec;
13813
13814         board_config = snd_hda_check_board_config(codec, ALC861_MODEL_LAST,
13815                                                   alc861_models,
13816                                                   alc861_cfg_tbl);
13817
13818         if (board_config < 0) {
13819                 printk(KERN_INFO "hda_codec: Unknown model for ALC861, "
13820                        "trying auto-probe from BIOS...\n");
13821                 board_config = ALC861_AUTO;
13822         }
13823
13824         if (board_config == ALC861_AUTO) {
13825                 /* automatic parse from the BIOS config */
13826                 err = alc861_parse_auto_config(codec);
13827                 if (err < 0) {
13828                         alc_free(codec);
13829                         return err;
13830                 } else if (!err) {
13831                         printk(KERN_INFO
13832                                "hda_codec: Cannot set up configuration "
13833                                "from BIOS.  Using base mode...\n");
13834                    board_config = ALC861_3ST_DIG;
13835                 }
13836         }
13837
13838         if (board_config != ALC861_AUTO)
13839                 setup_preset(spec, &alc861_presets[board_config]);
13840
13841         spec->stream_name_analog = "ALC861 Analog";
13842         spec->stream_analog_playback = &alc861_pcm_analog_playback;
13843         spec->stream_analog_capture = &alc861_pcm_analog_capture;
13844
13845         spec->stream_name_digital = "ALC861 Digital";
13846         spec->stream_digital_playback = &alc861_pcm_digital_playback;
13847         spec->stream_digital_capture = &alc861_pcm_digital_capture;
13848
13849         spec->vmaster_nid = 0x03;
13850
13851         codec->patch_ops = alc_patch_ops;
13852         if (board_config == ALC861_AUTO)
13853                 spec->init_hook = alc861_auto_init;
13854 #ifdef CONFIG_SND_HDA_POWER_SAVE
13855         if (!spec->loopback.amplist)
13856                 spec->loopback.amplist = alc861_loopbacks;
13857 #endif
13858         codec->proc_widget_hook = print_realtek_coef;
13859
13860         return 0;
13861 }
13862
13863 /*
13864  * ALC861-VD support
13865  *
13866  * Based on ALC882
13867  *
13868  * In addition, an independent DAC
13869  */
13870 #define ALC861VD_DIGOUT_NID     0x06
13871
13872 static hda_nid_t alc861vd_dac_nids[4] = {
13873         /* front, surr, clfe, side surr */
13874         0x02, 0x03, 0x04, 0x05
13875 };
13876
13877 /* dac_nids for ALC660vd are in a different order - according to
13878  * Realtek's driver.
13879  * This should probably tesult in a different mixer for 6stack models
13880  * of ALC660vd codecs, but for now there is only 3stack mixer
13881  * - and it is the same as in 861vd.
13882  * adc_nids in ALC660vd are (is) the same as in 861vd
13883  */
13884 static hda_nid_t alc660vd_dac_nids[3] = {
13885         /* front, rear, clfe, rear_surr */
13886         0x02, 0x04, 0x03
13887 };
13888
13889 static hda_nid_t alc861vd_adc_nids[1] = {
13890         /* ADC0 */
13891         0x09,
13892 };
13893
13894 static hda_nid_t alc861vd_capsrc_nids[1] = { 0x22 };
13895
13896 /* input MUX */
13897 /* FIXME: should be a matrix-type input source selection */
13898 static struct hda_input_mux alc861vd_capture_source = {
13899         .num_items = 4,
13900         .items = {
13901                 { "Mic", 0x0 },
13902                 { "Front Mic", 0x1 },
13903                 { "Line", 0x2 },
13904                 { "CD", 0x4 },
13905         },
13906 };
13907
13908 static struct hda_input_mux alc861vd_dallas_capture_source = {
13909         .num_items = 2,
13910         .items = {
13911                 { "Ext Mic", 0x0 },
13912                 { "Int Mic", 0x1 },
13913         },
13914 };
13915
13916 static struct hda_input_mux alc861vd_hp_capture_source = {
13917         .num_items = 2,
13918         .items = {
13919                 { "Front Mic", 0x0 },
13920                 { "ATAPI Mic", 0x1 },
13921         },
13922 };
13923
13924 /*
13925  * 2ch mode
13926  */
13927 static struct hda_channel_mode alc861vd_3stack_2ch_modes[1] = {
13928         { 2, NULL }
13929 };
13930
13931 /*
13932  * 6ch mode
13933  */
13934 static struct hda_verb alc861vd_6stack_ch6_init[] = {
13935         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13936         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13937         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13938         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13939         { } /* end */
13940 };
13941
13942 /*
13943  * 8ch mode
13944  */
13945 static struct hda_verb alc861vd_6stack_ch8_init[] = {
13946         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13947         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13948         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13949         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
13950         { } /* end */
13951 };
13952
13953 static struct hda_channel_mode alc861vd_6stack_modes[2] = {
13954         { 6, alc861vd_6stack_ch6_init },
13955         { 8, alc861vd_6stack_ch8_init },
13956 };
13957
13958 static struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
13959         {
13960                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13961                 .name = "Channel Mode",
13962                 .info = alc_ch_mode_info,
13963                 .get = alc_ch_mode_get,
13964                 .put = alc_ch_mode_put,
13965         },
13966         { } /* end */
13967 };
13968
13969 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
13970  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
13971  */
13972 static struct snd_kcontrol_new alc861vd_6st_mixer[] = {
13973         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
13974         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
13975
13976         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
13977         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
13978
13979         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0,
13980                                 HDA_OUTPUT),
13981         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0,
13982                                 HDA_OUTPUT),
13983         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
13984         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
13985
13986         HDA_CODEC_VOLUME("Side Playback Volume", 0x05, 0x0, HDA_OUTPUT),
13987         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
13988
13989         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
13990
13991         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
13992         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
13993         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
13994
13995         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
13996         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
13997         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
13998
13999         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14000         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14001
14002         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14003         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14004
14005         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
14006         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
14007
14008         { } /* end */
14009 };
14010
14011 static struct snd_kcontrol_new alc861vd_3st_mixer[] = {
14012         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14013         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14014
14015         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14016
14017         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
14018         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14019         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14020
14021         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
14022         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14023         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14024
14025         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14026         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14027
14028         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14029         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14030
14031         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
14032         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
14033
14034         { } /* end */
14035 };
14036
14037 static struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
14038         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14039         /*HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),*/
14040         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14041
14042         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14043
14044         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
14045         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14046         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14047
14048         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
14049         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14050         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14051
14052         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14053         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14054
14055         { } /* end */
14056 };
14057
14058 /* Pin assignment: Speaker=0x14, HP = 0x15,
14059  *                 Ext Mic=0x18, Int Mic = 0x19, CD = 0x1c, PC Beep = 0x1d
14060  */
14061 static struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
14062         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14063         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
14064         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14065         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
14066         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
14067         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14068         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14069         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
14070         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14071         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14072         HDA_CODEC_VOLUME("PC Beep Volume", 0x0b, 0x05, HDA_INPUT),
14073         HDA_CODEC_MUTE("PC Beep Switch", 0x0b, 0x05, HDA_INPUT),
14074         { } /* end */
14075 };
14076
14077 /* Pin assignment: Speaker=0x14, Line-out = 0x15,
14078  *                 Front Mic=0x18, ATAPI Mic = 0x19,
14079  */
14080 static struct snd_kcontrol_new alc861vd_hp_mixer[] = {
14081         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14082         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14083         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14084         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
14085         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14086         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14087         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14088         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14089
14090         { } /* end */
14091 };
14092
14093 /*
14094  * generic initialization of ADC, input mixers and output mixers
14095  */
14096 static struct hda_verb alc861vd_volume_init_verbs[] = {
14097         /*
14098          * Unmute ADC0 and set the default input to mic-in
14099          */
14100         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
14101         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14102
14103         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of
14104          * the analog-loopback mixer widget
14105          */
14106         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
14107         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14108         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14109         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14110         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14111         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14112
14113         /* Capture mixer: unmute Mic, F-Mic, Line, CD inputs */
14114         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14115         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14116         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14117         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
14118
14119         /*
14120          * Set up output mixers (0x02 - 0x05)
14121          */
14122         /* set vol=0 to output mixers */
14123         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14124         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14125         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14126         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14127
14128         /* set up input amps for analog loopback */
14129         /* Amp Indices: DAC = 0, mixer = 1 */
14130         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14131         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14132         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14133         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14134         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14135         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14136         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14137         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14138
14139         { }
14140 };
14141
14142 /*
14143  * 3-stack pin configuration:
14144  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
14145  */
14146 static struct hda_verb alc861vd_3stack_init_verbs[] = {
14147         /*
14148          * Set pin mode and muting
14149          */
14150         /* set front pin widgets 0x14 for output */
14151         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14152         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14153         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
14154
14155         /* Mic (rear) pin: input vref at 80% */
14156         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14157         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14158         /* Front Mic pin: input vref at 80% */
14159         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14160         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14161         /* Line In pin: input */
14162         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14163         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14164         /* Line-2 In: Headphone output (output 0 - 0x0c) */
14165         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14166         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14167         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
14168         /* CD pin widget for input */
14169         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14170
14171         { }
14172 };
14173
14174 /*
14175  * 6-stack pin configuration:
14176  */
14177 static struct hda_verb alc861vd_6stack_init_verbs[] = {
14178         /*
14179          * Set pin mode and muting
14180          */
14181         /* set front pin widgets 0x14 for output */
14182         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14183         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14184         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
14185
14186         /* Rear Pin: output 1 (0x0d) */
14187         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14188         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14189         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
14190         /* CLFE Pin: output 2 (0x0e) */
14191         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14192         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14193         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
14194         /* Side Pin: output 3 (0x0f) */
14195         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14196         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14197         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
14198
14199         /* Mic (rear) pin: input vref at 80% */
14200         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14201         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14202         /* Front Mic pin: input vref at 80% */
14203         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14204         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14205         /* Line In pin: input */
14206         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14207         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14208         /* Line-2 In: Headphone output (output 0 - 0x0c) */
14209         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14210         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14211         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
14212         /* CD pin widget for input */
14213         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14214
14215         { }
14216 };
14217
14218 static struct hda_verb alc861vd_eapd_verbs[] = {
14219         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
14220         { }
14221 };
14222
14223 static struct hda_verb alc660vd_eapd_verbs[] = {
14224         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
14225         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
14226         { }
14227 };
14228
14229 static struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
14230         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14231         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14232         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
14233         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14234         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14235         {}
14236 };
14237
14238 /* toggle speaker-output according to the hp-jack state */
14239 static void alc861vd_lenovo_hp_automute(struct hda_codec *codec)
14240 {
14241         unsigned int present;
14242         unsigned char bits;
14243
14244         present = snd_hda_codec_read(codec, 0x1b, 0,
14245                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14246         bits = present ? HDA_AMP_MUTE : 0;
14247         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
14248                                  HDA_AMP_MUTE, bits);
14249 }
14250
14251 static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
14252 {
14253         unsigned int present;
14254         unsigned char bits;
14255
14256         present = snd_hda_codec_read(codec, 0x18, 0,
14257                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14258         bits = present ? HDA_AMP_MUTE : 0;
14259         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
14260                                  HDA_AMP_MUTE, bits);
14261 }
14262
14263 static void alc861vd_lenovo_automute(struct hda_codec *codec)
14264 {
14265         alc861vd_lenovo_hp_automute(codec);
14266         alc861vd_lenovo_mic_automute(codec);
14267 }
14268
14269 static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
14270                                         unsigned int res)
14271 {
14272         switch (res >> 26) {
14273         case ALC880_HP_EVENT:
14274                 alc861vd_lenovo_hp_automute(codec);
14275                 break;
14276         case ALC880_MIC_EVENT:
14277                 alc861vd_lenovo_mic_automute(codec);
14278                 break;
14279         }
14280 }
14281
14282 static struct hda_verb alc861vd_dallas_verbs[] = {
14283         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14284         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14285         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14286         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14287
14288         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14289         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14290         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14291         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14292         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14293         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14294         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14295         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14296
14297         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14298         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14299         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14300         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14301         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14302         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14303         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14304         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14305
14306         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
14307         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14308         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
14309         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14310         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14311         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14312         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14313         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14314
14315         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14316         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14317         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14318         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14319
14320         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14321         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
14322         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14323
14324         { } /* end */
14325 };
14326
14327 /* toggle speaker-output according to the hp-jack state */
14328 static void alc861vd_dallas_automute(struct hda_codec *codec)
14329 {
14330         unsigned int present;
14331
14332         present = snd_hda_codec_read(codec, 0x15, 0,
14333                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14334         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
14335                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
14336 }
14337
14338 static void alc861vd_dallas_unsol_event(struct hda_codec *codec, unsigned int res)
14339 {
14340         if ((res >> 26) == ALC880_HP_EVENT)
14341                 alc861vd_dallas_automute(codec);
14342 }
14343
14344 #ifdef CONFIG_SND_HDA_POWER_SAVE
14345 #define alc861vd_loopbacks      alc880_loopbacks
14346 #endif
14347
14348 /* pcm configuration: identiacal with ALC880 */
14349 #define alc861vd_pcm_analog_playback    alc880_pcm_analog_playback
14350 #define alc861vd_pcm_analog_capture     alc880_pcm_analog_capture
14351 #define alc861vd_pcm_digital_playback   alc880_pcm_digital_playback
14352 #define alc861vd_pcm_digital_capture    alc880_pcm_digital_capture
14353
14354 /*
14355  * configuration and preset
14356  */
14357 static const char *alc861vd_models[ALC861VD_MODEL_LAST] = {
14358         [ALC660VD_3ST]          = "3stack-660",
14359         [ALC660VD_3ST_DIG]      = "3stack-660-digout",
14360         [ALC660VD_ASUS_V1S]     = "asus-v1s",
14361         [ALC861VD_3ST]          = "3stack",
14362         [ALC861VD_3ST_DIG]      = "3stack-digout",
14363         [ALC861VD_6ST_DIG]      = "6stack-digout",
14364         [ALC861VD_LENOVO]       = "lenovo",
14365         [ALC861VD_DALLAS]       = "dallas",
14366         [ALC861VD_HP]           = "hp",
14367         [ALC861VD_AUTO]         = "auto",
14368 };
14369
14370 static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
14371         SND_PCI_QUIRK(0x1019, 0xa88d, "Realtek ALC660 demo", ALC660VD_3ST),
14372         SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_HP),
14373         SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST),
14374         SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),
14375         SND_PCI_QUIRK(0x1043, 0x1633, "Asus V1Sn", ALC660VD_ASUS_V1S),
14376         SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG),
14377         SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
14378         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
14379         /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
14380         SND_PCI_QUIRK(0x1179, 0xff01, "DALLAS", ALC861VD_DALLAS),
14381         SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
14382         SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_DALLAS),
14383         SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
14384         SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo", ALC861VD_LENOVO),
14385         SND_PCI_QUIRK(0x17aa, 0x3802, "Lenovo 3000 C200", ALC861VD_LENOVO),
14386         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 N200", ALC861VD_LENOVO),
14387         SND_PCI_QUIRK(0x1849, 0x0862, "ASRock K8NF6G-VSTA", ALC861VD_6ST_DIG),
14388         {}
14389 };
14390
14391 static struct alc_config_preset alc861vd_presets[] = {
14392         [ALC660VD_3ST] = {
14393                 .mixers = { alc861vd_3st_mixer },
14394                 .init_verbs = { alc861vd_volume_init_verbs,
14395                                  alc861vd_3stack_init_verbs },
14396                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14397                 .dac_nids = alc660vd_dac_nids,
14398                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14399                 .channel_mode = alc861vd_3stack_2ch_modes,
14400                 .input_mux = &alc861vd_capture_source,
14401         },
14402         [ALC660VD_3ST_DIG] = {
14403                 .mixers = { alc861vd_3st_mixer },
14404                 .init_verbs = { alc861vd_volume_init_verbs,
14405                                  alc861vd_3stack_init_verbs },
14406                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14407                 .dac_nids = alc660vd_dac_nids,
14408                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14409                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14410                 .channel_mode = alc861vd_3stack_2ch_modes,
14411                 .input_mux = &alc861vd_capture_source,
14412         },
14413         [ALC861VD_3ST] = {
14414                 .mixers = { alc861vd_3st_mixer },
14415                 .init_verbs = { alc861vd_volume_init_verbs,
14416                                  alc861vd_3stack_init_verbs },
14417                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14418                 .dac_nids = alc861vd_dac_nids,
14419                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14420                 .channel_mode = alc861vd_3stack_2ch_modes,
14421                 .input_mux = &alc861vd_capture_source,
14422         },
14423         [ALC861VD_3ST_DIG] = {
14424                 .mixers = { alc861vd_3st_mixer },
14425                 .init_verbs = { alc861vd_volume_init_verbs,
14426                                  alc861vd_3stack_init_verbs },
14427                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14428                 .dac_nids = alc861vd_dac_nids,
14429                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14430                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14431                 .channel_mode = alc861vd_3stack_2ch_modes,
14432                 .input_mux = &alc861vd_capture_source,
14433         },
14434         [ALC861VD_6ST_DIG] = {
14435                 .mixers = { alc861vd_6st_mixer, alc861vd_chmode_mixer },
14436                 .init_verbs = { alc861vd_volume_init_verbs,
14437                                 alc861vd_6stack_init_verbs },
14438                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14439                 .dac_nids = alc861vd_dac_nids,
14440                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14441                 .num_channel_mode = ARRAY_SIZE(alc861vd_6stack_modes),
14442                 .channel_mode = alc861vd_6stack_modes,
14443                 .input_mux = &alc861vd_capture_source,
14444         },
14445         [ALC861VD_LENOVO] = {
14446                 .mixers = { alc861vd_lenovo_mixer },
14447                 .init_verbs = { alc861vd_volume_init_verbs,
14448                                 alc861vd_3stack_init_verbs,
14449                                 alc861vd_eapd_verbs,
14450                                 alc861vd_lenovo_unsol_verbs },
14451                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14452                 .dac_nids = alc660vd_dac_nids,
14453                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14454                 .channel_mode = alc861vd_3stack_2ch_modes,
14455                 .input_mux = &alc861vd_capture_source,
14456                 .unsol_event = alc861vd_lenovo_unsol_event,
14457                 .init_hook = alc861vd_lenovo_automute,
14458         },
14459         [ALC861VD_DALLAS] = {
14460                 .mixers = { alc861vd_dallas_mixer },
14461                 .init_verbs = { alc861vd_dallas_verbs },
14462                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14463                 .dac_nids = alc861vd_dac_nids,
14464                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14465                 .channel_mode = alc861vd_3stack_2ch_modes,
14466                 .input_mux = &alc861vd_dallas_capture_source,
14467                 .unsol_event = alc861vd_dallas_unsol_event,
14468                 .init_hook = alc861vd_dallas_automute,
14469         },
14470         [ALC861VD_HP] = {
14471                 .mixers = { alc861vd_hp_mixer },
14472                 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs },
14473                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14474                 .dac_nids = alc861vd_dac_nids,
14475                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14476                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14477                 .channel_mode = alc861vd_3stack_2ch_modes,
14478                 .input_mux = &alc861vd_hp_capture_source,
14479                 .unsol_event = alc861vd_dallas_unsol_event,
14480                 .init_hook = alc861vd_dallas_automute,
14481         },
14482         [ALC660VD_ASUS_V1S] = {
14483                 .mixers = { alc861vd_lenovo_mixer },
14484                 .init_verbs = { alc861vd_volume_init_verbs,
14485                                 alc861vd_3stack_init_verbs,
14486                                 alc861vd_eapd_verbs,
14487                                 alc861vd_lenovo_unsol_verbs },
14488                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14489                 .dac_nids = alc660vd_dac_nids,
14490                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14491                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14492                 .channel_mode = alc861vd_3stack_2ch_modes,
14493                 .input_mux = &alc861vd_capture_source,
14494                 .unsol_event = alc861vd_lenovo_unsol_event,
14495                 .init_hook = alc861vd_lenovo_automute,
14496         },
14497 };
14498
14499 /*
14500  * BIOS auto configuration
14501  */
14502 static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
14503                                 hda_nid_t nid, int pin_type, int dac_idx)
14504 {
14505         alc_set_pin_output(codec, nid, pin_type);
14506 }
14507
14508 static void alc861vd_auto_init_multi_out(struct hda_codec *codec)
14509 {
14510         struct alc_spec *spec = codec->spec;
14511         int i;
14512
14513         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
14514         for (i = 0; i <= HDA_SIDE; i++) {
14515                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
14516                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
14517                 if (nid)
14518                         alc861vd_auto_set_output_and_unmute(codec, nid,
14519                                                             pin_type, i);
14520         }
14521 }
14522
14523
14524 static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
14525 {
14526         struct alc_spec *spec = codec->spec;
14527         hda_nid_t pin;
14528
14529         pin = spec->autocfg.hp_pins[0];
14530         if (pin) /* connect to front and  use dac 0 */
14531                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
14532         pin = spec->autocfg.speaker_pins[0];
14533         if (pin)
14534                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
14535 }
14536
14537 #define alc861vd_is_input_pin(nid)      alc880_is_input_pin(nid)
14538 #define ALC861VD_PIN_CD_NID             ALC880_PIN_CD_NID
14539
14540 static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
14541 {
14542         struct alc_spec *spec = codec->spec;
14543         int i;
14544
14545         for (i = 0; i < AUTO_PIN_LAST; i++) {
14546                 hda_nid_t nid = spec->autocfg.input_pins[i];
14547                 if (alc861vd_is_input_pin(nid)) {
14548                         snd_hda_codec_write(codec, nid, 0,
14549                                         AC_VERB_SET_PIN_WIDGET_CONTROL,
14550                                         i <= AUTO_PIN_FRONT_MIC ?
14551                                                         PIN_VREF80 : PIN_IN);
14552                         if (nid != ALC861VD_PIN_CD_NID)
14553                                 snd_hda_codec_write(codec, nid, 0,
14554                                                 AC_VERB_SET_AMP_GAIN_MUTE,
14555                                                 AMP_OUT_MUTE);
14556                 }
14557         }
14558 }
14559
14560 #define alc861vd_auto_init_input_src    alc882_auto_init_input_src
14561
14562 #define alc861vd_idx_to_mixer_vol(nid)          ((nid) + 0x02)
14563 #define alc861vd_idx_to_mixer_switch(nid)       ((nid) + 0x0c)
14564
14565 /* add playback controls from the parsed DAC table */
14566 /* Based on ALC880 version. But ALC861VD has separate,
14567  * different NIDs for mute/unmute switch and volume control */
14568 static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
14569                                              const struct auto_pin_cfg *cfg)
14570 {
14571         char name[32];
14572         static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"};
14573         hda_nid_t nid_v, nid_s;
14574         int i, err;
14575
14576         for (i = 0; i < cfg->line_outs; i++) {
14577                 if (!spec->multiout.dac_nids[i])
14578                         continue;
14579                 nid_v = alc861vd_idx_to_mixer_vol(
14580                                 alc880_dac_to_idx(
14581                                         spec->multiout.dac_nids[i]));
14582                 nid_s = alc861vd_idx_to_mixer_switch(
14583                                 alc880_dac_to_idx(
14584                                         spec->multiout.dac_nids[i]));
14585
14586                 if (i == 2) {
14587                         /* Center/LFE */
14588                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
14589                                           "Center Playback Volume",
14590                                           HDA_COMPOSE_AMP_VAL(nid_v, 1, 0,
14591                                                               HDA_OUTPUT));
14592                         if (err < 0)
14593                                 return err;
14594                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
14595                                           "LFE Playback Volume",
14596                                           HDA_COMPOSE_AMP_VAL(nid_v, 2, 0,
14597                                                               HDA_OUTPUT));
14598                         if (err < 0)
14599                                 return err;
14600                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14601                                           "Center Playback Switch",
14602                                           HDA_COMPOSE_AMP_VAL(nid_s, 1, 2,
14603                                                               HDA_INPUT));
14604                         if (err < 0)
14605                                 return err;
14606                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14607                                           "LFE Playback Switch",
14608                                           HDA_COMPOSE_AMP_VAL(nid_s, 2, 2,
14609                                                               HDA_INPUT));
14610                         if (err < 0)
14611                                 return err;
14612                 } else {
14613                         sprintf(name, "%s Playback Volume", chname[i]);
14614                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
14615                                           HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
14616                                                               HDA_OUTPUT));
14617                         if (err < 0)
14618                                 return err;
14619                         sprintf(name, "%s Playback Switch", chname[i]);
14620                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
14621                                           HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
14622                                                               HDA_INPUT));
14623                         if (err < 0)
14624                                 return err;
14625                 }
14626         }
14627         return 0;
14628 }
14629
14630 /* add playback controls for speaker and HP outputs */
14631 /* Based on ALC880 version. But ALC861VD has separate,
14632  * different NIDs for mute/unmute switch and volume control */
14633 static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
14634                                         hda_nid_t pin, const char *pfx)
14635 {
14636         hda_nid_t nid_v, nid_s;
14637         int err;
14638         char name[32];
14639
14640         if (!pin)
14641                 return 0;
14642
14643         if (alc880_is_fixed_pin(pin)) {
14644                 nid_v = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
14645                 /* specify the DAC as the extra output */
14646                 if (!spec->multiout.hp_nid)
14647                         spec->multiout.hp_nid = nid_v;
14648                 else
14649                         spec->multiout.extra_out_nid[0] = nid_v;
14650                 /* control HP volume/switch on the output mixer amp */
14651                 nid_v = alc861vd_idx_to_mixer_vol(
14652                                 alc880_fixed_pin_idx(pin));
14653                 nid_s = alc861vd_idx_to_mixer_switch(
14654                                 alc880_fixed_pin_idx(pin));
14655
14656                 sprintf(name, "%s Playback Volume", pfx);
14657                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
14658                                   HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT));
14659                 if (err < 0)
14660                         return err;
14661                 sprintf(name, "%s Playback Switch", pfx);
14662                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
14663                                   HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT));
14664                 if (err < 0)
14665                         return err;
14666         } else if (alc880_is_multi_pin(pin)) {
14667                 /* set manual connection */
14668                 /* we have only a switch on HP-out PIN */
14669                 sprintf(name, "%s Playback Switch", pfx);
14670                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
14671                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
14672                 if (err < 0)
14673                         return err;
14674         }
14675         return 0;
14676 }
14677
14678 /* parse the BIOS configuration and set up the alc_spec
14679  * return 1 if successful, 0 if the proper config is not found,
14680  * or a negative error code
14681  * Based on ALC880 version - had to change it to override
14682  * alc880_auto_create_extra_out and alc880_auto_create_multi_out_ctls */
14683 static int alc861vd_parse_auto_config(struct hda_codec *codec)
14684 {
14685         struct alc_spec *spec = codec->spec;
14686         int err;
14687         static hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
14688
14689         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
14690                                            alc861vd_ignore);
14691         if (err < 0)
14692                 return err;
14693         if (!spec->autocfg.line_outs)
14694                 return 0; /* can't find valid BIOS pin config */
14695
14696         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
14697         if (err < 0)
14698                 return err;
14699         err = alc861vd_auto_create_multi_out_ctls(spec, &spec->autocfg);
14700         if (err < 0)
14701                 return err;
14702         err = alc861vd_auto_create_extra_out(spec,
14703                                              spec->autocfg.speaker_pins[0],
14704                                              "Speaker");
14705         if (err < 0)
14706                 return err;
14707         err = alc861vd_auto_create_extra_out(spec,
14708                                              spec->autocfg.hp_pins[0],
14709                                              "Headphone");
14710         if (err < 0)
14711                 return err;
14712         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
14713         if (err < 0)
14714                 return err;
14715
14716         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
14717
14718         if (spec->autocfg.dig_out_pin)
14719                 spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID;
14720
14721         if (spec->kctls.list)
14722                 add_mixer(spec, spec->kctls.list);
14723
14724         add_verb(spec, alc861vd_volume_init_verbs);
14725
14726         spec->num_mux_defs = 1;
14727         spec->input_mux = &spec->private_imux;
14728
14729         err = alc_auto_add_mic_boost(codec);
14730         if (err < 0)
14731                 return err;
14732
14733         store_pin_configs(codec);
14734         return 1;
14735 }
14736
14737 /* additional initialization for auto-configuration model */
14738 static void alc861vd_auto_init(struct hda_codec *codec)
14739 {
14740         struct alc_spec *spec = codec->spec;
14741         alc861vd_auto_init_multi_out(codec);
14742         alc861vd_auto_init_hp_out(codec);
14743         alc861vd_auto_init_analog_input(codec);
14744         alc861vd_auto_init_input_src(codec);
14745         if (spec->unsol_event)
14746                 alc_inithook(codec);
14747 }
14748
14749 static int patch_alc861vd(struct hda_codec *codec)
14750 {
14751         struct alc_spec *spec;
14752         int err, board_config;
14753
14754         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
14755         if (spec == NULL)
14756                 return -ENOMEM;
14757
14758         codec->spec = spec;
14759
14760         board_config = snd_hda_check_board_config(codec, ALC861VD_MODEL_LAST,
14761                                                   alc861vd_models,
14762                                                   alc861vd_cfg_tbl);
14763
14764         if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) {
14765                 printk(KERN_INFO "hda_codec: Unknown model for ALC660VD/"
14766                         "ALC861VD, trying auto-probe from BIOS...\n");
14767                 board_config = ALC861VD_AUTO;
14768         }
14769
14770         if (board_config == ALC861VD_AUTO) {
14771                 /* automatic parse from the BIOS config */
14772                 err = alc861vd_parse_auto_config(codec);
14773                 if (err < 0) {
14774                         alc_free(codec);
14775                         return err;
14776                 } else if (!err) {
14777                         printk(KERN_INFO
14778                                "hda_codec: Cannot set up configuration "
14779                                "from BIOS.  Using base mode...\n");
14780                         board_config = ALC861VD_3ST;
14781                 }
14782         }
14783
14784         if (board_config != ALC861VD_AUTO)
14785                 setup_preset(spec, &alc861vd_presets[board_config]);
14786
14787         if (codec->vendor_id == 0x10ec0660) {
14788                 spec->stream_name_analog = "ALC660-VD Analog";
14789                 spec->stream_name_digital = "ALC660-VD Digital";
14790                 /* always turn on EAPD */
14791                 add_verb(spec, alc660vd_eapd_verbs);
14792         } else {
14793                 spec->stream_name_analog = "ALC861VD Analog";
14794                 spec->stream_name_digital = "ALC861VD Digital";
14795         }
14796
14797         spec->stream_analog_playback = &alc861vd_pcm_analog_playback;
14798         spec->stream_analog_capture = &alc861vd_pcm_analog_capture;
14799
14800         spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
14801         spec->stream_digital_capture = &alc861vd_pcm_digital_capture;
14802
14803         spec->adc_nids = alc861vd_adc_nids;
14804         spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
14805         spec->capsrc_nids = alc861vd_capsrc_nids;
14806         spec->is_mix_capture = 1;
14807
14808         set_capture_mixer(spec);
14809
14810         spec->vmaster_nid = 0x02;
14811
14812         codec->patch_ops = alc_patch_ops;
14813
14814         if (board_config == ALC861VD_AUTO)
14815                 spec->init_hook = alc861vd_auto_init;
14816 #ifdef CONFIG_SND_HDA_POWER_SAVE
14817         if (!spec->loopback.amplist)
14818                 spec->loopback.amplist = alc861vd_loopbacks;
14819 #endif
14820         codec->proc_widget_hook = print_realtek_coef;
14821
14822         return 0;
14823 }
14824
14825 /*
14826  * ALC662 support
14827  *
14828  * ALC662 is almost identical with ALC880 but has cleaner and more flexible
14829  * configuration.  Each pin widget can choose any input DACs and a mixer.
14830  * Each ADC is connected from a mixer of all inputs.  This makes possible
14831  * 6-channel independent captures.
14832  *
14833  * In addition, an independent DAC for the multi-playback (not used in this
14834  * driver yet).
14835  */
14836 #define ALC662_DIGOUT_NID       0x06
14837 #define ALC662_DIGIN_NID        0x0a
14838
14839 static hda_nid_t alc662_dac_nids[4] = {
14840         /* front, rear, clfe, rear_surr */
14841         0x02, 0x03, 0x04
14842 };
14843
14844 static hda_nid_t alc662_adc_nids[1] = {
14845         /* ADC1-2 */
14846         0x09,
14847 };
14848
14849 static hda_nid_t alc662_capsrc_nids[1] = { 0x22 };
14850
14851 /* input MUX */
14852 /* FIXME: should be a matrix-type input source selection */
14853 static struct hda_input_mux alc662_capture_source = {
14854         .num_items = 4,
14855         .items = {
14856                 { "Mic", 0x0 },
14857                 { "Front Mic", 0x1 },
14858                 { "Line", 0x2 },
14859                 { "CD", 0x4 },
14860         },
14861 };
14862
14863 static struct hda_input_mux alc662_lenovo_101e_capture_source = {
14864         .num_items = 2,
14865         .items = {
14866                 { "Mic", 0x1 },
14867                 { "Line", 0x2 },
14868         },
14869 };
14870
14871 static struct hda_input_mux alc662_eeepc_capture_source = {
14872         .num_items = 2,
14873         .items = {
14874                 { "i-Mic", 0x1 },
14875                 { "e-Mic", 0x0 },
14876         },
14877 };
14878
14879 static struct hda_input_mux alc663_capture_source = {
14880         .num_items = 3,
14881         .items = {
14882                 { "Mic", 0x0 },
14883                 { "Front Mic", 0x1 },
14884                 { "Line", 0x2 },
14885         },
14886 };
14887
14888 static struct hda_input_mux alc663_m51va_capture_source = {
14889         .num_items = 2,
14890         .items = {
14891                 { "Ext-Mic", 0x0 },
14892                 { "D-Mic", 0x9 },
14893         },
14894 };
14895
14896 /*
14897  * 2ch mode
14898  */
14899 static struct hda_channel_mode alc662_3ST_2ch_modes[1] = {
14900         { 2, NULL }
14901 };
14902
14903 /*
14904  * 2ch mode
14905  */
14906 static struct hda_verb alc662_3ST_ch2_init[] = {
14907         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
14908         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
14909         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
14910         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
14911         { } /* end */
14912 };
14913
14914 /*
14915  * 6ch mode
14916  */
14917 static struct hda_verb alc662_3ST_ch6_init[] = {
14918         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14919         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
14920         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
14921         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14922         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
14923         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
14924         { } /* end */
14925 };
14926
14927 static struct hda_channel_mode alc662_3ST_6ch_modes[2] = {
14928         { 2, alc662_3ST_ch2_init },
14929         { 6, alc662_3ST_ch6_init },
14930 };
14931
14932 /*
14933  * 2ch mode
14934  */
14935 static struct hda_verb alc662_sixstack_ch6_init[] = {
14936         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
14937         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
14938         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14939         { } /* end */
14940 };
14941
14942 /*
14943  * 6ch mode
14944  */
14945 static struct hda_verb alc662_sixstack_ch8_init[] = {
14946         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14947         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14948         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14949         { } /* end */
14950 };
14951
14952 static struct hda_channel_mode alc662_5stack_modes[2] = {
14953         { 2, alc662_sixstack_ch6_init },
14954         { 6, alc662_sixstack_ch8_init },
14955 };
14956
14957 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
14958  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
14959  */
14960
14961 static struct snd_kcontrol_new alc662_base_mixer[] = {
14962         /* output mixer control */
14963         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
14964         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
14965         HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
14966         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
14967         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
14968         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
14969         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
14970         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
14971         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14972
14973         /*Input mixer control */
14974         HDA_CODEC_VOLUME("CD Playback Volume", 0xb, 0x4, HDA_INPUT),
14975         HDA_CODEC_MUTE("CD Playback Switch", 0xb, 0x4, HDA_INPUT),
14976         HDA_CODEC_VOLUME("Line Playback Volume", 0xb, 0x02, HDA_INPUT),
14977         HDA_CODEC_MUTE("Line Playback Switch", 0xb, 0x02, HDA_INPUT),
14978         HDA_CODEC_VOLUME("Mic Playback Volume", 0xb, 0x0, HDA_INPUT),
14979         HDA_CODEC_MUTE("Mic Playback Switch", 0xb, 0x0, HDA_INPUT),
14980         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0xb, 0x01, HDA_INPUT),
14981         HDA_CODEC_MUTE("Front Mic Playback Switch", 0xb, 0x01, HDA_INPUT),
14982         { } /* end */
14983 };
14984
14985 static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
14986         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14987         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
14988         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14989         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14990         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14991         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14992         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14993         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14994         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14995         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14996         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14997         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
14998         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
14999         { } /* end */
15000 };
15001
15002 static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
15003         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15004         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
15005         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15006         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
15007         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15008         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15009         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
15010         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
15011         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15012         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
15013         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
15014         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15015         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15016         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15017         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15018         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15019         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15020         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
15021         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
15022         { } /* end */
15023 };
15024
15025 static struct snd_kcontrol_new alc662_lenovo_101e_mixer[] = {
15026         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15027         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
15028         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15029         HDA_BIND_MUTE("Speaker Playback Switch", 0x03, 2, HDA_INPUT),
15030         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15031         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15032         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15033         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15034         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15035         { } /* end */
15036 };
15037
15038 static struct snd_kcontrol_new alc662_eeepc_p701_mixer[] = {
15039         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15040
15041         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15042         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15043
15044         HDA_CODEC_VOLUME("e-Mic Boost", 0x18, 0, HDA_INPUT),
15045         HDA_CODEC_VOLUME("e-Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15046         HDA_CODEC_MUTE("e-Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15047
15048         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
15049         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15050         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15051         { } /* end */
15052 };
15053
15054 static struct snd_kcontrol_new alc662_eeepc_ep20_mixer[] = {
15055         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15056         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15057         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15058         HDA_BIND_MUTE("Surround Playback Switch", 0x03, 2, HDA_INPUT),
15059         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15060         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15061         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT),
15062         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT),
15063         HDA_CODEC_MUTE("Speaker Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15064         HDA_BIND_MUTE("MuteCtrl Playback Switch", 0x0c, 2, HDA_INPUT),
15065         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15066         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15067         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15068         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15069         { } /* end */
15070 };
15071
15072 static struct hda_bind_ctls alc663_asus_bind_master_vol = {
15073         .ops = &snd_hda_bind_vol,
15074         .values = {
15075                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
15076                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
15077                 0
15078         },
15079 };
15080
15081 static struct hda_bind_ctls alc663_asus_one_bind_switch = {
15082         .ops = &snd_hda_bind_sw,
15083         .values = {
15084                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15085                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
15086                 0
15087         },
15088 };
15089
15090 static struct snd_kcontrol_new alc663_m51va_mixer[] = {
15091         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15092         HDA_BIND_SW("Master Playback Switch", &alc663_asus_one_bind_switch),
15093         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15094         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15095         { } /* end */
15096 };
15097
15098 static struct hda_bind_ctls alc663_asus_tree_bind_switch = {
15099         .ops = &snd_hda_bind_sw,
15100         .values = {
15101                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15102                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
15103                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
15104                 0
15105         },
15106 };
15107
15108 static struct snd_kcontrol_new alc663_two_hp_m1_mixer[] = {
15109         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15110         HDA_BIND_SW("Master Playback Switch", &alc663_asus_tree_bind_switch),
15111         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15112         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15113         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15114         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15115
15116         { } /* end */
15117 };
15118
15119 static struct hda_bind_ctls alc663_asus_four_bind_switch = {
15120         .ops = &snd_hda_bind_sw,
15121         .values = {
15122                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15123                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
15124                 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
15125                 0
15126         },
15127 };
15128
15129 static struct snd_kcontrol_new alc663_two_hp_m2_mixer[] = {
15130         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15131         HDA_BIND_SW("Master Playback Switch", &alc663_asus_four_bind_switch),
15132         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15133         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15134         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15135         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15136         { } /* end */
15137 };
15138
15139 static struct snd_kcontrol_new alc662_1bjd_mixer[] = {
15140         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15141         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15142         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15143         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15144         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15145         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15146         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15147         { } /* end */
15148 };
15149
15150 static struct hda_bind_ctls alc663_asus_two_bind_master_vol = {
15151         .ops = &snd_hda_bind_vol,
15152         .values = {
15153                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
15154                 HDA_COMPOSE_AMP_VAL(0x04, 3, 0, HDA_OUTPUT),
15155                 0
15156         },
15157 };
15158
15159 static struct hda_bind_ctls alc663_asus_two_bind_switch = {
15160         .ops = &snd_hda_bind_sw,
15161         .values = {
15162                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15163                 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT),
15164                 0
15165         },
15166 };
15167
15168 static struct snd_kcontrol_new alc663_asus_21jd_clfe_mixer[] = {
15169         HDA_BIND_VOL("Master Playback Volume",
15170                                 &alc663_asus_two_bind_master_vol),
15171         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
15172         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15173         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
15174         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15175         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15176         { } /* end */
15177 };
15178
15179 static struct snd_kcontrol_new alc663_asus_15jd_clfe_mixer[] = {
15180         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15181         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
15182         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15183         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
15184         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15185         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15186         { } /* end */
15187 };
15188
15189 static struct snd_kcontrol_new alc663_g71v_mixer[] = {
15190         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15191         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15192         HDA_CODEC_VOLUME("Front Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15193         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
15194         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
15195
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("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15199         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15200         { } /* end */
15201 };
15202
15203 static struct snd_kcontrol_new alc663_g50v_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", 0x21, 0x0, HDA_OUTPUT),
15207
15208         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15209         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15210         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15211         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15212         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15213         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15214         { } /* end */
15215 };
15216
15217 static struct snd_kcontrol_new alc662_chmode_mixer[] = {
15218         {
15219                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
15220                 .name = "Channel Mode",
15221                 .info = alc_ch_mode_info,
15222                 .get = alc_ch_mode_get,
15223                 .put = alc_ch_mode_put,
15224         },
15225         { } /* end */
15226 };
15227
15228 static struct hda_verb alc662_init_verbs[] = {
15229         /* ADC: mute amp left and right */
15230         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15231         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
15232         /* Front mixer: unmute input/output amp left and right (volume = 0) */
15233
15234         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15235         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15236         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
15237         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
15238         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
15239
15240         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15241         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15242         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15243         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15244         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15245         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15246
15247         /* Front Pin: output 0 (0x0c) */
15248         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15249         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15250
15251         /* Rear Pin: output 1 (0x0d) */
15252         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15253         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15254
15255         /* CLFE Pin: output 2 (0x0e) */
15256         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15257         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15258
15259         /* Mic (rear) pin: input vref at 80% */
15260         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
15261         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15262         /* Front Mic pin: input vref at 80% */
15263         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
15264         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15265         /* Line In pin: input */
15266         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15267         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15268         /* Line-2 In: Headphone output (output 0 - 0x0c) */
15269         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15270         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15271         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
15272         /* CD pin widget for input */
15273         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15274
15275         /* FIXME: use matrix-type input source selection */
15276         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
15277         /* Input mixer */
15278         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15279         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15280         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
15281         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
15282
15283         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15284         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15285         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
15286         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
15287
15288         /* always trun on EAPD */
15289         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
15290         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
15291
15292         { }
15293 };
15294
15295 static struct hda_verb alc662_sue_init_verbs[] = {
15296         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
15297         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
15298         {}
15299 };
15300
15301 static struct hda_verb alc662_eeepc_sue_init_verbs[] = {
15302         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15303         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15304         {}
15305 };
15306
15307 /* Set Unsolicited Event*/
15308 static struct hda_verb alc662_eeepc_ep20_sue_init_verbs[] = {
15309         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15310         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15311         {}
15312 };
15313
15314 /*
15315  * generic initialization of ADC, input mixers and output mixers
15316  */
15317 static struct hda_verb alc662_auto_init_verbs[] = {
15318         /*
15319          * Unmute ADC and set the default input to mic-in
15320          */
15321         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
15322         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15323
15324         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
15325          * mixer widget
15326          * Note: PASD motherboards uses the Line In 2 as the input for front
15327          * panel mic (mic 2)
15328          */
15329         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
15330         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15331         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15332         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
15333         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
15334         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
15335
15336         /*
15337          * Set up output mixers (0x0c - 0x0f)
15338          */
15339         /* set vol=0 to output mixers */
15340         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15341         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15342         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15343
15344         /* set up input amps for analog loopback */
15345         /* Amp Indices: DAC = 0, mixer = 1 */
15346         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15347         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15348         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15349         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15350         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15351         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15352
15353
15354         /* FIXME: use matrix-type input source selection */
15355         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
15356         /* Input mixer */
15357         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15358         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15359         { }
15360 };
15361
15362 /* additional verbs for ALC663 */
15363 static struct hda_verb alc663_auto_init_verbs[] = {
15364         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15365         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15366         { }
15367 };
15368
15369 static struct hda_verb alc663_m51va_init_verbs[] = {
15370         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15371         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15372         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15373         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15374         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15375         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15376         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
15377         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15378         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15379         {}
15380 };
15381
15382 static struct hda_verb alc663_21jd_amic_init_verbs[] = {
15383         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15384         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15385         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15386         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15387         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15388         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15389         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15390         {}
15391 };
15392
15393 static struct hda_verb alc662_1bjd_amic_init_verbs[] = {
15394         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15395         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15396         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15397         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
15398         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15399         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15400         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15401         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15402         {}
15403 };
15404
15405 static struct hda_verb alc663_15jd_amic_init_verbs[] = {
15406         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15407         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15408         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15409         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15410         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15411         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15412         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15413         {}
15414 };
15415
15416 static struct hda_verb alc663_two_hp_amic_m1_init_verbs[] = {
15417         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15418         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15419         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15420         {0x21, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
15421         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15422         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15423         {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
15424         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15425         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15426         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15427         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15428         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15429         {}
15430 };
15431
15432 static struct hda_verb alc663_two_hp_amic_m2_init_verbs[] = {
15433         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15434         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15435         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15436         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15437         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15438         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15439         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15440         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15441         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15442         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15443         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15444         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15445         {}
15446 };
15447
15448 static struct hda_verb alc663_g71v_init_verbs[] = {
15449         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15450         /* {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
15451         /* {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, */ /* Headphone */
15452
15453         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15454         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15455         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
15456
15457         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
15458         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_MIC_EVENT},
15459         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
15460         {}
15461 };
15462
15463 static struct hda_verb alc663_g50v_init_verbs[] = {
15464         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15465         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15466         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
15467
15468         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15469         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15470         {}
15471 };
15472
15473 static struct hda_verb alc662_ecs_init_verbs[] = {
15474         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0x701f},
15475         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15476         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15477         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15478         {}
15479 };
15480
15481 static struct snd_kcontrol_new alc662_auto_capture_mixer[] = {
15482         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
15483         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
15484         { } /* end */
15485 };
15486
15487 static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
15488 {
15489         unsigned int present;
15490         unsigned char bits;
15491
15492         present = snd_hda_codec_read(codec, 0x14, 0,
15493                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15494         bits = present ? HDA_AMP_MUTE : 0;
15495         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
15496                                  HDA_AMP_MUTE, bits);
15497 }
15498
15499 static void alc662_lenovo_101e_all_automute(struct hda_codec *codec)
15500 {
15501         unsigned int present;
15502         unsigned char bits;
15503
15504         present = snd_hda_codec_read(codec, 0x1b, 0,
15505                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15506         bits = present ? HDA_AMP_MUTE : 0;
15507         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
15508                                  HDA_AMP_MUTE, bits);
15509         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
15510                                  HDA_AMP_MUTE, bits);
15511 }
15512
15513 static void alc662_lenovo_101e_unsol_event(struct hda_codec *codec,
15514                                            unsigned int res)
15515 {
15516         if ((res >> 26) == ALC880_HP_EVENT)
15517                 alc662_lenovo_101e_all_automute(codec);
15518         if ((res >> 26) == ALC880_FRONT_EVENT)
15519                 alc662_lenovo_101e_ispeaker_automute(codec);
15520 }
15521
15522 static void alc662_eeepc_mic_automute(struct hda_codec *codec)
15523 {
15524         unsigned int present;
15525
15526         present = snd_hda_codec_read(codec, 0x18, 0,
15527                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15528         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15529                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15530         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15531                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15532         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15533                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
15534         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15535                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
15536 }
15537
15538 /* unsolicited event for HP jack sensing */
15539 static void alc662_eeepc_unsol_event(struct hda_codec *codec,
15540                                      unsigned int res)
15541 {
15542         if ((res >> 26) == ALC880_HP_EVENT)
15543                 alc262_hippo1_automute( codec );
15544
15545         if ((res >> 26) == ALC880_MIC_EVENT)
15546                 alc662_eeepc_mic_automute(codec);
15547 }
15548
15549 static void alc662_eeepc_inithook(struct hda_codec *codec)
15550 {
15551         alc262_hippo1_automute( codec );
15552         alc662_eeepc_mic_automute(codec);
15553 }
15554
15555 static void alc662_eeepc_ep20_automute(struct hda_codec *codec)
15556 {
15557         unsigned int mute;
15558         unsigned int present;
15559
15560         snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
15561         present = snd_hda_codec_read(codec, 0x14, 0,
15562                                      AC_VERB_GET_PIN_SENSE, 0);
15563         present = (present & 0x80000000) != 0;
15564         if (present) {
15565                 /* mute internal speaker */
15566                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
15567                                         HDA_AMP_MUTE, HDA_AMP_MUTE);
15568         } else {
15569                 /* unmute internal speaker if necessary */
15570                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
15571                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
15572                                         HDA_AMP_MUTE, mute);
15573         }
15574 }
15575
15576 /* unsolicited event for HP jack sensing */
15577 static void alc662_eeepc_ep20_unsol_event(struct hda_codec *codec,
15578                                           unsigned int res)
15579 {
15580         if ((res >> 26) == ALC880_HP_EVENT)
15581                 alc662_eeepc_ep20_automute(codec);
15582 }
15583
15584 static void alc662_eeepc_ep20_inithook(struct hda_codec *codec)
15585 {
15586         alc662_eeepc_ep20_automute(codec);
15587 }
15588
15589 static void alc663_m51va_speaker_automute(struct hda_codec *codec)
15590 {
15591         unsigned int present;
15592         unsigned char bits;
15593
15594         present = snd_hda_codec_read(codec, 0x21, 0,
15595                         AC_VERB_GET_PIN_SENSE, 0)
15596                         & AC_PINSENSE_PRESENCE;
15597         bits = present ? HDA_AMP_MUTE : 0;
15598         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15599                                 AMP_IN_MUTE(0), bits);
15600         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15601                                 AMP_IN_MUTE(0), bits);
15602 }
15603
15604 static void alc663_21jd_two_speaker_automute(struct hda_codec *codec)
15605 {
15606         unsigned int present;
15607         unsigned char bits;
15608
15609         present = snd_hda_codec_read(codec, 0x21, 0,
15610                         AC_VERB_GET_PIN_SENSE, 0)
15611                         & AC_PINSENSE_PRESENCE;
15612         bits = present ? HDA_AMP_MUTE : 0;
15613         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15614                                 AMP_IN_MUTE(0), bits);
15615         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15616                                 AMP_IN_MUTE(0), bits);
15617         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
15618                                 AMP_IN_MUTE(0), bits);
15619         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
15620                                 AMP_IN_MUTE(0), bits);
15621 }
15622
15623 static void alc663_15jd_two_speaker_automute(struct hda_codec *codec)
15624 {
15625         unsigned int present;
15626         unsigned char bits;
15627
15628         present = snd_hda_codec_read(codec, 0x15, 0,
15629                         AC_VERB_GET_PIN_SENSE, 0)
15630                         & AC_PINSENSE_PRESENCE;
15631         bits = present ? HDA_AMP_MUTE : 0;
15632         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15633                                 AMP_IN_MUTE(0), bits);
15634         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15635                                 AMP_IN_MUTE(0), bits);
15636         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
15637                                 AMP_IN_MUTE(0), bits);
15638         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
15639                                 AMP_IN_MUTE(0), bits);
15640 }
15641
15642 static void alc662_f5z_speaker_automute(struct hda_codec *codec)
15643 {
15644         unsigned int present;
15645         unsigned char bits;
15646
15647         present = snd_hda_codec_read(codec, 0x1b, 0,
15648                         AC_VERB_GET_PIN_SENSE, 0)
15649                         & AC_PINSENSE_PRESENCE;
15650         bits = present ? 0 : PIN_OUT;
15651         snd_hda_codec_write(codec, 0x14, 0,
15652                          AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
15653 }
15654
15655 static void alc663_two_hp_m1_speaker_automute(struct hda_codec *codec)
15656 {
15657         unsigned int present1, present2;
15658
15659         present1 = snd_hda_codec_read(codec, 0x21, 0,
15660                         AC_VERB_GET_PIN_SENSE, 0)
15661                         & AC_PINSENSE_PRESENCE;
15662         present2 = snd_hda_codec_read(codec, 0x15, 0,
15663                         AC_VERB_GET_PIN_SENSE, 0)
15664                         & AC_PINSENSE_PRESENCE;
15665
15666         if (present1 || present2) {
15667                 snd_hda_codec_write_cache(codec, 0x14, 0,
15668                         AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
15669         } else {
15670                 snd_hda_codec_write_cache(codec, 0x14, 0,
15671                         AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
15672         }
15673 }
15674
15675 static void alc663_two_hp_m2_speaker_automute(struct hda_codec *codec)
15676 {
15677         unsigned int present1, present2;
15678
15679         present1 = snd_hda_codec_read(codec, 0x1b, 0,
15680                                 AC_VERB_GET_PIN_SENSE, 0)
15681                                 & AC_PINSENSE_PRESENCE;
15682         present2 = snd_hda_codec_read(codec, 0x15, 0,
15683                                 AC_VERB_GET_PIN_SENSE, 0)
15684                                 & AC_PINSENSE_PRESENCE;
15685
15686         if (present1 || present2) {
15687                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15688                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
15689                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15690                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
15691         } else {
15692                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15693                                 AMP_IN_MUTE(0), 0);
15694                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15695                                 AMP_IN_MUTE(0), 0);
15696         }
15697 }
15698
15699 static void alc663_m51va_mic_automute(struct hda_codec *codec)
15700 {
15701         unsigned int present;
15702
15703         present = snd_hda_codec_read(codec, 0x18, 0,
15704                         AC_VERB_GET_PIN_SENSE, 0)
15705                         & AC_PINSENSE_PRESENCE;
15706         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15707                         0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15708         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15709                         0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15710         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15711                         0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
15712         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15713                         0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
15714 }
15715
15716 static void alc663_m51va_unsol_event(struct hda_codec *codec,
15717                                            unsigned int res)
15718 {
15719         switch (res >> 26) {
15720         case ALC880_HP_EVENT:
15721                 alc663_m51va_speaker_automute(codec);
15722                 break;
15723         case ALC880_MIC_EVENT:
15724                 alc663_m51va_mic_automute(codec);
15725                 break;
15726         }
15727 }
15728
15729 static void alc663_m51va_inithook(struct hda_codec *codec)
15730 {
15731         alc663_m51va_speaker_automute(codec);
15732         alc663_m51va_mic_automute(codec);
15733 }
15734
15735 /* ***************** Mode1 ******************************/
15736 static void alc663_mode1_unsol_event(struct hda_codec *codec,
15737                                            unsigned int res)
15738 {
15739         switch (res >> 26) {
15740         case ALC880_HP_EVENT:
15741                 alc663_m51va_speaker_automute(codec);
15742                 break;
15743         case ALC880_MIC_EVENT:
15744                 alc662_eeepc_mic_automute(codec);
15745                 break;
15746         }
15747 }
15748
15749 static void alc663_mode1_inithook(struct hda_codec *codec)
15750 {
15751         alc663_m51va_speaker_automute(codec);
15752         alc662_eeepc_mic_automute(codec);
15753 }
15754 /* ***************** Mode2 ******************************/
15755 static void alc662_mode2_unsol_event(struct hda_codec *codec,
15756                                            unsigned int res)
15757 {
15758         switch (res >> 26) {
15759         case ALC880_HP_EVENT:
15760                 alc662_f5z_speaker_automute(codec);
15761                 break;
15762         case ALC880_MIC_EVENT:
15763                 alc662_eeepc_mic_automute(codec);
15764                 break;
15765         }
15766 }
15767
15768 static void alc662_mode2_inithook(struct hda_codec *codec)
15769 {
15770         alc662_f5z_speaker_automute(codec);
15771         alc662_eeepc_mic_automute(codec);
15772 }
15773 /* ***************** Mode3 ******************************/
15774 static void alc663_mode3_unsol_event(struct hda_codec *codec,
15775                                            unsigned int res)
15776 {
15777         switch (res >> 26) {
15778         case ALC880_HP_EVENT:
15779                 alc663_two_hp_m1_speaker_automute(codec);
15780                 break;
15781         case ALC880_MIC_EVENT:
15782                 alc662_eeepc_mic_automute(codec);
15783                 break;
15784         }
15785 }
15786
15787 static void alc663_mode3_inithook(struct hda_codec *codec)
15788 {
15789         alc663_two_hp_m1_speaker_automute(codec);
15790         alc662_eeepc_mic_automute(codec);
15791 }
15792 /* ***************** Mode4 ******************************/
15793 static void alc663_mode4_unsol_event(struct hda_codec *codec,
15794                                            unsigned int res)
15795 {
15796         switch (res >> 26) {
15797         case ALC880_HP_EVENT:
15798                 alc663_21jd_two_speaker_automute(codec);
15799                 break;
15800         case ALC880_MIC_EVENT:
15801                 alc662_eeepc_mic_automute(codec);
15802                 break;
15803         }
15804 }
15805
15806 static void alc663_mode4_inithook(struct hda_codec *codec)
15807 {
15808         alc663_21jd_two_speaker_automute(codec);
15809         alc662_eeepc_mic_automute(codec);
15810 }
15811 /* ***************** Mode5 ******************************/
15812 static void alc663_mode5_unsol_event(struct hda_codec *codec,
15813                                            unsigned int res)
15814 {
15815         switch (res >> 26) {
15816         case ALC880_HP_EVENT:
15817                 alc663_15jd_two_speaker_automute(codec);
15818                 break;
15819         case ALC880_MIC_EVENT:
15820                 alc662_eeepc_mic_automute(codec);
15821                 break;
15822         }
15823 }
15824
15825 static void alc663_mode5_inithook(struct hda_codec *codec)
15826 {
15827         alc663_15jd_two_speaker_automute(codec);
15828         alc662_eeepc_mic_automute(codec);
15829 }
15830 /* ***************** Mode6 ******************************/
15831 static void alc663_mode6_unsol_event(struct hda_codec *codec,
15832                                            unsigned int res)
15833 {
15834         switch (res >> 26) {
15835         case ALC880_HP_EVENT:
15836                 alc663_two_hp_m2_speaker_automute(codec);
15837                 break;
15838         case ALC880_MIC_EVENT:
15839                 alc662_eeepc_mic_automute(codec);
15840                 break;
15841         }
15842 }
15843
15844 static void alc663_mode6_inithook(struct hda_codec *codec)
15845 {
15846         alc663_two_hp_m2_speaker_automute(codec);
15847         alc662_eeepc_mic_automute(codec);
15848 }
15849
15850 static void alc663_g71v_hp_automute(struct hda_codec *codec)
15851 {
15852         unsigned int present;
15853         unsigned char bits;
15854
15855         present = snd_hda_codec_read(codec, 0x21, 0,
15856                                      AC_VERB_GET_PIN_SENSE, 0)
15857                 & AC_PINSENSE_PRESENCE;
15858         bits = present ? HDA_AMP_MUTE : 0;
15859         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
15860                                  HDA_AMP_MUTE, bits);
15861         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
15862                                  HDA_AMP_MUTE, bits);
15863 }
15864
15865 static void alc663_g71v_front_automute(struct hda_codec *codec)
15866 {
15867         unsigned int present;
15868         unsigned char bits;
15869
15870         present = snd_hda_codec_read(codec, 0x15, 0,
15871                                      AC_VERB_GET_PIN_SENSE, 0)
15872                 & AC_PINSENSE_PRESENCE;
15873         bits = present ? HDA_AMP_MUTE : 0;
15874         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
15875                                  HDA_AMP_MUTE, bits);
15876 }
15877
15878 static void alc663_g71v_unsol_event(struct hda_codec *codec,
15879                                            unsigned int res)
15880 {
15881         switch (res >> 26) {
15882         case ALC880_HP_EVENT:
15883                 alc663_g71v_hp_automute(codec);
15884                 break;
15885         case ALC880_FRONT_EVENT:
15886                 alc663_g71v_front_automute(codec);
15887                 break;
15888         case ALC880_MIC_EVENT:
15889                 alc662_eeepc_mic_automute(codec);
15890                 break;
15891         }
15892 }
15893
15894 static void alc663_g71v_inithook(struct hda_codec *codec)
15895 {
15896         alc663_g71v_front_automute(codec);
15897         alc663_g71v_hp_automute(codec);
15898         alc662_eeepc_mic_automute(codec);
15899 }
15900
15901 static void alc663_g50v_unsol_event(struct hda_codec *codec,
15902                                            unsigned int res)
15903 {
15904         switch (res >> 26) {
15905         case ALC880_HP_EVENT:
15906                 alc663_m51va_speaker_automute(codec);
15907                 break;
15908         case ALC880_MIC_EVENT:
15909                 alc662_eeepc_mic_automute(codec);
15910                 break;
15911         }
15912 }
15913
15914 static void alc663_g50v_inithook(struct hda_codec *codec)
15915 {
15916         alc663_m51va_speaker_automute(codec);
15917         alc662_eeepc_mic_automute(codec);
15918 }
15919
15920 /* bind hp and internal speaker mute (with plug check) */
15921 static int alc662_ecs_master_sw_put(struct snd_kcontrol *kcontrol,
15922                                      struct snd_ctl_elem_value *ucontrol)
15923 {
15924         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
15925         long *valp = ucontrol->value.integer.value;
15926         int change;
15927
15928         change = snd_hda_codec_amp_update(codec, 0x1b, 0, HDA_OUTPUT, 0,
15929                                           HDA_AMP_MUTE,
15930                                           valp[0] ? 0 : HDA_AMP_MUTE);
15931         change |= snd_hda_codec_amp_update(codec, 0x1b, 1, HDA_OUTPUT, 0,
15932                                            HDA_AMP_MUTE,
15933                                            valp[1] ? 0 : HDA_AMP_MUTE);
15934         if (change)
15935                 alc262_hippo1_automute(codec);
15936         return change;
15937 }
15938
15939 static struct snd_kcontrol_new alc662_ecs_mixer[] = {
15940         HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15941         {
15942                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
15943                 .name = "Master Playback Switch",
15944                 .info = snd_hda_mixer_amp_switch_info,
15945                 .get = snd_hda_mixer_amp_switch_get,
15946                 .put = alc662_ecs_master_sw_put,
15947                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
15948         },
15949
15950         HDA_CODEC_VOLUME("e-Mic/LineIn Boost", 0x18, 0, HDA_INPUT),
15951         HDA_CODEC_VOLUME("e-Mic/LineIn Playback Volume", 0x0b, 0x0, HDA_INPUT),
15952         HDA_CODEC_MUTE("e-Mic/LineIn Playback Switch", 0x0b, 0x0, HDA_INPUT),
15953
15954         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
15955         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15956         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15957         { } /* end */
15958 };
15959
15960 #ifdef CONFIG_SND_HDA_POWER_SAVE
15961 #define alc662_loopbacks        alc880_loopbacks
15962 #endif
15963
15964
15965 /* pcm configuration: identiacal with ALC880 */
15966 #define alc662_pcm_analog_playback      alc880_pcm_analog_playback
15967 #define alc662_pcm_analog_capture       alc880_pcm_analog_capture
15968 #define alc662_pcm_digital_playback     alc880_pcm_digital_playback
15969 #define alc662_pcm_digital_capture      alc880_pcm_digital_capture
15970
15971 /*
15972  * configuration and preset
15973  */
15974 static const char *alc662_models[ALC662_MODEL_LAST] = {
15975         [ALC662_3ST_2ch_DIG]    = "3stack-dig",
15976         [ALC662_3ST_6ch_DIG]    = "3stack-6ch-dig",
15977         [ALC662_3ST_6ch]        = "3stack-6ch",
15978         [ALC662_5ST_DIG]        = "6stack-dig",
15979         [ALC662_LENOVO_101E]    = "lenovo-101e",
15980         [ALC662_ASUS_EEEPC_P701] = "eeepc-p701",
15981         [ALC662_ASUS_EEEPC_EP20] = "eeepc-ep20",
15982         [ALC662_ECS] = "ecs",
15983         [ALC663_ASUS_M51VA] = "m51va",
15984         [ALC663_ASUS_G71V] = "g71v",
15985         [ALC663_ASUS_H13] = "h13",
15986         [ALC663_ASUS_G50V] = "g50v",
15987         [ALC663_ASUS_MODE1] = "asus-mode1",
15988         [ALC662_ASUS_MODE2] = "asus-mode2",
15989         [ALC663_ASUS_MODE3] = "asus-mode3",
15990         [ALC663_ASUS_MODE4] = "asus-mode4",
15991         [ALC663_ASUS_MODE5] = "asus-mode5",
15992         [ALC663_ASUS_MODE6] = "asus-mode6",
15993         [ALC662_AUTO]           = "auto",
15994 };
15995
15996 static struct snd_pci_quirk alc662_cfg_tbl[] = {
15997         SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M51VA", ALC663_ASUS_M51VA),
15998         SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS G50V", ALC663_ASUS_G50V),
15999         SND_PCI_QUIRK(0x1043, 0x8290, "ASUS P5GC-MX", ALC662_3ST_6ch_DIG),
16000         SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
16001         SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20),
16002         SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC663_ASUS_MODE1),
16003         SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M50Vr", ALC663_ASUS_MODE1),
16004         SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC663_ASUS_MODE1),
16005         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC663_ASUS_MODE1),
16006         SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC663_ASUS_MODE1),
16007         SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS NB", ALC663_ASUS_MODE1),
16008         SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC663_ASUS_MODE1),
16009         SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC663_ASUS_MODE1),
16010         SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC663_ASUS_MODE1),
16011         SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC663_ASUS_MODE1),
16012         SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_ASUS_MODE2),
16013         SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_ASUS_MODE2),
16014         SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_ASUS_MODE2),
16015         SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_ASUS_MODE2),
16016         SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_ASUS_MODE2),
16017         SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_ASUS_MODE2),
16018         SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_ASUS_MODE2),
16019         SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_ASUS_MODE2),
16020         SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_ASUS_MODE2),
16021         SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_ASUS_MODE2),
16022         SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_ASUS_MODE2),
16023         SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_ASUS_MODE2),
16024         SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC663_ASUS_MODE3),
16025         SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC663_ASUS_MODE3),
16026         SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC663_ASUS_MODE3),
16027         SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC663_ASUS_MODE3),
16028         SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC663_ASUS_MODE3),
16029         SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC663_ASUS_MODE4),
16030         SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC663_ASUS_MODE5),
16031         SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC663_ASUS_MODE6),
16032         SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC663_ASUS_MODE6),
16033         SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC663_ASUS_MODE6),
16034         SND_PCI_QUIRK(0x105b, 0x0d47, "Foxconn 45CMX/45GMX/45CMX-K",
16035                       ALC662_3ST_6ch_DIG),
16036         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
16037         SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_ECS),
16038         SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_ECS),
16039         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte 945GCM-S2L",
16040                       ALC662_3ST_6ch_DIG),
16041         SND_PCI_QUIRK(0x1565, 0x820f, "Biostar TA780G M2+", ALC662_3ST_6ch_DIG),
16042         SND_PCI_QUIRK(0x1849, 0x3662, "ASROCK K10N78FullHD-hSLI R3.0",
16043                                         ALC662_3ST_6ch_DIG),
16044         SND_PCI_QUIRK(0x1854, 0x2000, "ASUS H13-2000", ALC663_ASUS_H13),
16045         SND_PCI_QUIRK(0x1854, 0x2001, "ASUS H13-2001", ALC663_ASUS_H13),
16046         SND_PCI_QUIRK(0x1854, 0x2002, "ASUS H13-2002", ALC663_ASUS_H13),
16047         {}
16048 };
16049
16050 static struct alc_config_preset alc662_presets[] = {
16051         [ALC662_3ST_2ch_DIG] = {
16052                 .mixers = { alc662_3ST_2ch_mixer },
16053                 .init_verbs = { alc662_init_verbs },
16054                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16055                 .dac_nids = alc662_dac_nids,
16056                 .dig_out_nid = ALC662_DIGOUT_NID,
16057                 .dig_in_nid = ALC662_DIGIN_NID,
16058                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16059                 .channel_mode = alc662_3ST_2ch_modes,
16060                 .input_mux = &alc662_capture_source,
16061         },
16062         [ALC662_3ST_6ch_DIG] = {
16063                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
16064                 .init_verbs = { alc662_init_verbs },
16065                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16066                 .dac_nids = alc662_dac_nids,
16067                 .dig_out_nid = ALC662_DIGOUT_NID,
16068                 .dig_in_nid = ALC662_DIGIN_NID,
16069                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16070                 .channel_mode = alc662_3ST_6ch_modes,
16071                 .need_dac_fix = 1,
16072                 .input_mux = &alc662_capture_source,
16073         },
16074         [ALC662_3ST_6ch] = {
16075                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
16076                 .init_verbs = { alc662_init_verbs },
16077                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16078                 .dac_nids = alc662_dac_nids,
16079                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16080                 .channel_mode = alc662_3ST_6ch_modes,
16081                 .need_dac_fix = 1,
16082                 .input_mux = &alc662_capture_source,
16083         },
16084         [ALC662_5ST_DIG] = {
16085                 .mixers = { alc662_base_mixer, alc662_chmode_mixer },
16086                 .init_verbs = { alc662_init_verbs },
16087                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16088                 .dac_nids = alc662_dac_nids,
16089                 .dig_out_nid = ALC662_DIGOUT_NID,
16090                 .dig_in_nid = ALC662_DIGIN_NID,
16091                 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
16092                 .channel_mode = alc662_5stack_modes,
16093                 .input_mux = &alc662_capture_source,
16094         },
16095         [ALC662_LENOVO_101E] = {
16096                 .mixers = { alc662_lenovo_101e_mixer },
16097                 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs },
16098                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16099                 .dac_nids = alc662_dac_nids,
16100                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16101                 .channel_mode = alc662_3ST_2ch_modes,
16102                 .input_mux = &alc662_lenovo_101e_capture_source,
16103                 .unsol_event = alc662_lenovo_101e_unsol_event,
16104                 .init_hook = alc662_lenovo_101e_all_automute,
16105         },
16106         [ALC662_ASUS_EEEPC_P701] = {
16107                 .mixers = { alc662_eeepc_p701_mixer },
16108                 .init_verbs = { alc662_init_verbs,
16109                                 alc662_eeepc_sue_init_verbs },
16110                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16111                 .dac_nids = alc662_dac_nids,
16112                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16113                 .channel_mode = alc662_3ST_2ch_modes,
16114                 .input_mux = &alc662_eeepc_capture_source,
16115                 .unsol_event = alc662_eeepc_unsol_event,
16116                 .init_hook = alc662_eeepc_inithook,
16117         },
16118         [ALC662_ASUS_EEEPC_EP20] = {
16119                 .mixers = { alc662_eeepc_ep20_mixer,
16120                             alc662_chmode_mixer },
16121                 .init_verbs = { alc662_init_verbs,
16122                                 alc662_eeepc_ep20_sue_init_verbs },
16123                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16124                 .dac_nids = alc662_dac_nids,
16125                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16126                 .channel_mode = alc662_3ST_6ch_modes,
16127                 .input_mux = &alc662_lenovo_101e_capture_source,
16128                 .unsol_event = alc662_eeepc_ep20_unsol_event,
16129                 .init_hook = alc662_eeepc_ep20_inithook,
16130         },
16131         [ALC662_ECS] = {
16132                 .mixers = { alc662_ecs_mixer },
16133                 .init_verbs = { alc662_init_verbs,
16134                                 alc662_ecs_init_verbs },
16135                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16136                 .dac_nids = alc662_dac_nids,
16137                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16138                 .channel_mode = alc662_3ST_2ch_modes,
16139                 .input_mux = &alc662_eeepc_capture_source,
16140                 .unsol_event = alc662_eeepc_unsol_event,
16141                 .init_hook = alc662_eeepc_inithook,
16142         },
16143         [ALC663_ASUS_M51VA] = {
16144                 .mixers = { alc663_m51va_mixer },
16145                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
16146                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16147                 .dac_nids = alc662_dac_nids,
16148                 .dig_out_nid = ALC662_DIGOUT_NID,
16149                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16150                 .channel_mode = alc662_3ST_2ch_modes,
16151                 .input_mux = &alc663_m51va_capture_source,
16152                 .unsol_event = alc663_m51va_unsol_event,
16153                 .init_hook = alc663_m51va_inithook,
16154         },
16155         [ALC663_ASUS_G71V] = {
16156                 .mixers = { alc663_g71v_mixer },
16157                 .init_verbs = { alc662_init_verbs, alc663_g71v_init_verbs },
16158                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16159                 .dac_nids = alc662_dac_nids,
16160                 .dig_out_nid = ALC662_DIGOUT_NID,
16161                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16162                 .channel_mode = alc662_3ST_2ch_modes,
16163                 .input_mux = &alc662_eeepc_capture_source,
16164                 .unsol_event = alc663_g71v_unsol_event,
16165                 .init_hook = alc663_g71v_inithook,
16166         },
16167         [ALC663_ASUS_H13] = {
16168                 .mixers = { alc663_m51va_mixer },
16169                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
16170                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16171                 .dac_nids = alc662_dac_nids,
16172                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16173                 .channel_mode = alc662_3ST_2ch_modes,
16174                 .input_mux = &alc663_m51va_capture_source,
16175                 .unsol_event = alc663_m51va_unsol_event,
16176                 .init_hook = alc663_m51va_inithook,
16177         },
16178         [ALC663_ASUS_G50V] = {
16179                 .mixers = { alc663_g50v_mixer },
16180                 .init_verbs = { alc662_init_verbs, alc663_g50v_init_verbs },
16181                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16182                 .dac_nids = alc662_dac_nids,
16183                 .dig_out_nid = ALC662_DIGOUT_NID,
16184                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16185                 .channel_mode = alc662_3ST_6ch_modes,
16186                 .input_mux = &alc663_capture_source,
16187                 .unsol_event = alc663_g50v_unsol_event,
16188                 .init_hook = alc663_g50v_inithook,
16189         },
16190         [ALC663_ASUS_MODE1] = {
16191                 .mixers = { alc663_m51va_mixer },
16192                 .cap_mixer = alc662_auto_capture_mixer,
16193                 .init_verbs = { alc662_init_verbs,
16194                                 alc663_21jd_amic_init_verbs },
16195                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16196                 .hp_nid = 0x03,
16197                 .dac_nids = alc662_dac_nids,
16198                 .dig_out_nid = ALC662_DIGOUT_NID,
16199                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16200                 .channel_mode = alc662_3ST_2ch_modes,
16201                 .input_mux = &alc662_eeepc_capture_source,
16202                 .unsol_event = alc663_mode1_unsol_event,
16203                 .init_hook = alc663_mode1_inithook,
16204         },
16205         [ALC662_ASUS_MODE2] = {
16206                 .mixers = { alc662_1bjd_mixer },
16207                 .cap_mixer = alc662_auto_capture_mixer,
16208                 .init_verbs = { alc662_init_verbs,
16209                                 alc662_1bjd_amic_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 = &alc662_eeepc_capture_source,
16216                 .unsol_event = alc662_mode2_unsol_event,
16217                 .init_hook = alc662_mode2_inithook,
16218         },
16219         [ALC663_ASUS_MODE3] = {
16220                 .mixers = { alc663_two_hp_m1_mixer },
16221                 .cap_mixer = alc662_auto_capture_mixer,
16222                 .init_verbs = { alc662_init_verbs,
16223                                 alc663_two_hp_amic_m1_init_verbs },
16224                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16225                 .hp_nid = 0x03,
16226                 .dac_nids = alc662_dac_nids,
16227                 .dig_out_nid = ALC662_DIGOUT_NID,
16228                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16229                 .channel_mode = alc662_3ST_2ch_modes,
16230                 .input_mux = &alc662_eeepc_capture_source,
16231                 .unsol_event = alc663_mode3_unsol_event,
16232                 .init_hook = alc663_mode3_inithook,
16233         },
16234         [ALC663_ASUS_MODE4] = {
16235                 .mixers = { alc663_asus_21jd_clfe_mixer },
16236                 .cap_mixer = alc662_auto_capture_mixer,
16237                 .init_verbs = { alc662_init_verbs,
16238                                 alc663_21jd_amic_init_verbs},
16239                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16240                 .hp_nid = 0x03,
16241                 .dac_nids = alc662_dac_nids,
16242                 .dig_out_nid = ALC662_DIGOUT_NID,
16243                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16244                 .channel_mode = alc662_3ST_2ch_modes,
16245                 .input_mux = &alc662_eeepc_capture_source,
16246                 .unsol_event = alc663_mode4_unsol_event,
16247                 .init_hook = alc663_mode4_inithook,
16248         },
16249         [ALC663_ASUS_MODE5] = {
16250                 .mixers = { alc663_asus_15jd_clfe_mixer },
16251                 .cap_mixer = alc662_auto_capture_mixer,
16252                 .init_verbs = { alc662_init_verbs,
16253                                 alc663_15jd_amic_init_verbs },
16254                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16255                 .hp_nid = 0x03,
16256                 .dac_nids = alc662_dac_nids,
16257                 .dig_out_nid = ALC662_DIGOUT_NID,
16258                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16259                 .channel_mode = alc662_3ST_2ch_modes,
16260                 .input_mux = &alc662_eeepc_capture_source,
16261                 .unsol_event = alc663_mode5_unsol_event,
16262                 .init_hook = alc663_mode5_inithook,
16263         },
16264         [ALC663_ASUS_MODE6] = {
16265                 .mixers = { alc663_two_hp_m2_mixer },
16266                 .cap_mixer = alc662_auto_capture_mixer,
16267                 .init_verbs = { alc662_init_verbs,
16268                                 alc663_two_hp_amic_m2_init_verbs },
16269                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16270                 .hp_nid = 0x03,
16271                 .dac_nids = alc662_dac_nids,
16272                 .dig_out_nid = ALC662_DIGOUT_NID,
16273                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16274                 .channel_mode = alc662_3ST_2ch_modes,
16275                 .input_mux = &alc662_eeepc_capture_source,
16276                 .unsol_event = alc663_mode6_unsol_event,
16277                 .init_hook = alc663_mode6_inithook,
16278         },
16279 };
16280
16281
16282 /*
16283  * BIOS auto configuration
16284  */
16285
16286 /* add playback controls from the parsed DAC table */
16287 static int alc662_auto_create_multi_out_ctls(struct alc_spec *spec,
16288                                              const struct auto_pin_cfg *cfg)
16289 {
16290         char name[32];
16291         static const char *chname[4] = {
16292                 "Front", "Surround", NULL /*CLFE*/, "Side"
16293         };
16294         hda_nid_t nid;
16295         int i, err;
16296
16297         for (i = 0; i < cfg->line_outs; i++) {
16298                 if (!spec->multiout.dac_nids[i])
16299                         continue;
16300                 nid = alc880_idx_to_dac(i);
16301                 if (i == 2) {
16302                         /* Center/LFE */
16303                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
16304                                           "Center Playback Volume",
16305                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
16306                                                               HDA_OUTPUT));
16307                         if (err < 0)
16308                                 return err;
16309                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
16310                                           "LFE Playback Volume",
16311                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
16312                                                               HDA_OUTPUT));
16313                         if (err < 0)
16314                                 return err;
16315                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
16316                                           "Center Playback Switch",
16317                                           HDA_COMPOSE_AMP_VAL(0x0e, 1, 0,
16318                                                               HDA_INPUT));
16319                         if (err < 0)
16320                                 return err;
16321                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
16322                                           "LFE Playback Switch",
16323                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
16324                                                               HDA_INPUT));
16325                         if (err < 0)
16326                                 return err;
16327                 } else {
16328                         sprintf(name, "%s Playback Volume", chname[i]);
16329                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
16330                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
16331                                                               HDA_OUTPUT));
16332                         if (err < 0)
16333                                 return err;
16334                         sprintf(name, "%s Playback Switch", chname[i]);
16335                         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
16336                                 HDA_COMPOSE_AMP_VAL(alc880_idx_to_mixer(i),
16337                                                     3, 0, HDA_INPUT));
16338                         if (err < 0)
16339                                 return err;
16340                 }
16341         }
16342         return 0;
16343 }
16344
16345 /* add playback controls for speaker and HP outputs */
16346 static int alc662_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
16347                                         const char *pfx)
16348 {
16349         hda_nid_t nid;
16350         int err;
16351         char name[32];
16352
16353         if (!pin)
16354                 return 0;
16355
16356         if (pin == 0x17) {
16357                 /* ALC663 has a mono output pin on 0x17 */
16358                 sprintf(name, "%s Playback Switch", pfx);
16359                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
16360                                   HDA_COMPOSE_AMP_VAL(pin, 2, 0, HDA_OUTPUT));
16361                 return err;
16362         }
16363
16364         if (alc880_is_fixed_pin(pin)) {
16365                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
16366                 /* printk("DAC nid=%x\n",nid); */
16367                 /* specify the DAC as the extra output */
16368                 if (!spec->multiout.hp_nid)
16369                         spec->multiout.hp_nid = nid;
16370                 else
16371                         spec->multiout.extra_out_nid[0] = nid;
16372                 /* control HP volume/switch on the output mixer amp */
16373                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
16374                 sprintf(name, "%s Playback Volume", pfx);
16375                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
16376                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
16377                 if (err < 0)
16378                         return err;
16379                 sprintf(name, "%s Playback Switch", pfx);
16380                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
16381                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
16382                 if (err < 0)
16383                         return err;
16384         } else if (alc880_is_multi_pin(pin)) {
16385                 /* set manual connection */
16386                 /* we have only a switch on HP-out PIN */
16387                 sprintf(name, "%s Playback Switch", pfx);
16388                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
16389                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
16390                 if (err < 0)
16391                         return err;
16392         }
16393         return 0;
16394 }
16395
16396 /* create playback/capture controls for input pins */
16397 static int alc662_auto_create_analog_input_ctls(struct alc_spec *spec,
16398                                                 const struct auto_pin_cfg *cfg)
16399 {
16400         struct hda_input_mux *imux = &spec->private_imux;
16401         int i, err, idx;
16402
16403         for (i = 0; i < AUTO_PIN_LAST; i++) {
16404                 if (alc880_is_input_pin(cfg->input_pins[i])) {
16405                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
16406                         err = new_analog_input(spec, cfg->input_pins[i],
16407                                                auto_pin_cfg_labels[i],
16408                                                idx, 0x0b);
16409                         if (err < 0)
16410                                 return err;
16411                         imux->items[imux->num_items].label =
16412                                 auto_pin_cfg_labels[i];
16413                         imux->items[imux->num_items].index =
16414                                 alc880_input_pin_idx(cfg->input_pins[i]);
16415                         imux->num_items++;
16416                 }
16417         }
16418         return 0;
16419 }
16420
16421 static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
16422                                               hda_nid_t nid, int pin_type,
16423                                               int dac_idx)
16424 {
16425         alc_set_pin_output(codec, nid, pin_type);
16426         /* need the manual connection? */
16427         if (alc880_is_multi_pin(nid)) {
16428                 struct alc_spec *spec = codec->spec;
16429                 int idx = alc880_multi_pin_idx(nid);
16430                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
16431                                     AC_VERB_SET_CONNECT_SEL,
16432                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
16433         }
16434 }
16435
16436 static void alc662_auto_init_multi_out(struct hda_codec *codec)
16437 {
16438         struct alc_spec *spec = codec->spec;
16439         int i;
16440
16441         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
16442         for (i = 0; i <= HDA_SIDE; i++) {
16443                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
16444                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
16445                 if (nid)
16446                         alc662_auto_set_output_and_unmute(codec, nid, pin_type,
16447                                                           i);
16448         }
16449 }
16450
16451 static void alc662_auto_init_hp_out(struct hda_codec *codec)
16452 {
16453         struct alc_spec *spec = codec->spec;
16454         hda_nid_t pin;
16455
16456         pin = spec->autocfg.hp_pins[0];
16457         if (pin) /* connect to front */
16458                 /* use dac 0 */
16459                 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
16460         pin = spec->autocfg.speaker_pins[0];
16461         if (pin)
16462                 alc662_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
16463 }
16464
16465 #define alc662_is_input_pin(nid)        alc880_is_input_pin(nid)
16466 #define ALC662_PIN_CD_NID               ALC880_PIN_CD_NID
16467
16468 static void alc662_auto_init_analog_input(struct hda_codec *codec)
16469 {
16470         struct alc_spec *spec = codec->spec;
16471         int i;
16472
16473         for (i = 0; i < AUTO_PIN_LAST; i++) {
16474                 hda_nid_t nid = spec->autocfg.input_pins[i];
16475                 if (alc662_is_input_pin(nid)) {
16476                         snd_hda_codec_write(codec, nid, 0,
16477                                             AC_VERB_SET_PIN_WIDGET_CONTROL,
16478                                             (i <= AUTO_PIN_FRONT_MIC ?
16479                                              PIN_VREF80 : PIN_IN));
16480                         if (nid != ALC662_PIN_CD_NID)
16481                                 snd_hda_codec_write(codec, nid, 0,
16482                                                     AC_VERB_SET_AMP_GAIN_MUTE,
16483                                                     AMP_OUT_MUTE);
16484                 }
16485         }
16486 }
16487
16488 #define alc662_auto_init_input_src      alc882_auto_init_input_src
16489
16490 static int alc662_parse_auto_config(struct hda_codec *codec)
16491 {
16492         struct alc_spec *spec = codec->spec;
16493         int err;
16494         static hda_nid_t alc662_ignore[] = { 0x1d, 0 };
16495
16496         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
16497                                            alc662_ignore);
16498         if (err < 0)
16499                 return err;
16500         if (!spec->autocfg.line_outs)
16501                 return 0; /* can't find valid BIOS pin config */
16502
16503         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
16504         if (err < 0)
16505                 return err;
16506         err = alc662_auto_create_multi_out_ctls(spec, &spec->autocfg);
16507         if (err < 0)
16508                 return err;
16509         err = alc662_auto_create_extra_out(spec,
16510                                            spec->autocfg.speaker_pins[0],
16511                                            "Speaker");
16512         if (err < 0)
16513                 return err;
16514         err = alc662_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
16515                                            "Headphone");
16516         if (err < 0)
16517                 return err;
16518         err = alc662_auto_create_analog_input_ctls(spec, &spec->autocfg);
16519         if (err < 0)
16520                 return err;
16521
16522         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
16523
16524         if (spec->autocfg.dig_out_pin)
16525                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
16526
16527         if (spec->kctls.list)
16528                 add_mixer(spec, spec->kctls.list);
16529
16530         spec->num_mux_defs = 1;
16531         spec->input_mux = &spec->private_imux;
16532
16533         add_verb(spec, alc662_auto_init_verbs);
16534         if (codec->vendor_id == 0x10ec0663)
16535                 add_verb(spec, alc663_auto_init_verbs);
16536
16537         err = alc_auto_add_mic_boost(codec);
16538         if (err < 0)
16539                 return err;
16540
16541         store_pin_configs(codec);
16542         return 1;
16543 }
16544
16545 /* additional initialization for auto-configuration model */
16546 static void alc662_auto_init(struct hda_codec *codec)
16547 {
16548         struct alc_spec *spec = codec->spec;
16549         alc662_auto_init_multi_out(codec);
16550         alc662_auto_init_hp_out(codec);
16551         alc662_auto_init_analog_input(codec);
16552         alc662_auto_init_input_src(codec);
16553         if (spec->unsol_event)
16554                 alc_inithook(codec);
16555 }
16556
16557 static int patch_alc662(struct hda_codec *codec)
16558 {
16559         struct alc_spec *spec;
16560         int err, board_config;
16561
16562         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
16563         if (!spec)
16564                 return -ENOMEM;
16565
16566         codec->spec = spec;
16567
16568         alc_fix_pll_init(codec, 0x20, 0x04, 15);
16569
16570         board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
16571                                                   alc662_models,
16572                                                   alc662_cfg_tbl);
16573         if (board_config < 0) {
16574                 printk(KERN_INFO "hda_codec: Unknown model for ALC662, "
16575                        "trying auto-probe from BIOS...\n");
16576                 board_config = ALC662_AUTO;
16577         }
16578
16579         if (board_config == ALC662_AUTO) {
16580                 /* automatic parse from the BIOS config */
16581                 err = alc662_parse_auto_config(codec);
16582                 if (err < 0) {
16583                         alc_free(codec);
16584                         return err;
16585                 } else if (!err) {
16586                         printk(KERN_INFO
16587                                "hda_codec: Cannot set up configuration "
16588                                "from BIOS.  Using base mode...\n");
16589                         board_config = ALC662_3ST_2ch_DIG;
16590                 }
16591         }
16592
16593         if (board_config != ALC662_AUTO)
16594                 setup_preset(spec, &alc662_presets[board_config]);
16595
16596         if (codec->vendor_id == 0x10ec0663) {
16597                 spec->stream_name_analog = "ALC663 Analog";
16598                 spec->stream_name_digital = "ALC663 Digital";
16599         } else if (codec->vendor_id == 0x10ec0272) {
16600                 spec->stream_name_analog = "ALC272 Analog";
16601                 spec->stream_name_digital = "ALC272 Digital";
16602         } else {
16603                 spec->stream_name_analog = "ALC662 Analog";
16604                 spec->stream_name_digital = "ALC662 Digital";
16605         }
16606
16607         spec->stream_analog_playback = &alc662_pcm_analog_playback;
16608         spec->stream_analog_capture = &alc662_pcm_analog_capture;
16609
16610         spec->stream_digital_playback = &alc662_pcm_digital_playback;
16611         spec->stream_digital_capture = &alc662_pcm_digital_capture;
16612
16613         spec->adc_nids = alc662_adc_nids;
16614         spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
16615         spec->capsrc_nids = alc662_capsrc_nids;
16616         spec->is_mix_capture = 1;
16617
16618         if (!spec->cap_mixer)
16619                 set_capture_mixer(spec);
16620
16621         spec->vmaster_nid = 0x02;
16622
16623         codec->patch_ops = alc_patch_ops;
16624         if (board_config == ALC662_AUTO)
16625                 spec->init_hook = alc662_auto_init;
16626 #ifdef CONFIG_SND_HDA_POWER_SAVE
16627         if (!spec->loopback.amplist)
16628                 spec->loopback.amplist = alc662_loopbacks;
16629 #endif
16630         codec->proc_widget_hook = print_realtek_coef;
16631
16632         return 0;
16633 }
16634
16635 /*
16636  * patch entries
16637  */
16638 static struct hda_codec_preset snd_hda_preset_realtek[] = {
16639         { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
16640         { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
16641         { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
16642         { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
16643         { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
16644         { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
16645         { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
16646           .patch = patch_alc861 },
16647         { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
16648         { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
16649         { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
16650         { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
16651           .patch = patch_alc883 },
16652         { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
16653           .patch = patch_alc662 },
16654         { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
16655         { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
16656         { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
16657         { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 },
16658         { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
16659           .patch = patch_alc882 }, /* should be patch_alc883() in future */
16660         { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
16661           .patch = patch_alc882 }, /* should be patch_alc883() in future */
16662         { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
16663         { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc883 },
16664         { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
16665           .patch = patch_alc883 },
16666         { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc883 },
16667         { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc883 },
16668         {} /* terminator */
16669 };
16670
16671 MODULE_ALIAS("snd-hda-codec-id:10ec*");
16672
16673 MODULE_LICENSE("GPL");
16674 MODULE_DESCRIPTION("Realtek HD-audio codec");
16675
16676 static struct hda_codec_preset_list realtek_list = {
16677         .preset = snd_hda_preset_realtek,
16678         .owner = THIS_MODULE,
16679 };
16680
16681 static int __init patch_realtek_init(void)
16682 {
16683         return snd_hda_add_codec_preset(&realtek_list);
16684 }
16685
16686 static void __exit patch_realtek_exit(void)
16687 {
16688         snd_hda_delete_codec_preset(&realtek_list);
16689 }
16690
16691 module_init(patch_realtek_init)
16692 module_exit(patch_realtek_exit)