ALSA: hda_intel: more strict alc880_parse_auto_config dig_nid checking
[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 #include "hda_beep.h"
34
35 #define ALC880_FRONT_EVENT              0x01
36 #define ALC880_DCVOL_EVENT              0x02
37 #define ALC880_HP_EVENT                 0x04
38 #define ALC880_MIC_EVENT                0x08
39
40 /* ALC880 board config type */
41 enum {
42         ALC880_3ST,
43         ALC880_3ST_DIG,
44         ALC880_5ST,
45         ALC880_5ST_DIG,
46         ALC880_W810,
47         ALC880_Z71V,
48         ALC880_6ST,
49         ALC880_6ST_DIG,
50         ALC880_F1734,
51         ALC880_ASUS,
52         ALC880_ASUS_DIG,
53         ALC880_ASUS_W1V,
54         ALC880_ASUS_DIG2,
55         ALC880_FUJITSU,
56         ALC880_UNIWILL_DIG,
57         ALC880_UNIWILL,
58         ALC880_UNIWILL_P53,
59         ALC880_CLEVO,
60         ALC880_TCL_S700,
61         ALC880_LG,
62         ALC880_LG_LW,
63         ALC880_MEDION_RIM,
64 #ifdef CONFIG_SND_DEBUG
65         ALC880_TEST,
66 #endif
67         ALC880_AUTO,
68         ALC880_MODEL_LAST /* last tag */
69 };
70
71 /* ALC260 models */
72 enum {
73         ALC260_BASIC,
74         ALC260_HP,
75         ALC260_HP_DC7600,
76         ALC260_HP_3013,
77         ALC260_FUJITSU_S702X,
78         ALC260_ACER,
79         ALC260_WILL,
80         ALC260_REPLACER_672V,
81         ALC260_FAVORIT100,
82 #ifdef CONFIG_SND_DEBUG
83         ALC260_TEST,
84 #endif
85         ALC260_AUTO,
86         ALC260_MODEL_LAST /* last tag */
87 };
88
89 /* ALC262 models */
90 enum {
91         ALC262_BASIC,
92         ALC262_HIPPO,
93         ALC262_HIPPO_1,
94         ALC262_FUJITSU,
95         ALC262_HP_BPC,
96         ALC262_HP_BPC_D7000_WL,
97         ALC262_HP_BPC_D7000_WF,
98         ALC262_HP_TC_T5735,
99         ALC262_HP_RP5700,
100         ALC262_BENQ_ED8,
101         ALC262_SONY_ASSAMD,
102         ALC262_BENQ_T31,
103         ALC262_ULTRA,
104         ALC262_LENOVO_3000,
105         ALC262_NEC,
106         ALC262_TOSHIBA_S06,
107         ALC262_TOSHIBA_RX1,
108         ALC262_TYAN,
109         ALC262_AUTO,
110         ALC262_MODEL_LAST /* last tag */
111 };
112
113 /* ALC268 models */
114 enum {
115         ALC267_QUANTA_IL1,
116         ALC268_3ST,
117         ALC268_TOSHIBA,
118         ALC268_ACER,
119         ALC268_ACER_DMIC,
120         ALC268_ACER_ASPIRE_ONE,
121         ALC268_DELL,
122         ALC268_ZEPTO,
123 #ifdef CONFIG_SND_DEBUG
124         ALC268_TEST,
125 #endif
126         ALC268_AUTO,
127         ALC268_MODEL_LAST /* last tag */
128 };
129
130 /* ALC269 models */
131 enum {
132         ALC269_BASIC,
133         ALC269_QUANTA_FL1,
134         ALC269_ASUS_EEEPC_P703,
135         ALC269_ASUS_EEEPC_P901,
136         ALC269_FUJITSU,
137         ALC269_LIFEBOOK,
138         ALC269_AUTO,
139         ALC269_MODEL_LAST /* last tag */
140 };
141
142 /* ALC861 models */
143 enum {
144         ALC861_3ST,
145         ALC660_3ST,
146         ALC861_3ST_DIG,
147         ALC861_6ST_DIG,
148         ALC861_UNIWILL_M31,
149         ALC861_TOSHIBA,
150         ALC861_ASUS,
151         ALC861_ASUS_LAPTOP,
152         ALC861_AUTO,
153         ALC861_MODEL_LAST,
154 };
155
156 /* ALC861-VD models */
157 enum {
158         ALC660VD_3ST,
159         ALC660VD_3ST_DIG,
160         ALC660VD_ASUS_V1S,
161         ALC861VD_3ST,
162         ALC861VD_3ST_DIG,
163         ALC861VD_6ST_DIG,
164         ALC861VD_LENOVO,
165         ALC861VD_DALLAS,
166         ALC861VD_HP,
167         ALC861VD_AUTO,
168         ALC861VD_MODEL_LAST,
169 };
170
171 /* ALC662 models */
172 enum {
173         ALC662_3ST_2ch_DIG,
174         ALC662_3ST_6ch_DIG,
175         ALC662_3ST_6ch,
176         ALC662_5ST_DIG,
177         ALC662_LENOVO_101E,
178         ALC662_ASUS_EEEPC_P701,
179         ALC662_ASUS_EEEPC_EP20,
180         ALC663_ASUS_M51VA,
181         ALC663_ASUS_G71V,
182         ALC663_ASUS_H13,
183         ALC663_ASUS_G50V,
184         ALC662_ECS,
185         ALC663_ASUS_MODE1,
186         ALC662_ASUS_MODE2,
187         ALC663_ASUS_MODE3,
188         ALC663_ASUS_MODE4,
189         ALC663_ASUS_MODE5,
190         ALC663_ASUS_MODE6,
191         ALC272_DELL,
192         ALC272_DELL_ZM1,
193         ALC272_SAMSUNG_NC10,
194         ALC662_AUTO,
195         ALC662_MODEL_LAST,
196 };
197
198 /* ALC882 models */
199 enum {
200         ALC882_3ST_DIG,
201         ALC882_6ST_DIG,
202         ALC882_ARIMA,
203         ALC882_W2JC,
204         ALC882_TARGA,
205         ALC882_ASUS_A7J,
206         ALC882_ASUS_A7M,
207         ALC885_MACPRO,
208         ALC885_MBP3,
209         ALC885_MB5,
210         ALC885_IMAC24,
211         ALC882_AUTO,
212         ALC882_MODEL_LAST,
213 };
214
215 /* ALC883 models */
216 enum {
217         ALC883_3ST_2ch_DIG,
218         ALC883_3ST_6ch_DIG,
219         ALC883_3ST_6ch,
220         ALC883_6ST_DIG,
221         ALC883_TARGA_DIG,
222         ALC883_TARGA_2ch_DIG,
223         ALC883_TARGA_8ch_DIG,
224         ALC883_ACER,
225         ALC883_ACER_ASPIRE,
226         ALC888_ACER_ASPIRE_4930G,
227         ALC888_ACER_ASPIRE_6530G,
228         ALC888_ACER_ASPIRE_8930G,
229         ALC883_MEDION,
230         ALC883_MEDION_MD2,
231         ALC883_LAPTOP_EAPD,
232         ALC883_LENOVO_101E_2ch,
233         ALC883_LENOVO_NB0763,
234         ALC888_LENOVO_MS7195_DIG,
235         ALC888_LENOVO_SKY,
236         ALC883_HAIER_W66,
237         ALC888_3ST_HP,
238         ALC888_6ST_DELL,
239         ALC883_MITAC,
240         ALC883_CLEVO_M720,
241         ALC883_FUJITSU_PI2515,
242         ALC888_FUJITSU_XA3530,
243         ALC883_3ST_6ch_INTEL,
244         ALC888_ASUS_M90V,
245         ALC888_ASUS_EEE1601,
246         ALC889A_MB31,
247         ALC1200_ASUS_P5Q,
248         ALC883_SONY_VAIO_TT,
249         ALC883_AUTO,
250         ALC883_MODEL_LAST,
251 };
252
253 /* for GPIO Poll */
254 #define GPIO_MASK       0x03
255
256 /* extra amp-initialization sequence types */
257 enum {
258         ALC_INIT_NONE,
259         ALC_INIT_DEFAULT,
260         ALC_INIT_GPIO1,
261         ALC_INIT_GPIO2,
262         ALC_INIT_GPIO3,
263 };
264
265 struct alc_spec {
266         /* codec parameterization */
267         struct snd_kcontrol_new *mixers[5];     /* mixer arrays */
268         unsigned int num_mixers;
269         struct snd_kcontrol_new *cap_mixer;     /* capture mixer */
270         unsigned int beep_amp;  /* beep amp value, set via set_beep_amp() */
271
272         const struct hda_verb *init_verbs[5];   /* initialization verbs
273                                                  * don't forget NULL
274                                                  * termination!
275                                                  */
276         unsigned int num_init_verbs;
277
278         char stream_name_analog[16];    /* analog PCM stream */
279         struct hda_pcm_stream *stream_analog_playback;
280         struct hda_pcm_stream *stream_analog_capture;
281         struct hda_pcm_stream *stream_analog_alt_playback;
282         struct hda_pcm_stream *stream_analog_alt_capture;
283
284         char stream_name_digital[16];   /* digital PCM stream */
285         struct hda_pcm_stream *stream_digital_playback;
286         struct hda_pcm_stream *stream_digital_capture;
287
288         /* playback */
289         struct hda_multi_out multiout;  /* playback set-up
290                                          * max_channels, dacs must be set
291                                          * dig_out_nid and hp_nid are optional
292                                          */
293         hda_nid_t alt_dac_nid;
294         hda_nid_t slave_dig_outs[3];    /* optional - for auto-parsing */
295         int dig_out_type;
296
297         /* capture */
298         unsigned int num_adc_nids;
299         hda_nid_t *adc_nids;
300         hda_nid_t *capsrc_nids;
301         hda_nid_t dig_in_nid;           /* digital-in NID; optional */
302
303         /* capture source */
304         unsigned int num_mux_defs;
305         const struct hda_input_mux *input_mux;
306         unsigned int cur_mux[3];
307
308         /* channel model */
309         const struct hda_channel_mode *channel_mode;
310         int num_channel_mode;
311         int need_dac_fix;
312         int const_channel_count;
313         int ext_channel_count;
314
315         /* PCM information */
316         struct hda_pcm pcm_rec[3];      /* used in alc_build_pcms() */
317
318         /* dynamic controls, init_verbs and input_mux */
319         struct auto_pin_cfg autocfg;
320         struct snd_array kctls;
321         struct hda_input_mux private_imux[3];
322         hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
323
324         /* hooks */
325         void (*init_hook)(struct hda_codec *codec);
326         void (*unsol_event)(struct hda_codec *codec, unsigned int res);
327
328         /* for pin sensing */
329         unsigned int sense_updated: 1;
330         unsigned int jack_present: 1;
331         unsigned int master_sw: 1;
332
333         /* other flags */
334         unsigned int no_analog :1; /* digital I/O only */
335         int init_amp;
336
337         /* for virtual master */
338         hda_nid_t vmaster_nid;
339 #ifdef CONFIG_SND_HDA_POWER_SAVE
340         struct hda_loopback_check loopback;
341 #endif
342
343         /* for PLL fix */
344         hda_nid_t pll_nid;
345         unsigned int pll_coef_idx, pll_coef_bit;
346 };
347
348 /*
349  * configuration template - to be copied to the spec instance
350  */
351 struct alc_config_preset {
352         struct snd_kcontrol_new *mixers[5]; /* should be identical size
353                                              * with spec
354                                              */
355         struct snd_kcontrol_new *cap_mixer; /* capture mixer */
356         const struct hda_verb *init_verbs[5];
357         unsigned int num_dacs;
358         hda_nid_t *dac_nids;
359         hda_nid_t dig_out_nid;          /* optional */
360         hda_nid_t hp_nid;               /* optional */
361         hda_nid_t *slave_dig_outs;
362         unsigned int num_adc_nids;
363         hda_nid_t *adc_nids;
364         hda_nid_t *capsrc_nids;
365         hda_nid_t dig_in_nid;
366         unsigned int num_channel_mode;
367         const struct hda_channel_mode *channel_mode;
368         int need_dac_fix;
369         int const_channel_count;
370         unsigned int num_mux_defs;
371         const struct hda_input_mux *input_mux;
372         void (*unsol_event)(struct hda_codec *, unsigned int);
373         void (*init_hook)(struct hda_codec *);
374 #ifdef CONFIG_SND_HDA_POWER_SAVE
375         struct hda_amp_list *loopbacks;
376 #endif
377 };
378
379
380 /*
381  * input MUX handling
382  */
383 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
384                              struct snd_ctl_elem_info *uinfo)
385 {
386         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
387         struct alc_spec *spec = codec->spec;
388         unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
389         if (mux_idx >= spec->num_mux_defs)
390                 mux_idx = 0;
391         return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
392 }
393
394 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
395                             struct snd_ctl_elem_value *ucontrol)
396 {
397         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
398         struct alc_spec *spec = codec->spec;
399         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
400
401         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
402         return 0;
403 }
404
405 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
406                             struct snd_ctl_elem_value *ucontrol)
407 {
408         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
409         struct alc_spec *spec = codec->spec;
410         const struct hda_input_mux *imux;
411         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
412         unsigned int mux_idx;
413         hda_nid_t nid = spec->capsrc_nids ?
414                 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
415         unsigned int type;
416
417         mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
418         imux = &spec->input_mux[mux_idx];
419
420         type = (get_wcaps(codec, nid) & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
421         if (type == AC_WID_AUD_MIX) {
422                 /* Matrix-mixer style (e.g. ALC882) */
423                 unsigned int *cur_val = &spec->cur_mux[adc_idx];
424                 unsigned int i, idx;
425
426                 idx = ucontrol->value.enumerated.item[0];
427                 if (idx >= imux->num_items)
428                         idx = imux->num_items - 1;
429                 if (*cur_val == idx)
430                         return 0;
431                 for (i = 0; i < imux->num_items; i++) {
432                         unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
433                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
434                                                  imux->items[i].index,
435                                                  HDA_AMP_MUTE, v);
436                 }
437                 *cur_val = idx;
438                 return 1;
439         } else {
440                 /* MUX style (e.g. ALC880) */
441                 return snd_hda_input_mux_put(codec, imux, ucontrol, nid,
442                                              &spec->cur_mux[adc_idx]);
443         }
444 }
445
446 /*
447  * channel mode setting
448  */
449 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
450                             struct snd_ctl_elem_info *uinfo)
451 {
452         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
453         struct alc_spec *spec = codec->spec;
454         return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
455                                     spec->num_channel_mode);
456 }
457
458 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
459                            struct snd_ctl_elem_value *ucontrol)
460 {
461         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
462         struct alc_spec *spec = codec->spec;
463         return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
464                                    spec->num_channel_mode,
465                                    spec->ext_channel_count);
466 }
467
468 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
469                            struct snd_ctl_elem_value *ucontrol)
470 {
471         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
472         struct alc_spec *spec = codec->spec;
473         int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
474                                       spec->num_channel_mode,
475                                       &spec->ext_channel_count);
476         if (err >= 0 && !spec->const_channel_count) {
477                 spec->multiout.max_channels = spec->ext_channel_count;
478                 if (spec->need_dac_fix)
479                         spec->multiout.num_dacs = spec->multiout.max_channels / 2;
480         }
481         return err;
482 }
483
484 /*
485  * Control the mode of pin widget settings via the mixer.  "pc" is used
486  * instead of "%" to avoid consequences of accidently treating the % as
487  * being part of a format specifier.  Maximum allowed length of a value is
488  * 63 characters plus NULL terminator.
489  *
490  * Note: some retasking pin complexes seem to ignore requests for input
491  * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
492  * are requested.  Therefore order this list so that this behaviour will not
493  * cause problems when mixer clients move through the enum sequentially.
494  * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
495  * March 2006.
496  */
497 static char *alc_pin_mode_names[] = {
498         "Mic 50pc bias", "Mic 80pc bias",
499         "Line in", "Line out", "Headphone out",
500 };
501 static unsigned char alc_pin_mode_values[] = {
502         PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
503 };
504 /* The control can present all 5 options, or it can limit the options based
505  * in the pin being assumed to be exclusively an input or an output pin.  In
506  * addition, "input" pins may or may not process the mic bias option
507  * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
508  * accept requests for bias as of chip versions up to March 2006) and/or
509  * wiring in the computer.
510  */
511 #define ALC_PIN_DIR_IN              0x00
512 #define ALC_PIN_DIR_OUT             0x01
513 #define ALC_PIN_DIR_INOUT           0x02
514 #define ALC_PIN_DIR_IN_NOMICBIAS    0x03
515 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
516
517 /* Info about the pin modes supported by the different pin direction modes.
518  * For each direction the minimum and maximum values are given.
519  */
520 static signed char alc_pin_mode_dir_info[5][2] = {
521         { 0, 2 },    /* ALC_PIN_DIR_IN */
522         { 3, 4 },    /* ALC_PIN_DIR_OUT */
523         { 0, 4 },    /* ALC_PIN_DIR_INOUT */
524         { 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
525         { 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
526 };
527 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
528 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
529 #define alc_pin_mode_n_items(_dir) \
530         (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
531
532 static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
533                              struct snd_ctl_elem_info *uinfo)
534 {
535         unsigned int item_num = uinfo->value.enumerated.item;
536         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
537
538         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
539         uinfo->count = 1;
540         uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
541
542         if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
543                 item_num = alc_pin_mode_min(dir);
544         strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
545         return 0;
546 }
547
548 static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
549                             struct snd_ctl_elem_value *ucontrol)
550 {
551         unsigned int i;
552         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
553         hda_nid_t nid = kcontrol->private_value & 0xffff;
554         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
555         long *valp = ucontrol->value.integer.value;
556         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
557                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
558                                                  0x00);
559
560         /* Find enumerated value for current pinctl setting */
561         i = alc_pin_mode_min(dir);
562         while (alc_pin_mode_values[i] != pinctl && i <= alc_pin_mode_max(dir))
563                 i++;
564         *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
565         return 0;
566 }
567
568 static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
569                             struct snd_ctl_elem_value *ucontrol)
570 {
571         signed int change;
572         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
573         hda_nid_t nid = kcontrol->private_value & 0xffff;
574         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
575         long val = *ucontrol->value.integer.value;
576         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
577                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
578                                                  0x00);
579
580         if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
581                 val = alc_pin_mode_min(dir);
582
583         change = pinctl != alc_pin_mode_values[val];
584         if (change) {
585                 /* Set pin mode to that requested */
586                 snd_hda_codec_write_cache(codec, nid, 0,
587                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
588                                           alc_pin_mode_values[val]);
589
590                 /* Also enable the retasking pin's input/output as required
591                  * for the requested pin mode.  Enum values of 2 or less are
592                  * input modes.
593                  *
594                  * Dynamically switching the input/output buffers probably
595                  * reduces noise slightly (particularly on input) so we'll
596                  * do it.  However, having both input and output buffers
597                  * enabled simultaneously doesn't seem to be problematic if
598                  * this turns out to be necessary in the future.
599                  */
600                 if (val <= 2) {
601                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
602                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
603                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
604                                                  HDA_AMP_MUTE, 0);
605                 } else {
606                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
607                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
608                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
609                                                  HDA_AMP_MUTE, 0);
610                 }
611         }
612         return change;
613 }
614
615 #define ALC_PIN_MODE(xname, nid, dir) \
616         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
617           .info = alc_pin_mode_info, \
618           .get = alc_pin_mode_get, \
619           .put = alc_pin_mode_put, \
620           .private_value = nid | (dir<<16) }
621
622 /* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
623  * together using a mask with more than one bit set.  This control is
624  * currently used only by the ALC260 test model.  At this stage they are not
625  * needed for any "production" models.
626  */
627 #ifdef CONFIG_SND_DEBUG
628 #define alc_gpio_data_info      snd_ctl_boolean_mono_info
629
630 static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
631                              struct snd_ctl_elem_value *ucontrol)
632 {
633         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
634         hda_nid_t nid = kcontrol->private_value & 0xffff;
635         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
636         long *valp = ucontrol->value.integer.value;
637         unsigned int val = snd_hda_codec_read(codec, nid, 0,
638                                               AC_VERB_GET_GPIO_DATA, 0x00);
639
640         *valp = (val & mask) != 0;
641         return 0;
642 }
643 static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
644                              struct snd_ctl_elem_value *ucontrol)
645 {
646         signed int change;
647         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
648         hda_nid_t nid = kcontrol->private_value & 0xffff;
649         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
650         long val = *ucontrol->value.integer.value;
651         unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
652                                                     AC_VERB_GET_GPIO_DATA,
653                                                     0x00);
654
655         /* Set/unset the masked GPIO bit(s) as needed */
656         change = (val == 0 ? 0 : mask) != (gpio_data & mask);
657         if (val == 0)
658                 gpio_data &= ~mask;
659         else
660                 gpio_data |= mask;
661         snd_hda_codec_write_cache(codec, nid, 0,
662                                   AC_VERB_SET_GPIO_DATA, gpio_data);
663
664         return change;
665 }
666 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
667         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
668           .info = alc_gpio_data_info, \
669           .get = alc_gpio_data_get, \
670           .put = alc_gpio_data_put, \
671           .private_value = nid | (mask<<16) }
672 #endif   /* CONFIG_SND_DEBUG */
673
674 /* A switch control to allow the enabling of the digital IO pins on the
675  * ALC260.  This is incredibly simplistic; the intention of this control is
676  * to provide something in the test model allowing digital outputs to be
677  * identified if present.  If models are found which can utilise these
678  * outputs a more complete mixer control can be devised for those models if
679  * necessary.
680  */
681 #ifdef CONFIG_SND_DEBUG
682 #define alc_spdif_ctrl_info     snd_ctl_boolean_mono_info
683
684 static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
685                               struct snd_ctl_elem_value *ucontrol)
686 {
687         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
688         hda_nid_t nid = kcontrol->private_value & 0xffff;
689         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
690         long *valp = ucontrol->value.integer.value;
691         unsigned int val = snd_hda_codec_read(codec, nid, 0,
692                                               AC_VERB_GET_DIGI_CONVERT_1, 0x00);
693
694         *valp = (val & mask) != 0;
695         return 0;
696 }
697 static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
698                               struct snd_ctl_elem_value *ucontrol)
699 {
700         signed int change;
701         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
702         hda_nid_t nid = kcontrol->private_value & 0xffff;
703         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
704         long val = *ucontrol->value.integer.value;
705         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
706                                                     AC_VERB_GET_DIGI_CONVERT_1,
707                                                     0x00);
708
709         /* Set/unset the masked control bit(s) as needed */
710         change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
711         if (val==0)
712                 ctrl_data &= ~mask;
713         else
714                 ctrl_data |= mask;
715         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
716                                   ctrl_data);
717
718         return change;
719 }
720 #define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
721         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
722           .info = alc_spdif_ctrl_info, \
723           .get = alc_spdif_ctrl_get, \
724           .put = alc_spdif_ctrl_put, \
725           .private_value = nid | (mask<<16) }
726 #endif   /* CONFIG_SND_DEBUG */
727
728 /* A switch control to allow the enabling EAPD digital outputs on the ALC26x.
729  * Again, this is only used in the ALC26x test models to help identify when
730  * the EAPD line must be asserted for features to work.
731  */
732 #ifdef CONFIG_SND_DEBUG
733 #define alc_eapd_ctrl_info      snd_ctl_boolean_mono_info
734
735 static int alc_eapd_ctrl_get(struct snd_kcontrol *kcontrol,
736                               struct snd_ctl_elem_value *ucontrol)
737 {
738         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
739         hda_nid_t nid = kcontrol->private_value & 0xffff;
740         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
741         long *valp = ucontrol->value.integer.value;
742         unsigned int val = snd_hda_codec_read(codec, nid, 0,
743                                               AC_VERB_GET_EAPD_BTLENABLE, 0x00);
744
745         *valp = (val & mask) != 0;
746         return 0;
747 }
748
749 static int alc_eapd_ctrl_put(struct snd_kcontrol *kcontrol,
750                               struct snd_ctl_elem_value *ucontrol)
751 {
752         int change;
753         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
754         hda_nid_t nid = kcontrol->private_value & 0xffff;
755         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
756         long val = *ucontrol->value.integer.value;
757         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
758                                                     AC_VERB_GET_EAPD_BTLENABLE,
759                                                     0x00);
760
761         /* Set/unset the masked control bit(s) as needed */
762         change = (!val ? 0 : mask) != (ctrl_data & mask);
763         if (!val)
764                 ctrl_data &= ~mask;
765         else
766                 ctrl_data |= mask;
767         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
768                                   ctrl_data);
769
770         return change;
771 }
772
773 #define ALC_EAPD_CTRL_SWITCH(xname, nid, mask) \
774         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
775           .info = alc_eapd_ctrl_info, \
776           .get = alc_eapd_ctrl_get, \
777           .put = alc_eapd_ctrl_put, \
778           .private_value = nid | (mask<<16) }
779 #endif   /* CONFIG_SND_DEBUG */
780
781 /*
782  * set up the input pin config (depending on the given auto-pin type)
783  */
784 static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
785                               int auto_pin_type)
786 {
787         unsigned int val = PIN_IN;
788
789         if (auto_pin_type <= AUTO_PIN_FRONT_MIC) {
790                 unsigned int pincap;
791                 pincap = snd_hda_query_pin_caps(codec, nid);
792                 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
793                 if (pincap & AC_PINCAP_VREF_80)
794                         val = PIN_VREF80;
795                 else if (pincap & AC_PINCAP_VREF_50)
796                         val = PIN_VREF50;
797                 else if (pincap & AC_PINCAP_VREF_100)
798                         val = PIN_VREF100;
799                 else if (pincap & AC_PINCAP_VREF_GRD)
800                         val = PIN_VREFGRD;
801         }
802         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
803 }
804
805 /*
806  */
807 static void add_mixer(struct alc_spec *spec, struct snd_kcontrol_new *mix)
808 {
809         if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
810                 return;
811         spec->mixers[spec->num_mixers++] = mix;
812 }
813
814 static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
815 {
816         if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
817                 return;
818         spec->init_verbs[spec->num_init_verbs++] = verb;
819 }
820
821 #ifdef CONFIG_PROC_FS
822 /*
823  * hook for proc
824  */
825 static void print_realtek_coef(struct snd_info_buffer *buffer,
826                                struct hda_codec *codec, hda_nid_t nid)
827 {
828         int coeff;
829
830         if (nid != 0x20)
831                 return;
832         coeff = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PROC_COEF, 0);
833         snd_iprintf(buffer, "  Processing Coefficient: 0x%02x\n", coeff);
834         coeff = snd_hda_codec_read(codec, nid, 0,
835                                    AC_VERB_GET_COEF_INDEX, 0);
836         snd_iprintf(buffer, "  Coefficient Index: 0x%02x\n", coeff);
837 }
838 #else
839 #define print_realtek_coef      NULL
840 #endif
841
842 /*
843  * set up from the preset table
844  */
845 static void setup_preset(struct alc_spec *spec,
846                          const struct alc_config_preset *preset)
847 {
848         int i;
849
850         for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
851                 add_mixer(spec, preset->mixers[i]);
852         spec->cap_mixer = preset->cap_mixer;
853         for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
854              i++)
855                 add_verb(spec, preset->init_verbs[i]);
856
857         spec->channel_mode = preset->channel_mode;
858         spec->num_channel_mode = preset->num_channel_mode;
859         spec->need_dac_fix = preset->need_dac_fix;
860         spec->const_channel_count = preset->const_channel_count;
861
862         if (preset->const_channel_count)
863                 spec->multiout.max_channels = preset->const_channel_count;
864         else
865                 spec->multiout.max_channels = spec->channel_mode[0].channels;
866         spec->ext_channel_count = spec->channel_mode[0].channels;
867
868         spec->multiout.num_dacs = preset->num_dacs;
869         spec->multiout.dac_nids = preset->dac_nids;
870         spec->multiout.dig_out_nid = preset->dig_out_nid;
871         spec->multiout.slave_dig_outs = preset->slave_dig_outs;
872         spec->multiout.hp_nid = preset->hp_nid;
873
874         spec->num_mux_defs = preset->num_mux_defs;
875         if (!spec->num_mux_defs)
876                 spec->num_mux_defs = 1;
877         spec->input_mux = preset->input_mux;
878
879         spec->num_adc_nids = preset->num_adc_nids;
880         spec->adc_nids = preset->adc_nids;
881         spec->capsrc_nids = preset->capsrc_nids;
882         spec->dig_in_nid = preset->dig_in_nid;
883
884         spec->unsol_event = preset->unsol_event;
885         spec->init_hook = preset->init_hook;
886 #ifdef CONFIG_SND_HDA_POWER_SAVE
887         spec->loopback.amplist = preset->loopbacks;
888 #endif
889 }
890
891 /* Enable GPIO mask and set output */
892 static struct hda_verb alc_gpio1_init_verbs[] = {
893         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
894         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
895         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
896         { }
897 };
898
899 static struct hda_verb alc_gpio2_init_verbs[] = {
900         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
901         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
902         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
903         { }
904 };
905
906 static struct hda_verb alc_gpio3_init_verbs[] = {
907         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
908         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
909         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
910         { }
911 };
912
913 /*
914  * Fix hardware PLL issue
915  * On some codecs, the analog PLL gating control must be off while
916  * the default value is 1.
917  */
918 static void alc_fix_pll(struct hda_codec *codec)
919 {
920         struct alc_spec *spec = codec->spec;
921         unsigned int val;
922
923         if (!spec->pll_nid)
924                 return;
925         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
926                             spec->pll_coef_idx);
927         val = snd_hda_codec_read(codec, spec->pll_nid, 0,
928                                  AC_VERB_GET_PROC_COEF, 0);
929         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
930                             spec->pll_coef_idx);
931         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
932                             val & ~(1 << spec->pll_coef_bit));
933 }
934
935 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
936                              unsigned int coef_idx, unsigned int coef_bit)
937 {
938         struct alc_spec *spec = codec->spec;
939         spec->pll_nid = nid;
940         spec->pll_coef_idx = coef_idx;
941         spec->pll_coef_bit = coef_bit;
942         alc_fix_pll(codec);
943 }
944
945 static void alc_automute_pin(struct hda_codec *codec)
946 {
947         struct alc_spec *spec = codec->spec;
948         unsigned int present, pincap;
949         unsigned int nid = spec->autocfg.hp_pins[0];
950         int i;
951
952         pincap = snd_hda_query_pin_caps(codec, nid);
953         if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */
954                 snd_hda_codec_read(codec, nid, 0, AC_VERB_SET_PIN_SENSE, 0);
955         present = snd_hda_codec_read(codec, nid, 0,
956                                      AC_VERB_GET_PIN_SENSE, 0);
957         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
958         for (i = 0; i < ARRAY_SIZE(spec->autocfg.speaker_pins); i++) {
959                 nid = spec->autocfg.speaker_pins[i];
960                 if (!nid)
961                         break;
962                 snd_hda_codec_write(codec, nid, 0,
963                                     AC_VERB_SET_PIN_WIDGET_CONTROL,
964                                     spec->jack_present ? 0 : PIN_OUT);
965         }
966 }
967
968 #if 0 /* it's broken in some cases -- temporarily disabled */
969 static void alc_mic_automute(struct hda_codec *codec)
970 {
971         struct alc_spec *spec = codec->spec;
972         unsigned int present;
973         unsigned int mic_nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
974         unsigned int fmic_nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
975         unsigned int mix_nid = spec->capsrc_nids[0];
976         unsigned int capsrc_idx_mic, capsrc_idx_fmic;
977
978         capsrc_idx_mic = mic_nid - 0x18;
979         capsrc_idx_fmic = fmic_nid - 0x18;
980         present = snd_hda_codec_read(codec, mic_nid, 0,
981                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
982         snd_hda_codec_write(codec, mix_nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
983                     0x7000 | (capsrc_idx_mic << 8) | (present ? 0 : 0x80));
984         snd_hda_codec_write(codec, mix_nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
985                     0x7000 | (capsrc_idx_fmic << 8) | (present ? 0x80 : 0));
986         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, capsrc_idx_fmic,
987                          HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
988 }
989 #else
990 #define alc_mic_automute(codec) do {} while(0) /* NOP */
991 #endif /* disabled */
992
993 /* unsolicited event for HP jack sensing */
994 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
995 {
996         if (codec->vendor_id == 0x10ec0880)
997                 res >>= 28;
998         else
999                 res >>= 26;
1000         switch (res) {
1001         case ALC880_HP_EVENT:
1002                 alc_automute_pin(codec);
1003                 break;
1004         case ALC880_MIC_EVENT:
1005                 alc_mic_automute(codec);
1006                 break;
1007         }
1008 }
1009
1010 static void alc_inithook(struct hda_codec *codec)
1011 {
1012         alc_automute_pin(codec);
1013         alc_mic_automute(codec);
1014 }
1015
1016 /* additional initialization for ALC888 variants */
1017 static void alc888_coef_init(struct hda_codec *codec)
1018 {
1019         unsigned int tmp;
1020
1021         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
1022         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
1023         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
1024         if ((tmp & 0xf0) == 0x20)
1025                 /* alc888S-VC */
1026                 snd_hda_codec_read(codec, 0x20, 0,
1027                                    AC_VERB_SET_PROC_COEF, 0x830);
1028          else
1029                  /* alc888-VB */
1030                  snd_hda_codec_read(codec, 0x20, 0,
1031                                     AC_VERB_SET_PROC_COEF, 0x3030);
1032 }
1033
1034 static void alc_auto_init_amp(struct hda_codec *codec, int type)
1035 {
1036         unsigned int tmp;
1037
1038         switch (type) {
1039         case ALC_INIT_GPIO1:
1040                 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
1041                 break;
1042         case ALC_INIT_GPIO2:
1043                 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
1044                 break;
1045         case ALC_INIT_GPIO3:
1046                 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
1047                 break;
1048         case ALC_INIT_DEFAULT:
1049                 switch (codec->vendor_id) {
1050                 case 0x10ec0260:
1051                         snd_hda_codec_write(codec, 0x0f, 0,
1052                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1053                         snd_hda_codec_write(codec, 0x10, 0,
1054                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1055                         break;
1056                 case 0x10ec0262:
1057                 case 0x10ec0267:
1058                 case 0x10ec0268:
1059                 case 0x10ec0269:
1060                 case 0x10ec0272:
1061                 case 0x10ec0660:
1062                 case 0x10ec0662:
1063                 case 0x10ec0663:
1064                 case 0x10ec0862:
1065                 case 0x10ec0889:
1066                         snd_hda_codec_write(codec, 0x14, 0,
1067                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1068                         snd_hda_codec_write(codec, 0x15, 0,
1069                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1070                         break;
1071                 }
1072                 switch (codec->vendor_id) {
1073                 case 0x10ec0260:
1074                         snd_hda_codec_write(codec, 0x1a, 0,
1075                                             AC_VERB_SET_COEF_INDEX, 7);
1076                         tmp = snd_hda_codec_read(codec, 0x1a, 0,
1077                                                  AC_VERB_GET_PROC_COEF, 0);
1078                         snd_hda_codec_write(codec, 0x1a, 0,
1079                                             AC_VERB_SET_COEF_INDEX, 7);
1080                         snd_hda_codec_write(codec, 0x1a, 0,
1081                                             AC_VERB_SET_PROC_COEF,
1082                                             tmp | 0x2010);
1083                         break;
1084                 case 0x10ec0262:
1085                 case 0x10ec0880:
1086                 case 0x10ec0882:
1087                 case 0x10ec0883:
1088                 case 0x10ec0885:
1089                 case 0x10ec0887:
1090                 case 0x10ec0889:
1091                         snd_hda_codec_write(codec, 0x20, 0,
1092                                             AC_VERB_SET_COEF_INDEX, 7);
1093                         tmp = snd_hda_codec_read(codec, 0x20, 0,
1094                                                  AC_VERB_GET_PROC_COEF, 0);
1095                         snd_hda_codec_write(codec, 0x20, 0,
1096                                             AC_VERB_SET_COEF_INDEX, 7);
1097                         snd_hda_codec_write(codec, 0x20, 0,
1098                                             AC_VERB_SET_PROC_COEF,
1099                                             tmp | 0x2010);
1100                         break;
1101                 case 0x10ec0888:
1102                         alc888_coef_init(codec);
1103                         break;
1104                 case 0x10ec0267:
1105                 case 0x10ec0268:
1106                         snd_hda_codec_write(codec, 0x20, 0,
1107                                             AC_VERB_SET_COEF_INDEX, 7);
1108                         tmp = snd_hda_codec_read(codec, 0x20, 0,
1109                                                  AC_VERB_GET_PROC_COEF, 0);
1110                         snd_hda_codec_write(codec, 0x20, 0,
1111                                             AC_VERB_SET_COEF_INDEX, 7);
1112                         snd_hda_codec_write(codec, 0x20, 0,
1113                                             AC_VERB_SET_PROC_COEF,
1114                                             tmp | 0x3000);
1115                         break;
1116                 }
1117                 break;
1118         }
1119 }
1120
1121 static void alc_init_auto_hp(struct hda_codec *codec)
1122 {
1123         struct alc_spec *spec = codec->spec;
1124
1125         if (!spec->autocfg.hp_pins[0])
1126                 return;
1127
1128         if (!spec->autocfg.speaker_pins[0]) {
1129                 if (spec->autocfg.line_out_pins[0] &&
1130                     spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
1131                         spec->autocfg.speaker_pins[0] =
1132                                 spec->autocfg.line_out_pins[0];
1133                 else
1134                         return;
1135         }
1136
1137         snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
1138                     spec->autocfg.hp_pins[0]);
1139         snd_hda_codec_write_cache(codec, spec->autocfg.hp_pins[0], 0,
1140                                   AC_VERB_SET_UNSOLICITED_ENABLE,
1141                                   AC_USRSP_EN | ALC880_HP_EVENT);
1142         spec->unsol_event = alc_sku_unsol_event;
1143 }
1144
1145 /* check subsystem ID and set up device-specific initialization;
1146  * return 1 if initialized, 0 if invalid SSID
1147  */
1148 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1149  *      31 ~ 16 :       Manufacture ID
1150  *      15 ~ 8  :       SKU ID
1151  *      7  ~ 0  :       Assembly ID
1152  *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1153  */
1154 static int alc_subsystem_id(struct hda_codec *codec,
1155                             hda_nid_t porta, hda_nid_t porte,
1156                             hda_nid_t portd)
1157 {
1158         unsigned int ass, tmp, i;
1159         unsigned nid;
1160         struct alc_spec *spec = codec->spec;
1161
1162         ass = codec->subsystem_id & 0xffff;
1163         if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1164                 goto do_sku;
1165
1166         /* invalid SSID, check the special NID pin defcfg instead */
1167         /*
1168          * 31~30        : port connectivity
1169          * 29~21        : reserve
1170          * 20           : PCBEEP input
1171          * 19~16        : Check sum (15:1)
1172          * 15~1         : Custom
1173          * 0            : override
1174         */
1175         nid = 0x1d;
1176         if (codec->vendor_id == 0x10ec0260)
1177                 nid = 0x17;
1178         ass = snd_hda_codec_get_pincfg(codec, nid);
1179         snd_printd("realtek: No valid SSID, "
1180                    "checking pincfg 0x%08x for NID 0x%x\n",
1181                    ass, nid);
1182         if (!(ass & 1) && !(ass & 0x100000))
1183                 return 0;
1184         if ((ass >> 30) != 1)   /* no physical connection */
1185                 return 0;
1186
1187         /* check sum */
1188         tmp = 0;
1189         for (i = 1; i < 16; i++) {
1190                 if ((ass >> i) & 1)
1191                         tmp++;
1192         }
1193         if (((ass >> 16) & 0xf) != tmp)
1194                 return 0;
1195 do_sku:
1196         snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1197                    ass & 0xffff, codec->vendor_id);
1198         /*
1199          * 0 : override
1200          * 1 :  Swap Jack
1201          * 2 : 0 --> Desktop, 1 --> Laptop
1202          * 3~5 : External Amplifier control
1203          * 7~6 : Reserved
1204         */
1205         tmp = (ass & 0x38) >> 3;        /* external Amp control */
1206         switch (tmp) {
1207         case 1:
1208                 spec->init_amp = ALC_INIT_GPIO1;
1209                 break;
1210         case 3:
1211                 spec->init_amp = ALC_INIT_GPIO2;
1212                 break;
1213         case 7:
1214                 spec->init_amp = ALC_INIT_GPIO3;
1215                 break;
1216         case 5:
1217                 spec->init_amp = ALC_INIT_DEFAULT;
1218                 break;
1219         }
1220
1221         /* is laptop or Desktop and enable the function "Mute internal speaker
1222          * when the external headphone out jack is plugged"
1223          */
1224         if (!(ass & 0x8000))
1225                 return 1;
1226         /*
1227          * 10~8 : Jack location
1228          * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1229          * 14~13: Resvered
1230          * 15   : 1 --> enable the function "Mute internal speaker
1231          *              when the external headphone out jack is plugged"
1232          */
1233         if (!spec->autocfg.hp_pins[0]) {
1234                 tmp = (ass >> 11) & 0x3;        /* HP to chassis */
1235                 if (tmp == 0)
1236                         spec->autocfg.hp_pins[0] = porta;
1237                 else if (tmp == 1)
1238                         spec->autocfg.hp_pins[0] = porte;
1239                 else if (tmp == 2)
1240                         spec->autocfg.hp_pins[0] = portd;
1241                 else
1242                         return 1;
1243         }
1244
1245         alc_init_auto_hp(codec);
1246         return 1;
1247 }
1248
1249 static void alc_ssid_check(struct hda_codec *codec,
1250                            hda_nid_t porta, hda_nid_t porte, hda_nid_t portd)
1251 {
1252         if (!alc_subsystem_id(codec, porta, porte, portd)) {
1253                 struct alc_spec *spec = codec->spec;
1254                 snd_printd("realtek: "
1255                            "Enable default setup for auto mode as fallback\n");
1256                 spec->init_amp = ALC_INIT_DEFAULT;
1257                 alc_init_auto_hp(codec);
1258         }
1259 }
1260
1261 /*
1262  * Fix-up pin default configurations
1263  */
1264
1265 struct alc_pincfg {
1266         hda_nid_t nid;
1267         u32 val;
1268 };
1269
1270 static void alc_fix_pincfg(struct hda_codec *codec,
1271                            const struct snd_pci_quirk *quirk,
1272                            const struct alc_pincfg **pinfix)
1273 {
1274         const struct alc_pincfg *cfg;
1275
1276         quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1277         if (!quirk)
1278                 return;
1279
1280         cfg = pinfix[quirk->value];
1281         for (; cfg->nid; cfg++)
1282                 snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val);
1283 }
1284
1285 /*
1286  * ALC888
1287  */
1288
1289 /*
1290  * 2ch mode
1291  */
1292 static struct hda_verb alc888_4ST_ch2_intel_init[] = {
1293 /* Mic-in jack as mic in */
1294         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1295         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1296 /* Line-in jack as Line in */
1297         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1298         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1299 /* Line-Out as Front */
1300         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1301         { } /* end */
1302 };
1303
1304 /*
1305  * 4ch mode
1306  */
1307 static struct hda_verb alc888_4ST_ch4_intel_init[] = {
1308 /* Mic-in jack as mic in */
1309         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1310         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1311 /* Line-in jack as Surround */
1312         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1313         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1314 /* Line-Out as Front */
1315         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1316         { } /* end */
1317 };
1318
1319 /*
1320  * 6ch mode
1321  */
1322 static struct hda_verb alc888_4ST_ch6_intel_init[] = {
1323 /* Mic-in jack as CLFE */
1324         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1325         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1326 /* Line-in jack as Surround */
1327         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1328         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1329 /* Line-Out as CLFE (workaround because Mic-in is not loud enough) */
1330         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1331         { } /* end */
1332 };
1333
1334 /*
1335  * 8ch mode
1336  */
1337 static struct hda_verb alc888_4ST_ch8_intel_init[] = {
1338 /* Mic-in jack as CLFE */
1339         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1340         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1341 /* Line-in jack as Surround */
1342         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1343         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1344 /* Line-Out as Side */
1345         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1346         { } /* end */
1347 };
1348
1349 static struct hda_channel_mode alc888_4ST_8ch_intel_modes[4] = {
1350         { 2, alc888_4ST_ch2_intel_init },
1351         { 4, alc888_4ST_ch4_intel_init },
1352         { 6, alc888_4ST_ch6_intel_init },
1353         { 8, alc888_4ST_ch8_intel_init },
1354 };
1355
1356 /*
1357  * ALC888 Fujitsu Siemens Amillo xa3530
1358  */
1359
1360 static struct hda_verb alc888_fujitsu_xa3530_verbs[] = {
1361 /* Front Mic: set to PIN_IN (empty by default) */
1362         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1363 /* Connect Internal HP to Front */
1364         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1365         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1366         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1367 /* Connect Bass HP to Front */
1368         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1369         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1370         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1371 /* Connect Line-Out side jack (SPDIF) to Side */
1372         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1373         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1374         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1375 /* Connect Mic jack to CLFE */
1376         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1377         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1378         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},
1379 /* Connect Line-in jack to Surround */
1380         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1381         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1382         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
1383 /* Connect HP out jack to Front */
1384         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1385         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1386         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1387 /* Enable unsolicited event for HP jack and Line-out jack */
1388         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1389         {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1390         {}
1391 };
1392
1393 static void alc_automute_amp(struct hda_codec *codec)
1394 {
1395         struct alc_spec *spec = codec->spec;
1396         unsigned int val, mute, pincap;
1397         hda_nid_t nid;
1398         int i;
1399
1400         spec->jack_present = 0;
1401         for (i = 0; i < ARRAY_SIZE(spec->autocfg.hp_pins); i++) {
1402                 nid = spec->autocfg.hp_pins[i];
1403                 if (!nid)
1404                         break;
1405                 pincap = snd_hda_query_pin_caps(codec, nid);
1406                 if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */
1407                         snd_hda_codec_read(codec, nid, 0,
1408                                            AC_VERB_SET_PIN_SENSE, 0);
1409                 val = snd_hda_codec_read(codec, nid, 0,
1410                                          AC_VERB_GET_PIN_SENSE, 0);
1411                 if (val & AC_PINSENSE_PRESENCE) {
1412                         spec->jack_present = 1;
1413                         break;
1414                 }
1415         }
1416
1417         mute = spec->jack_present ? HDA_AMP_MUTE : 0;
1418         /* Toggle internal speakers muting */
1419         for (i = 0; i < ARRAY_SIZE(spec->autocfg.speaker_pins); i++) {
1420                 nid = spec->autocfg.speaker_pins[i];
1421                 if (!nid)
1422                         break;
1423                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
1424                                          HDA_AMP_MUTE, mute);
1425         }
1426 }
1427
1428 static void alc_automute_amp_unsol_event(struct hda_codec *codec,
1429                                          unsigned int res)
1430 {
1431         if (codec->vendor_id == 0x10ec0880)
1432                 res >>= 28;
1433         else
1434                 res >>= 26;
1435         if (res == ALC880_HP_EVENT)
1436                 alc_automute_amp(codec);
1437 }
1438
1439 static void alc888_fujitsu_xa3530_init_hook(struct hda_codec *codec)
1440 {
1441         struct alc_spec *spec = codec->spec;
1442
1443         spec->autocfg.hp_pins[0] = 0x17; /* line-out */
1444         spec->autocfg.hp_pins[1] = 0x1b; /* hp */
1445         spec->autocfg.speaker_pins[0] = 0x14; /* speaker */
1446         spec->autocfg.speaker_pins[1] = 0x15; /* bass */
1447         alc_automute_amp(codec);
1448 }
1449
1450 /*
1451  * ALC888 Acer Aspire 4930G model
1452  */
1453
1454 static struct hda_verb alc888_acer_aspire_4930g_verbs[] = {
1455 /* Front Mic: set to PIN_IN (empty by default) */
1456         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1457 /* Unselect Front Mic by default in input mixer 3 */
1458         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1459 /* Enable unsolicited event for HP jack */
1460         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1461 /* Connect Internal HP to front */
1462         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1463         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1464         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1465 /* Connect HP out to front */
1466         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1467         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1468         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1469         { }
1470 };
1471
1472 /*
1473  * ALC888 Acer Aspire 6530G model
1474  */
1475
1476 static struct hda_verb alc888_acer_aspire_6530g_verbs[] = {
1477 /* Bias voltage on for external mic port */
1478         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN | PIN_VREF80},
1479 /* Front Mic: set to PIN_IN (empty by default) */
1480         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1481 /* Unselect Front Mic by default in input mixer 3 */
1482         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1483 /* Enable unsolicited event for HP jack */
1484         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1485 /* Enable speaker output */
1486         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1487         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1488 /* Enable headphone output */
1489         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | PIN_HP},
1490         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1491         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1492         { }
1493 };
1494
1495 /*
1496  * ALC889 Acer Aspire 8930G model
1497  */
1498
1499 static struct hda_verb alc889_acer_aspire_8930g_verbs[] = {
1500 /* Front Mic: set to PIN_IN (empty by default) */
1501         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1502 /* Unselect Front Mic by default in input mixer 3 */
1503         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1504 /* Enable unsolicited event for HP jack */
1505         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1506 /* Connect Internal Front to Front */
1507         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1508         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1509         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1510 /* Connect Internal Rear to Rear */
1511         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1512         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1513         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},
1514 /* Connect Internal CLFE to CLFE */
1515         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1516         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1517         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
1518 /* Connect HP out to Front */
1519         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | PIN_HP},
1520         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1521         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1522 /* Enable all DACs */
1523 /*  DAC DISABLE/MUTE 1? */
1524 /*  setting bits 1-5 disables DAC nids 0x02-0x06 apparently. Init=0x38 */
1525         {0x20, AC_VERB_SET_COEF_INDEX, 0x03},
1526         {0x20, AC_VERB_SET_PROC_COEF, 0x0000},
1527 /*  DAC DISABLE/MUTE 2? */
1528 /*  some bit here disables the other DACs. Init=0x4900 */
1529         {0x20, AC_VERB_SET_COEF_INDEX, 0x08},
1530         {0x20, AC_VERB_SET_PROC_COEF, 0x0000},
1531 /* Enable amplifiers */
1532         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
1533         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
1534 /* DMIC fix
1535  * This laptop has a stereo digital microphone. The mics are only 1cm apart
1536  * which makes the stereo useless. However, either the mic or the ALC889
1537  * makes the signal become a difference/sum signal instead of standard
1538  * stereo, which is annoying. So instead we flip this bit which makes the
1539  * codec replicate the sum signal to both channels, turning it into a
1540  * normal mono mic.
1541  */
1542 /*  DMIC_CONTROL? Init value = 0x0001 */
1543         {0x20, AC_VERB_SET_COEF_INDEX, 0x0b},
1544         {0x20, AC_VERB_SET_PROC_COEF, 0x0003},
1545         { }
1546 };
1547
1548 static struct hda_input_mux alc888_2_capture_sources[2] = {
1549         /* Front mic only available on one ADC */
1550         {
1551                 .num_items = 4,
1552                 .items = {
1553                         { "Mic", 0x0 },
1554                         { "Line", 0x2 },
1555                         { "CD", 0x4 },
1556                         { "Front Mic", 0xb },
1557                 },
1558         },
1559         {
1560                 .num_items = 3,
1561                 .items = {
1562                         { "Mic", 0x0 },
1563                         { "Line", 0x2 },
1564                         { "CD", 0x4 },
1565                 },
1566         }
1567 };
1568
1569 static struct hda_input_mux alc888_acer_aspire_6530_sources[2] = {
1570         /* Interal mic only available on one ADC */
1571         {
1572                 .num_items = 5,
1573                 .items = {
1574                         { "Ext Mic", 0x0 },
1575                         { "Line In", 0x2 },
1576                         { "CD", 0x4 },
1577                         { "Input Mix", 0xa },
1578                         { "Int Mic", 0xb },
1579                 },
1580         },
1581         {
1582                 .num_items = 4,
1583                 .items = {
1584                         { "Ext Mic", 0x0 },
1585                         { "Line In", 0x2 },
1586                         { "CD", 0x4 },
1587                         { "Input Mix", 0xa },
1588                 },
1589         }
1590 };
1591
1592 static struct hda_input_mux alc889_capture_sources[3] = {
1593         /* Digital mic only available on first "ADC" */
1594         {
1595                 .num_items = 5,
1596                 .items = {
1597                         { "Mic", 0x0 },
1598                         { "Line", 0x2 },
1599                         { "CD", 0x4 },
1600                         { "Front Mic", 0xb },
1601                         { "Input Mix", 0xa },
1602                 },
1603         },
1604         {
1605                 .num_items = 4,
1606                 .items = {
1607                         { "Mic", 0x0 },
1608                         { "Line", 0x2 },
1609                         { "CD", 0x4 },
1610                         { "Input Mix", 0xa },
1611                 },
1612         },
1613         {
1614                 .num_items = 4,
1615                 .items = {
1616                         { "Mic", 0x0 },
1617                         { "Line", 0x2 },
1618                         { "CD", 0x4 },
1619                         { "Input Mix", 0xa },
1620                 },
1621         }
1622 };
1623
1624 static struct snd_kcontrol_new alc888_base_mixer[] = {
1625         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1626         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1627         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1628         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1629         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
1630                 HDA_OUTPUT),
1631         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1632         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1633         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1634         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1635         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1636         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1637         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1638         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1639         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1640         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1641         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
1642         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1643         { } /* end */
1644 };
1645
1646 static void alc888_acer_aspire_4930g_init_hook(struct hda_codec *codec)
1647 {
1648         struct alc_spec *spec = codec->spec;
1649
1650         spec->autocfg.hp_pins[0] = 0x15;
1651         spec->autocfg.speaker_pins[0] = 0x14;
1652         alc_automute_amp(codec);
1653 }
1654
1655 static void alc888_acer_aspire_6530g_init_hook(struct hda_codec *codec)
1656 {
1657         struct alc_spec *spec = codec->spec;
1658
1659         spec->autocfg.hp_pins[0] = 0x15;
1660         spec->autocfg.speaker_pins[0] = 0x14;
1661         spec->autocfg.speaker_pins[1] = 0x16;
1662         spec->autocfg.speaker_pins[2] = 0x17;
1663         alc_automute_amp(codec);
1664 }
1665
1666 static void alc889_acer_aspire_8930g_init_hook(struct hda_codec *codec)
1667 {
1668         struct alc_spec *spec = codec->spec;
1669
1670         spec->autocfg.hp_pins[0] = 0x15;
1671         spec->autocfg.speaker_pins[0] = 0x14;
1672         spec->autocfg.speaker_pins[1] = 0x16;
1673         spec->autocfg.speaker_pins[2] = 0x1b;
1674         alc_automute_amp(codec);
1675 }
1676
1677 /*
1678  * ALC880 3-stack model
1679  *
1680  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
1681  * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
1682  *                 F-Mic = 0x1b, HP = 0x19
1683  */
1684
1685 static hda_nid_t alc880_dac_nids[4] = {
1686         /* front, rear, clfe, rear_surr */
1687         0x02, 0x05, 0x04, 0x03
1688 };
1689
1690 static hda_nid_t alc880_adc_nids[3] = {
1691         /* ADC0-2 */
1692         0x07, 0x08, 0x09,
1693 };
1694
1695 /* The datasheet says the node 0x07 is connected from inputs,
1696  * but it shows zero connection in the real implementation on some devices.
1697  * Note: this is a 915GAV bug, fixed on 915GLV
1698  */
1699 static hda_nid_t alc880_adc_nids_alt[2] = {
1700         /* ADC1-2 */
1701         0x08, 0x09,
1702 };
1703
1704 #define ALC880_DIGOUT_NID       0x06
1705 #define ALC880_DIGIN_NID        0x0a
1706
1707 static struct hda_input_mux alc880_capture_source = {
1708         .num_items = 4,
1709         .items = {
1710                 { "Mic", 0x0 },
1711                 { "Front Mic", 0x3 },
1712                 { "Line", 0x2 },
1713                 { "CD", 0x4 },
1714         },
1715 };
1716
1717 /* channel source setting (2/6 channel selection for 3-stack) */
1718 /* 2ch mode */
1719 static struct hda_verb alc880_threestack_ch2_init[] = {
1720         /* set line-in to input, mute it */
1721         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1722         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1723         /* set mic-in to input vref 80%, mute it */
1724         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1725         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1726         { } /* end */
1727 };
1728
1729 /* 6ch mode */
1730 static struct hda_verb alc880_threestack_ch6_init[] = {
1731         /* set line-in to output, unmute it */
1732         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1733         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1734         /* set mic-in to output, unmute it */
1735         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1736         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1737         { } /* end */
1738 };
1739
1740 static struct hda_channel_mode alc880_threestack_modes[2] = {
1741         { 2, alc880_threestack_ch2_init },
1742         { 6, alc880_threestack_ch6_init },
1743 };
1744
1745 static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
1746         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1747         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1748         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1749         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
1750         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1751         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1752         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1753         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1754         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1755         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1756         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1757         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1758         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1759         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1760         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
1761         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
1762         HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
1763         {
1764                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1765                 .name = "Channel Mode",
1766                 .info = alc_ch_mode_info,
1767                 .get = alc_ch_mode_get,
1768                 .put = alc_ch_mode_put,
1769         },
1770         { } /* end */
1771 };
1772
1773 /* capture mixer elements */
1774 static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1775                             struct snd_ctl_elem_info *uinfo)
1776 {
1777         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1778         struct alc_spec *spec = codec->spec;
1779         int err;
1780
1781         mutex_lock(&codec->control_mutex);
1782         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1783                                                       HDA_INPUT);
1784         err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
1785         mutex_unlock(&codec->control_mutex);
1786         return err;
1787 }
1788
1789 static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1790                            unsigned int size, unsigned int __user *tlv)
1791 {
1792         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1793         struct alc_spec *spec = codec->spec;
1794         int err;
1795
1796         mutex_lock(&codec->control_mutex);
1797         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1798                                                       HDA_INPUT);
1799         err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
1800         mutex_unlock(&codec->control_mutex);
1801         return err;
1802 }
1803
1804 typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1805                              struct snd_ctl_elem_value *ucontrol);
1806
1807 static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1808                                  struct snd_ctl_elem_value *ucontrol,
1809                                  getput_call_t func)
1810 {
1811         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1812         struct alc_spec *spec = codec->spec;
1813         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1814         int err;
1815
1816         mutex_lock(&codec->control_mutex);
1817         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[adc_idx],
1818                                                       3, 0, HDA_INPUT);
1819         err = func(kcontrol, ucontrol);
1820         mutex_unlock(&codec->control_mutex);
1821         return err;
1822 }
1823
1824 static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1825                            struct snd_ctl_elem_value *ucontrol)
1826 {
1827         return alc_cap_getput_caller(kcontrol, ucontrol,
1828                                      snd_hda_mixer_amp_volume_get);
1829 }
1830
1831 static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1832                            struct snd_ctl_elem_value *ucontrol)
1833 {
1834         return alc_cap_getput_caller(kcontrol, ucontrol,
1835                                      snd_hda_mixer_amp_volume_put);
1836 }
1837
1838 /* capture mixer elements */
1839 #define alc_cap_sw_info         snd_ctl_boolean_stereo_info
1840
1841 static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1842                           struct snd_ctl_elem_value *ucontrol)
1843 {
1844         return alc_cap_getput_caller(kcontrol, ucontrol,
1845                                      snd_hda_mixer_amp_switch_get);
1846 }
1847
1848 static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1849                           struct snd_ctl_elem_value *ucontrol)
1850 {
1851         return alc_cap_getput_caller(kcontrol, ucontrol,
1852                                      snd_hda_mixer_amp_switch_put);
1853 }
1854
1855 #define _DEFINE_CAPMIX(num) \
1856         { \
1857                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1858                 .name = "Capture Switch", \
1859                 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1860                 .count = num, \
1861                 .info = alc_cap_sw_info, \
1862                 .get = alc_cap_sw_get, \
1863                 .put = alc_cap_sw_put, \
1864         }, \
1865         { \
1866                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1867                 .name = "Capture Volume", \
1868                 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1869                            SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1870                            SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1871                 .count = num, \
1872                 .info = alc_cap_vol_info, \
1873                 .get = alc_cap_vol_get, \
1874                 .put = alc_cap_vol_put, \
1875                 .tlv = { .c = alc_cap_vol_tlv }, \
1876         }
1877
1878 #define _DEFINE_CAPSRC(num) \
1879         { \
1880                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1881                 /* .name = "Capture Source", */ \
1882                 .name = "Input Source", \
1883                 .count = num, \
1884                 .info = alc_mux_enum_info, \
1885                 .get = alc_mux_enum_get, \
1886                 .put = alc_mux_enum_put, \
1887         }
1888
1889 #define DEFINE_CAPMIX(num) \
1890 static struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1891         _DEFINE_CAPMIX(num),                                  \
1892         _DEFINE_CAPSRC(num),                                  \
1893         { } /* end */                                         \
1894 }
1895
1896 #define DEFINE_CAPMIX_NOSRC(num) \
1897 static struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
1898         _DEFINE_CAPMIX(num),                                        \
1899         { } /* end */                                               \
1900 }
1901
1902 /* up to three ADCs */
1903 DEFINE_CAPMIX(1);
1904 DEFINE_CAPMIX(2);
1905 DEFINE_CAPMIX(3);
1906 DEFINE_CAPMIX_NOSRC(1);
1907 DEFINE_CAPMIX_NOSRC(2);
1908 DEFINE_CAPMIX_NOSRC(3);
1909
1910 /*
1911  * ALC880 5-stack model
1912  *
1913  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
1914  *      Side = 0x02 (0xd)
1915  * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
1916  *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
1917  */
1918
1919 /* additional mixers to alc880_three_stack_mixer */
1920 static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
1921         HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1922         HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
1923         { } /* end */
1924 };
1925
1926 /* channel source setting (6/8 channel selection for 5-stack) */
1927 /* 6ch mode */
1928 static struct hda_verb alc880_fivestack_ch6_init[] = {
1929         /* set line-in to input, mute it */
1930         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1931         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1932         { } /* end */
1933 };
1934
1935 /* 8ch mode */
1936 static struct hda_verb alc880_fivestack_ch8_init[] = {
1937         /* set line-in to output, unmute it */
1938         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1939         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1940         { } /* end */
1941 };
1942
1943 static struct hda_channel_mode alc880_fivestack_modes[2] = {
1944         { 6, alc880_fivestack_ch6_init },
1945         { 8, alc880_fivestack_ch8_init },
1946 };
1947
1948
1949 /*
1950  * ALC880 6-stack model
1951  *
1952  * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
1953  *      Side = 0x05 (0x0f)
1954  * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
1955  *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
1956  */
1957
1958 static hda_nid_t alc880_6st_dac_nids[4] = {
1959         /* front, rear, clfe, rear_surr */
1960         0x02, 0x03, 0x04, 0x05
1961 };
1962
1963 static struct hda_input_mux alc880_6stack_capture_source = {
1964         .num_items = 4,
1965         .items = {
1966                 { "Mic", 0x0 },
1967                 { "Front Mic", 0x1 },
1968                 { "Line", 0x2 },
1969                 { "CD", 0x4 },
1970         },
1971 };
1972
1973 /* fixed 8-channels */
1974 static struct hda_channel_mode alc880_sixstack_modes[1] = {
1975         { 8, NULL },
1976 };
1977
1978 static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
1979         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1980         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1981         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1982         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1983         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1984         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1985         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1986         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1987         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1988         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1989         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1990         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1991         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1992         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1993         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1994         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1995         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1996         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1997         {
1998                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1999                 .name = "Channel Mode",
2000                 .info = alc_ch_mode_info,
2001                 .get = alc_ch_mode_get,
2002                 .put = alc_ch_mode_put,
2003         },
2004         { } /* end */
2005 };
2006
2007
2008 /*
2009  * ALC880 W810 model
2010  *
2011  * W810 has rear IO for:
2012  * Front (DAC 02)
2013  * Surround (DAC 03)
2014  * Center/LFE (DAC 04)
2015  * Digital out (06)
2016  *
2017  * The system also has a pair of internal speakers, and a headphone jack.
2018  * These are both connected to Line2 on the codec, hence to DAC 02.
2019  *
2020  * There is a variable resistor to control the speaker or headphone
2021  * volume. This is a hardware-only device without a software API.
2022  *
2023  * Plugging headphones in will disable the internal speakers. This is
2024  * implemented in hardware, not via the driver using jack sense. In
2025  * a similar fashion, plugging into the rear socket marked "front" will
2026  * disable both the speakers and headphones.
2027  *
2028  * For input, there's a microphone jack, and an "audio in" jack.
2029  * These may not do anything useful with this driver yet, because I
2030  * haven't setup any initialization verbs for these yet...
2031  */
2032
2033 static hda_nid_t alc880_w810_dac_nids[3] = {
2034         /* front, rear/surround, clfe */
2035         0x02, 0x03, 0x04
2036 };
2037
2038 /* fixed 6 channels */
2039 static struct hda_channel_mode alc880_w810_modes[1] = {
2040         { 6, NULL }
2041 };
2042
2043 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
2044 static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
2045         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2046         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2047         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2048         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2049         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2050         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2051         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2052         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2053         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
2054         { } /* end */
2055 };
2056
2057
2058 /*
2059  * Z710V model
2060  *
2061  * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
2062  * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
2063  *                 Line = 0x1a
2064  */
2065
2066 static hda_nid_t alc880_z71v_dac_nids[1] = {
2067         0x02
2068 };
2069 #define ALC880_Z71V_HP_DAC      0x03
2070
2071 /* fixed 2 channels */
2072 static struct hda_channel_mode alc880_2_jack_modes[1] = {
2073         { 2, NULL }
2074 };
2075
2076 static struct snd_kcontrol_new alc880_z71v_mixer[] = {
2077         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2078         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2079         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2080         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
2081         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2082         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2083         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2084         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2085         { } /* end */
2086 };
2087
2088
2089 /*
2090  * ALC880 F1734 model
2091  *
2092  * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
2093  * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
2094  */
2095
2096 static hda_nid_t alc880_f1734_dac_nids[1] = {
2097         0x03
2098 };
2099 #define ALC880_F1734_HP_DAC     0x02
2100
2101 static struct snd_kcontrol_new alc880_f1734_mixer[] = {
2102         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2103         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2104         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2105         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2106         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2107         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2108         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2109         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2110         { } /* end */
2111 };
2112
2113 static struct hda_input_mux alc880_f1734_capture_source = {
2114         .num_items = 2,
2115         .items = {
2116                 { "Mic", 0x1 },
2117                 { "CD", 0x4 },
2118         },
2119 };
2120
2121
2122 /*
2123  * ALC880 ASUS model
2124  *
2125  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
2126  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
2127  *  Mic = 0x18, Line = 0x1a
2128  */
2129
2130 #define alc880_asus_dac_nids    alc880_w810_dac_nids    /* identical with w810 */
2131 #define alc880_asus_modes       alc880_threestack_modes /* 2/6 channel mode */
2132
2133 static struct snd_kcontrol_new alc880_asus_mixer[] = {
2134         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2135         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2136         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2137         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2138         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2139         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2140         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2141         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2142         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2143         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2144         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2145         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2146         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2147         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2148         {
2149                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2150                 .name = "Channel Mode",
2151                 .info = alc_ch_mode_info,
2152                 .get = alc_ch_mode_get,
2153                 .put = alc_ch_mode_put,
2154         },
2155         { } /* end */
2156 };
2157
2158 /*
2159  * ALC880 ASUS W1V model
2160  *
2161  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
2162  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
2163  *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
2164  */
2165
2166 /* additional mixers to alc880_asus_mixer */
2167 static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
2168         HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
2169         HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
2170         { } /* end */
2171 };
2172
2173 /* TCL S700 */
2174 static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
2175         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2176         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
2177         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
2178         HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
2179         HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
2180         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
2181         HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
2182         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
2183         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
2184         { } /* end */
2185 };
2186
2187 /* Uniwill */
2188 static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
2189         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2190         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2191         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2192         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2193         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2194         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2195         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2196         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2197         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2198         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2199         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2200         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2201         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2202         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2203         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2204         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2205         {
2206                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2207                 .name = "Channel Mode",
2208                 .info = alc_ch_mode_info,
2209                 .get = alc_ch_mode_get,
2210                 .put = alc_ch_mode_put,
2211         },
2212         { } /* end */
2213 };
2214
2215 static struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
2216         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2217         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2218         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2219         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2220         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2221         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
2222         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2223         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2224         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2225         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2226         { } /* end */
2227 };
2228
2229 static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
2230         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2231         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
2232         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2233         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
2234         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2235         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2236         { } /* end */
2237 };
2238
2239 /*
2240  * virtual master controls
2241  */
2242
2243 /*
2244  * slave controls for virtual master
2245  */
2246 static const char *alc_slave_vols[] = {
2247         "Front Playback Volume",
2248         "Surround Playback Volume",
2249         "Center Playback Volume",
2250         "LFE Playback Volume",
2251         "Side Playback Volume",
2252         "Headphone Playback Volume",
2253         "Speaker Playback Volume",
2254         "Mono Playback Volume",
2255         "Line-Out Playback Volume",
2256         "PCM Playback Volume",
2257         NULL,
2258 };
2259
2260 static const char *alc_slave_sws[] = {
2261         "Front Playback Switch",
2262         "Surround Playback Switch",
2263         "Center Playback Switch",
2264         "LFE Playback Switch",
2265         "Side Playback Switch",
2266         "Headphone Playback Switch",
2267         "Speaker Playback Switch",
2268         "Mono Playback Switch",
2269         "IEC958 Playback Switch",
2270         NULL,
2271 };
2272
2273 /*
2274  * build control elements
2275  */
2276
2277 static void alc_free_kctls(struct hda_codec *codec);
2278
2279 /* additional beep mixers; the actual parameters are overwritten at build */
2280 static struct snd_kcontrol_new alc_beep_mixer[] = {
2281         HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
2282         HDA_CODEC_MUTE("Beep Playback Switch", 0, 0, HDA_INPUT),
2283         { } /* end */
2284 };
2285
2286 static int alc_build_controls(struct hda_codec *codec)
2287 {
2288         struct alc_spec *spec = codec->spec;
2289         int err;
2290         int i;
2291
2292         for (i = 0; i < spec->num_mixers; i++) {
2293                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
2294                 if (err < 0)
2295                         return err;
2296         }
2297         if (spec->cap_mixer) {
2298                 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
2299                 if (err < 0)
2300                         return err;
2301         }
2302         if (spec->multiout.dig_out_nid) {
2303                 err = snd_hda_create_spdif_out_ctls(codec,
2304                                                     spec->multiout.dig_out_nid);
2305                 if (err < 0)
2306                         return err;
2307                 if (!spec->no_analog) {
2308                         err = snd_hda_create_spdif_share_sw(codec,
2309                                                             &spec->multiout);
2310                         if (err < 0)
2311                                 return err;
2312                         spec->multiout.share_spdif = 1;
2313                 }
2314         }
2315         if (spec->dig_in_nid) {
2316                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
2317                 if (err < 0)
2318                         return err;
2319         }
2320
2321         /* create beep controls if needed */
2322         if (spec->beep_amp) {
2323                 struct snd_kcontrol_new *knew;
2324                 for (knew = alc_beep_mixer; knew->name; knew++) {
2325                         struct snd_kcontrol *kctl;
2326                         kctl = snd_ctl_new1(knew, codec);
2327                         if (!kctl)
2328                                 return -ENOMEM;
2329                         kctl->private_value = spec->beep_amp;
2330                         err = snd_hda_ctl_add(codec, kctl);
2331                         if (err < 0)
2332                                 return err;
2333                 }
2334         }
2335
2336         /* if we have no master control, let's create it */
2337         if (!spec->no_analog &&
2338             !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
2339                 unsigned int vmaster_tlv[4];
2340                 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
2341                                         HDA_OUTPUT, vmaster_tlv);
2342                 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
2343                                           vmaster_tlv, alc_slave_vols);
2344                 if (err < 0)
2345                         return err;
2346         }
2347         if (!spec->no_analog &&
2348             !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
2349                 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
2350                                           NULL, alc_slave_sws);
2351                 if (err < 0)
2352                         return err;
2353         }
2354
2355         alc_free_kctls(codec); /* no longer needed */
2356         return 0;
2357 }
2358
2359
2360 /*
2361  * initialize the codec volumes, etc
2362  */
2363
2364 /*
2365  * generic initialization of ADC, input mixers and output mixers
2366  */
2367 static struct hda_verb alc880_volume_init_verbs[] = {
2368         /*
2369          * Unmute ADC0-2 and set the default input to mic-in
2370          */
2371         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
2372         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2373         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
2374         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2375         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
2376         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2377
2378         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2379          * mixer widget
2380          * Note: PASD motherboards uses the Line In 2 as the input for front
2381          * panel mic (mic 2)
2382          */
2383         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
2384         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2385         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2386         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2387         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2388         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2389         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2390         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2391
2392         /*
2393          * Set up output mixers (0x0c - 0x0f)
2394          */
2395         /* set vol=0 to output mixers */
2396         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2397         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2398         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2399         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2400         /* set up input amps for analog loopback */
2401         /* Amp Indices: DAC = 0, mixer = 1 */
2402         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2403         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2404         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2405         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2406         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2407         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2408         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2409         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2410
2411         { }
2412 };
2413
2414 /*
2415  * 3-stack pin configuration:
2416  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
2417  */
2418 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
2419         /*
2420          * preset connection lists of input pins
2421          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2422          */
2423         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2424         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2425         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2426
2427         /*
2428          * Set pin mode and muting
2429          */
2430         /* set front pin widgets 0x14 for output */
2431         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2432         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2433         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2434         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2435         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2436         /* Mic2 (as headphone out) for HP output */
2437         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2438         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2439         /* Line In pin widget for input */
2440         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2441         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2442         /* Line2 (as front mic) pin widget for input and vref at 80% */
2443         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2444         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2445         /* CD pin widget for input */
2446         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2447
2448         { }
2449 };
2450
2451 /*
2452  * 5-stack pin configuration:
2453  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
2454  * line-in/side = 0x1a, f-mic = 0x1b
2455  */
2456 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
2457         /*
2458          * preset connection lists of input pins
2459          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2460          */
2461         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2462         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
2463
2464         /*
2465          * Set pin mode and muting
2466          */
2467         /* set pin widgets 0x14-0x17 for output */
2468         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2469         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2470         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2471         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2472         /* unmute pins for output (no gain on this amp) */
2473         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2474         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2475         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2476         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2477
2478         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2479         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2480         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2481         /* Mic2 (as headphone out) for HP output */
2482         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2483         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2484         /* Line In pin widget for input */
2485         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2486         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2487         /* Line2 (as front mic) pin widget for input and vref at 80% */
2488         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2489         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2490         /* CD pin widget for input */
2491         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2492
2493         { }
2494 };
2495
2496 /*
2497  * W810 pin configuration:
2498  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
2499  */
2500 static struct hda_verb alc880_pin_w810_init_verbs[] = {
2501         /* hphone/speaker input selector: front DAC */
2502         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
2503
2504         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2505         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2506         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2507         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2508         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2509         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2510
2511         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2512         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2513
2514         { }
2515 };
2516
2517 /*
2518  * Z71V pin configuration:
2519  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
2520  */
2521 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
2522         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2523         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2524         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2525         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2526
2527         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2528         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2529         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2530         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2531
2532         { }
2533 };
2534
2535 /*
2536  * 6-stack pin configuration:
2537  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
2538  * f-mic = 0x19, line = 0x1a, HP = 0x1b
2539  */
2540 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
2541         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2542
2543         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2544         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2545         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2546         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2547         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2548         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2549         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2550         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2551
2552         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2553         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2554         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2555         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2556         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2557         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2558         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2559         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2560         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2561
2562         { }
2563 };
2564
2565 /*
2566  * Uniwill pin configuration:
2567  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
2568  * line = 0x1a
2569  */
2570 static struct hda_verb alc880_uniwill_init_verbs[] = {
2571         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2572
2573         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2574         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2575         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2576         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2577         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2578         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2579         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2580         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2581         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2582         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2583         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2584         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2585         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2586         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2587
2588         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2589         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2590         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2591         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2592         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2593         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2594         /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
2595         /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
2596         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2597
2598         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2599         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
2600
2601         { }
2602 };
2603
2604 /*
2605 * Uniwill P53
2606 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19,
2607  */
2608 static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
2609         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2610
2611         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2612         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2613         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2614         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2615         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2616         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2617         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2618         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2619         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2620         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2621         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2622         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2623
2624         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2625         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2626         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2627         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2628         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2629         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2630
2631         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2632         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
2633
2634         { }
2635 };
2636
2637 static struct hda_verb alc880_beep_init_verbs[] = {
2638         { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
2639         { }
2640 };
2641
2642 /* auto-toggle front mic */
2643 static void alc880_uniwill_mic_automute(struct hda_codec *codec)
2644 {
2645         unsigned int present;
2646         unsigned char bits;
2647
2648         present = snd_hda_codec_read(codec, 0x18, 0,
2649                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2650         bits = present ? HDA_AMP_MUTE : 0;
2651         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
2652 }
2653
2654 static void alc880_uniwill_init_hook(struct hda_codec *codec)
2655 {
2656         struct alc_spec *spec = codec->spec;
2657
2658         spec->autocfg.hp_pins[0] = 0x14;
2659         spec->autocfg.speaker_pins[0] = 0x15;
2660         spec->autocfg.speaker_pins[0] = 0x16;
2661         alc_automute_amp(codec);
2662         alc880_uniwill_mic_automute(codec);
2663 }
2664
2665 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
2666                                        unsigned int res)
2667 {
2668         /* Looks like the unsol event is incompatible with the standard
2669          * definition.  4bit tag is placed at 28 bit!
2670          */
2671         switch (res >> 28) {
2672         case ALC880_MIC_EVENT:
2673                 alc880_uniwill_mic_automute(codec);
2674                 break;
2675         default:
2676                 alc_automute_amp_unsol_event(codec, res);
2677                 break;
2678         }
2679 }
2680
2681 static void alc880_uniwill_p53_init_hook(struct hda_codec *codec)
2682 {
2683         struct alc_spec *spec = codec->spec;
2684
2685         spec->autocfg.hp_pins[0] = 0x14;
2686         spec->autocfg.speaker_pins[0] = 0x15;
2687         alc_automute_amp(codec);
2688 }
2689
2690 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
2691 {
2692         unsigned int present;
2693
2694         present = snd_hda_codec_read(codec, 0x21, 0,
2695                                      AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
2696         present &= HDA_AMP_VOLMASK;
2697         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
2698                                  HDA_AMP_VOLMASK, present);
2699         snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
2700                                  HDA_AMP_VOLMASK, present);
2701 }
2702
2703 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
2704                                            unsigned int res)
2705 {
2706         /* Looks like the unsol event is incompatible with the standard
2707          * definition.  4bit tag is placed at 28 bit!
2708          */
2709         if ((res >> 28) == ALC880_DCVOL_EVENT)
2710                 alc880_uniwill_p53_dcvol_automute(codec);
2711         else
2712                 alc_automute_amp_unsol_event(codec, res);
2713 }
2714
2715 /*
2716  * F1734 pin configuration:
2717  * HP = 0x14, speaker-out = 0x15, mic = 0x18
2718  */
2719 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
2720         {0x07, AC_VERB_SET_CONNECT_SEL, 0x01},
2721         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2722         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2723         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2724         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2725
2726         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2727         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2728         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2729         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2730
2731         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2732         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2733         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
2734         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2735         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2736         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2737         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2738         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2739         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2740
2741         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
2742         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_DCVOL_EVENT},
2743
2744         { }
2745 };
2746
2747 /*
2748  * ASUS pin configuration:
2749  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
2750  */
2751 static struct hda_verb alc880_pin_asus_init_verbs[] = {
2752         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2753         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2754         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2755         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2756
2757         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2758         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2759         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2760         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2761         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2762         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2763         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2764         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2765
2766         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2767         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2768         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2769         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2770         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2771         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2772         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2773         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2774         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2775
2776         { }
2777 };
2778
2779 /* Enable GPIO mask and set output */
2780 #define alc880_gpio1_init_verbs alc_gpio1_init_verbs
2781 #define alc880_gpio2_init_verbs alc_gpio2_init_verbs
2782 #define alc880_gpio3_init_verbs alc_gpio3_init_verbs
2783
2784 /* Clevo m520g init */
2785 static struct hda_verb alc880_pin_clevo_init_verbs[] = {
2786         /* headphone output */
2787         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2788         /* line-out */
2789         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2790         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2791         /* Line-in */
2792         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2793         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2794         /* CD */
2795         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2796         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2797         /* Mic1 (rear panel) */
2798         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2799         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2800         /* Mic2 (front panel) */
2801         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2802         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2803         /* headphone */
2804         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2805         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2806         /* change to EAPD mode */
2807         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2808         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2809
2810         { }
2811 };
2812
2813 static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
2814         /* change to EAPD mode */
2815         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2816         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2817
2818         /* Headphone output */
2819         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2820         /* Front output*/
2821         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2822         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
2823
2824         /* Line In pin widget for input */
2825         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2826         /* CD pin widget for input */
2827         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2828         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2829         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2830
2831         /* change to EAPD mode */
2832         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2833         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
2834
2835         { }
2836 };
2837
2838 /*
2839  * LG m1 express dual
2840  *
2841  * Pin assignment:
2842  *   Rear Line-In/Out (blue): 0x14
2843  *   Build-in Mic-In: 0x15
2844  *   Speaker-out: 0x17
2845  *   HP-Out (green): 0x1b
2846  *   Mic-In/Out (red): 0x19
2847  *   SPDIF-Out: 0x1e
2848  */
2849
2850 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
2851 static hda_nid_t alc880_lg_dac_nids[3] = {
2852         0x05, 0x02, 0x03
2853 };
2854
2855 /* seems analog CD is not working */
2856 static struct hda_input_mux alc880_lg_capture_source = {
2857         .num_items = 3,
2858         .items = {
2859                 { "Mic", 0x1 },
2860                 { "Line", 0x5 },
2861                 { "Internal Mic", 0x6 },
2862         },
2863 };
2864
2865 /* 2,4,6 channel modes */
2866 static struct hda_verb alc880_lg_ch2_init[] = {
2867         /* set line-in and mic-in to input */
2868         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2869         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2870         { }
2871 };
2872
2873 static struct hda_verb alc880_lg_ch4_init[] = {
2874         /* set line-in to out and mic-in to input */
2875         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2876         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2877         { }
2878 };
2879
2880 static struct hda_verb alc880_lg_ch6_init[] = {
2881         /* set line-in and mic-in to output */
2882         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2883         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2884         { }
2885 };
2886
2887 static struct hda_channel_mode alc880_lg_ch_modes[3] = {
2888         { 2, alc880_lg_ch2_init },
2889         { 4, alc880_lg_ch4_init },
2890         { 6, alc880_lg_ch6_init },
2891 };
2892
2893 static struct snd_kcontrol_new alc880_lg_mixer[] = {
2894         HDA_CODEC_VOLUME("Front Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2895         HDA_BIND_MUTE("Front Playback Switch", 0x0f, 2, HDA_INPUT),
2896         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2897         HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
2898         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
2899         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
2900         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
2901         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
2902         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2903         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2904         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
2905         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
2906         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
2907         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
2908         {
2909                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2910                 .name = "Channel Mode",
2911                 .info = alc_ch_mode_info,
2912                 .get = alc_ch_mode_get,
2913                 .put = alc_ch_mode_put,
2914         },
2915         { } /* end */
2916 };
2917
2918 static struct hda_verb alc880_lg_init_verbs[] = {
2919         /* set capture source to mic-in */
2920         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2921         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2922         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2923         /* mute all amp mixer inputs */
2924         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
2925         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2926         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2927         /* line-in to input */
2928         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2929         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2930         /* built-in mic */
2931         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2932         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2933         /* speaker-out */
2934         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2935         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2936         /* mic-in to input */
2937         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2938         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2939         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2940         /* HP-out */
2941         {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
2942         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2943         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2944         /* jack sense */
2945         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2946         { }
2947 };
2948
2949 /* toggle speaker-output according to the hp-jack state */
2950 static void alc880_lg_init_hook(struct hda_codec *codec)
2951 {
2952         struct alc_spec *spec = codec->spec;
2953
2954         spec->autocfg.hp_pins[0] = 0x1b;
2955         spec->autocfg.speaker_pins[0] = 0x17;
2956         alc_automute_amp(codec);
2957 }
2958
2959 /*
2960  * LG LW20
2961  *
2962  * Pin assignment:
2963  *   Speaker-out: 0x14
2964  *   Mic-In: 0x18
2965  *   Built-in Mic-In: 0x19
2966  *   Line-In: 0x1b
2967  *   HP-Out: 0x1a
2968  *   SPDIF-Out: 0x1e
2969  */
2970
2971 static struct hda_input_mux alc880_lg_lw_capture_source = {
2972         .num_items = 3,
2973         .items = {
2974                 { "Mic", 0x0 },
2975                 { "Internal Mic", 0x1 },
2976                 { "Line In", 0x2 },
2977         },
2978 };
2979
2980 #define alc880_lg_lw_modes alc880_threestack_modes
2981
2982 static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
2983         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2984         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2985         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2986         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
2987         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2988         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2989         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2990         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2991         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2992         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2993         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2994         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2995         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
2996         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
2997         {
2998                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2999                 .name = "Channel Mode",
3000                 .info = alc_ch_mode_info,
3001                 .get = alc_ch_mode_get,
3002                 .put = alc_ch_mode_put,
3003         },
3004         { } /* end */
3005 };
3006
3007 static struct hda_verb alc880_lg_lw_init_verbs[] = {
3008         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3009         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
3010         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
3011
3012         /* set capture source to mic-in */
3013         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3014         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3015         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3016         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
3017         /* speaker-out */
3018         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3019         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3020         /* HP-out */
3021         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3022         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3023         /* mic-in to input */
3024         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3025         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3026         /* built-in mic */
3027         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3028         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3029         /* jack sense */
3030         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3031         { }
3032 };
3033
3034 /* toggle speaker-output according to the hp-jack state */
3035 static void alc880_lg_lw_init_hook(struct hda_codec *codec)
3036 {
3037         struct alc_spec *spec = codec->spec;
3038
3039         spec->autocfg.hp_pins[0] = 0x1b;
3040         spec->autocfg.speaker_pins[0] = 0x14;
3041         alc_automute_amp(codec);
3042 }
3043
3044 static struct snd_kcontrol_new alc880_medion_rim_mixer[] = {
3045         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3046         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
3047         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
3048         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
3049         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
3050         HDA_CODEC_MUTE("Internal Playback Switch", 0x0b, 0x1, HDA_INPUT),
3051         { } /* end */
3052 };
3053
3054 static struct hda_input_mux alc880_medion_rim_capture_source = {
3055         .num_items = 2,
3056         .items = {
3057                 { "Mic", 0x0 },
3058                 { "Internal Mic", 0x1 },
3059         },
3060 };
3061
3062 static struct hda_verb alc880_medion_rim_init_verbs[] = {
3063         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
3064
3065         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3066         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3067
3068         /* Mic1 (rear panel) pin widget for input and vref at 80% */
3069         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3070         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3071         /* Mic2 (as headphone out) for HP output */
3072         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3073         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3074         /* Internal Speaker */
3075         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3076         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3077
3078         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
3079         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
3080
3081         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
3082         { }
3083 };
3084
3085 /* toggle speaker-output according to the hp-jack state */
3086 static void alc880_medion_rim_automute(struct hda_codec *codec)
3087 {
3088         struct alc_spec *spec = codec->spec;
3089         alc_automute_amp(codec);
3090         /* toggle EAPD */
3091         if (spec->jack_present)
3092                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0);
3093         else
3094                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 2);
3095 }
3096
3097 static void alc880_medion_rim_unsol_event(struct hda_codec *codec,
3098                                           unsigned int res)
3099 {
3100         /* Looks like the unsol event is incompatible with the standard
3101          * definition.  4bit tag is placed at 28 bit!
3102          */
3103         if ((res >> 28) == ALC880_HP_EVENT)
3104                 alc880_medion_rim_automute(codec);
3105 }
3106
3107 static void alc880_medion_rim_init_hook(struct hda_codec *codec)
3108 {
3109         struct alc_spec *spec = codec->spec;
3110
3111         spec->autocfg.hp_pins[0] = 0x14;
3112         spec->autocfg.speaker_pins[0] = 0x1b;
3113         alc880_medion_rim_automute(codec);
3114 }
3115
3116 #ifdef CONFIG_SND_HDA_POWER_SAVE
3117 static struct hda_amp_list alc880_loopbacks[] = {
3118         { 0x0b, HDA_INPUT, 0 },
3119         { 0x0b, HDA_INPUT, 1 },
3120         { 0x0b, HDA_INPUT, 2 },
3121         { 0x0b, HDA_INPUT, 3 },
3122         { 0x0b, HDA_INPUT, 4 },
3123         { } /* end */
3124 };
3125
3126 static struct hda_amp_list alc880_lg_loopbacks[] = {
3127         { 0x0b, HDA_INPUT, 1 },
3128         { 0x0b, HDA_INPUT, 6 },
3129         { 0x0b, HDA_INPUT, 7 },
3130         { } /* end */
3131 };
3132 #endif
3133
3134 /*
3135  * Common callbacks
3136  */
3137
3138 static int alc_init(struct hda_codec *codec)
3139 {
3140         struct alc_spec *spec = codec->spec;
3141         unsigned int i;
3142
3143         alc_fix_pll(codec);
3144         alc_auto_init_amp(codec, spec->init_amp);
3145
3146         for (i = 0; i < spec->num_init_verbs; i++)
3147                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
3148
3149         if (spec->init_hook)
3150                 spec->init_hook(codec);
3151
3152         return 0;
3153 }
3154
3155 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
3156 {
3157         struct alc_spec *spec = codec->spec;
3158
3159         if (spec->unsol_event)
3160                 spec->unsol_event(codec, res);
3161 }
3162
3163 #ifdef CONFIG_SND_HDA_POWER_SAVE
3164 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
3165 {
3166         struct alc_spec *spec = codec->spec;
3167         return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
3168 }
3169 #endif
3170
3171 /*
3172  * Analog playback callbacks
3173  */
3174 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
3175                                     struct hda_codec *codec,
3176                                     struct snd_pcm_substream *substream)
3177 {
3178         struct alc_spec *spec = codec->spec;
3179         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
3180                                              hinfo);
3181 }
3182
3183 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3184                                        struct hda_codec *codec,
3185                                        unsigned int stream_tag,
3186                                        unsigned int format,
3187                                        struct snd_pcm_substream *substream)
3188 {
3189         struct alc_spec *spec = codec->spec;
3190         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
3191                                                 stream_tag, format, substream);
3192 }
3193
3194 static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
3195                                        struct hda_codec *codec,
3196                                        struct snd_pcm_substream *substream)
3197 {
3198         struct alc_spec *spec = codec->spec;
3199         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
3200 }
3201
3202 /*
3203  * Digital out
3204  */
3205 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
3206                                         struct hda_codec *codec,
3207                                         struct snd_pcm_substream *substream)
3208 {
3209         struct alc_spec *spec = codec->spec;
3210         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
3211 }
3212
3213 static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
3214                                            struct hda_codec *codec,
3215                                            unsigned int stream_tag,
3216                                            unsigned int format,
3217                                            struct snd_pcm_substream *substream)
3218 {
3219         struct alc_spec *spec = codec->spec;
3220         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
3221                                              stream_tag, format, substream);
3222 }
3223
3224 static int alc880_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
3225                                            struct hda_codec *codec,
3226                                            struct snd_pcm_substream *substream)
3227 {
3228         struct alc_spec *spec = codec->spec;
3229         return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
3230 }
3231
3232 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
3233                                          struct hda_codec *codec,
3234                                          struct snd_pcm_substream *substream)
3235 {
3236         struct alc_spec *spec = codec->spec;
3237         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
3238 }
3239
3240 /*
3241  * Analog capture
3242  */
3243 static int alc880_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3244                                       struct hda_codec *codec,
3245                                       unsigned int stream_tag,
3246                                       unsigned int format,
3247                                       struct snd_pcm_substream *substream)
3248 {
3249         struct alc_spec *spec = codec->spec;
3250
3251         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
3252                                    stream_tag, 0, format);
3253         return 0;
3254 }
3255
3256 static int alc880_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3257                                       struct hda_codec *codec,
3258                                       struct snd_pcm_substream *substream)
3259 {
3260         struct alc_spec *spec = codec->spec;
3261
3262         snd_hda_codec_cleanup_stream(codec,
3263                                      spec->adc_nids[substream->number + 1]);
3264         return 0;
3265 }
3266
3267
3268 /*
3269  */
3270 static struct hda_pcm_stream alc880_pcm_analog_playback = {
3271         .substreams = 1,
3272         .channels_min = 2,
3273         .channels_max = 8,
3274         /* NID is set in alc_build_pcms */
3275         .ops = {
3276                 .open = alc880_playback_pcm_open,
3277                 .prepare = alc880_playback_pcm_prepare,
3278                 .cleanup = alc880_playback_pcm_cleanup
3279         },
3280 };
3281
3282 static struct hda_pcm_stream alc880_pcm_analog_capture = {
3283         .substreams = 1,
3284         .channels_min = 2,
3285         .channels_max = 2,
3286         /* NID is set in alc_build_pcms */
3287 };
3288
3289 static struct hda_pcm_stream alc880_pcm_analog_alt_playback = {
3290         .substreams = 1,
3291         .channels_min = 2,
3292         .channels_max = 2,
3293         /* NID is set in alc_build_pcms */
3294 };
3295
3296 static struct hda_pcm_stream alc880_pcm_analog_alt_capture = {
3297         .substreams = 2, /* can be overridden */
3298         .channels_min = 2,
3299         .channels_max = 2,
3300         /* NID is set in alc_build_pcms */
3301         .ops = {
3302                 .prepare = alc880_alt_capture_pcm_prepare,
3303                 .cleanup = alc880_alt_capture_pcm_cleanup
3304         },
3305 };
3306
3307 static struct hda_pcm_stream alc880_pcm_digital_playback = {
3308         .substreams = 1,
3309         .channels_min = 2,
3310         .channels_max = 2,
3311         /* NID is set in alc_build_pcms */
3312         .ops = {
3313                 .open = alc880_dig_playback_pcm_open,
3314                 .close = alc880_dig_playback_pcm_close,
3315                 .prepare = alc880_dig_playback_pcm_prepare,
3316                 .cleanup = alc880_dig_playback_pcm_cleanup
3317         },
3318 };
3319
3320 static struct hda_pcm_stream alc880_pcm_digital_capture = {
3321         .substreams = 1,
3322         .channels_min = 2,
3323         .channels_max = 2,
3324         /* NID is set in alc_build_pcms */
3325 };
3326
3327 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
3328 static struct hda_pcm_stream alc_pcm_null_stream = {
3329         .substreams = 0,
3330         .channels_min = 0,
3331         .channels_max = 0,
3332 };
3333
3334 static int alc_build_pcms(struct hda_codec *codec)
3335 {
3336         struct alc_spec *spec = codec->spec;
3337         struct hda_pcm *info = spec->pcm_rec;
3338         int i;
3339
3340         codec->num_pcms = 1;
3341         codec->pcm_info = info;
3342
3343         if (spec->no_analog)
3344                 goto skip_analog;
3345
3346         snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
3347                  "%s Analog", codec->chip_name);
3348         info->name = spec->stream_name_analog;
3349         
3350         if (spec->stream_analog_playback) {
3351                 if (snd_BUG_ON(!spec->multiout.dac_nids))
3352                         return -EINVAL;
3353                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
3354                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
3355         }
3356         if (spec->stream_analog_capture) {
3357                 if (snd_BUG_ON(!spec->adc_nids))
3358                         return -EINVAL;
3359                 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
3360                 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
3361         }
3362
3363         if (spec->channel_mode) {
3364                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
3365                 for (i = 0; i < spec->num_channel_mode; i++) {
3366                         if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
3367                                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
3368                         }
3369                 }
3370         }
3371
3372  skip_analog:
3373         /* SPDIF for stream index #1 */
3374         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
3375                 snprintf(spec->stream_name_digital,
3376                          sizeof(spec->stream_name_digital),
3377                          "%s Digital", codec->chip_name);
3378                 codec->num_pcms = 2;
3379                 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
3380                 info = spec->pcm_rec + 1;
3381                 info->name = spec->stream_name_digital;
3382                 if (spec->dig_out_type)
3383                         info->pcm_type = spec->dig_out_type;
3384                 else
3385                         info->pcm_type = HDA_PCM_TYPE_SPDIF;
3386                 if (spec->multiout.dig_out_nid &&
3387                     spec->stream_digital_playback) {
3388                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
3389                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
3390                 }
3391                 if (spec->dig_in_nid &&
3392                     spec->stream_digital_capture) {
3393                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
3394                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
3395                 }
3396                 /* FIXME: do we need this for all Realtek codec models? */
3397                 codec->spdif_status_reset = 1;
3398         }
3399
3400         if (spec->no_analog)
3401                 return 0;
3402
3403         /* If the use of more than one ADC is requested for the current
3404          * model, configure a second analog capture-only PCM.
3405          */
3406         /* Additional Analaog capture for index #2 */
3407         if ((spec->alt_dac_nid && spec->stream_analog_alt_playback) ||
3408             (spec->num_adc_nids > 1 && spec->stream_analog_alt_capture)) {
3409                 codec->num_pcms = 3;
3410                 info = spec->pcm_rec + 2;
3411                 info->name = spec->stream_name_analog;
3412                 if (spec->alt_dac_nid) {
3413                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
3414                                 *spec->stream_analog_alt_playback;
3415                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
3416                                 spec->alt_dac_nid;
3417                 } else {
3418                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
3419                                 alc_pcm_null_stream;
3420                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
3421                 }
3422                 if (spec->num_adc_nids > 1) {
3423                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
3424                                 *spec->stream_analog_alt_capture;
3425                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
3426                                 spec->adc_nids[1];
3427                         info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
3428                                 spec->num_adc_nids - 1;
3429                 } else {
3430                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
3431                                 alc_pcm_null_stream;
3432                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
3433                 }
3434         }
3435
3436         return 0;
3437 }
3438
3439 static void alc_free_kctls(struct hda_codec *codec)
3440 {
3441         struct alc_spec *spec = codec->spec;
3442
3443         if (spec->kctls.list) {
3444                 struct snd_kcontrol_new *kctl = spec->kctls.list;
3445                 int i;
3446                 for (i = 0; i < spec->kctls.used; i++)
3447                         kfree(kctl[i].name);
3448         }
3449         snd_array_free(&spec->kctls);
3450 }
3451
3452 static void alc_free(struct hda_codec *codec)
3453 {
3454         struct alc_spec *spec = codec->spec;
3455
3456         if (!spec)
3457                 return;
3458
3459         alc_free_kctls(codec);
3460         kfree(spec);
3461         snd_hda_detach_beep_device(codec);
3462 }
3463
3464 #ifdef SND_HDA_NEEDS_RESUME
3465 static int alc_resume(struct hda_codec *codec)
3466 {
3467         codec->patch_ops.init(codec);
3468         snd_hda_codec_resume_amp(codec);
3469         snd_hda_codec_resume_cache(codec);
3470         return 0;
3471 }
3472 #endif
3473
3474 /*
3475  */
3476 static struct hda_codec_ops alc_patch_ops = {
3477         .build_controls = alc_build_controls,
3478         .build_pcms = alc_build_pcms,
3479         .init = alc_init,
3480         .free = alc_free,
3481         .unsol_event = alc_unsol_event,
3482 #ifdef SND_HDA_NEEDS_RESUME
3483         .resume = alc_resume,
3484 #endif
3485 #ifdef CONFIG_SND_HDA_POWER_SAVE
3486         .check_power_status = alc_check_power_status,
3487 #endif
3488 };
3489
3490
3491 /*
3492  * Test configuration for debugging
3493  *
3494  * Almost all inputs/outputs are enabled.  I/O pins can be configured via
3495  * enum controls.
3496  */
3497 #ifdef CONFIG_SND_DEBUG
3498 static hda_nid_t alc880_test_dac_nids[4] = {
3499         0x02, 0x03, 0x04, 0x05
3500 };
3501
3502 static struct hda_input_mux alc880_test_capture_source = {
3503         .num_items = 7,
3504         .items = {
3505                 { "In-1", 0x0 },
3506                 { "In-2", 0x1 },
3507                 { "In-3", 0x2 },
3508                 { "In-4", 0x3 },
3509                 { "CD", 0x4 },
3510                 { "Front", 0x5 },
3511                 { "Surround", 0x6 },
3512         },
3513 };
3514
3515 static struct hda_channel_mode alc880_test_modes[4] = {
3516         { 2, NULL },
3517         { 4, NULL },
3518         { 6, NULL },
3519         { 8, NULL },
3520 };
3521
3522 static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
3523                                  struct snd_ctl_elem_info *uinfo)
3524 {
3525         static char *texts[] = {
3526                 "N/A", "Line Out", "HP Out",
3527                 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
3528         };
3529         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3530         uinfo->count = 1;
3531         uinfo->value.enumerated.items = 8;
3532         if (uinfo->value.enumerated.item >= 8)
3533                 uinfo->value.enumerated.item = 7;
3534         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3535         return 0;
3536 }
3537
3538 static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
3539                                 struct snd_ctl_elem_value *ucontrol)
3540 {
3541         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3542         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3543         unsigned int pin_ctl, item = 0;
3544
3545         pin_ctl = snd_hda_codec_read(codec, nid, 0,
3546                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3547         if (pin_ctl & AC_PINCTL_OUT_EN) {
3548                 if (pin_ctl & AC_PINCTL_HP_EN)
3549                         item = 2;
3550                 else
3551                         item = 1;
3552         } else if (pin_ctl & AC_PINCTL_IN_EN) {
3553                 switch (pin_ctl & AC_PINCTL_VREFEN) {
3554                 case AC_PINCTL_VREF_HIZ: item = 3; break;
3555                 case AC_PINCTL_VREF_50:  item = 4; break;
3556                 case AC_PINCTL_VREF_GRD: item = 5; break;
3557                 case AC_PINCTL_VREF_80:  item = 6; break;
3558                 case AC_PINCTL_VREF_100: item = 7; break;
3559                 }
3560         }
3561         ucontrol->value.enumerated.item[0] = item;
3562         return 0;
3563 }
3564
3565 static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
3566                                 struct snd_ctl_elem_value *ucontrol)
3567 {
3568         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3569         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3570         static unsigned int ctls[] = {
3571                 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
3572                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
3573                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
3574                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
3575                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
3576                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
3577         };
3578         unsigned int old_ctl, new_ctl;
3579
3580         old_ctl = snd_hda_codec_read(codec, nid, 0,
3581                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3582         new_ctl = ctls[ucontrol->value.enumerated.item[0]];
3583         if (old_ctl != new_ctl) {
3584                 int val;
3585                 snd_hda_codec_write_cache(codec, nid, 0,
3586                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
3587                                           new_ctl);
3588                 val = ucontrol->value.enumerated.item[0] >= 3 ?
3589                         HDA_AMP_MUTE : 0;
3590                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3591                                          HDA_AMP_MUTE, val);
3592                 return 1;
3593         }
3594         return 0;
3595 }
3596
3597 static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
3598                                  struct snd_ctl_elem_info *uinfo)
3599 {
3600         static char *texts[] = {
3601                 "Front", "Surround", "CLFE", "Side"
3602         };
3603         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3604         uinfo->count = 1;
3605         uinfo->value.enumerated.items = 4;
3606         if (uinfo->value.enumerated.item >= 4)
3607                 uinfo->value.enumerated.item = 3;
3608         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3609         return 0;
3610 }
3611
3612 static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
3613                                 struct snd_ctl_elem_value *ucontrol)
3614 {
3615         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3616         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3617         unsigned int sel;
3618
3619         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
3620         ucontrol->value.enumerated.item[0] = sel & 3;
3621         return 0;
3622 }
3623
3624 static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
3625                                 struct snd_ctl_elem_value *ucontrol)
3626 {
3627         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3628         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3629         unsigned int sel;
3630
3631         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
3632         if (ucontrol->value.enumerated.item[0] != sel) {
3633                 sel = ucontrol->value.enumerated.item[0] & 3;
3634                 snd_hda_codec_write_cache(codec, nid, 0,
3635                                           AC_VERB_SET_CONNECT_SEL, sel);
3636                 return 1;
3637         }
3638         return 0;
3639 }
3640
3641 #define PIN_CTL_TEST(xname,nid) {                       \
3642                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3643                         .name = xname,                 \
3644                         .info = alc_test_pin_ctl_info, \
3645                         .get = alc_test_pin_ctl_get,   \
3646                         .put = alc_test_pin_ctl_put,   \
3647                         .private_value = nid           \
3648                         }
3649
3650 #define PIN_SRC_TEST(xname,nid) {                       \
3651                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3652                         .name = xname,                 \
3653                         .info = alc_test_pin_src_info, \
3654                         .get = alc_test_pin_src_get,   \
3655                         .put = alc_test_pin_src_put,   \
3656                         .private_value = nid           \
3657                         }
3658
3659 static struct snd_kcontrol_new alc880_test_mixer[] = {
3660         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3661         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
3662         HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
3663         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3664         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
3665         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
3666         HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
3667         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
3668         PIN_CTL_TEST("Front Pin Mode", 0x14),
3669         PIN_CTL_TEST("Surround Pin Mode", 0x15),
3670         PIN_CTL_TEST("CLFE Pin Mode", 0x16),
3671         PIN_CTL_TEST("Side Pin Mode", 0x17),
3672         PIN_CTL_TEST("In-1 Pin Mode", 0x18),
3673         PIN_CTL_TEST("In-2 Pin Mode", 0x19),
3674         PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
3675         PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
3676         PIN_SRC_TEST("In-1 Pin Source", 0x18),
3677         PIN_SRC_TEST("In-2 Pin Source", 0x19),
3678         PIN_SRC_TEST("In-3 Pin Source", 0x1a),
3679         PIN_SRC_TEST("In-4 Pin Source", 0x1b),
3680         HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
3681         HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
3682         HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
3683         HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
3684         HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
3685         HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
3686         HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
3687         HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
3688         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
3689         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
3690         {
3691                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3692                 .name = "Channel Mode",
3693                 .info = alc_ch_mode_info,
3694                 .get = alc_ch_mode_get,
3695                 .put = alc_ch_mode_put,
3696         },
3697         { } /* end */
3698 };
3699
3700 static struct hda_verb alc880_test_init_verbs[] = {
3701         /* Unmute inputs of 0x0c - 0x0f */
3702         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3703         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3704         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3705         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3706         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3707         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3708         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3709         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3710         /* Vol output for 0x0c-0x0f */
3711         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3712         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3713         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3714         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3715         /* Set output pins 0x14-0x17 */
3716         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3717         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3718         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3719         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3720         /* Unmute output pins 0x14-0x17 */
3721         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3722         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3723         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3724         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3725         /* Set input pins 0x18-0x1c */
3726         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3727         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3728         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3729         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3730         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3731         /* Mute input pins 0x18-0x1b */
3732         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3733         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3734         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3735         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3736         /* ADC set up */
3737         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3738         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
3739         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3740         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
3741         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3742         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
3743         /* Analog input/passthru */
3744         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3745         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3746         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3747         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3748         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3749         { }
3750 };
3751 #endif
3752
3753 /*
3754  */
3755
3756 static const char *alc880_models[ALC880_MODEL_LAST] = {
3757         [ALC880_3ST]            = "3stack",
3758         [ALC880_TCL_S700]       = "tcl",
3759         [ALC880_3ST_DIG]        = "3stack-digout",
3760         [ALC880_CLEVO]          = "clevo",
3761         [ALC880_5ST]            = "5stack",
3762         [ALC880_5ST_DIG]        = "5stack-digout",
3763         [ALC880_W810]           = "w810",
3764         [ALC880_Z71V]           = "z71v",
3765         [ALC880_6ST]            = "6stack",
3766         [ALC880_6ST_DIG]        = "6stack-digout",
3767         [ALC880_ASUS]           = "asus",
3768         [ALC880_ASUS_W1V]       = "asus-w1v",
3769         [ALC880_ASUS_DIG]       = "asus-dig",
3770         [ALC880_ASUS_DIG2]      = "asus-dig2",
3771         [ALC880_UNIWILL_DIG]    = "uniwill",
3772         [ALC880_UNIWILL_P53]    = "uniwill-p53",
3773         [ALC880_FUJITSU]        = "fujitsu",
3774         [ALC880_F1734]          = "F1734",
3775         [ALC880_LG]             = "lg",
3776         [ALC880_LG_LW]          = "lg-lw",
3777         [ALC880_MEDION_RIM]     = "medion",
3778 #ifdef CONFIG_SND_DEBUG
3779         [ALC880_TEST]           = "test",
3780 #endif
3781         [ALC880_AUTO]           = "auto",
3782 };
3783
3784 static struct snd_pci_quirk alc880_cfg_tbl[] = {
3785         SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
3786         SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
3787         SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
3788         SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
3789         SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
3790         SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
3791         SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
3792         SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
3793         SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
3794         SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
3795         SND_PCI_QUIRK(0x103c, 0x2a09, "HP", ALC880_5ST),
3796         SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
3797         SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
3798         SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
3799         SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
3800         SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
3801         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
3802         SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
3803         /* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
3804         SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
3805         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
3806         SND_PCI_QUIRK(0x1043, 0x814e, "ASUS P5GD1 w/SPDIF", ALC880_6ST_DIG),
3807         SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
3808         SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
3809         SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
3810         SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_ASUS), /* default ASUS */
3811         SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
3812         SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
3813         SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
3814         SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
3815         SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
3816         SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
3817         SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
3818         SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
3819         SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
3820         SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
3821         SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
3822         SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
3823         SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
3824         SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
3825         SND_PCI_QUIRK(0x1584, 0x9054, "Uniwlll", ALC880_F1734),
3826         SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
3827         SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
3828         SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
3829         SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_MEDION_RIM),
3830         SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
3831         SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
3832         SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
3833         SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FUJITSU),
3834         SND_PCI_QUIRK(0x1734, 0x10ac, "FSC", ALC880_UNIWILL),
3835         SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
3836         SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
3837         SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
3838         SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
3839         SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
3840         SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
3841         SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG), /* broken BIOS */
3842         SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
3843         SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
3844         SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
3845         SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
3846         SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
3847         SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
3848         SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
3849         SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
3850         SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
3851         SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
3852         SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
3853         /* default Intel */
3854         SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_3ST),
3855         SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
3856         SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
3857         {}
3858 };
3859
3860 /*
3861  * ALC880 codec presets
3862  */
3863 static struct alc_config_preset alc880_presets[] = {
3864         [ALC880_3ST] = {
3865                 .mixers = { alc880_three_stack_mixer },
3866                 .init_verbs = { alc880_volume_init_verbs,
3867                                 alc880_pin_3stack_init_verbs },
3868                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3869                 .dac_nids = alc880_dac_nids,
3870                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3871                 .channel_mode = alc880_threestack_modes,
3872                 .need_dac_fix = 1,
3873                 .input_mux = &alc880_capture_source,
3874         },
3875         [ALC880_3ST_DIG] = {
3876                 .mixers = { alc880_three_stack_mixer },
3877                 .init_verbs = { alc880_volume_init_verbs,
3878                                 alc880_pin_3stack_init_verbs },
3879                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3880                 .dac_nids = alc880_dac_nids,
3881                 .dig_out_nid = ALC880_DIGOUT_NID,
3882                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3883                 .channel_mode = alc880_threestack_modes,
3884                 .need_dac_fix = 1,
3885                 .input_mux = &alc880_capture_source,
3886         },
3887         [ALC880_TCL_S700] = {
3888                 .mixers = { alc880_tcl_s700_mixer },
3889                 .init_verbs = { alc880_volume_init_verbs,
3890                                 alc880_pin_tcl_S700_init_verbs,
3891                                 alc880_gpio2_init_verbs },
3892                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3893                 .dac_nids = alc880_dac_nids,
3894                 .adc_nids = alc880_adc_nids_alt, /* FIXME: correct? */
3895                 .num_adc_nids = 1, /* single ADC */
3896                 .hp_nid = 0x03,
3897                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3898                 .channel_mode = alc880_2_jack_modes,
3899                 .input_mux = &alc880_capture_source,
3900         },
3901         [ALC880_5ST] = {
3902                 .mixers = { alc880_three_stack_mixer,
3903                             alc880_five_stack_mixer},
3904                 .init_verbs = { alc880_volume_init_verbs,
3905                                 alc880_pin_5stack_init_verbs },
3906                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3907                 .dac_nids = alc880_dac_nids,
3908                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3909                 .channel_mode = alc880_fivestack_modes,
3910                 .input_mux = &alc880_capture_source,
3911         },
3912         [ALC880_5ST_DIG] = {
3913                 .mixers = { alc880_three_stack_mixer,
3914                             alc880_five_stack_mixer },
3915                 .init_verbs = { alc880_volume_init_verbs,
3916                                 alc880_pin_5stack_init_verbs },
3917                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3918                 .dac_nids = alc880_dac_nids,
3919                 .dig_out_nid = ALC880_DIGOUT_NID,
3920                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3921                 .channel_mode = alc880_fivestack_modes,
3922                 .input_mux = &alc880_capture_source,
3923         },
3924         [ALC880_6ST] = {
3925                 .mixers = { alc880_six_stack_mixer },
3926                 .init_verbs = { alc880_volume_init_verbs,
3927                                 alc880_pin_6stack_init_verbs },
3928                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3929                 .dac_nids = alc880_6st_dac_nids,
3930                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3931                 .channel_mode = alc880_sixstack_modes,
3932                 .input_mux = &alc880_6stack_capture_source,
3933         },
3934         [ALC880_6ST_DIG] = {
3935                 .mixers = { alc880_six_stack_mixer },
3936                 .init_verbs = { alc880_volume_init_verbs,
3937                                 alc880_pin_6stack_init_verbs },
3938                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3939                 .dac_nids = alc880_6st_dac_nids,
3940                 .dig_out_nid = ALC880_DIGOUT_NID,
3941                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3942                 .channel_mode = alc880_sixstack_modes,
3943                 .input_mux = &alc880_6stack_capture_source,
3944         },
3945         [ALC880_W810] = {
3946                 .mixers = { alc880_w810_base_mixer },
3947                 .init_verbs = { alc880_volume_init_verbs,
3948                                 alc880_pin_w810_init_verbs,
3949                                 alc880_gpio2_init_verbs },
3950                 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
3951                 .dac_nids = alc880_w810_dac_nids,
3952                 .dig_out_nid = ALC880_DIGOUT_NID,
3953                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3954                 .channel_mode = alc880_w810_modes,
3955                 .input_mux = &alc880_capture_source,
3956         },
3957         [ALC880_Z71V] = {
3958                 .mixers = { alc880_z71v_mixer },
3959                 .init_verbs = { alc880_volume_init_verbs,
3960                                 alc880_pin_z71v_init_verbs },
3961                 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
3962                 .dac_nids = alc880_z71v_dac_nids,
3963                 .dig_out_nid = ALC880_DIGOUT_NID,
3964                 .hp_nid = 0x03,
3965                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3966                 .channel_mode = alc880_2_jack_modes,
3967                 .input_mux = &alc880_capture_source,
3968         },
3969         [ALC880_F1734] = {
3970                 .mixers = { alc880_f1734_mixer },
3971                 .init_verbs = { alc880_volume_init_verbs,
3972                                 alc880_pin_f1734_init_verbs },
3973                 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
3974                 .dac_nids = alc880_f1734_dac_nids,
3975                 .hp_nid = 0x02,
3976                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3977                 .channel_mode = alc880_2_jack_modes,
3978                 .input_mux = &alc880_f1734_capture_source,
3979                 .unsol_event = alc880_uniwill_p53_unsol_event,
3980                 .init_hook = alc880_uniwill_p53_init_hook,
3981         },
3982         [ALC880_ASUS] = {
3983                 .mixers = { alc880_asus_mixer },
3984                 .init_verbs = { alc880_volume_init_verbs,
3985                                 alc880_pin_asus_init_verbs,
3986                                 alc880_gpio1_init_verbs },
3987                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3988                 .dac_nids = alc880_asus_dac_nids,
3989                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3990                 .channel_mode = alc880_asus_modes,
3991                 .need_dac_fix = 1,
3992                 .input_mux = &alc880_capture_source,
3993         },
3994         [ALC880_ASUS_DIG] = {
3995                 .mixers = { alc880_asus_mixer },
3996                 .init_verbs = { alc880_volume_init_verbs,
3997                                 alc880_pin_asus_init_verbs,
3998                                 alc880_gpio1_init_verbs },
3999                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4000                 .dac_nids = alc880_asus_dac_nids,
4001                 .dig_out_nid = ALC880_DIGOUT_NID,
4002                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4003                 .channel_mode = alc880_asus_modes,
4004                 .need_dac_fix = 1,
4005                 .input_mux = &alc880_capture_source,
4006         },
4007         [ALC880_ASUS_DIG2] = {
4008                 .mixers = { alc880_asus_mixer },
4009                 .init_verbs = { alc880_volume_init_verbs,
4010                                 alc880_pin_asus_init_verbs,
4011                                 alc880_gpio2_init_verbs }, /* use GPIO2 */
4012                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4013                 .dac_nids = alc880_asus_dac_nids,
4014                 .dig_out_nid = ALC880_DIGOUT_NID,
4015                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4016                 .channel_mode = alc880_asus_modes,
4017                 .need_dac_fix = 1,
4018                 .input_mux = &alc880_capture_source,
4019         },
4020         [ALC880_ASUS_W1V] = {
4021                 .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
4022                 .init_verbs = { alc880_volume_init_verbs,
4023                                 alc880_pin_asus_init_verbs,
4024                                 alc880_gpio1_init_verbs },
4025                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4026                 .dac_nids = alc880_asus_dac_nids,
4027                 .dig_out_nid = ALC880_DIGOUT_NID,
4028                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4029                 .channel_mode = alc880_asus_modes,
4030                 .need_dac_fix = 1,
4031                 .input_mux = &alc880_capture_source,
4032         },
4033         [ALC880_UNIWILL_DIG] = {
4034                 .mixers = { alc880_asus_mixer },
4035                 .init_verbs = { alc880_volume_init_verbs,
4036                                 alc880_pin_asus_init_verbs },
4037                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4038                 .dac_nids = alc880_asus_dac_nids,
4039                 .dig_out_nid = ALC880_DIGOUT_NID,
4040                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
4041                 .channel_mode = alc880_asus_modes,
4042                 .need_dac_fix = 1,
4043                 .input_mux = &alc880_capture_source,
4044         },
4045         [ALC880_UNIWILL] = {
4046                 .mixers = { alc880_uniwill_mixer },
4047                 .init_verbs = { alc880_volume_init_verbs,
4048                                 alc880_uniwill_init_verbs },
4049                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4050                 .dac_nids = alc880_asus_dac_nids,
4051                 .dig_out_nid = ALC880_DIGOUT_NID,
4052                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
4053                 .channel_mode = alc880_threestack_modes,
4054                 .need_dac_fix = 1,
4055                 .input_mux = &alc880_capture_source,
4056                 .unsol_event = alc880_uniwill_unsol_event,
4057                 .init_hook = alc880_uniwill_init_hook,
4058         },
4059         [ALC880_UNIWILL_P53] = {
4060                 .mixers = { alc880_uniwill_p53_mixer },
4061                 .init_verbs = { alc880_volume_init_verbs,
4062                                 alc880_uniwill_p53_init_verbs },
4063                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
4064                 .dac_nids = alc880_asus_dac_nids,
4065                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
4066                 .channel_mode = alc880_threestack_modes,
4067                 .input_mux = &alc880_capture_source,
4068                 .unsol_event = alc880_uniwill_p53_unsol_event,
4069                 .init_hook = alc880_uniwill_p53_init_hook,
4070         },
4071         [ALC880_FUJITSU] = {
4072                 .mixers = { alc880_fujitsu_mixer },
4073                 .init_verbs = { alc880_volume_init_verbs,
4074                                 alc880_uniwill_p53_init_verbs,
4075                                 alc880_beep_init_verbs },
4076                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4077                 .dac_nids = alc880_dac_nids,
4078                 .dig_out_nid = ALC880_DIGOUT_NID,
4079                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4080                 .channel_mode = alc880_2_jack_modes,
4081                 .input_mux = &alc880_capture_source,
4082                 .unsol_event = alc880_uniwill_p53_unsol_event,
4083                 .init_hook = alc880_uniwill_p53_init_hook,
4084         },
4085         [ALC880_CLEVO] = {
4086                 .mixers = { alc880_three_stack_mixer },
4087                 .init_verbs = { alc880_volume_init_verbs,
4088                                 alc880_pin_clevo_init_verbs },
4089                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4090                 .dac_nids = alc880_dac_nids,
4091                 .hp_nid = 0x03,
4092                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
4093                 .channel_mode = alc880_threestack_modes,
4094                 .need_dac_fix = 1,
4095                 .input_mux = &alc880_capture_source,
4096         },
4097         [ALC880_LG] = {
4098                 .mixers = { alc880_lg_mixer },
4099                 .init_verbs = { alc880_volume_init_verbs,
4100                                 alc880_lg_init_verbs },
4101                 .num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
4102                 .dac_nids = alc880_lg_dac_nids,
4103                 .dig_out_nid = ALC880_DIGOUT_NID,
4104                 .num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
4105                 .channel_mode = alc880_lg_ch_modes,
4106                 .need_dac_fix = 1,
4107                 .input_mux = &alc880_lg_capture_source,
4108                 .unsol_event = alc_automute_amp_unsol_event,
4109                 .init_hook = alc880_lg_init_hook,
4110 #ifdef CONFIG_SND_HDA_POWER_SAVE
4111                 .loopbacks = alc880_lg_loopbacks,
4112 #endif
4113         },
4114         [ALC880_LG_LW] = {
4115                 .mixers = { alc880_lg_lw_mixer },
4116                 .init_verbs = { alc880_volume_init_verbs,
4117                                 alc880_lg_lw_init_verbs },
4118                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4119                 .dac_nids = alc880_dac_nids,
4120                 .dig_out_nid = ALC880_DIGOUT_NID,
4121                 .num_channel_mode = ARRAY_SIZE(alc880_lg_lw_modes),
4122                 .channel_mode = alc880_lg_lw_modes,
4123                 .input_mux = &alc880_lg_lw_capture_source,
4124                 .unsol_event = alc_automute_amp_unsol_event,
4125                 .init_hook = alc880_lg_lw_init_hook,
4126         },
4127         [ALC880_MEDION_RIM] = {
4128                 .mixers = { alc880_medion_rim_mixer },
4129                 .init_verbs = { alc880_volume_init_verbs,
4130                                 alc880_medion_rim_init_verbs,
4131                                 alc_gpio2_init_verbs },
4132                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
4133                 .dac_nids = alc880_dac_nids,
4134                 .dig_out_nid = ALC880_DIGOUT_NID,
4135                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
4136                 .channel_mode = alc880_2_jack_modes,
4137                 .input_mux = &alc880_medion_rim_capture_source,
4138                 .unsol_event = alc880_medion_rim_unsol_event,
4139                 .init_hook = alc880_medion_rim_init_hook,
4140         },
4141 #ifdef CONFIG_SND_DEBUG
4142         [ALC880_TEST] = {
4143                 .mixers = { alc880_test_mixer },
4144                 .init_verbs = { alc880_test_init_verbs },
4145                 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
4146                 .dac_nids = alc880_test_dac_nids,
4147                 .dig_out_nid = ALC880_DIGOUT_NID,
4148                 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
4149                 .channel_mode = alc880_test_modes,
4150                 .input_mux = &alc880_test_capture_source,
4151         },
4152 #endif
4153 };
4154
4155 /*
4156  * Automatic parse of I/O pins from the BIOS configuration
4157  */
4158
4159 enum {
4160         ALC_CTL_WIDGET_VOL,
4161         ALC_CTL_WIDGET_MUTE,
4162         ALC_CTL_BIND_MUTE,
4163 };
4164 static struct snd_kcontrol_new alc880_control_templates[] = {
4165         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
4166         HDA_CODEC_MUTE(NULL, 0, 0, 0),
4167         HDA_BIND_MUTE(NULL, 0, 0, 0),
4168 };
4169
4170 /* add dynamic controls */
4171 static int add_control(struct alc_spec *spec, int type, const char *name,
4172                        unsigned long val)
4173 {
4174         struct snd_kcontrol_new *knew;
4175
4176         snd_array_init(&spec->kctls, sizeof(*knew), 32);
4177         knew = snd_array_new(&spec->kctls);
4178         if (!knew)
4179                 return -ENOMEM;
4180         *knew = alc880_control_templates[type];
4181         knew->name = kstrdup(name, GFP_KERNEL);
4182         if (!knew->name)
4183                 return -ENOMEM;
4184         knew->private_value = val;
4185         return 0;
4186 }
4187
4188 #define alc880_is_fixed_pin(nid)        ((nid) >= 0x14 && (nid) <= 0x17)
4189 #define alc880_fixed_pin_idx(nid)       ((nid) - 0x14)
4190 #define alc880_is_multi_pin(nid)        ((nid) >= 0x18)
4191 #define alc880_multi_pin_idx(nid)       ((nid) - 0x18)
4192 #define alc880_is_input_pin(nid)        ((nid) >= 0x18)
4193 #define alc880_input_pin_idx(nid)       ((nid) - 0x18)
4194 #define alc880_idx_to_dac(nid)          ((nid) + 0x02)
4195 #define alc880_dac_to_idx(nid)          ((nid) - 0x02)
4196 #define alc880_idx_to_mixer(nid)        ((nid) + 0x0c)
4197 #define alc880_idx_to_selector(nid)     ((nid) + 0x10)
4198 #define ALC880_PIN_CD_NID               0x1c
4199
4200 /* fill in the dac_nids table from the parsed pin configuration */
4201 static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
4202                                      const struct auto_pin_cfg *cfg)
4203 {
4204         hda_nid_t nid;
4205         int assigned[4];
4206         int i, j;
4207
4208         memset(assigned, 0, sizeof(assigned));
4209         spec->multiout.dac_nids = spec->private_dac_nids;
4210
4211         /* check the pins hardwired to audio widget */
4212         for (i = 0; i < cfg->line_outs; i++) {
4213                 nid = cfg->line_out_pins[i];
4214                 if (alc880_is_fixed_pin(nid)) {
4215                         int idx = alc880_fixed_pin_idx(nid);
4216                         spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
4217                         assigned[idx] = 1;
4218                 }
4219         }
4220         /* left pins can be connect to any audio widget */
4221         for (i = 0; i < cfg->line_outs; i++) {
4222                 nid = cfg->line_out_pins[i];
4223                 if (alc880_is_fixed_pin(nid))
4224                         continue;
4225                 /* search for an empty channel */
4226                 for (j = 0; j < cfg->line_outs; j++) {
4227                         if (!assigned[j]) {
4228                                 spec->multiout.dac_nids[i] =
4229                                         alc880_idx_to_dac(j);
4230                                 assigned[j] = 1;
4231                                 break;
4232                         }
4233                 }
4234         }
4235         spec->multiout.num_dacs = cfg->line_outs;
4236         return 0;
4237 }
4238
4239 /* add playback controls from the parsed DAC table */
4240 static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
4241                                              const struct auto_pin_cfg *cfg)
4242 {
4243         char name[32];
4244         static const char *chname[4] = {
4245                 "Front", "Surround", NULL /*CLFE*/, "Side"
4246         };
4247         hda_nid_t nid;
4248         int i, err;
4249
4250         for (i = 0; i < cfg->line_outs; i++) {
4251                 if (!spec->multiout.dac_nids[i])
4252                         continue;
4253                 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
4254                 if (i == 2) {
4255                         /* Center/LFE */
4256                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
4257                                           "Center Playback Volume",
4258                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
4259                                                               HDA_OUTPUT));
4260                         if (err < 0)
4261                                 return err;
4262                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
4263                                           "LFE Playback Volume",
4264                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
4265                                                               HDA_OUTPUT));
4266                         if (err < 0)
4267                                 return err;
4268                         err = add_control(spec, ALC_CTL_BIND_MUTE,
4269                                           "Center Playback Switch",
4270                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
4271                                                               HDA_INPUT));
4272                         if (err < 0)
4273                                 return err;
4274                         err = add_control(spec, ALC_CTL_BIND_MUTE,
4275                                           "LFE Playback Switch",
4276                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
4277                                                               HDA_INPUT));
4278                         if (err < 0)
4279                                 return err;
4280                 } else {
4281                         sprintf(name, "%s Playback Volume", chname[i]);
4282                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4283                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
4284                                                               HDA_OUTPUT));
4285                         if (err < 0)
4286                                 return err;
4287                         sprintf(name, "%s Playback Switch", chname[i]);
4288                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
4289                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
4290                                                               HDA_INPUT));
4291                         if (err < 0)
4292                                 return err;
4293                 }
4294         }
4295         return 0;
4296 }
4297
4298 /* add playback controls for speaker and HP outputs */
4299 static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
4300                                         const char *pfx)
4301 {
4302         hda_nid_t nid;
4303         int err;
4304         char name[32];
4305
4306         if (!pin)
4307                 return 0;
4308
4309         if (alc880_is_fixed_pin(pin)) {
4310                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
4311                 /* specify the DAC as the extra output */
4312                 if (!spec->multiout.hp_nid)
4313                         spec->multiout.hp_nid = nid;
4314                 else
4315                         spec->multiout.extra_out_nid[0] = nid;
4316                 /* control HP volume/switch on the output mixer amp */
4317                 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
4318                 sprintf(name, "%s Playback Volume", pfx);
4319                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4320                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
4321                 if (err < 0)
4322                         return err;
4323                 sprintf(name, "%s Playback Switch", pfx);
4324                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
4325                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
4326                 if (err < 0)
4327                         return err;
4328         } else if (alc880_is_multi_pin(pin)) {
4329                 /* set manual connection */
4330                 /* we have only a switch on HP-out PIN */
4331                 sprintf(name, "%s Playback Switch", pfx);
4332                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
4333                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4334                 if (err < 0)
4335                         return err;
4336         }
4337         return 0;
4338 }
4339
4340 /* create input playback/capture controls for the given pin */
4341 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
4342                             const char *ctlname,
4343                             int idx, hda_nid_t mix_nid)
4344 {
4345         char name[32];
4346         int err;
4347
4348         sprintf(name, "%s Playback Volume", ctlname);
4349         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4350                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
4351         if (err < 0)
4352                 return err;
4353         sprintf(name, "%s Playback Switch", ctlname);
4354         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
4355                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
4356         if (err < 0)
4357                 return err;
4358         return 0;
4359 }
4360
4361 /* create playback/capture controls for input pins */
4362 static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec,
4363                                                 const struct auto_pin_cfg *cfg)
4364 {
4365         struct hda_input_mux *imux = &spec->private_imux[0];
4366         int i, err, idx;
4367
4368         for (i = 0; i < AUTO_PIN_LAST; i++) {
4369                 if (alc880_is_input_pin(cfg->input_pins[i])) {
4370                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
4371                         err = new_analog_input(spec, cfg->input_pins[i],
4372                                                auto_pin_cfg_labels[i],
4373                                                idx, 0x0b);
4374                         if (err < 0)
4375                                 return err;
4376                         imux->items[imux->num_items].label =
4377                                 auto_pin_cfg_labels[i];
4378                         imux->items[imux->num_items].index =
4379                                 alc880_input_pin_idx(cfg->input_pins[i]);
4380                         imux->num_items++;
4381                 }
4382         }
4383         return 0;
4384 }
4385
4386 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
4387                                unsigned int pin_type)
4388 {
4389         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4390                             pin_type);
4391         /* unmute pin */
4392         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4393                             AMP_OUT_UNMUTE);
4394 }
4395
4396 static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
4397                                               hda_nid_t nid, int pin_type,
4398                                               int dac_idx)
4399 {
4400         alc_set_pin_output(codec, nid, pin_type);
4401         /* need the manual connection? */
4402         if (alc880_is_multi_pin(nid)) {
4403                 struct alc_spec *spec = codec->spec;
4404                 int idx = alc880_multi_pin_idx(nid);
4405                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
4406                                     AC_VERB_SET_CONNECT_SEL,
4407                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
4408         }
4409 }
4410
4411 static int get_pin_type(int line_out_type)
4412 {
4413         if (line_out_type == AUTO_PIN_HP_OUT)
4414                 return PIN_HP;
4415         else
4416                 return PIN_OUT;
4417 }
4418
4419 static void alc880_auto_init_multi_out(struct hda_codec *codec)
4420 {
4421         struct alc_spec *spec = codec->spec;
4422         int i;
4423
4424         for (i = 0; i < spec->autocfg.line_outs; i++) {
4425                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
4426                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
4427                 alc880_auto_set_output_and_unmute(codec, nid, pin_type, i);
4428         }
4429 }
4430
4431 static void alc880_auto_init_extra_out(struct hda_codec *codec)
4432 {
4433         struct alc_spec *spec = codec->spec;
4434         hda_nid_t pin;
4435
4436         pin = spec->autocfg.speaker_pins[0];
4437         if (pin) /* connect to front */
4438                 alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
4439         pin = spec->autocfg.hp_pins[0];
4440         if (pin) /* connect to front */
4441                 alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
4442 }
4443
4444 static void alc880_auto_init_analog_input(struct hda_codec *codec)
4445 {
4446         struct alc_spec *spec = codec->spec;
4447         int i;
4448
4449         for (i = 0; i < AUTO_PIN_LAST; i++) {
4450                 hda_nid_t nid = spec->autocfg.input_pins[i];
4451                 if (alc880_is_input_pin(nid)) {
4452                         alc_set_input_pin(codec, nid, i);
4453                         if (nid != ALC880_PIN_CD_NID &&
4454                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
4455                                 snd_hda_codec_write(codec, nid, 0,
4456                                                     AC_VERB_SET_AMP_GAIN_MUTE,
4457                                                     AMP_OUT_MUTE);
4458                 }
4459         }
4460 }
4461
4462 /* parse the BIOS configuration and set up the alc_spec */
4463 /* return 1 if successful, 0 if the proper config is not found,
4464  * or a negative error code
4465  */
4466 static int alc880_parse_auto_config(struct hda_codec *codec)
4467 {
4468         struct alc_spec *spec = codec->spec;
4469         int i, err;
4470         static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4471
4472         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
4473                                            alc880_ignore);
4474         if (err < 0)
4475                 return err;
4476         if (!spec->autocfg.line_outs)
4477                 return 0; /* can't find valid BIOS pin config */
4478
4479         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
4480         if (err < 0)
4481                 return err;
4482         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
4483         if (err < 0)
4484                 return err;
4485         err = alc880_auto_create_extra_out(spec,
4486                                            spec->autocfg.speaker_pins[0],
4487                                            "Speaker");
4488         if (err < 0)
4489                 return err;
4490         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
4491                                            "Headphone");
4492         if (err < 0)
4493                 return err;
4494         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
4495         if (err < 0)
4496                 return err;
4497
4498         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4499
4500         /* check multiple SPDIF-out (for recent codecs) */
4501         for (i = 0; i < spec->autocfg.dig_outs; i++) {
4502                 hda_nid_t dig_nid;
4503                 err = snd_hda_get_connections(codec,
4504                                               spec->autocfg.dig_out_pins[i],
4505                                               &dig_nid, 1);
4506                 if (err < 0)
4507                         continue;
4508                 if (dig_nid > 0x7f) {
4509                         printk(KERN_ERR "alc880_auto: invalid dig_nid "
4510                                 "connection 0x%x for NID 0x%x\n", dig_nid,
4511                                 spec->autocfg.dig_out_pins[i]);
4512                         continue;
4513                 }
4514                 if (!i)
4515                         spec->multiout.dig_out_nid = dig_nid;
4516                 else {
4517                         spec->multiout.slave_dig_outs = spec->slave_dig_outs;
4518                         spec->slave_dig_outs[i - 1] = dig_nid;
4519                         if (i == ARRAY_SIZE(spec->slave_dig_outs) - 1)
4520                                 break;
4521                 }
4522         }
4523         if (spec->autocfg.dig_in_pin)
4524                 spec->dig_in_nid = ALC880_DIGIN_NID;
4525
4526         if (spec->kctls.list)
4527                 add_mixer(spec, spec->kctls.list);
4528
4529         add_verb(spec, alc880_volume_init_verbs);
4530
4531         spec->num_mux_defs = 1;
4532         spec->input_mux = &spec->private_imux[0];
4533
4534         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
4535
4536         return 1;
4537 }
4538
4539 /* additional initialization for auto-configuration model */
4540 static void alc880_auto_init(struct hda_codec *codec)
4541 {
4542         struct alc_spec *spec = codec->spec;
4543         alc880_auto_init_multi_out(codec);
4544         alc880_auto_init_extra_out(codec);
4545         alc880_auto_init_analog_input(codec);
4546         if (spec->unsol_event)
4547                 alc_inithook(codec);
4548 }
4549
4550 static void set_capture_mixer(struct alc_spec *spec)
4551 {
4552         static struct snd_kcontrol_new *caps[2][3] = {
4553                 { alc_capture_mixer_nosrc1,
4554                   alc_capture_mixer_nosrc2,
4555                   alc_capture_mixer_nosrc3 },
4556                 { alc_capture_mixer1,
4557                   alc_capture_mixer2,
4558                   alc_capture_mixer3 },
4559         };
4560         if (spec->num_adc_nids > 0 && spec->num_adc_nids <= 3) {
4561                 int mux;
4562                 if (spec->input_mux && spec->input_mux->num_items > 1)
4563                         mux = 1;
4564                 else
4565                         mux = 0;
4566                 spec->cap_mixer = caps[mux][spec->num_adc_nids - 1];
4567         }
4568 }
4569
4570 #define set_beep_amp(spec, nid, idx, dir) \
4571         ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4572
4573 /*
4574  * OK, here we have finally the patch for ALC880
4575  */
4576
4577 static int patch_alc880(struct hda_codec *codec)
4578 {
4579         struct alc_spec *spec;
4580         int board_config;
4581         int err;
4582
4583         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4584         if (spec == NULL)
4585                 return -ENOMEM;
4586
4587         codec->spec = spec;
4588
4589         board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
4590                                                   alc880_models,
4591                                                   alc880_cfg_tbl);
4592         if (board_config < 0) {
4593                 printk(KERN_INFO "hda_codec: Unknown model for %s, "
4594                        "trying auto-probe from BIOS...\n", codec->chip_name);
4595                 board_config = ALC880_AUTO;
4596         }
4597
4598         if (board_config == ALC880_AUTO) {
4599                 /* automatic parse from the BIOS config */
4600                 err = alc880_parse_auto_config(codec);
4601                 if (err < 0) {
4602                         alc_free(codec);
4603                         return err;
4604                 } else if (!err) {
4605                         printk(KERN_INFO
4606                                "hda_codec: Cannot set up configuration "
4607                                "from BIOS.  Using 3-stack mode...\n");
4608                         board_config = ALC880_3ST;
4609                 }
4610         }
4611
4612         err = snd_hda_attach_beep_device(codec, 0x1);
4613         if (err < 0) {
4614                 alc_free(codec);
4615                 return err;
4616         }
4617
4618         if (board_config != ALC880_AUTO)
4619                 setup_preset(spec, &alc880_presets[board_config]);
4620
4621         spec->stream_analog_playback = &alc880_pcm_analog_playback;
4622         spec->stream_analog_capture = &alc880_pcm_analog_capture;
4623         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
4624
4625         spec->stream_digital_playback = &alc880_pcm_digital_playback;
4626         spec->stream_digital_capture = &alc880_pcm_digital_capture;
4627
4628         if (!spec->adc_nids && spec->input_mux) {
4629                 /* check whether NID 0x07 is valid */
4630                 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
4631                 /* get type */
4632                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
4633                 if (wcap != AC_WID_AUD_IN) {
4634                         spec->adc_nids = alc880_adc_nids_alt;
4635                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
4636                 } else {
4637                         spec->adc_nids = alc880_adc_nids;
4638                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
4639                 }
4640         }
4641         set_capture_mixer(spec);
4642         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4643
4644         spec->vmaster_nid = 0x0c;
4645
4646         codec->patch_ops = alc_patch_ops;
4647         if (board_config == ALC880_AUTO)
4648                 spec->init_hook = alc880_auto_init;
4649 #ifdef CONFIG_SND_HDA_POWER_SAVE
4650         if (!spec->loopback.amplist)
4651                 spec->loopback.amplist = alc880_loopbacks;
4652 #endif
4653         codec->proc_widget_hook = print_realtek_coef;
4654
4655         return 0;
4656 }
4657
4658
4659 /*
4660  * ALC260 support
4661  */
4662
4663 static hda_nid_t alc260_dac_nids[1] = {
4664         /* front */
4665         0x02,
4666 };
4667
4668 static hda_nid_t alc260_adc_nids[1] = {
4669         /* ADC0 */
4670         0x04,
4671 };
4672
4673 static hda_nid_t alc260_adc_nids_alt[1] = {
4674         /* ADC1 */
4675         0x05,
4676 };
4677
4678 /* NIDs used when simultaneous access to both ADCs makes sense.  Note that
4679  * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
4680  */
4681 static hda_nid_t alc260_dual_adc_nids[2] = {
4682         /* ADC0, ADC1 */
4683         0x04, 0x05
4684 };
4685
4686 #define ALC260_DIGOUT_NID       0x03
4687 #define ALC260_DIGIN_NID        0x06
4688
4689 static struct hda_input_mux alc260_capture_source = {
4690         .num_items = 4,
4691         .items = {
4692                 { "Mic", 0x0 },
4693                 { "Front Mic", 0x1 },
4694                 { "Line", 0x2 },
4695                 { "CD", 0x4 },
4696         },
4697 };
4698
4699 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
4700  * headphone jack and the internal CD lines since these are the only pins at
4701  * which audio can appear.  For flexibility, also allow the option of
4702  * recording the mixer output on the second ADC (ADC0 doesn't have a
4703  * connection to the mixer output).
4704  */
4705 static struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
4706         {
4707                 .num_items = 3,
4708                 .items = {
4709                         { "Mic/Line", 0x0 },
4710                         { "CD", 0x4 },
4711                         { "Headphone", 0x2 },
4712                 },
4713         },
4714         {
4715                 .num_items = 4,
4716                 .items = {
4717                         { "Mic/Line", 0x0 },
4718                         { "CD", 0x4 },
4719                         { "Headphone", 0x2 },
4720                         { "Mixer", 0x5 },
4721                 },
4722         },
4723
4724 };
4725
4726 /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
4727  * the Fujitsu S702x, but jacks are marked differently.
4728  */
4729 static struct hda_input_mux alc260_acer_capture_sources[2] = {
4730         {
4731                 .num_items = 4,
4732                 .items = {
4733                         { "Mic", 0x0 },
4734                         { "Line", 0x2 },
4735                         { "CD", 0x4 },
4736                         { "Headphone", 0x5 },
4737                 },
4738         },
4739         {
4740                 .num_items = 5,
4741                 .items = {
4742                         { "Mic", 0x0 },
4743                         { "Line", 0x2 },
4744                         { "CD", 0x4 },
4745                         { "Headphone", 0x6 },
4746                         { "Mixer", 0x5 },
4747                 },
4748         },
4749 };
4750
4751 /* Maxdata Favorit 100XS */
4752 static struct hda_input_mux alc260_favorit100_capture_sources[2] = {
4753         {
4754                 .num_items = 2,
4755                 .items = {
4756                         { "Line/Mic", 0x0 },
4757                         { "CD", 0x4 },
4758                 },
4759         },
4760         {
4761                 .num_items = 3,
4762                 .items = {
4763                         { "Line/Mic", 0x0 },
4764                         { "CD", 0x4 },
4765                         { "Mixer", 0x5 },
4766                 },
4767         },
4768 };
4769
4770 /*
4771  * This is just place-holder, so there's something for alc_build_pcms to look
4772  * at when it calculates the maximum number of channels. ALC260 has no mixer
4773  * element which allows changing the channel mode, so the verb list is
4774  * never used.
4775  */
4776 static struct hda_channel_mode alc260_modes[1] = {
4777         { 2, NULL },
4778 };
4779
4780
4781 /* Mixer combinations
4782  *
4783  * basic: base_output + input + pc_beep + capture
4784  * HP: base_output + input + capture_alt
4785  * HP_3013: hp_3013 + input + capture
4786  * fujitsu: fujitsu + capture
4787  * acer: acer + capture
4788  */
4789
4790 static struct snd_kcontrol_new alc260_base_output_mixer[] = {
4791         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4792         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
4793         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4794         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
4795         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4796         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4797         { } /* end */
4798 };
4799
4800 static struct snd_kcontrol_new alc260_input_mixer[] = {
4801         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4802         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4803         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4804         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4805         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4806         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4807         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
4808         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
4809         { } /* end */
4810 };
4811
4812 /* update HP, line and mono out pins according to the master switch */
4813 static void alc260_hp_master_update(struct hda_codec *codec,
4814                                     hda_nid_t hp, hda_nid_t line,
4815                                     hda_nid_t mono)
4816 {
4817         struct alc_spec *spec = codec->spec;
4818         unsigned int val = spec->master_sw ? PIN_HP : 0;
4819         /* change HP and line-out pins */
4820         snd_hda_codec_write(codec, hp, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4821                             val);
4822         snd_hda_codec_write(codec, line, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4823                             val);
4824         /* mono (speaker) depending on the HP jack sense */
4825         val = (val && !spec->jack_present) ? PIN_OUT : 0;
4826         snd_hda_codec_write(codec, mono, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4827                             val);
4828 }
4829
4830 static int alc260_hp_master_sw_get(struct snd_kcontrol *kcontrol,
4831                                    struct snd_ctl_elem_value *ucontrol)
4832 {
4833         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4834         struct alc_spec *spec = codec->spec;
4835         *ucontrol->value.integer.value = spec->master_sw;
4836         return 0;
4837 }
4838
4839 static int alc260_hp_master_sw_put(struct snd_kcontrol *kcontrol,
4840                                    struct snd_ctl_elem_value *ucontrol)
4841 {
4842         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4843         struct alc_spec *spec = codec->spec;
4844         int val = !!*ucontrol->value.integer.value;
4845         hda_nid_t hp, line, mono;
4846
4847         if (val == spec->master_sw)
4848                 return 0;
4849         spec->master_sw = val;
4850         hp = (kcontrol->private_value >> 16) & 0xff;
4851         line = (kcontrol->private_value >> 8) & 0xff;
4852         mono = kcontrol->private_value & 0xff;
4853         alc260_hp_master_update(codec, hp, line, mono);
4854         return 1;
4855 }
4856
4857 static struct snd_kcontrol_new alc260_hp_output_mixer[] = {
4858         {
4859                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4860                 .name = "Master Playback Switch",
4861                 .info = snd_ctl_boolean_mono_info,
4862                 .get = alc260_hp_master_sw_get,
4863                 .put = alc260_hp_master_sw_put,
4864                 .private_value = (0x0f << 16) | (0x10 << 8) | 0x11
4865         },
4866         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4867         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
4868         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4869         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
4870         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4871                               HDA_OUTPUT),
4872         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4873         { } /* end */
4874 };
4875
4876 static struct hda_verb alc260_hp_unsol_verbs[] = {
4877         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4878         {},
4879 };
4880
4881 static void alc260_hp_automute(struct hda_codec *codec)
4882 {
4883         struct alc_spec *spec = codec->spec;
4884         unsigned int present;
4885
4886         present = snd_hda_codec_read(codec, 0x10, 0,
4887                                      AC_VERB_GET_PIN_SENSE, 0);
4888         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4889         alc260_hp_master_update(codec, 0x0f, 0x10, 0x11);
4890 }
4891
4892 static void alc260_hp_unsol_event(struct hda_codec *codec, unsigned int res)
4893 {
4894         if ((res >> 26) == ALC880_HP_EVENT)
4895                 alc260_hp_automute(codec);
4896 }
4897
4898 static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
4899         {
4900                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4901                 .name = "Master Playback Switch",
4902                 .info = snd_ctl_boolean_mono_info,
4903                 .get = alc260_hp_master_sw_get,
4904                 .put = alc260_hp_master_sw_put,
4905                 .private_value = (0x15 << 16) | (0x10 << 8) | 0x11
4906         },
4907         HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4908         HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
4909         HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
4910         HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
4911         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4912         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
4913         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4914         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
4915         { } /* end */
4916 };
4917
4918 static struct hda_bind_ctls alc260_dc7600_bind_master_vol = {
4919         .ops = &snd_hda_bind_vol,
4920         .values = {
4921                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_OUTPUT),
4922                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
4923                 HDA_COMPOSE_AMP_VAL(0x0a, 3, 0, HDA_OUTPUT),
4924                 0
4925         },
4926 };
4927
4928 static struct hda_bind_ctls alc260_dc7600_bind_switch = {
4929         .ops = &snd_hda_bind_sw,
4930         .values = {
4931                 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
4932                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
4933                 0
4934         },
4935 };
4936
4937 static struct snd_kcontrol_new alc260_hp_dc7600_mixer[] = {
4938         HDA_BIND_VOL("Master Playback Volume", &alc260_dc7600_bind_master_vol),
4939         HDA_BIND_SW("LineOut Playback Switch", &alc260_dc7600_bind_switch),
4940         HDA_CODEC_MUTE("Speaker Playback Switch", 0x0f, 0x0, HDA_OUTPUT),
4941         HDA_CODEC_MUTE("Headphone Playback Switch", 0x10, 0x0, HDA_OUTPUT),
4942         { } /* end */
4943 };
4944
4945 static struct hda_verb alc260_hp_3013_unsol_verbs[] = {
4946         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4947         {},
4948 };
4949
4950 static void alc260_hp_3013_automute(struct hda_codec *codec)
4951 {
4952         struct alc_spec *spec = codec->spec;
4953         unsigned int present;
4954
4955         present = snd_hda_codec_read(codec, 0x15, 0,
4956                                      AC_VERB_GET_PIN_SENSE, 0);
4957         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4958         alc260_hp_master_update(codec, 0x15, 0x10, 0x11);
4959 }
4960
4961 static void alc260_hp_3013_unsol_event(struct hda_codec *codec,
4962                                        unsigned int res)
4963 {
4964         if ((res >> 26) == ALC880_HP_EVENT)
4965                 alc260_hp_3013_automute(codec);
4966 }
4967
4968 static void alc260_hp_3012_automute(struct hda_codec *codec)
4969 {
4970         unsigned int present, bits;
4971
4972         present = snd_hda_codec_read(codec, 0x10, 0,
4973                         AC_VERB_GET_PIN_SENSE, 0) & AC_PINSENSE_PRESENCE;
4974
4975         bits = present ? 0 : PIN_OUT;
4976         snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4977                             bits);
4978         snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4979                             bits);
4980         snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4981                             bits);
4982 }
4983
4984 static void alc260_hp_3012_unsol_event(struct hda_codec *codec,
4985                                        unsigned int res)
4986 {
4987         if ((res >> 26) == ALC880_HP_EVENT)
4988                 alc260_hp_3012_automute(codec);
4989 }
4990
4991 /* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12,
4992  * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
4993  */
4994 static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
4995         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4996         HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
4997         ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4998         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4999         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5000         HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
5001         HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
5002         ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
5003         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5004         HDA_BIND_MUTE("Speaker Playback Switch", 0x09, 2, HDA_INPUT),
5005         { } /* end */
5006 };
5007
5008 /* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks.  Note that current
5009  * versions of the ALC260 don't act on requests to enable mic bias from NID
5010  * 0x0f (used to drive the headphone jack in these laptops).  The ALC260
5011  * datasheet doesn't mention this restriction.  At this stage it's not clear
5012  * whether this behaviour is intentional or is a hardware bug in chip
5013  * revisions available in early 2006.  Therefore for now allow the
5014  * "Headphone Jack Mode" control to span all choices, but if it turns out
5015  * that the lack of mic bias for this NID is intentional we could change the
5016  * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
5017  *
5018  * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
5019  * don't appear to make the mic bias available from the "line" jack, even
5020  * though the NID used for this jack (0x14) can supply it.  The theory is
5021  * that perhaps Acer have included blocking capacitors between the ALC260
5022  * and the output jack.  If this turns out to be the case for all such
5023  * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
5024  * to ALC_PIN_DIR_INOUT_NOMICBIAS.
5025  *
5026  * The C20x Tablet series have a mono internal speaker which is controlled
5027  * via the chip's Mono sum widget and pin complex, so include the necessary
5028  * controls for such models.  On models without a "mono speaker" the control
5029  * won't do anything.
5030  */
5031 static struct snd_kcontrol_new alc260_acer_mixer[] = {
5032         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5033         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
5034         ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
5035         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
5036                               HDA_OUTPUT),
5037         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2,
5038                            HDA_INPUT),
5039         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5040         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5041         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
5042         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
5043         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
5044         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
5045         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
5046         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
5047         { } /* end */
5048 };
5049
5050 /* Maxdata Favorit 100XS: one output and one input (0x12) jack
5051  */
5052 static struct snd_kcontrol_new alc260_favorit100_mixer[] = {
5053         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5054         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
5055         ALC_PIN_MODE("Output Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
5056         HDA_CODEC_VOLUME("Line/Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
5057         HDA_CODEC_MUTE("Line/Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
5058         ALC_PIN_MODE("Line/Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
5059         { } /* end */
5060 };
5061
5062 /* Packard bell V7900  ALC260 pin usage: HP = 0x0f, Mic jack = 0x12,
5063  * Line In jack = 0x14, CD audio =  0x16, pc beep = 0x17.
5064  */
5065 static struct snd_kcontrol_new alc260_will_mixer[] = {
5066         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5067         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
5068         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
5069         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
5070         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
5071         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
5072         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
5073         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
5074         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5075         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5076         { } /* end */
5077 };
5078
5079 /* Replacer 672V ALC260 pin usage: Mic jack = 0x12,
5080  * Line In jack = 0x14, ATAPI Mic = 0x13, speaker = 0x0f.
5081  */
5082 static struct snd_kcontrol_new alc260_replacer_672v_mixer[] = {
5083         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5084         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
5085         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
5086         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
5087         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
5088         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x07, 0x1, HDA_INPUT),
5089         HDA_CODEC_MUTE("ATATI Mic Playback Switch", 0x07, 0x1, HDA_INPUT),
5090         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
5091         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
5092         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
5093         { } /* end */
5094 };
5095
5096 /*
5097  * initialization verbs
5098  */
5099 static struct hda_verb alc260_init_verbs[] = {
5100         /* Line In pin widget for input */
5101         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5102         /* CD pin widget for input */
5103         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5104         /* Mic1 (rear panel) pin widget for input and vref at 80% */
5105         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5106         /* Mic2 (front panel) pin widget for input and vref at 80% */
5107         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5108         /* LINE-2 is used for line-out in rear */
5109         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5110         /* select line-out */
5111         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
5112         /* LINE-OUT pin */
5113         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5114         /* enable HP */
5115         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5116         /* enable Mono */
5117         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5118         /* mute capture amp left and right */
5119         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5120         /* set connection select to line in (default select for this ADC) */
5121         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
5122         /* mute capture amp left and right */
5123         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5124         /* set connection select to line in (default select for this ADC) */
5125         {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
5126         /* set vol=0 Line-Out mixer amp left and right */
5127         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5128         /* unmute pin widget amp left and right (no gain on this amp) */
5129         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5130         /* set vol=0 HP mixer amp left and right */
5131         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5132         /* unmute pin widget amp left and right (no gain on this amp) */
5133         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5134         /* set vol=0 Mono mixer amp left and right */
5135         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5136         /* unmute pin widget amp left and right (no gain on this amp) */
5137         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5138         /* unmute LINE-2 out pin */
5139         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5140         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
5141          * Line In 2 = 0x03
5142          */
5143         /* mute analog inputs */
5144         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5145         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5146         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5147         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5148         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5149         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
5150         /* mute Front out path */
5151         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5152         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5153         /* mute Headphone out path */
5154         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5155         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5156         /* mute Mono out path */
5157         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5158         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5159         { }
5160 };
5161
5162 #if 0 /* should be identical with alc260_init_verbs? */
5163 static struct hda_verb alc260_hp_init_verbs[] = {
5164         /* Headphone and output */
5165         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
5166         /* mono output */
5167         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5168         /* Mic1 (rear panel) pin widget for input and vref at 80% */
5169         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
5170         /* Mic2 (front panel) pin widget for input and vref at 80% */
5171         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
5172         /* Line In pin widget for input */
5173         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
5174         /* Line-2 pin widget for output */
5175         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5176         /* CD pin widget for input */
5177         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
5178         /* unmute amp left and right */
5179         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
5180         /* set connection select to line in (default select for this ADC) */
5181         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
5182         /* unmute Line-Out mixer amp left and right (volume = 0) */
5183         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5184         /* mute pin widget amp left and right (no gain on this amp) */
5185         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5186         /* unmute HP mixer amp left and right (volume = 0) */
5187         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5188         /* mute pin widget amp left and right (no gain on this amp) */
5189         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5190         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
5191          * Line In 2 = 0x03
5192          */
5193         /* mute analog inputs */
5194         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5195         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5196         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5197         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5198         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5199         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
5200         /* Unmute Front out path */
5201         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5202         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5203         /* Unmute Headphone out path */
5204         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5205         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5206         /* Unmute Mono out path */
5207         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5208         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5209         { }
5210 };
5211 #endif
5212
5213 static struct hda_verb alc260_hp_3013_init_verbs[] = {
5214         /* Line out and output */
5215         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5216         /* mono output */
5217         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5218         /* Mic1 (rear panel) pin widget for input and vref at 80% */
5219         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
5220         /* Mic2 (front panel) pin widget for input and vref at 80% */
5221         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
5222         /* Line In pin widget for input */
5223         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
5224         /* Headphone pin widget for output */
5225         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
5226         /* CD pin widget for input */
5227         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
5228         /* unmute amp left and right */
5229         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
5230         /* set connection select to line in (default select for this ADC) */
5231         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
5232         /* unmute Line-Out mixer amp left and right (volume = 0) */
5233         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5234         /* mute pin widget amp left and right (no gain on this amp) */
5235         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5236         /* unmute HP mixer amp left and right (volume = 0) */
5237         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5238         /* mute pin widget amp left and right (no gain on this amp) */
5239         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5240         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
5241          * Line In 2 = 0x03
5242          */
5243         /* mute analog inputs */
5244         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5245         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5246         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5247         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5248         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5249         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
5250         /* Unmute Front out path */
5251         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5252         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5253         /* Unmute Headphone out path */
5254         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5255         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5256         /* Unmute Mono out path */
5257         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5258         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5259         { }
5260 };
5261
5262 /* Initialisation sequence for ALC260 as configured in Fujitsu S702x
5263  * laptops.  ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
5264  * audio = 0x16, internal speaker = 0x10.
5265  */
5266 static struct hda_verb alc260_fujitsu_init_verbs[] = {
5267         /* Disable all GPIOs */
5268         {0x01, AC_VERB_SET_GPIO_MASK, 0},
5269         /* Internal speaker is connected to headphone pin */
5270         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5271         /* Headphone/Line-out jack connects to Line1 pin; make it an output */
5272         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5273         /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
5274         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5275         /* Ensure all other unused pins are disabled and muted. */
5276         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5277         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5278         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5279         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5280         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5281         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5282         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5283         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5284
5285         /* Disable digital (SPDIF) pins */
5286         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5287         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5288
5289         /* Ensure Line1 pin widget takes its input from the OUT1 sum bus
5290          * when acting as an output.
5291          */
5292         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5293
5294         /* Start with output sum widgets muted and their output gains at min */
5295         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5296         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5297         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5298         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5299         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5300         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5301         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5302         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5303         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5304
5305         /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
5306         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5307         /* Unmute Line1 pin widget output buffer since it starts as an output.
5308          * If the pin mode is changed by the user the pin mode control will
5309          * take care of enabling the pin's input/output buffers as needed.
5310          * Therefore there's no need to enable the input buffer at this
5311          * stage.
5312          */
5313         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5314         /* Unmute input buffer of pin widget used for Line-in (no equiv
5315          * mixer ctrl)
5316          */
5317         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5318
5319         /* Mute capture amp left and right */
5320         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5321         /* Set ADC connection select to match default mixer setting - line
5322          * in (on mic1 pin)
5323          */
5324         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5325
5326         /* Do the same for the second ADC: mute capture input amp and
5327          * set ADC connection to line in (on mic1 pin)
5328          */
5329         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5330         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5331
5332         /* Mute all inputs to mixer widget (even unconnected ones) */
5333         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5334         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5335         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5336         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5337         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5338         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5339         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5340         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5341
5342         { }
5343 };
5344
5345 /* Initialisation sequence for ALC260 as configured in Acer TravelMate and
5346  * similar laptops (adapted from Fujitsu init verbs).
5347  */
5348 static struct hda_verb alc260_acer_init_verbs[] = {
5349         /* On TravelMate laptops, GPIO 0 enables the internal speaker and
5350          * the headphone jack.  Turn this on and rely on the standard mute
5351          * methods whenever the user wants to turn these outputs off.
5352          */
5353         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5354         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5355         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5356         /* Internal speaker/Headphone jack is connected to Line-out pin */
5357         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5358         /* Internal microphone/Mic jack is connected to Mic1 pin */
5359         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
5360         /* Line In jack is connected to Line1 pin */
5361         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5362         /* Some Acers (eg: C20x Tablets) use Mono pin for internal speaker */
5363         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5364         /* Ensure all other unused pins are disabled and muted. */
5365         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5366         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5367         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5368         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5369         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5370         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5371         /* Disable digital (SPDIF) pins */
5372         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5373         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5374
5375         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
5376          * bus when acting as outputs.
5377          */
5378         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5379         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5380
5381         /* Start with output sum widgets muted and their output gains at min */
5382         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5383         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5384         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5385         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5386         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5387         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5388         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5389         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5390         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5391
5392         /* Unmute Line-out pin widget amp left and right
5393          * (no equiv mixer ctrl)
5394          */
5395         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5396         /* Unmute mono pin widget amp output (no equiv mixer ctrl) */
5397         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5398         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
5399          * inputs. If the pin mode is changed by the user the pin mode control
5400          * will take care of enabling the pin's input/output buffers as needed.
5401          * Therefore there's no need to enable the input buffer at this
5402          * stage.
5403          */
5404         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5405         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5406
5407         /* Mute capture amp left and right */
5408         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5409         /* Set ADC connection select to match default mixer setting - mic
5410          * (on mic1 pin)
5411          */
5412         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5413
5414         /* Do similar with the second ADC: mute capture input amp and
5415          * set ADC connection to mic to match ALSA's default state.
5416          */
5417         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5418         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5419
5420         /* Mute all inputs to mixer widget (even unconnected ones) */
5421         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5422         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5423         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5424         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5425         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5426         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5427         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5428         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5429
5430         { }
5431 };
5432
5433 /* Initialisation sequence for Maxdata Favorit 100XS
5434  * (adapted from Acer init verbs).
5435  */
5436 static struct hda_verb alc260_favorit100_init_verbs[] = {
5437         /* GPIO 0 enables the output jack.
5438          * Turn this on and rely on the standard mute
5439          * methods whenever the user wants to turn these outputs off.
5440          */
5441         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5442         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5443         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5444         /* Line/Mic input jack is connected to Mic1 pin */
5445         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
5446         /* Ensure all other unused pins are disabled and muted. */
5447         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5448         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5449         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5450         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5451         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5452         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5453         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5454         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5455         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5456         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5457         /* Disable digital (SPDIF) pins */
5458         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5459         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5460
5461         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
5462          * bus when acting as outputs.
5463          */
5464         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5465         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5466
5467         /* Start with output sum widgets muted and their output gains at min */
5468         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5469         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5470         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5471         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5472         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5473         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5474         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5475         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5476         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5477
5478         /* Unmute Line-out pin widget amp left and right
5479          * (no equiv mixer ctrl)
5480          */
5481         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5482         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
5483          * inputs. If the pin mode is changed by the user the pin mode control
5484          * will take care of enabling the pin's input/output buffers as needed.
5485          * Therefore there's no need to enable the input buffer at this
5486          * stage.
5487          */
5488         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5489
5490         /* Mute capture amp left and right */
5491         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5492         /* Set ADC connection select to match default mixer setting - mic
5493          * (on mic1 pin)
5494          */
5495         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5496
5497         /* Do similar with the second ADC: mute capture input amp and
5498          * set ADC connection to mic to match ALSA's default state.
5499          */
5500         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5501         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5502
5503         /* Mute all inputs to mixer widget (even unconnected ones) */
5504         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5505         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5506         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5507         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5508         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5509         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5510         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5511         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5512
5513         { }
5514 };
5515
5516 static struct hda_verb alc260_will_verbs[] = {
5517         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5518         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x00},
5519         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
5520         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
5521         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
5522         {0x1a, AC_VERB_SET_PROC_COEF, 0x3040},
5523         {}
5524 };
5525
5526 static struct hda_verb alc260_replacer_672v_verbs[] = {
5527         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
5528         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
5529         {0x1a, AC_VERB_SET_PROC_COEF, 0x3050},
5530
5531         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5532         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5533         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5534
5535         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5536         {}
5537 };
5538
5539 /* toggle speaker-output according to the hp-jack state */
5540 static void alc260_replacer_672v_automute(struct hda_codec *codec)
5541 {
5542         unsigned int present;
5543
5544         /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
5545         present = snd_hda_codec_read(codec, 0x0f, 0,
5546                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5547         if (present) {
5548                 snd_hda_codec_write_cache(codec, 0x01, 0,
5549                                           AC_VERB_SET_GPIO_DATA, 1);
5550                 snd_hda_codec_write_cache(codec, 0x0f, 0,
5551                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
5552                                           PIN_HP);
5553         } else {
5554                 snd_hda_codec_write_cache(codec, 0x01, 0,
5555                                           AC_VERB_SET_GPIO_DATA, 0);
5556                 snd_hda_codec_write_cache(codec, 0x0f, 0,
5557                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
5558                                           PIN_OUT);
5559         }
5560 }
5561
5562 static void alc260_replacer_672v_unsol_event(struct hda_codec *codec,
5563                                        unsigned int res)
5564 {
5565         if ((res >> 26) == ALC880_HP_EVENT)
5566                 alc260_replacer_672v_automute(codec);
5567 }
5568
5569 static struct hda_verb alc260_hp_dc7600_verbs[] = {
5570         {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
5571         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
5572         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5573         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5574         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5575         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5576         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5577         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5578         {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5579         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5580         {}
5581 };
5582
5583 /* Test configuration for debugging, modelled after the ALC880 test
5584  * configuration.
5585  */
5586 #ifdef CONFIG_SND_DEBUG
5587 static hda_nid_t alc260_test_dac_nids[1] = {
5588         0x02,
5589 };
5590 static hda_nid_t alc260_test_adc_nids[2] = {
5591         0x04, 0x05,
5592 };
5593 /* For testing the ALC260, each input MUX needs its own definition since
5594  * the signal assignments are different.  This assumes that the first ADC
5595  * is NID 0x04.
5596  */
5597 static struct hda_input_mux alc260_test_capture_sources[2] = {
5598         {
5599                 .num_items = 7,
5600                 .items = {
5601                         { "MIC1 pin", 0x0 },
5602                         { "MIC2 pin", 0x1 },
5603                         { "LINE1 pin", 0x2 },
5604                         { "LINE2 pin", 0x3 },
5605                         { "CD pin", 0x4 },
5606                         { "LINE-OUT pin", 0x5 },
5607                         { "HP-OUT pin", 0x6 },
5608                 },
5609         },
5610         {
5611                 .num_items = 8,
5612                 .items = {
5613                         { "MIC1 pin", 0x0 },
5614                         { "MIC2 pin", 0x1 },
5615                         { "LINE1 pin", 0x2 },
5616                         { "LINE2 pin", 0x3 },
5617                         { "CD pin", 0x4 },
5618                         { "Mixer", 0x5 },
5619                         { "LINE-OUT pin", 0x6 },
5620                         { "HP-OUT pin", 0x7 },
5621                 },
5622         },
5623 };
5624 static struct snd_kcontrol_new alc260_test_mixer[] = {
5625         /* Output driver widgets */
5626         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
5627         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
5628         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5629         HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
5630         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5631         HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),
5632
5633         /* Modes for retasking pin widgets
5634          * Note: the ALC260 doesn't seem to act on requests to enable mic
5635          * bias from NIDs 0x0f and 0x10.  The ALC260 datasheet doesn't
5636          * mention this restriction.  At this stage it's not clear whether
5637          * this behaviour is intentional or is a hardware bug in chip
5638          * revisions available at least up until early 2006.  Therefore for
5639          * now allow the "HP-OUT" and "LINE-OUT" Mode controls to span all
5640          * choices, but if it turns out that the lack of mic bias for these
5641          * NIDs is intentional we could change their modes from
5642          * ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
5643          */
5644         ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
5645         ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
5646         ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
5647         ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
5648         ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
5649         ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),
5650
5651         /* Loopback mixer controls */
5652         HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
5653         HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
5654         HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
5655         HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
5656         HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
5657         HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
5658         HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
5659         HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
5660         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5661         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5662         HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
5663         HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
5664         HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
5665         HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
5666
5667         /* Controls for GPIO pins, assuming they are configured as outputs */
5668         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
5669         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
5670         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
5671         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
5672
5673         /* Switches to allow the digital IO pins to be enabled.  The datasheet
5674          * is ambigious as to which NID is which; testing on laptops which
5675          * make this output available should provide clarification.
5676          */
5677         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
5678         ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),
5679
5680         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
5681          * this output to turn on an external amplifier.
5682          */
5683         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
5684         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
5685
5686         { } /* end */
5687 };
5688 static struct hda_verb alc260_test_init_verbs[] = {
5689         /* Enable all GPIOs as outputs with an initial value of 0 */
5690         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
5691         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5692         {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
5693
5694         /* Enable retasking pins as output, initially without power amp */
5695         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5696         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5697         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5698         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5699         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5700         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5701
5702         /* Disable digital (SPDIF) pins initially, but users can enable
5703          * them via a mixer switch.  In the case of SPDIF-out, this initverb
5704          * payload also sets the generation to 0, output to be in "consumer"
5705          * PCM format, copyright asserted, no pre-emphasis and no validity
5706          * control.
5707          */
5708         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5709         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5710
5711         /* Ensure mic1, mic2, line1 and line2 pin widgets take input from the
5712          * OUT1 sum bus when acting as an output.
5713          */
5714         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5715         {0x0c, AC_VERB_SET_CONNECT_SEL, 0},
5716         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5717         {0x0e, AC_VERB_SET_CONNECT_SEL, 0},
5718
5719         /* Start with output sum widgets muted and their output gains at min */
5720         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5721         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5722         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5723         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5724         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5725         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5726         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5727         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5728         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5729
5730         /* Unmute retasking pin widget output buffers since the default
5731          * state appears to be output.  As the pin mode is changed by the
5732          * user the pin mode control will take care of enabling the pin's
5733          * input/output buffers as needed.
5734          */
5735         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5736         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5737         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5738         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5739         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5740         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5741         /* Also unmute the mono-out pin widget */
5742         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5743
5744         /* Mute capture amp left and right */
5745         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5746         /* Set ADC connection select to match default mixer setting (mic1
5747          * pin)
5748          */
5749         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5750
5751         /* Do the same for the second ADC: mute capture input amp and
5752          * set ADC connection to mic1 pin
5753          */
5754         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5755         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5756
5757         /* Mute all inputs to mixer widget (even unconnected ones) */
5758         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5759         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5760         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5761         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5762         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5763         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5764         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5765         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5766
5767         { }
5768 };
5769 #endif
5770
5771 #define alc260_pcm_analog_playback      alc880_pcm_analog_alt_playback
5772 #define alc260_pcm_analog_capture       alc880_pcm_analog_capture
5773
5774 #define alc260_pcm_digital_playback     alc880_pcm_digital_playback
5775 #define alc260_pcm_digital_capture      alc880_pcm_digital_capture
5776
5777 /*
5778  * for BIOS auto-configuration
5779  */
5780
5781 static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
5782                                         const char *pfx, int *vol_bits)
5783 {
5784         hda_nid_t nid_vol;
5785         unsigned long vol_val, sw_val;
5786         char name[32];
5787         int err;
5788
5789         if (nid >= 0x0f && nid < 0x11) {
5790                 nid_vol = nid - 0x7;
5791                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
5792                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
5793         } else if (nid == 0x11) {
5794                 nid_vol = nid - 0x7;
5795                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT);
5796                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
5797         } else if (nid >= 0x12 && nid <= 0x15) {
5798                 nid_vol = 0x08;
5799                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
5800                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
5801         } else
5802                 return 0; /* N/A */
5803
5804         if (!(*vol_bits & (1 << nid_vol))) {
5805                 /* first control for the volume widget */
5806                 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
5807                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name, vol_val);
5808                 if (err < 0)
5809                         return err;
5810                 *vol_bits |= (1 << nid_vol);
5811         }
5812         snprintf(name, sizeof(name), "%s Playback Switch", pfx);
5813         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, sw_val);
5814         if (err < 0)
5815                 return err;
5816         return 1;
5817 }
5818
5819 /* add playback controls from the parsed DAC table */
5820 static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
5821                                              const struct auto_pin_cfg *cfg)
5822 {
5823         hda_nid_t nid;
5824         int err;
5825         int vols = 0;
5826
5827         spec->multiout.num_dacs = 1;
5828         spec->multiout.dac_nids = spec->private_dac_nids;
5829         spec->multiout.dac_nids[0] = 0x02;
5830
5831         nid = cfg->line_out_pins[0];
5832         if (nid) {
5833                 err = alc260_add_playback_controls(spec, nid, "Front", &vols);
5834                 if (err < 0)
5835                         return err;
5836         }
5837
5838         nid = cfg->speaker_pins[0];
5839         if (nid) {
5840                 err = alc260_add_playback_controls(spec, nid, "Speaker", &vols);
5841                 if (err < 0)
5842                         return err;
5843         }
5844
5845         nid = cfg->hp_pins[0];
5846         if (nid) {
5847                 err = alc260_add_playback_controls(spec, nid, "Headphone",
5848                                                    &vols);
5849                 if (err < 0)
5850                         return err;
5851         }
5852         return 0;
5853 }
5854
5855 /* create playback/capture controls for input pins */
5856 static int alc260_auto_create_analog_input_ctls(struct alc_spec *spec,
5857                                                 const struct auto_pin_cfg *cfg)
5858 {
5859         struct hda_input_mux *imux = &spec->private_imux[0];
5860         int i, err, idx;
5861
5862         for (i = 0; i < AUTO_PIN_LAST; i++) {
5863                 if (cfg->input_pins[i] >= 0x12) {
5864                         idx = cfg->input_pins[i] - 0x12;
5865                         err = new_analog_input(spec, cfg->input_pins[i],
5866                                                auto_pin_cfg_labels[i], idx,
5867                                                0x07);
5868                         if (err < 0)
5869                                 return err;
5870                         imux->items[imux->num_items].label =
5871                                 auto_pin_cfg_labels[i];
5872                         imux->items[imux->num_items].index = idx;
5873                         imux->num_items++;
5874                 }
5875                 if (cfg->input_pins[i] >= 0x0f && cfg->input_pins[i] <= 0x10){
5876                         idx = cfg->input_pins[i] - 0x09;
5877                         err = new_analog_input(spec, cfg->input_pins[i],
5878                                                auto_pin_cfg_labels[i], idx,
5879                                                0x07);
5880                         if (err < 0)
5881                                 return err;
5882                         imux->items[imux->num_items].label =
5883                                 auto_pin_cfg_labels[i];
5884                         imux->items[imux->num_items].index = idx;
5885                         imux->num_items++;
5886                 }
5887         }
5888         return 0;
5889 }
5890
5891 static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
5892                                               hda_nid_t nid, int pin_type,
5893                                               int sel_idx)
5894 {
5895         alc_set_pin_output(codec, nid, pin_type);
5896         /* need the manual connection? */
5897         if (nid >= 0x12) {
5898                 int idx = nid - 0x12;
5899                 snd_hda_codec_write(codec, idx + 0x0b, 0,
5900                                     AC_VERB_SET_CONNECT_SEL, sel_idx);
5901         }
5902 }
5903
5904 static void alc260_auto_init_multi_out(struct hda_codec *codec)
5905 {
5906         struct alc_spec *spec = codec->spec;
5907         hda_nid_t nid;
5908
5909         nid = spec->autocfg.line_out_pins[0];
5910         if (nid) {
5911                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
5912                 alc260_auto_set_output_and_unmute(codec, nid, pin_type, 0);
5913         }
5914
5915         nid = spec->autocfg.speaker_pins[0];
5916         if (nid)
5917                 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
5918
5919         nid = spec->autocfg.hp_pins[0];
5920         if (nid)
5921                 alc260_auto_set_output_and_unmute(codec, nid, PIN_HP, 0);
5922 }
5923
5924 #define ALC260_PIN_CD_NID               0x16
5925 static void alc260_auto_init_analog_input(struct hda_codec *codec)
5926 {
5927         struct alc_spec *spec = codec->spec;
5928         int i;
5929
5930         for (i = 0; i < AUTO_PIN_LAST; i++) {
5931                 hda_nid_t nid = spec->autocfg.input_pins[i];
5932                 if (nid >= 0x12) {
5933                         alc_set_input_pin(codec, nid, i);
5934                         if (nid != ALC260_PIN_CD_NID &&
5935                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
5936                                 snd_hda_codec_write(codec, nid, 0,
5937                                                     AC_VERB_SET_AMP_GAIN_MUTE,
5938                                                     AMP_OUT_MUTE);
5939                 }
5940         }
5941 }
5942
5943 /*
5944  * generic initialization of ADC, input mixers and output mixers
5945  */
5946 static struct hda_verb alc260_volume_init_verbs[] = {
5947         /*
5948          * Unmute ADC0-1 and set the default input to mic-in
5949          */
5950         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5951         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5952         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5953         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5954
5955         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5956          * mixer widget
5957          * Note: PASD motherboards uses the Line In 2 as the input for
5958          * front panel mic (mic 2)
5959          */
5960         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
5961         /* mute analog inputs */
5962         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5963         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5964         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5965         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5966         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5967
5968         /*
5969          * Set up output mixers (0x08 - 0x0a)
5970          */
5971         /* set vol=0 to output mixers */
5972         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5973         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5974         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5975         /* set up input amps for analog loopback */
5976         /* Amp Indices: DAC = 0, mixer = 1 */
5977         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5978         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5979         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5980         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5981         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5982         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5983
5984         { }
5985 };
5986
5987 static int alc260_parse_auto_config(struct hda_codec *codec)
5988 {
5989         struct alc_spec *spec = codec->spec;
5990         int err;
5991         static hda_nid_t alc260_ignore[] = { 0x17, 0 };
5992
5993         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
5994                                            alc260_ignore);
5995         if (err < 0)
5996                 return err;
5997         err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg);
5998         if (err < 0)
5999                 return err;
6000         if (!spec->kctls.list)
6001                 return 0; /* can't find valid BIOS pin config */
6002         err = alc260_auto_create_analog_input_ctls(spec, &spec->autocfg);
6003         if (err < 0)
6004                 return err;
6005
6006         spec->multiout.max_channels = 2;
6007
6008         if (spec->autocfg.dig_outs)
6009                 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
6010         if (spec->kctls.list)
6011                 add_mixer(spec, spec->kctls.list);
6012
6013         add_verb(spec, alc260_volume_init_verbs);
6014
6015         spec->num_mux_defs = 1;
6016         spec->input_mux = &spec->private_imux[0];
6017
6018         alc_ssid_check(codec, 0x10, 0x15, 0x0f);
6019
6020         return 1;
6021 }
6022
6023 /* additional initialization for auto-configuration model */
6024 static void alc260_auto_init(struct hda_codec *codec)
6025 {
6026         struct alc_spec *spec = codec->spec;
6027         alc260_auto_init_multi_out(codec);
6028         alc260_auto_init_analog_input(codec);
6029         if (spec->unsol_event)
6030                 alc_inithook(codec);
6031 }
6032
6033 #ifdef CONFIG_SND_HDA_POWER_SAVE
6034 static struct hda_amp_list alc260_loopbacks[] = {
6035         { 0x07, HDA_INPUT, 0 },
6036         { 0x07, HDA_INPUT, 1 },
6037         { 0x07, HDA_INPUT, 2 },
6038         { 0x07, HDA_INPUT, 3 },
6039         { 0x07, HDA_INPUT, 4 },
6040         { } /* end */
6041 };
6042 #endif
6043
6044 /*
6045  * ALC260 configurations
6046  */
6047 static const char *alc260_models[ALC260_MODEL_LAST] = {
6048         [ALC260_BASIC]          = "basic",
6049         [ALC260_HP]             = "hp",
6050         [ALC260_HP_3013]        = "hp-3013",
6051         [ALC260_HP_DC7600]      = "hp-dc7600",
6052         [ALC260_FUJITSU_S702X]  = "fujitsu",
6053         [ALC260_ACER]           = "acer",
6054         [ALC260_WILL]           = "will",
6055         [ALC260_REPLACER_672V]  = "replacer",
6056         [ALC260_FAVORIT100]     = "favorit100",
6057 #ifdef CONFIG_SND_DEBUG
6058         [ALC260_TEST]           = "test",
6059 #endif
6060         [ALC260_AUTO]           = "auto",
6061 };
6062
6063 static struct snd_pci_quirk alc260_cfg_tbl[] = {
6064         SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER),
6065         SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
6066         SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FAVORIT100),
6067         SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
6068         SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_HP_3013),
6069         SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
6070         SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP_3013),
6071         SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_DC7600),
6072         SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
6073         SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
6074         SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP),
6075         SND_PCI_QUIRK(0x103c, 0x3016, "HP", ALC260_HP),
6076         SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_BASIC),
6077         SND_PCI_QUIRK(0x104d, 0x81cc, "Sony VAIO", ALC260_BASIC),
6078         SND_PCI_QUIRK(0x104d, 0x81cd, "Sony VAIO", ALC260_BASIC),
6079         SND_PCI_QUIRK(0x10cf, 0x1326, "Fujitsu S702X", ALC260_FUJITSU_S702X),
6080         SND_PCI_QUIRK(0x152d, 0x0729, "CTL U553W", ALC260_BASIC),
6081         SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_REPLACER_672V),
6082         SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_WILL),
6083         {}
6084 };
6085
6086 static struct alc_config_preset alc260_presets[] = {
6087         [ALC260_BASIC] = {
6088                 .mixers = { alc260_base_output_mixer,
6089                             alc260_input_mixer },
6090                 .init_verbs = { alc260_init_verbs },
6091                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6092                 .dac_nids = alc260_dac_nids,
6093                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
6094                 .adc_nids = alc260_adc_nids,
6095                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6096                 .channel_mode = alc260_modes,
6097                 .input_mux = &alc260_capture_source,
6098         },
6099         [ALC260_HP] = {
6100                 .mixers = { alc260_hp_output_mixer,
6101                             alc260_input_mixer },
6102                 .init_verbs = { alc260_init_verbs,
6103                                 alc260_hp_unsol_verbs },
6104                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6105                 .dac_nids = alc260_dac_nids,
6106                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
6107                 .adc_nids = alc260_adc_nids_alt,
6108                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6109                 .channel_mode = alc260_modes,
6110                 .input_mux = &alc260_capture_source,
6111                 .unsol_event = alc260_hp_unsol_event,
6112                 .init_hook = alc260_hp_automute,
6113         },
6114         [ALC260_HP_DC7600] = {
6115                 .mixers = { alc260_hp_dc7600_mixer,
6116                             alc260_input_mixer },
6117                 .init_verbs = { alc260_init_verbs,
6118                                 alc260_hp_dc7600_verbs },
6119                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6120                 .dac_nids = alc260_dac_nids,
6121                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
6122                 .adc_nids = alc260_adc_nids_alt,
6123                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6124                 .channel_mode = alc260_modes,
6125                 .input_mux = &alc260_capture_source,
6126                 .unsol_event = alc260_hp_3012_unsol_event,
6127                 .init_hook = alc260_hp_3012_automute,
6128         },
6129         [ALC260_HP_3013] = {
6130                 .mixers = { alc260_hp_3013_mixer,
6131                             alc260_input_mixer },
6132                 .init_verbs = { alc260_hp_3013_init_verbs,
6133                                 alc260_hp_3013_unsol_verbs },
6134                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6135                 .dac_nids = alc260_dac_nids,
6136                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
6137                 .adc_nids = alc260_adc_nids_alt,
6138                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6139                 .channel_mode = alc260_modes,
6140                 .input_mux = &alc260_capture_source,
6141                 .unsol_event = alc260_hp_3013_unsol_event,
6142                 .init_hook = alc260_hp_3013_automute,
6143         },
6144         [ALC260_FUJITSU_S702X] = {
6145                 .mixers = { alc260_fujitsu_mixer },
6146                 .init_verbs = { alc260_fujitsu_init_verbs },
6147                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6148                 .dac_nids = alc260_dac_nids,
6149                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
6150                 .adc_nids = alc260_dual_adc_nids,
6151                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6152                 .channel_mode = alc260_modes,
6153                 .num_mux_defs = ARRAY_SIZE(alc260_fujitsu_capture_sources),
6154                 .input_mux = alc260_fujitsu_capture_sources,
6155         },
6156         [ALC260_ACER] = {
6157                 .mixers = { alc260_acer_mixer },
6158                 .init_verbs = { alc260_acer_init_verbs },
6159                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6160                 .dac_nids = alc260_dac_nids,
6161                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
6162                 .adc_nids = alc260_dual_adc_nids,
6163                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6164                 .channel_mode = alc260_modes,
6165                 .num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources),
6166                 .input_mux = alc260_acer_capture_sources,
6167         },
6168         [ALC260_FAVORIT100] = {
6169                 .mixers = { alc260_favorit100_mixer },
6170                 .init_verbs = { alc260_favorit100_init_verbs },
6171                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6172                 .dac_nids = alc260_dac_nids,
6173                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
6174                 .adc_nids = alc260_dual_adc_nids,
6175                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6176                 .channel_mode = alc260_modes,
6177                 .num_mux_defs = ARRAY_SIZE(alc260_favorit100_capture_sources),
6178                 .input_mux = alc260_favorit100_capture_sources,
6179         },
6180         [ALC260_WILL] = {
6181                 .mixers = { alc260_will_mixer },
6182                 .init_verbs = { alc260_init_verbs, alc260_will_verbs },
6183                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6184                 .dac_nids = alc260_dac_nids,
6185                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
6186                 .adc_nids = alc260_adc_nids,
6187                 .dig_out_nid = ALC260_DIGOUT_NID,
6188                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6189                 .channel_mode = alc260_modes,
6190                 .input_mux = &alc260_capture_source,
6191         },
6192         [ALC260_REPLACER_672V] = {
6193                 .mixers = { alc260_replacer_672v_mixer },
6194                 .init_verbs = { alc260_init_verbs, alc260_replacer_672v_verbs },
6195                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6196                 .dac_nids = alc260_dac_nids,
6197                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
6198                 .adc_nids = alc260_adc_nids,
6199                 .dig_out_nid = ALC260_DIGOUT_NID,
6200                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6201                 .channel_mode = alc260_modes,
6202                 .input_mux = &alc260_capture_source,
6203                 .unsol_event = alc260_replacer_672v_unsol_event,
6204                 .init_hook = alc260_replacer_672v_automute,
6205         },
6206 #ifdef CONFIG_SND_DEBUG
6207         [ALC260_TEST] = {
6208                 .mixers = { alc260_test_mixer },
6209                 .init_verbs = { alc260_test_init_verbs },
6210                 .num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
6211                 .dac_nids = alc260_test_dac_nids,
6212                 .num_adc_nids = ARRAY_SIZE(alc260_test_adc_nids),
6213                 .adc_nids = alc260_test_adc_nids,
6214                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6215                 .channel_mode = alc260_modes,
6216                 .num_mux_defs = ARRAY_SIZE(alc260_test_capture_sources),
6217                 .input_mux = alc260_test_capture_sources,
6218         },
6219 #endif
6220 };
6221
6222 static int patch_alc260(struct hda_codec *codec)
6223 {
6224         struct alc_spec *spec;
6225         int err, board_config;
6226
6227         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6228         if (spec == NULL)
6229                 return -ENOMEM;
6230
6231         codec->spec = spec;
6232
6233         board_config = snd_hda_check_board_config(codec, ALC260_MODEL_LAST,
6234                                                   alc260_models,
6235                                                   alc260_cfg_tbl);
6236         if (board_config < 0) {
6237                 snd_printd(KERN_INFO "hda_codec: Unknown model for %s, "
6238                            "trying auto-probe from BIOS...\n",
6239                            codec->chip_name);
6240                 board_config = ALC260_AUTO;
6241         }
6242
6243         if (board_config == ALC260_AUTO) {
6244                 /* automatic parse from the BIOS config */
6245                 err = alc260_parse_auto_config(codec);
6246                 if (err < 0) {
6247                         alc_free(codec);
6248                         return err;
6249                 } else if (!err) {
6250                         printk(KERN_INFO
6251                                "hda_codec: Cannot set up configuration "
6252                                "from BIOS.  Using base mode...\n");
6253                         board_config = ALC260_BASIC;
6254                 }
6255         }
6256
6257         err = snd_hda_attach_beep_device(codec, 0x1);
6258         if (err < 0) {
6259                 alc_free(codec);
6260                 return err;
6261         }
6262
6263         if (board_config != ALC260_AUTO)
6264                 setup_preset(spec, &alc260_presets[board_config]);
6265
6266         spec->stream_analog_playback = &alc260_pcm_analog_playback;
6267         spec->stream_analog_capture = &alc260_pcm_analog_capture;
6268
6269         spec->stream_digital_playback = &alc260_pcm_digital_playback;
6270         spec->stream_digital_capture = &alc260_pcm_digital_capture;
6271
6272         if (!spec->adc_nids && spec->input_mux) {
6273                 /* check whether NID 0x04 is valid */
6274                 unsigned int wcap = get_wcaps(codec, 0x04);
6275                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
6276                 /* get type */
6277                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
6278                         spec->adc_nids = alc260_adc_nids_alt;
6279                         spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
6280                 } else {
6281                         spec->adc_nids = alc260_adc_nids;
6282                         spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
6283                 }
6284         }
6285         set_capture_mixer(spec);
6286         set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
6287
6288         spec->vmaster_nid = 0x08;
6289
6290         codec->patch_ops = alc_patch_ops;
6291         if (board_config == ALC260_AUTO)
6292                 spec->init_hook = alc260_auto_init;
6293 #ifdef CONFIG_SND_HDA_POWER_SAVE
6294         if (!spec->loopback.amplist)
6295                 spec->loopback.amplist = alc260_loopbacks;
6296 #endif
6297         codec->proc_widget_hook = print_realtek_coef;
6298
6299         return 0;
6300 }
6301
6302
6303 /*
6304  * ALC882 support
6305  *
6306  * ALC882 is almost identical with ALC880 but has cleaner and more flexible
6307  * configuration.  Each pin widget can choose any input DACs and a mixer.
6308  * Each ADC is connected from a mixer of all inputs.  This makes possible
6309  * 6-channel independent captures.
6310  *
6311  * In addition, an independent DAC for the multi-playback (not used in this
6312  * driver yet).
6313  */
6314 #define ALC882_DIGOUT_NID       0x06
6315 #define ALC882_DIGIN_NID        0x0a
6316
6317 static struct hda_channel_mode alc882_ch_modes[1] = {
6318         { 8, NULL }
6319 };
6320
6321 static hda_nid_t alc882_dac_nids[4] = {
6322         /* front, rear, clfe, rear_surr */
6323         0x02, 0x03, 0x04, 0x05
6324 };
6325
6326 /* identical with ALC880 */
6327 #define alc882_adc_nids         alc880_adc_nids
6328 #define alc882_adc_nids_alt     alc880_adc_nids_alt
6329
6330 static hda_nid_t alc882_capsrc_nids[3] = { 0x24, 0x23, 0x22 };
6331 static hda_nid_t alc882_capsrc_nids_alt[2] = { 0x23, 0x22 };
6332
6333 /* input MUX */
6334 /* FIXME: should be a matrix-type input source selection */
6335
6336 static struct hda_input_mux alc882_capture_source = {
6337         .num_items = 4,
6338         .items = {
6339                 { "Mic", 0x0 },
6340                 { "Front Mic", 0x1 },
6341                 { "Line", 0x2 },
6342                 { "CD", 0x4 },
6343         },
6344 };
6345
6346 static struct hda_input_mux mb5_capture_source = {
6347         .num_items = 3,
6348         .items = {
6349                 { "Mic", 0x1 },
6350                 { "Line", 0x2 },
6351                 { "CD", 0x4 },
6352         },
6353 };
6354
6355 /*
6356  * 2ch mode
6357  */
6358 static struct hda_verb alc882_3ST_ch2_init[] = {
6359         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6360         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6361         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6362         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6363         { } /* end */
6364 };
6365
6366 /*
6367  * 6ch mode
6368  */
6369 static struct hda_verb alc882_3ST_ch6_init[] = {
6370         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6371         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6372         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6373         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6374         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6375         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6376         { } /* end */
6377 };
6378
6379 static struct hda_channel_mode alc882_3ST_6ch_modes[2] = {
6380         { 2, alc882_3ST_ch2_init },
6381         { 6, alc882_3ST_ch6_init },
6382 };
6383
6384 /*
6385  * 6ch mode
6386  */
6387 static struct hda_verb alc882_sixstack_ch6_init[] = {
6388         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
6389         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6390         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6391         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6392         { } /* end */
6393 };
6394
6395 /*
6396  * 8ch mode
6397  */
6398 static struct hda_verb alc882_sixstack_ch8_init[] = {
6399         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6400         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6401         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6402         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6403         { } /* end */
6404 };
6405
6406 static struct hda_channel_mode alc882_sixstack_modes[2] = {
6407         { 6, alc882_sixstack_ch6_init },
6408         { 8, alc882_sixstack_ch8_init },
6409 };
6410
6411 /*
6412  * macbook pro ALC885 can switch LineIn to LineOut without losing Mic
6413  */
6414
6415 /*
6416  * 2ch mode
6417  */
6418 static struct hda_verb alc885_mbp_ch2_init[] = {
6419         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6420         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6421         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6422         { } /* end */
6423 };
6424
6425 /*
6426  * 6ch mode
6427  */
6428 static struct hda_verb alc885_mbp_ch6_init[] = {
6429         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6430         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6431         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6432         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6433         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6434         { } /* end */
6435 };
6436
6437 static struct hda_channel_mode alc885_mbp_6ch_modes[2] = {
6438         { 2, alc885_mbp_ch2_init },
6439         { 6, alc885_mbp_ch6_init },
6440 };
6441
6442 /*
6443  * 2ch
6444  * Speakers/Woofer/HP = Front
6445  * LineIn = Input
6446  */
6447 static struct hda_verb alc885_mb5_ch2_init[] = {
6448         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6449         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6450         { } /* end */
6451 };
6452
6453 /*
6454  * 6ch mode
6455  * Speakers/HP = Front
6456  * Woofer = LFE
6457  * LineIn = Surround
6458  */
6459 static struct hda_verb alc885_mb5_ch6_init[] = {
6460         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6461         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6462         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
6463         { } /* end */
6464 };
6465
6466 static struct hda_channel_mode alc885_mb5_6ch_modes[2] = {
6467         { 2, alc885_mb5_ch2_init },
6468         { 6, alc885_mb5_ch6_init },
6469 };
6470
6471 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
6472  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
6473  */
6474 static struct snd_kcontrol_new alc882_base_mixer[] = {
6475         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6476         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6477         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6478         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6479         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6480         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6481         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6482         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6483         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
6484         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
6485         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6486         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6487         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6488         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6489         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6490         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6491         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6492         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6493         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6494         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6495         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6496         { } /* end */
6497 };
6498
6499 static struct snd_kcontrol_new alc885_mbp3_mixer[] = {
6500         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
6501         HDA_BIND_MUTE   ("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
6502         HDA_CODEC_MUTE  ("Speaker Playback Switch", 0x14, 0x00, HDA_OUTPUT),
6503         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
6504         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6505         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6506         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
6507         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
6508         HDA_CODEC_VOLUME("Line Boost", 0x1a, 0x00, HDA_INPUT),
6509         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
6510         { } /* end */
6511 };
6512
6513 static struct snd_kcontrol_new alc885_mb5_mixer[] = {
6514         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
6515         HDA_BIND_MUTE   ("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
6516         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
6517         HDA_BIND_MUTE   ("Surround Playback Switch", 0x0d, 0x02, HDA_INPUT),
6518         HDA_CODEC_VOLUME("LFE Playback Volume", 0x0e, 0x00, HDA_OUTPUT),
6519         HDA_BIND_MUTE   ("LFE Playback Switch", 0x0e, 0x02, HDA_INPUT),
6520         HDA_CODEC_VOLUME("HP Playback Volume", 0x0f, 0x00, HDA_OUTPUT),
6521         HDA_BIND_MUTE   ("HP Playback Switch", 0x0f, 0x02, HDA_INPUT),
6522         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6523         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6524         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
6525         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
6526         HDA_CODEC_VOLUME("Line Boost", 0x15, 0x00, HDA_INPUT),
6527         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0x00, HDA_INPUT),
6528         { } /* end */
6529 };
6530
6531 static struct snd_kcontrol_new alc882_w2jc_mixer[] = {
6532         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6533         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6534         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6535         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6536         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6537         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6538         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6539         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6540         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6541         { } /* end */
6542 };
6543
6544 static struct snd_kcontrol_new alc882_targa_mixer[] = {
6545         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6546         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6547         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6548         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6549         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6550         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6551         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6552         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6553         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6554         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6555         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6556         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6557         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6558         { } /* end */
6559 };
6560
6561 /* Pin assignment: Front=0x14, HP = 0x15, Front = 0x16, ???
6562  *                 Front Mic=0x18, Line In = 0x1a, Line In = 0x1b, CD = 0x1c
6563  */
6564 static struct snd_kcontrol_new alc882_asus_a7j_mixer[] = {
6565         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6566         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6567         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6568         HDA_CODEC_MUTE("Mobile Front Playback Switch", 0x16, 0x0, HDA_OUTPUT),
6569         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6570         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6571         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6572         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6573         HDA_CODEC_VOLUME("Mobile Line Playback Volume", 0x0b, 0x03, HDA_INPUT),
6574         HDA_CODEC_MUTE("Mobile Line Playback Switch", 0x0b, 0x03, HDA_INPUT),
6575         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6576         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6577         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6578         { } /* end */
6579 };
6580
6581 static struct snd_kcontrol_new alc882_asus_a7m_mixer[] = {
6582         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6583         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6584         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6585         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6586         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6587         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6588         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6589         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6590         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6591         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6592         { } /* end */
6593 };
6594
6595 static struct snd_kcontrol_new alc882_chmode_mixer[] = {
6596         {
6597                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6598                 .name = "Channel Mode",
6599                 .info = alc_ch_mode_info,
6600                 .get = alc_ch_mode_get,
6601                 .put = alc_ch_mode_put,
6602         },
6603         { } /* end */
6604 };
6605
6606 static struct hda_verb alc882_init_verbs[] = {
6607         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6608         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6609         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6610         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6611         /* Rear mixer */
6612         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6613         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6614         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6615         /* CLFE mixer */
6616         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6617         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6618         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6619         /* Side mixer */
6620         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6621         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6622         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6623
6624         /* Front Pin: output 0 (0x0c) */
6625         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6626         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6627         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6628         /* Rear Pin: output 1 (0x0d) */
6629         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6630         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6631         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
6632         /* CLFE Pin: output 2 (0x0e) */
6633         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6634         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6635         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
6636         /* Side Pin: output 3 (0x0f) */
6637         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6638         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6639         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
6640         /* Mic (rear) pin: input vref at 80% */
6641         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6642         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6643         /* Front Mic pin: input vref at 80% */
6644         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6645         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6646         /* Line In pin: input */
6647         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6648         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6649         /* Line-2 In: Headphone output (output 0 - 0x0c) */
6650         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6651         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6652         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
6653         /* CD pin widget for input */
6654         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6655
6656         /* FIXME: use matrix-type input source selection */
6657         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6658         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6659         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6660         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6661         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6662         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6663         /* Input mixer2 */
6664         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6665         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6666         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6667         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6668         /* Input mixer3 */
6669         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6670         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6671         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6672         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6673         /* ADC1: mute amp left and right */
6674         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6675         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6676         /* ADC2: mute amp left and right */
6677         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6678         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6679         /* ADC3: mute amp left and right */
6680         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6681         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6682
6683         { }
6684 };
6685
6686 static struct hda_verb alc882_eapd_verbs[] = {
6687         /* change to EAPD mode */
6688         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
6689         {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
6690         { }
6691 };
6692
6693 /* Mac Pro test */
6694 static struct snd_kcontrol_new alc882_macpro_mixer[] = {
6695         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6696         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6697         HDA_CODEC_MUTE("Headphone Playback Switch", 0x18, 0x0, HDA_OUTPUT),
6698         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
6699         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
6700         /* FIXME: this looks suspicious...
6701         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x02, HDA_INPUT),
6702         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x02, HDA_INPUT),
6703         */
6704         { } /* end */
6705 };
6706
6707 static struct hda_verb alc882_macpro_init_verbs[] = {
6708         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6709         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6710         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6711         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6712         /* Front Pin: output 0 (0x0c) */
6713         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6714         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6715         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6716         /* Front Mic pin: input vref at 80% */
6717         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6718         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6719         /* Speaker:  output */
6720         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6721         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6722         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x04},
6723         /* Headphone output (output 0 - 0x0c) */
6724         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6725         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6726         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
6727
6728         /* FIXME: use matrix-type input source selection */
6729         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6730         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6731         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6732         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6733         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6734         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6735         /* Input mixer2 */
6736         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6737         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6738         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6739         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6740         /* Input mixer3 */
6741         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6742         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6743         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6744         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6745         /* ADC1: mute amp left and right */
6746         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6747         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6748         /* ADC2: mute amp left and right */
6749         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6750         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6751         /* ADC3: mute amp left and right */
6752         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6753         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6754
6755         { }
6756 };
6757
6758 /* Macbook 5,1 */
6759 static struct hda_verb alc885_mb5_init_verbs[] = {
6760         /* DACs */
6761         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6762         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6763         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6764         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6765         /* Front mixer */
6766         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6767         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6768         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6769         /* Surround mixer */
6770         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6771         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6772         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6773         /* LFE mixer */
6774         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6775         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6776         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6777         /* HP mixer */
6778         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6779         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6780         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6781         /* Front Pin (0x0c) */
6782         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x01},
6783         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6784         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
6785         /* LFE Pin (0x0e) */
6786         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x01},
6787         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6788         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x02},
6789         /* HP Pin (0x0f) */
6790         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6791         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6792         {0x14, AC_VERB_SET_CONNECT_SEL, 0x03},
6793         /* Front Mic pin: input vref at 80% */
6794         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6795         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6796         /* Line In pin */
6797         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6798         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6799
6800         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6801         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6802         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6803         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6804         { }
6805 };
6806
6807 /* Macbook Pro rev3 */
6808 static struct hda_verb alc885_mbp3_init_verbs[] = {
6809         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6810         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6811         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6812         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6813         /* Rear mixer */
6814         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6815         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6816         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6817         /* Front Pin: output 0 (0x0c) */
6818         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6819         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6820         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6821         /* HP Pin: output 0 (0x0d) */
6822         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},
6823         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6824         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6825         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6826         /* Mic (rear) pin: input vref at 80% */
6827         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6828         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6829         /* Front Mic pin: input vref at 80% */
6830         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6831         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6832         /* Line In pin: use output 1 when in LineOut mode */
6833         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6834         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6835         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
6836
6837         /* FIXME: use matrix-type input source selection */
6838         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6839         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6840         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6841         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6842         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6843         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6844         /* Input mixer2 */
6845         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6846         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6847         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6848         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6849         /* Input mixer3 */
6850         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6851         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6852         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6853         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6854         /* ADC1: mute amp left and right */
6855         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6856         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6857         /* ADC2: mute amp left and right */
6858         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6859         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6860         /* ADC3: mute amp left and right */
6861         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6862         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6863
6864         { }
6865 };
6866
6867 /* iMac 24 mixer. */
6868 static struct snd_kcontrol_new alc885_imac24_mixer[] = {
6869         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
6870         HDA_CODEC_MUTE("Master Playback Switch", 0x0c, 0x00, HDA_INPUT),
6871         { } /* end */
6872 };
6873
6874 /* iMac 24 init verbs. */
6875 static struct hda_verb alc885_imac24_init_verbs[] = {
6876         /* Internal speakers: output 0 (0x0c) */
6877         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6878         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6879         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
6880         /* Internal speakers: output 0 (0x0c) */
6881         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6882         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6883         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
6884         /* Headphone: output 0 (0x0c) */
6885         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6886         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6887         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6888         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6889         /* Front Mic: input vref at 80% */
6890         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6891         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6892         { }
6893 };
6894
6895 /* Toggle speaker-output according to the hp-jack state */
6896 static void alc885_imac24_automute_init_hook(struct hda_codec *codec)
6897 {
6898         struct alc_spec *spec = codec->spec;
6899
6900         spec->autocfg.hp_pins[0] = 0x14;
6901         spec->autocfg.speaker_pins[0] = 0x18;
6902         spec->autocfg.speaker_pins[1] = 0x1a;
6903         alc_automute_amp(codec);
6904 }
6905
6906 static void alc885_mbp3_init_hook(struct hda_codec *codec)
6907 {
6908         struct alc_spec *spec = codec->spec;
6909
6910         spec->autocfg.hp_pins[0] = 0x15;
6911         spec->autocfg.speaker_pins[0] = 0x14;
6912         alc_automute_amp(codec);
6913 }
6914
6915
6916 static struct hda_verb alc882_targa_verbs[] = {
6917         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6918         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6919
6920         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6921         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6922
6923         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6924         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6925         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6926
6927         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6928         { } /* end */
6929 };
6930
6931 /* toggle speaker-output according to the hp-jack state */
6932 static void alc882_targa_automute(struct hda_codec *codec)
6933 {
6934         struct alc_spec *spec = codec->spec;
6935         alc_automute_amp(codec);
6936         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
6937                                   spec->jack_present ? 1 : 3);
6938 }
6939
6940 static void alc882_targa_init_hook(struct hda_codec *codec)
6941 {
6942         struct alc_spec *spec = codec->spec;
6943
6944         spec->autocfg.hp_pins[0] = 0x14;
6945         spec->autocfg.speaker_pins[0] = 0x1b;
6946         alc882_targa_automute(codec);
6947 }
6948
6949 static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res)
6950 {
6951         if ((res >> 26) == ALC880_HP_EVENT)
6952                 alc882_targa_automute(codec);
6953 }
6954
6955 static struct hda_verb alc882_asus_a7j_verbs[] = {
6956         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6957         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6958
6959         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6960         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6961         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6962
6963         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6964         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6965         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6966
6967         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6968         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6969         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6970         { } /* end */
6971 };
6972
6973 static struct hda_verb alc882_asus_a7m_verbs[] = {
6974         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6975         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6976
6977         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6978         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6979         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6980
6981         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6982         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6983         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6984
6985         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6986         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6987         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6988         { } /* end */
6989 };
6990
6991 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
6992 {
6993         unsigned int gpiostate, gpiomask, gpiodir;
6994
6995         gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
6996                                        AC_VERB_GET_GPIO_DATA, 0);
6997
6998         if (!muted)
6999                 gpiostate |= (1 << pin);
7000         else
7001                 gpiostate &= ~(1 << pin);
7002
7003         gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
7004                                       AC_VERB_GET_GPIO_MASK, 0);
7005         gpiomask |= (1 << pin);
7006
7007         gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
7008                                      AC_VERB_GET_GPIO_DIRECTION, 0);
7009         gpiodir |= (1 << pin);
7010
7011
7012         snd_hda_codec_write(codec, codec->afg, 0,
7013                             AC_VERB_SET_GPIO_MASK, gpiomask);
7014         snd_hda_codec_write(codec, codec->afg, 0,
7015                             AC_VERB_SET_GPIO_DIRECTION, gpiodir);
7016
7017         msleep(1);
7018
7019         snd_hda_codec_write(codec, codec->afg, 0,
7020                             AC_VERB_SET_GPIO_DATA, gpiostate);
7021 }
7022
7023 /* set up GPIO at initialization */
7024 static void alc885_macpro_init_hook(struct hda_codec *codec)
7025 {
7026         alc882_gpio_mute(codec, 0, 0);
7027         alc882_gpio_mute(codec, 1, 0);
7028 }
7029
7030 /* set up GPIO and update auto-muting at initialization */
7031 static void alc885_imac24_init_hook(struct hda_codec *codec)
7032 {
7033         alc885_macpro_init_hook(codec);
7034         alc885_imac24_automute_init_hook(codec);
7035 }
7036
7037 /*
7038  * generic initialization of ADC, input mixers and output mixers
7039  */
7040 static struct hda_verb alc882_auto_init_verbs[] = {
7041         /*
7042          * Unmute ADC0-2 and set the default input to mic-in
7043          */
7044         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
7045         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7046         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7047         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7048         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7049         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7050
7051         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
7052          * mixer widget
7053          * Note: PASD motherboards uses the Line In 2 as the input for
7054          * front panel mic (mic 2)
7055          */
7056         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
7057         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7058         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7059         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7060         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7061         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7062
7063         /*
7064          * Set up output mixers (0x0c - 0x0f)
7065          */
7066         /* set vol=0 to output mixers */
7067         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7068         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7069         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7070         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7071         /* set up input amps for analog loopback */
7072         /* Amp Indices: DAC = 0, mixer = 1 */
7073         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7074         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7075         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7076         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7077         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7078         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7079         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7080         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7081         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7082         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7083
7084         /* FIXME: use matrix-type input source selection */
7085         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7086         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
7087         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7088         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7089         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
7090         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
7091         /* Input mixer2 */
7092         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7093         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7094         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
7095         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
7096         /* Input mixer3 */
7097         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7098         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7099         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
7100         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
7101
7102         { }
7103 };
7104
7105 #ifdef CONFIG_SND_HDA_POWER_SAVE
7106 #define alc882_loopbacks        alc880_loopbacks
7107 #endif
7108
7109 /* pcm configuration: identical with ALC880 */
7110 #define alc882_pcm_analog_playback      alc880_pcm_analog_playback
7111 #define alc882_pcm_analog_capture       alc880_pcm_analog_capture
7112 #define alc882_pcm_digital_playback     alc880_pcm_digital_playback
7113 #define alc882_pcm_digital_capture      alc880_pcm_digital_capture
7114
7115 /*
7116  * configuration and preset
7117  */
7118 static const char *alc882_models[ALC882_MODEL_LAST] = {
7119         [ALC882_3ST_DIG]        = "3stack-dig",
7120         [ALC882_6ST_DIG]        = "6stack-dig",
7121         [ALC882_ARIMA]          = "arima",
7122         [ALC882_W2JC]           = "w2jc",
7123         [ALC882_TARGA]          = "targa",
7124         [ALC882_ASUS_A7J]       = "asus-a7j",
7125         [ALC882_ASUS_A7M]       = "asus-a7m",
7126         [ALC885_MACPRO]         = "macpro",
7127         [ALC885_MB5]            = "mb5",
7128         [ALC885_MBP3]           = "mbp3",
7129         [ALC885_IMAC24]         = "imac24",
7130         [ALC882_AUTO]           = "auto",
7131 };
7132
7133 static struct snd_pci_quirk alc882_cfg_tbl[] = {
7134         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),
7135         SND_PCI_QUIRK(0x1043, 0x060d, "Asus A7J", ALC882_ASUS_A7J),
7136         SND_PCI_QUIRK(0x1043, 0x1243, "Asus A7J", ALC882_ASUS_A7J),
7137         SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_ASUS_A7M),
7138         SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_W2JC),
7139         SND_PCI_QUIRK(0x1043, 0x817f, "Asus P5LD2", ALC882_6ST_DIG),
7140         SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
7141         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
7142         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte P35 DS3R", ALC882_6ST_DIG),
7143         SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8  */
7144         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
7145         SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA),
7146         {}
7147 };
7148
7149 static struct alc_config_preset alc882_presets[] = {
7150         [ALC882_3ST_DIG] = {
7151                 .mixers = { alc882_base_mixer },
7152                 .init_verbs = { alc882_init_verbs },
7153                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7154                 .dac_nids = alc882_dac_nids,
7155                 .dig_out_nid = ALC882_DIGOUT_NID,
7156                 .dig_in_nid = ALC882_DIGIN_NID,
7157                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
7158                 .channel_mode = alc882_ch_modes,
7159                 .need_dac_fix = 1,
7160                 .input_mux = &alc882_capture_source,
7161         },
7162         [ALC882_6ST_DIG] = {
7163                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
7164                 .init_verbs = { alc882_init_verbs },
7165                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7166                 .dac_nids = alc882_dac_nids,
7167                 .dig_out_nid = ALC882_DIGOUT_NID,
7168                 .dig_in_nid = ALC882_DIGIN_NID,
7169                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
7170                 .channel_mode = alc882_sixstack_modes,
7171                 .input_mux = &alc882_capture_source,
7172         },
7173         [ALC882_ARIMA] = {
7174                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
7175                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs },
7176                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7177                 .dac_nids = alc882_dac_nids,
7178                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
7179                 .channel_mode = alc882_sixstack_modes,
7180                 .input_mux = &alc882_capture_source,
7181         },
7182         [ALC882_W2JC] = {
7183                 .mixers = { alc882_w2jc_mixer, alc882_chmode_mixer },
7184                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
7185                                 alc880_gpio1_init_verbs },
7186                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7187                 .dac_nids = alc882_dac_nids,
7188                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
7189                 .channel_mode = alc880_threestack_modes,
7190                 .need_dac_fix = 1,
7191                 .input_mux = &alc882_capture_source,
7192                 .dig_out_nid = ALC882_DIGOUT_NID,
7193         },
7194         [ALC885_MBP3] = {
7195                 .mixers = { alc885_mbp3_mixer, alc882_chmode_mixer },
7196                 .init_verbs = { alc885_mbp3_init_verbs,
7197                                 alc880_gpio1_init_verbs },
7198                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7199                 .dac_nids = alc882_dac_nids,
7200                 .channel_mode = alc885_mbp_6ch_modes,
7201                 .num_channel_mode = ARRAY_SIZE(alc885_mbp_6ch_modes),
7202                 .input_mux = &alc882_capture_source,
7203                 .dig_out_nid = ALC882_DIGOUT_NID,
7204                 .dig_in_nid = ALC882_DIGIN_NID,
7205                 .unsol_event = alc_automute_amp_unsol_event,
7206                 .init_hook = alc885_mbp3_init_hook,
7207         },
7208         [ALC885_MB5] = {
7209                 .mixers = { alc885_mb5_mixer, alc882_chmode_mixer },
7210                 .init_verbs = { alc885_mb5_init_verbs,
7211                                 alc880_gpio1_init_verbs },
7212                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7213                 .dac_nids = alc882_dac_nids,
7214                 .channel_mode = alc885_mb5_6ch_modes,
7215                 .num_channel_mode = ARRAY_SIZE(alc885_mb5_6ch_modes),
7216                 .input_mux = &mb5_capture_source,
7217                 .dig_out_nid = ALC882_DIGOUT_NID,
7218                 .dig_in_nid = ALC882_DIGIN_NID,
7219         },
7220         [ALC885_MACPRO] = {
7221                 .mixers = { alc882_macpro_mixer },
7222                 .init_verbs = { alc882_macpro_init_verbs },
7223                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7224                 .dac_nids = alc882_dac_nids,
7225                 .dig_out_nid = ALC882_DIGOUT_NID,
7226                 .dig_in_nid = ALC882_DIGIN_NID,
7227                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
7228                 .channel_mode = alc882_ch_modes,
7229                 .input_mux = &alc882_capture_source,
7230                 .init_hook = alc885_macpro_init_hook,
7231         },
7232         [ALC885_IMAC24] = {
7233                 .mixers = { alc885_imac24_mixer },
7234                 .init_verbs = { alc885_imac24_init_verbs },
7235                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7236                 .dac_nids = alc882_dac_nids,
7237                 .dig_out_nid = ALC882_DIGOUT_NID,
7238                 .dig_in_nid = ALC882_DIGIN_NID,
7239                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
7240                 .channel_mode = alc882_ch_modes,
7241                 .input_mux = &alc882_capture_source,
7242                 .unsol_event = alc_automute_amp_unsol_event,
7243                 .init_hook = alc885_imac24_init_hook,
7244         },
7245         [ALC882_TARGA] = {
7246                 .mixers = { alc882_targa_mixer, alc882_chmode_mixer },
7247                 .init_verbs = { alc882_init_verbs, alc880_gpio3_init_verbs,
7248                                 alc882_targa_verbs},
7249                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7250                 .dac_nids = alc882_dac_nids,
7251                 .dig_out_nid = ALC882_DIGOUT_NID,
7252                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
7253                 .adc_nids = alc882_adc_nids,
7254                 .capsrc_nids = alc882_capsrc_nids,
7255                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
7256                 .channel_mode = alc882_3ST_6ch_modes,
7257                 .need_dac_fix = 1,
7258                 .input_mux = &alc882_capture_source,
7259                 .unsol_event = alc882_targa_unsol_event,
7260                 .init_hook = alc882_targa_init_hook,
7261         },
7262         [ALC882_ASUS_A7J] = {
7263                 .mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer },
7264                 .init_verbs = { alc882_init_verbs, alc882_asus_a7j_verbs},
7265                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7266                 .dac_nids = alc882_dac_nids,
7267                 .dig_out_nid = ALC882_DIGOUT_NID,
7268                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
7269                 .adc_nids = alc882_adc_nids,
7270                 .capsrc_nids = alc882_capsrc_nids,
7271                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
7272                 .channel_mode = alc882_3ST_6ch_modes,
7273                 .need_dac_fix = 1,
7274                 .input_mux = &alc882_capture_source,
7275         },
7276         [ALC882_ASUS_A7M] = {
7277                 .mixers = { alc882_asus_a7m_mixer, alc882_chmode_mixer },
7278                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
7279                                 alc880_gpio1_init_verbs,
7280                                 alc882_asus_a7m_verbs },
7281                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7282                 .dac_nids = alc882_dac_nids,
7283                 .dig_out_nid = ALC882_DIGOUT_NID,
7284                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
7285                 .channel_mode = alc880_threestack_modes,
7286                 .need_dac_fix = 1,
7287                 .input_mux = &alc882_capture_source,
7288         },
7289 };
7290
7291
7292 /*
7293  * Pin config fixes
7294  */
7295 enum {
7296         PINFIX_ABIT_AW9D_MAX
7297 };
7298
7299 static struct alc_pincfg alc882_abit_aw9d_pinfix[] = {
7300         { 0x15, 0x01080104 }, /* side */
7301         { 0x16, 0x01011012 }, /* rear */
7302         { 0x17, 0x01016011 }, /* clfe */
7303         { }
7304 };
7305
7306 static const struct alc_pincfg *alc882_pin_fixes[] = {
7307         [PINFIX_ABIT_AW9D_MAX] = alc882_abit_aw9d_pinfix,
7308 };
7309
7310 static struct snd_pci_quirk alc882_pinfix_tbl[] = {
7311         SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
7312         {}
7313 };
7314
7315 /*
7316  * BIOS auto configuration
7317  */
7318 static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
7319                                               hda_nid_t nid, int pin_type,
7320                                               int dac_idx)
7321 {
7322         /* set as output */
7323         struct alc_spec *spec = codec->spec;
7324         int idx;
7325
7326         alc_set_pin_output(codec, nid, pin_type);
7327         if (spec->multiout.dac_nids[dac_idx] == 0x25)
7328                 idx = 4;
7329         else
7330                 idx = spec->multiout.dac_nids[dac_idx] - 2;
7331         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
7332
7333 }
7334
7335 static void alc882_auto_init_multi_out(struct hda_codec *codec)
7336 {
7337         struct alc_spec *spec = codec->spec;
7338         int i;
7339
7340         for (i = 0; i <= HDA_SIDE; i++) {
7341                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
7342                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
7343                 if (nid)
7344                         alc882_auto_set_output_and_unmute(codec, nid, pin_type,
7345                                                           i);
7346         }
7347 }
7348
7349 static void alc882_auto_init_hp_out(struct hda_codec *codec)
7350 {
7351         struct alc_spec *spec = codec->spec;
7352         hda_nid_t pin;
7353
7354         pin = spec->autocfg.hp_pins[0];
7355         if (pin) /* connect to front */
7356                 /* use dac 0 */
7357                 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
7358         pin = spec->autocfg.speaker_pins[0];
7359         if (pin)
7360                 alc882_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
7361 }
7362
7363 #define alc882_is_input_pin(nid)        alc880_is_input_pin(nid)
7364 #define ALC882_PIN_CD_NID               ALC880_PIN_CD_NID
7365
7366 static void alc882_auto_init_analog_input(struct hda_codec *codec)
7367 {
7368         struct alc_spec *spec = codec->spec;
7369         int i;
7370
7371         for (i = 0; i < AUTO_PIN_LAST; i++) {
7372                 hda_nid_t nid = spec->autocfg.input_pins[i];
7373                 if (!nid)
7374                         continue;
7375                 alc_set_input_pin(codec, nid, AUTO_PIN_FRONT_MIC /*i*/);
7376                 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
7377                         snd_hda_codec_write(codec, nid, 0,
7378                                             AC_VERB_SET_AMP_GAIN_MUTE,
7379                                             AMP_OUT_MUTE);
7380         }
7381 }
7382
7383 static void alc882_auto_init_input_src(struct hda_codec *codec)
7384 {
7385         struct alc_spec *spec = codec->spec;
7386         int c;
7387
7388         for (c = 0; c < spec->num_adc_nids; c++) {
7389                 hda_nid_t conn_list[HDA_MAX_NUM_INPUTS];
7390                 hda_nid_t nid = spec->capsrc_nids[c];
7391                 unsigned int mux_idx;
7392                 const struct hda_input_mux *imux;
7393                 int conns, mute, idx, item;
7394
7395                 conns = snd_hda_get_connections(codec, nid, conn_list,
7396                                                 ARRAY_SIZE(conn_list));
7397                 if (conns < 0)
7398                         continue;
7399                 mux_idx = c >= spec->num_mux_defs ? 0 : c;
7400                 imux = &spec->input_mux[mux_idx];
7401                 for (idx = 0; idx < conns; idx++) {
7402                         /* if the current connection is the selected one,
7403                          * unmute it as default - otherwise mute it
7404                          */
7405                         mute = AMP_IN_MUTE(idx);
7406                         for (item = 0; item < imux->num_items; item++) {
7407                                 if (imux->items[item].index == idx) {
7408                                         if (spec->cur_mux[c] == item)
7409                                                 mute = AMP_IN_UNMUTE(idx);
7410                                         break;
7411                                 }
7412                         }
7413                         /* check if we have a selector or mixer
7414                          * we could check for the widget type instead, but
7415                          * just check for Amp-In presence (in case of mixer
7416                          * without amp-in there is something wrong, this
7417                          * function shouldn't be used or capsrc nid is wrong)
7418                          */
7419                         if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)
7420                                 snd_hda_codec_write(codec, nid, 0,
7421                                                     AC_VERB_SET_AMP_GAIN_MUTE,
7422                                                     mute);
7423                         else if (mute != AMP_IN_MUTE(idx))
7424                                 snd_hda_codec_write(codec, nid, 0,
7425                                                     AC_VERB_SET_CONNECT_SEL,
7426                                                     idx);
7427                 }
7428         }
7429 }
7430
7431 /* add mic boosts if needed */
7432 static int alc_auto_add_mic_boost(struct hda_codec *codec)
7433 {
7434         struct alc_spec *spec = codec->spec;
7435         int err;
7436         hda_nid_t nid;
7437
7438         nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
7439         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
7440                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
7441                                   "Mic Boost",
7442                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
7443                 if (err < 0)
7444                         return err;
7445         }
7446         nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
7447         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
7448                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
7449                                   "Front Mic Boost",
7450                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
7451                 if (err < 0)
7452                         return err;
7453         }
7454         return 0;
7455 }
7456
7457 /* almost identical with ALC880 parser... */
7458 static int alc882_parse_auto_config(struct hda_codec *codec)
7459 {
7460         struct alc_spec *spec = codec->spec;
7461         int err = alc880_parse_auto_config(codec);
7462
7463         if (err < 0)
7464                 return err;
7465         else if (!err)
7466                 return 0; /* no config found */
7467
7468         err = alc_auto_add_mic_boost(codec);
7469         if (err < 0)
7470                 return err;
7471
7472         /* hack - override the init verbs */
7473         spec->init_verbs[0] = alc882_auto_init_verbs;
7474
7475         return 1; /* config found */
7476 }
7477
7478 /* additional initialization for auto-configuration model */
7479 static void alc882_auto_init(struct hda_codec *codec)
7480 {
7481         struct alc_spec *spec = codec->spec;
7482         alc882_auto_init_multi_out(codec);
7483         alc882_auto_init_hp_out(codec);
7484         alc882_auto_init_analog_input(codec);
7485         alc882_auto_init_input_src(codec);
7486         if (spec->unsol_event)
7487                 alc_inithook(codec);
7488 }
7489
7490 static int patch_alc883(struct hda_codec *codec); /* called in patch_alc882() */
7491
7492 static int patch_alc882(struct hda_codec *codec)
7493 {
7494         struct alc_spec *spec;
7495         int err, board_config;
7496
7497         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
7498         if (spec == NULL)
7499                 return -ENOMEM;
7500
7501         codec->spec = spec;
7502
7503         board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
7504                                                   alc882_models,
7505                                                   alc882_cfg_tbl);
7506
7507         if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
7508                 /* Pick up systems that don't supply PCI SSID */
7509                 switch (codec->subsystem_id) {
7510                 case 0x106b0c00: /* Mac Pro */
7511                         board_config = ALC885_MACPRO;
7512                         break;
7513                 case 0x106b1000: /* iMac 24 */
7514                 case 0x106b2800: /* AppleTV */
7515                 case 0x106b3e00: /* iMac 24 Aluminium */
7516                         board_config = ALC885_IMAC24;
7517                         break;
7518                 case 0x106b00a0: /* MacBookPro3,1 - Another revision */
7519                 case 0x106b00a1: /* Macbook (might be wrong - PCI SSID?) */
7520                 case 0x106b00a4: /* MacbookPro4,1 */
7521                 case 0x106b2c00: /* Macbook Pro rev3 */
7522                 /* Macbook 3.1 (0x106b3600) is handled by patch_alc883() */
7523                 case 0x106b3800: /* MacbookPro4,1 - latter revision */
7524                         board_config = ALC885_MBP3;
7525                         break;
7526                 case 0x106b3f00: /* Macbook 5,1 */
7527                 case 0x106b4000: /* Macbook Pro 5,1 - FIXME: HP jack sense
7528                                   *   seems not working, so apparently
7529                                   *   no perfect solution yet
7530                                   */
7531                         board_config = ALC885_MB5;
7532                         break;
7533                 default:
7534                         /* ALC889A is handled better as ALC888-compatible */
7535                         if (codec->revision_id == 0x100101 ||
7536                             codec->revision_id == 0x100103) {
7537                                 alc_free(codec);
7538                                 return patch_alc883(codec);
7539                         }
7540                         printk(KERN_INFO "hda_codec: Unknown model for %s, "
7541                                "trying auto-probe from BIOS...\n",
7542                                codec->chip_name);
7543                         board_config = ALC882_AUTO;
7544                 }
7545         }
7546
7547         alc_fix_pincfg(codec, alc882_pinfix_tbl, alc882_pin_fixes);
7548
7549         if (board_config == ALC882_AUTO) {
7550                 /* automatic parse from the BIOS config */
7551                 err = alc882_parse_auto_config(codec);
7552                 if (err < 0) {
7553                         alc_free(codec);
7554                         return err;
7555                 } else if (!err) {
7556                         printk(KERN_INFO
7557                                "hda_codec: Cannot set up configuration "
7558                                "from BIOS.  Using base mode...\n");
7559                         board_config = ALC882_3ST_DIG;
7560                 }
7561         }
7562
7563         err = snd_hda_attach_beep_device(codec, 0x1);
7564         if (err < 0) {
7565                 alc_free(codec);
7566                 return err;
7567         }
7568
7569         if (board_config != ALC882_AUTO)
7570                 setup_preset(spec, &alc882_presets[board_config]);
7571
7572         spec->stream_analog_playback = &alc882_pcm_analog_playback;
7573         spec->stream_analog_capture = &alc882_pcm_analog_capture;
7574         /* FIXME: setup DAC5 */
7575         /*spec->stream_analog_alt_playback = &alc880_pcm_analog_alt_playback;*/
7576         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
7577
7578         spec->stream_digital_playback = &alc882_pcm_digital_playback;
7579         spec->stream_digital_capture = &alc882_pcm_digital_capture;
7580
7581         if (!spec->adc_nids && spec->input_mux) {
7582                 /* check whether NID 0x07 is valid */
7583                 unsigned int wcap = get_wcaps(codec, 0x07);
7584                 /* get type */
7585                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
7586                 if (wcap != AC_WID_AUD_IN) {
7587                         spec->adc_nids = alc882_adc_nids_alt;
7588                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt);
7589                         spec->capsrc_nids = alc882_capsrc_nids_alt;
7590                 } else {
7591                         spec->adc_nids = alc882_adc_nids;
7592                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
7593                         spec->capsrc_nids = alc882_capsrc_nids;
7594                 }
7595         }
7596         set_capture_mixer(spec);
7597         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
7598
7599         spec->vmaster_nid = 0x0c;
7600
7601         codec->patch_ops = alc_patch_ops;
7602         if (board_config == ALC882_AUTO)
7603                 spec->init_hook = alc882_auto_init;
7604 #ifdef CONFIG_SND_HDA_POWER_SAVE
7605         if (!spec->loopback.amplist)
7606                 spec->loopback.amplist = alc882_loopbacks;
7607 #endif
7608         codec->proc_widget_hook = print_realtek_coef;
7609
7610         return 0;
7611 }
7612
7613 /*
7614  * ALC883 support
7615  *
7616  * ALC883 is almost identical with ALC880 but has cleaner and more flexible
7617  * configuration.  Each pin widget can choose any input DACs and a mixer.
7618  * Each ADC is connected from a mixer of all inputs.  This makes possible
7619  * 6-channel independent captures.
7620  *
7621  * In addition, an independent DAC for the multi-playback (not used in this
7622  * driver yet).
7623  */
7624 #define ALC883_DIGOUT_NID       0x06
7625 #define ALC883_DIGIN_NID        0x0a
7626
7627 #define ALC1200_DIGOUT_NID      0x10
7628
7629 static hda_nid_t alc883_dac_nids[4] = {
7630         /* front, rear, clfe, rear_surr */
7631         0x02, 0x03, 0x04, 0x05
7632 };
7633
7634 static hda_nid_t alc883_adc_nids[2] = {
7635         /* ADC1-2 */
7636         0x08, 0x09,
7637 };
7638
7639 static hda_nid_t alc883_adc_nids_alt[1] = {
7640         /* ADC1 */
7641         0x08,
7642 };
7643
7644 static hda_nid_t alc883_adc_nids_rev[2] = {
7645         /* ADC2-1 */
7646         0x09, 0x08
7647 };
7648
7649 #define alc889_adc_nids         alc880_adc_nids
7650
7651 static hda_nid_t alc883_capsrc_nids[2] = { 0x23, 0x22 };
7652
7653 static hda_nid_t alc883_capsrc_nids_rev[2] = { 0x22, 0x23 };
7654
7655 #define alc889_capsrc_nids      alc882_capsrc_nids
7656
7657 /* input MUX */
7658 /* FIXME: should be a matrix-type input source selection */
7659
7660 static struct hda_input_mux alc883_capture_source = {
7661         .num_items = 4,
7662         .items = {
7663                 { "Mic", 0x0 },
7664                 { "Front Mic", 0x1 },
7665                 { "Line", 0x2 },
7666                 { "CD", 0x4 },
7667         },
7668 };
7669
7670 static struct hda_input_mux alc883_3stack_6ch_intel = {
7671         .num_items = 4,
7672         .items = {
7673                 { "Mic", 0x1 },
7674                 { "Front Mic", 0x0 },
7675                 { "Line", 0x2 },
7676                 { "CD", 0x4 },
7677         },
7678 };
7679
7680 static struct hda_input_mux alc883_lenovo_101e_capture_source = {
7681         .num_items = 2,
7682         .items = {
7683                 { "Mic", 0x1 },
7684                 { "Line", 0x2 },
7685         },
7686 };
7687
7688 static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
7689         .num_items = 4,
7690         .items = {
7691                 { "Mic", 0x0 },
7692                 { "iMic", 0x1 },
7693                 { "Line", 0x2 },
7694                 { "CD", 0x4 },
7695         },
7696 };
7697
7698 static struct hda_input_mux alc883_fujitsu_pi2515_capture_source = {
7699         .num_items = 2,
7700         .items = {
7701                 { "Mic", 0x0 },
7702                 { "Int Mic", 0x1 },
7703         },
7704 };
7705
7706 static struct hda_input_mux alc883_lenovo_sky_capture_source = {
7707         .num_items = 3,
7708         .items = {
7709                 { "Mic", 0x0 },
7710                 { "Front Mic", 0x1 },
7711                 { "Line", 0x4 },
7712         },
7713 };
7714
7715 static struct hda_input_mux alc883_asus_eee1601_capture_source = {
7716         .num_items = 2,
7717         .items = {
7718                 { "Mic", 0x0 },
7719                 { "Line", 0x2 },
7720         },
7721 };
7722
7723 static struct hda_input_mux alc889A_mb31_capture_source = {
7724         .num_items = 2,
7725         .items = {
7726                 { "Mic", 0x0 },
7727                 /* Front Mic (0x01) unused */
7728                 { "Line", 0x2 },
7729                 /* Line 2 (0x03) unused */
7730                 /* CD (0x04) unsused? */
7731         },
7732 };
7733
7734 /*
7735  * 2ch mode
7736  */
7737 static struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
7738         { 2, NULL }
7739 };
7740
7741 /*
7742  * 2ch mode
7743  */
7744 static struct hda_verb alc883_3ST_ch2_init[] = {
7745         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7746         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7747         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7748         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7749         { } /* end */
7750 };
7751
7752 /*
7753  * 4ch mode
7754  */
7755 static struct hda_verb alc883_3ST_ch4_init[] = {
7756         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7757         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7758         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7759         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7760         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7761         { } /* end */
7762 };
7763
7764 /*
7765  * 6ch mode
7766  */
7767 static struct hda_verb alc883_3ST_ch6_init[] = {
7768         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7769         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7770         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
7771         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7772         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7773         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7774         { } /* end */
7775 };
7776
7777 static struct hda_channel_mode alc883_3ST_6ch_modes[3] = {
7778         { 2, alc883_3ST_ch2_init },
7779         { 4, alc883_3ST_ch4_init },
7780         { 6, alc883_3ST_ch6_init },
7781 };
7782
7783
7784 /*
7785  * 2ch mode
7786  */
7787 static struct hda_verb alc883_4ST_ch2_init[] = {
7788         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7789         { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7790         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7791         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7792         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7793         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7794         { } /* end */
7795 };
7796
7797 /*
7798  * 4ch mode
7799  */
7800 static struct hda_verb alc883_4ST_ch4_init[] = {
7801         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7802         { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7803         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7804         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7805         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7806         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7807         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7808         { } /* end */
7809 };
7810
7811 /*
7812  * 6ch mode
7813  */
7814 static struct hda_verb alc883_4ST_ch6_init[] = {
7815         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7816         { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7817         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7818         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7819         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
7820         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7821         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7822         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7823         { } /* end */
7824 };
7825
7826 /*
7827  * 8ch mode
7828  */
7829 static struct hda_verb alc883_4ST_ch8_init[] = {
7830         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7831         { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7832         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03 },
7833         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7834         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7835         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
7836         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7837         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7838         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7839         { } /* end */
7840 };
7841
7842 static struct hda_channel_mode alc883_4ST_8ch_modes[4] = {
7843         { 2, alc883_4ST_ch2_init },
7844         { 4, alc883_4ST_ch4_init },
7845         { 6, alc883_4ST_ch6_init },
7846         { 8, alc883_4ST_ch8_init },
7847 };
7848
7849
7850 /*
7851  * 2ch mode
7852  */
7853 static struct hda_verb alc883_3ST_ch2_intel_init[] = {
7854         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7855         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7856         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7857         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7858         { } /* end */
7859 };
7860
7861 /*
7862  * 4ch mode
7863  */
7864 static struct hda_verb alc883_3ST_ch4_intel_init[] = {
7865         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7866         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7867         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7868         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7869         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7870         { } /* end */
7871 };
7872
7873 /*
7874  * 6ch mode
7875  */
7876 static struct hda_verb alc883_3ST_ch6_intel_init[] = {
7877         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7878         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7879         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x02 },
7880         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7881         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7882         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7883         { } /* end */
7884 };
7885
7886 static struct hda_channel_mode alc883_3ST_6ch_intel_modes[3] = {
7887         { 2, alc883_3ST_ch2_intel_init },
7888         { 4, alc883_3ST_ch4_intel_init },
7889         { 6, alc883_3ST_ch6_intel_init },
7890 };
7891
7892 /*
7893  * 6ch mode
7894  */
7895 static struct hda_verb alc883_sixstack_ch6_init[] = {
7896         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
7897         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7898         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7899         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7900         { } /* end */
7901 };
7902
7903 /*
7904  * 8ch mode
7905  */
7906 static struct hda_verb alc883_sixstack_ch8_init[] = {
7907         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7908         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7909         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7910         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7911         { } /* end */
7912 };
7913
7914 static struct hda_channel_mode alc883_sixstack_modes[2] = {
7915         { 6, alc883_sixstack_ch6_init },
7916         { 8, alc883_sixstack_ch8_init },
7917 };
7918
7919 /* 2ch mode (Speaker:front, Subwoofer:CLFE, Line:input, Headphones:front) */
7920 static struct hda_verb alc889A_mb31_ch2_init[] = {
7921         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},             /* HP as front */
7922         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Subwoofer on */
7923         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},    /* Line as input */
7924         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},   /* Line off */
7925         { } /* end */
7926 };
7927
7928 /* 4ch mode (Speaker:front, Subwoofer:CLFE, Line:CLFE, Headphones:front) */
7929 static struct hda_verb alc889A_mb31_ch4_init[] = {
7930         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},             /* HP as front */
7931         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Subwoofer on */
7932         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},   /* Line as output */
7933         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Line on */
7934         { } /* end */
7935 };
7936
7937 /* 5ch mode (Speaker:front, Subwoofer:CLFE, Line:input, Headphones:rear) */
7938 static struct hda_verb alc889A_mb31_ch5_init[] = {
7939         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},             /* HP as rear */
7940         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Subwoofer on */
7941         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},    /* Line as input */
7942         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},   /* Line off */
7943         { } /* end */
7944 };
7945
7946 /* 6ch mode (Speaker:front, Subwoofer:off, Line:CLFE, Headphones:Rear) */
7947 static struct hda_verb alc889A_mb31_ch6_init[] = {
7948         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},             /* HP as front */
7949         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},   /* Subwoofer off */
7950         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},   /* Line as output */
7951         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Line on */
7952         { } /* end */
7953 };
7954
7955 static struct hda_channel_mode alc889A_mb31_6ch_modes[4] = {
7956         { 2, alc889A_mb31_ch2_init },
7957         { 4, alc889A_mb31_ch4_init },
7958         { 5, alc889A_mb31_ch5_init },
7959         { 6, alc889A_mb31_ch6_init },
7960 };
7961
7962 static struct hda_verb alc883_medion_eapd_verbs[] = {
7963         /* eanable EAPD on medion laptop */
7964         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7965         {0x20, AC_VERB_SET_PROC_COEF, 0x3070},
7966         { }
7967 };
7968
7969 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
7970  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
7971  */
7972
7973 static struct snd_kcontrol_new alc883_base_mixer[] = {
7974         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7975         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7976         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7977         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7978         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7979         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7980         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7981         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7982         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7983         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7984         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7985         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7986         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7987         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7988         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7989         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7990         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7991         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7992         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7993         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7994         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7995         { } /* end */
7996 };
7997
7998 static struct snd_kcontrol_new alc883_mitac_mixer[] = {
7999         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8000         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8001         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
8002         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
8003         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
8004         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
8005         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8006         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8007         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8008         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8009         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8010         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8011         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8012         { } /* end */
8013 };
8014
8015 static struct snd_kcontrol_new alc883_clevo_m720_mixer[] = {
8016         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8017         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
8018         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8019         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
8020         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8021         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8022         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8023         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8024         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
8025         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8026         { } /* end */
8027 };
8028
8029 static struct snd_kcontrol_new alc883_2ch_fujitsu_pi2515_mixer[] = {
8030         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8031         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
8032         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8033         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
8034         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8035         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8036         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8037         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8038         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
8039         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8040         { } /* end */
8041 };
8042
8043 static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
8044         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8045         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8046         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8047         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8048         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8049         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8050         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8051         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8052         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8053         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8054         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8055         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8056         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8057         { } /* end */
8058 };
8059
8060 static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
8061         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8062         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8063         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8064         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
8065         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
8066         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
8067         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
8068         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
8069         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8070         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8071         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8072         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8073         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8074         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8075         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8076         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8077         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8078         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8079         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8080         { } /* end */
8081 };
8082
8083 static struct snd_kcontrol_new alc883_3ST_6ch_intel_mixer[] = {
8084         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8085         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8086         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8087         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
8088         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
8089                               HDA_OUTPUT),
8090         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
8091         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
8092         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
8093         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8094         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8095         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8096         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8097         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8098         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8099         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
8100         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8101         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8102         HDA_CODEC_VOLUME("Front Mic Boost", 0x18, 0, HDA_INPUT),
8103         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8104         { } /* end */
8105 };
8106
8107 static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
8108         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8109         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8110         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8111         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
8112         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
8113         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
8114         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
8115         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
8116         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8117         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8118         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8119         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8120         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8121         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8122         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8123         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8124         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8125         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8126         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8127         { } /* end */
8128 };
8129
8130 static struct snd_kcontrol_new alc883_targa_mixer[] = {
8131         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8132         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8133         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8134         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8135         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
8136         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
8137         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
8138         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
8139         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
8140         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8141         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8142         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8143         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8144         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8145         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8146         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8147         { } /* end */
8148 };
8149
8150 static struct snd_kcontrol_new alc883_targa_2ch_mixer[] = {
8151         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8152         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8153         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8154         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8155         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8156         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8157         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8158         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8159         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8160         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
8161         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8162         { } /* end */
8163 };
8164
8165 static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
8166         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8167         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8168         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8169         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
8170         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8171         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8172         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8173         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8174         { } /* end */
8175 };
8176
8177 static struct snd_kcontrol_new alc883_lenovo_nb0763_mixer[] = {
8178         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8179         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
8180         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8181         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8182         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8183         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8184         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8185         HDA_CODEC_VOLUME("iMic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8186         HDA_CODEC_MUTE("iMic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8187         { } /* end */
8188 };
8189
8190 static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
8191         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8192         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8193         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8194         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8195         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8196         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8197         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8198         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8199         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8200         { } /* end */
8201 };
8202
8203 static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
8204         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8205         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8206         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8207         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8208         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8209         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8210         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8211         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8212         { } /* end */
8213 };
8214
8215 static struct snd_kcontrol_new alc888_acer_aspire_6530_mixer[] = {
8216         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8217         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8218         HDA_CODEC_VOLUME("LFE Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
8219         HDA_BIND_MUTE("LFE Playback Switch", 0x0f, 2, HDA_INPUT),
8220         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8221         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8222         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8223         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8224         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8225         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8226         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8227         { } /* end */
8228 };
8229
8230 static struct snd_kcontrol_new alc888_lenovo_sky_mixer[] = {
8231         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8232         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8233         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
8234         HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
8235         HDA_CODEC_VOLUME_MONO("Center Playback Volume",
8236                                                 0x0d, 1, 0x0, HDA_OUTPUT),
8237         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
8238         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
8239         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
8240         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
8241         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
8242         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8243         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8244         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8245         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8246         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8247         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8248         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8249         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8250         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8251         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8252         { } /* end */
8253 };
8254
8255 static struct snd_kcontrol_new alc889A_mb31_mixer[] = {
8256         /* Output mixers */
8257         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
8258         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
8259         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
8260         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 0x02, HDA_INPUT),
8261         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x00,
8262                 HDA_OUTPUT),
8263         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x02, HDA_INPUT),
8264         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x00, HDA_OUTPUT),
8265         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x02, HDA_INPUT),
8266         /* Output switches */
8267         HDA_CODEC_MUTE("Enable Speaker", 0x14, 0x00, HDA_OUTPUT),
8268         HDA_CODEC_MUTE("Enable Headphones", 0x15, 0x00, HDA_OUTPUT),
8269         HDA_CODEC_MUTE_MONO("Enable LFE", 0x16, 2, 0x00, HDA_OUTPUT),
8270         /* Boost mixers */
8271         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
8272         HDA_CODEC_VOLUME("Line Boost", 0x1a, 0x00, HDA_INPUT),
8273         /* Input mixers */
8274         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
8275         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
8276         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8277         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8278         { } /* end */
8279 };
8280
8281 static struct snd_kcontrol_new alc883_vaiott_mixer[] = {
8282         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8283         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8284         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8285         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8286         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
8287         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8288         { } /* end */
8289 };
8290
8291 static struct hda_bind_ctls alc883_bind_cap_vol = {
8292         .ops = &snd_hda_bind_vol,
8293         .values = {
8294                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
8295                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
8296                 0
8297         },
8298 };
8299
8300 static struct hda_bind_ctls alc883_bind_cap_switch = {
8301         .ops = &snd_hda_bind_sw,
8302         .values = {
8303                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
8304                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
8305                 0
8306         },
8307 };
8308
8309 static struct snd_kcontrol_new alc883_asus_eee1601_mixer[] = {
8310         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8311         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8312         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8313         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8314         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8315         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8316         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8317         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8318         { } /* end */
8319 };
8320
8321 static struct snd_kcontrol_new alc883_asus_eee1601_cap_mixer[] = {
8322         HDA_BIND_VOL("Capture Volume", &alc883_bind_cap_vol),
8323         HDA_BIND_SW("Capture Switch", &alc883_bind_cap_switch),
8324         {
8325                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8326                 /* .name = "Capture Source", */
8327                 .name = "Input Source",
8328                 .count = 1,
8329                 .info = alc_mux_enum_info,
8330                 .get = alc_mux_enum_get,
8331                 .put = alc_mux_enum_put,
8332         },
8333         { } /* end */
8334 };
8335
8336 static struct snd_kcontrol_new alc883_chmode_mixer[] = {
8337         {
8338                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8339                 .name = "Channel Mode",
8340                 .info = alc_ch_mode_info,
8341                 .get = alc_ch_mode_get,
8342                 .put = alc_ch_mode_put,
8343         },
8344         { } /* end */
8345 };
8346
8347 static struct hda_verb alc883_init_verbs[] = {
8348         /* ADC1: mute amp left and right */
8349         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8350         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8351         /* ADC2: mute amp left and right */
8352         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8353         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8354         /* Front mixer: unmute input/output amp left and right (volume = 0) */
8355         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8356         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8357         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8358         /* Rear mixer */
8359         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8360         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8361         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8362         /* CLFE mixer */
8363         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8364         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8365         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8366         /* Side mixer */
8367         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8368         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8369         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8370
8371         /* mute analog input loopbacks */
8372         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8373         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8374         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8375         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8376         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8377
8378         /* Front Pin: output 0 (0x0c) */
8379         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8380         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8381         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8382         /* Rear Pin: output 1 (0x0d) */
8383         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8384         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8385         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
8386         /* CLFE Pin: output 2 (0x0e) */
8387         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8388         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8389         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
8390         /* Side Pin: output 3 (0x0f) */
8391         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8392         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8393         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
8394         /* Mic (rear) pin: input vref at 80% */
8395         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
8396         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8397         /* Front Mic pin: input vref at 80% */
8398         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
8399         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8400         /* Line In pin: input */
8401         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
8402         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8403         /* Line-2 In: Headphone output (output 0 - 0x0c) */
8404         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8405         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8406         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8407         /* CD pin widget for input */
8408         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
8409
8410         /* FIXME: use matrix-type input source selection */
8411         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8412         /* Input mixer2 */
8413         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8414         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8415         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8416         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8417         /* Input mixer3 */
8418         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8419         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8420         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8421         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8422         { }
8423 };
8424
8425 /* toggle speaker-output according to the hp-jack state */
8426 static void alc883_mitac_init_hook(struct hda_codec *codec)
8427 {
8428         struct alc_spec *spec = codec->spec;
8429
8430         spec->autocfg.hp_pins[0] = 0x15;
8431         spec->autocfg.speaker_pins[0] = 0x14;
8432         spec->autocfg.speaker_pins[1] = 0x17;
8433         alc_automute_amp(codec);
8434 }
8435
8436 /* auto-toggle front mic */
8437 /*
8438 static void alc883_mitac_mic_automute(struct hda_codec *codec)
8439 {
8440         unsigned int present;
8441         unsigned char bits;
8442
8443         present = snd_hda_codec_read(codec, 0x18, 0,
8444                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8445         bits = present ? HDA_AMP_MUTE : 0;
8446         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
8447 }
8448 */
8449
8450 static struct hda_verb alc883_mitac_verbs[] = {
8451         /* HP */
8452         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8453         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8454         /* Subwoofer */
8455         {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
8456         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8457
8458         /* enable unsolicited event */
8459         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8460         /* {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN}, */
8461
8462         { } /* end */
8463 };
8464
8465 static struct hda_verb alc883_clevo_m720_verbs[] = {
8466         /* HP */
8467         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8468         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8469         /* Int speaker */
8470         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
8471         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8472
8473         /* enable unsolicited event */
8474         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8475         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
8476
8477         { } /* end */
8478 };
8479
8480 static struct hda_verb alc883_2ch_fujitsu_pi2515_verbs[] = {
8481         /* HP */
8482         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8483         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8484         /* Subwoofer */
8485         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
8486         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8487
8488         /* enable unsolicited event */
8489         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8490
8491         { } /* end */
8492 };
8493
8494 static struct hda_verb alc883_targa_verbs[] = {
8495         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8496         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8497
8498         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8499         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8500
8501 /* Connect Line-Out side jack (SPDIF) to Side */
8502         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8503         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8504         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
8505 /* Connect Mic jack to CLFE */
8506         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8507         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8508         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},
8509 /* Connect Line-in jack to Surround */
8510         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8511         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8512         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
8513 /* Connect HP out jack to Front */
8514         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8515         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8516         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8517
8518         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8519
8520         { } /* end */
8521 };
8522
8523 static struct hda_verb alc883_lenovo_101e_verbs[] = {
8524         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8525         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT|AC_USRSP_EN},
8526         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT|AC_USRSP_EN},
8527         { } /* end */
8528 };
8529
8530 static struct hda_verb alc883_lenovo_nb0763_verbs[] = {
8531         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8532         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8533         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8534         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8535         { } /* end */
8536 };
8537
8538 static struct hda_verb alc888_lenovo_ms7195_verbs[] = {
8539         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8540         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8541         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8542         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT | AC_USRSP_EN},
8543         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT    | AC_USRSP_EN},
8544         { } /* end */
8545 };
8546
8547 static struct hda_verb alc883_haier_w66_verbs[] = {
8548         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8549         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8550
8551         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8552
8553         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8554         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8555         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8556         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8557         { } /* end */
8558 };
8559
8560 static struct hda_verb alc888_lenovo_sky_verbs[] = {
8561         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8562         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8563         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8564         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8565         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8566         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8567         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
8568         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8569         { } /* end */
8570 };
8571
8572 static struct hda_verb alc888_6st_dell_verbs[] = {
8573         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8574         { }
8575 };
8576
8577 static struct hda_verb alc883_vaiott_verbs[] = {
8578         /* HP */
8579         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8580         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8581
8582         /* enable unsolicited event */
8583         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8584
8585         { } /* end */
8586 };
8587
8588 static void alc888_3st_hp_init_hook(struct hda_codec *codec)
8589 {
8590         struct alc_spec *spec = codec->spec;
8591
8592         spec->autocfg.hp_pins[0] = 0x1b;
8593         spec->autocfg.speaker_pins[0] = 0x14;
8594         spec->autocfg.speaker_pins[1] = 0x16;
8595         spec->autocfg.speaker_pins[2] = 0x18;
8596         alc_automute_amp(codec);
8597 }
8598
8599 static struct hda_verb alc888_3st_hp_verbs[] = {
8600         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
8601         {0x16, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Rear : output 1 (0x0d) */
8602         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},  /* CLFE : output 2 (0x0e) */
8603         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8604         { } /* end */
8605 };
8606
8607 /*
8608  * 2ch mode
8609  */
8610 static struct hda_verb alc888_3st_hp_2ch_init[] = {
8611         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
8612         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8613         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
8614         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8615         { } /* end */
8616 };
8617
8618 /*
8619  * 4ch mode
8620  */
8621 static struct hda_verb alc888_3st_hp_4ch_init[] = {
8622         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
8623         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8624         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8625         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8626         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x01 },
8627         { } /* end */
8628 };
8629
8630 /*
8631  * 6ch mode
8632  */
8633 static struct hda_verb alc888_3st_hp_6ch_init[] = {
8634         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8635         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8636         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
8637         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8638         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8639         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x01 },
8640         { } /* end */
8641 };
8642
8643 static struct hda_channel_mode alc888_3st_hp_modes[3] = {
8644         { 2, alc888_3st_hp_2ch_init },
8645         { 4, alc888_3st_hp_4ch_init },
8646         { 6, alc888_3st_hp_6ch_init },
8647 };
8648
8649 /* toggle front-jack and RCA according to the hp-jack state */
8650 static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
8651 {
8652         unsigned int present;
8653
8654         present = snd_hda_codec_read(codec, 0x1b, 0,
8655                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8656         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8657                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8658         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8659                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8660 }
8661
8662 /* toggle RCA according to the front-jack state */
8663 static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
8664 {
8665         unsigned int present;
8666
8667         present = snd_hda_codec_read(codec, 0x14, 0,
8668                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8669         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8670                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8671 }
8672
8673 static void alc883_lenovo_ms7195_unsol_event(struct hda_codec *codec,
8674                                              unsigned int res)
8675 {
8676         if ((res >> 26) == ALC880_HP_EVENT)
8677                 alc888_lenovo_ms7195_front_automute(codec);
8678         if ((res >> 26) == ALC880_FRONT_EVENT)
8679                 alc888_lenovo_ms7195_rca_automute(codec);
8680 }
8681
8682 static struct hda_verb alc883_medion_md2_verbs[] = {
8683         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8684         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8685
8686         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8687
8688         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8689         { } /* end */
8690 };
8691
8692 /* toggle speaker-output according to the hp-jack state */
8693 static void alc883_medion_md2_init_hook(struct hda_codec *codec)
8694 {
8695         struct alc_spec *spec = codec->spec;
8696
8697         spec->autocfg.hp_pins[0] = 0x14;
8698         spec->autocfg.speaker_pins[0] = 0x15;
8699         alc_automute_amp(codec);
8700 }
8701
8702 /* toggle speaker-output according to the hp-jack state */
8703 #define alc883_targa_init_hook          alc882_targa_init_hook
8704 #define alc883_targa_unsol_event        alc882_targa_unsol_event
8705
8706 static void alc883_clevo_m720_mic_automute(struct hda_codec *codec)
8707 {
8708         unsigned int present;
8709
8710         present = snd_hda_codec_read(codec, 0x18, 0,
8711                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8712         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
8713                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8714 }
8715
8716 static void alc883_clevo_m720_init_hook(struct hda_codec *codec)
8717 {
8718         struct alc_spec *spec = codec->spec;
8719
8720         spec->autocfg.hp_pins[0] = 0x15;
8721         spec->autocfg.speaker_pins[0] = 0x14;
8722         alc_automute_amp(codec);
8723         alc883_clevo_m720_mic_automute(codec);
8724 }
8725
8726 static void alc883_clevo_m720_unsol_event(struct hda_codec *codec,
8727                                            unsigned int res)
8728 {
8729         switch (res >> 26) {
8730         case ALC880_MIC_EVENT:
8731                 alc883_clevo_m720_mic_automute(codec);
8732                 break;
8733         default:
8734                 alc_automute_amp_unsol_event(codec, res);
8735                 break;
8736         }
8737 }
8738
8739 /* toggle speaker-output according to the hp-jack state */
8740 static void alc883_2ch_fujitsu_pi2515_init_hook(struct hda_codec *codec)
8741 {
8742         struct alc_spec *spec = codec->spec;
8743
8744         spec->autocfg.hp_pins[0] = 0x14;
8745         spec->autocfg.speaker_pins[0] = 0x15;
8746         alc_automute_amp(codec);
8747 }
8748
8749 static void alc883_haier_w66_init_hook(struct hda_codec *codec)
8750 {
8751         struct alc_spec *spec = codec->spec;
8752
8753         spec->autocfg.hp_pins[0] = 0x1b;
8754         spec->autocfg.speaker_pins[0] = 0x14;
8755         alc_automute_amp(codec);
8756 }
8757
8758 static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
8759 {
8760         unsigned int present;
8761         unsigned char bits;
8762
8763         present = snd_hda_codec_read(codec, 0x14, 0, AC_VERB_GET_PIN_SENSE, 0)
8764                 & AC_PINSENSE_PRESENCE;
8765         bits = present ? HDA_AMP_MUTE : 0;
8766         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8767                                  HDA_AMP_MUTE, bits);
8768 }
8769
8770 static void alc883_lenovo_101e_all_automute(struct hda_codec *codec)
8771 {
8772         unsigned int present;
8773         unsigned char bits;
8774
8775         present = snd_hda_codec_read(codec, 0x1b, 0,
8776                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8777         bits = present ? HDA_AMP_MUTE : 0;
8778         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8779                                  HDA_AMP_MUTE, bits);
8780         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8781                                  HDA_AMP_MUTE, bits);
8782 }
8783
8784 static void alc883_lenovo_101e_unsol_event(struct hda_codec *codec,
8785                                            unsigned int res)
8786 {
8787         if ((res >> 26) == ALC880_HP_EVENT)
8788                 alc883_lenovo_101e_all_automute(codec);
8789         if ((res >> 26) == ALC880_FRONT_EVENT)
8790                 alc883_lenovo_101e_ispeaker_automute(codec);
8791 }
8792
8793 /* toggle speaker-output according to the hp-jack state */
8794 static void alc883_acer_aspire_init_hook(struct hda_codec *codec)
8795 {
8796         struct alc_spec *spec = codec->spec;
8797
8798         spec->autocfg.hp_pins[0] = 0x14;
8799         spec->autocfg.speaker_pins[0] = 0x15;
8800         spec->autocfg.speaker_pins[1] = 0x16;
8801         alc_automute_amp(codec);
8802 }
8803
8804 static struct hda_verb alc883_acer_eapd_verbs[] = {
8805         /* HP Pin: output 0 (0x0c) */
8806         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8807         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8808         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8809         /* Front Pin: output 0 (0x0c) */
8810         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8811         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8812         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8813         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
8814         /* eanable EAPD on medion laptop */
8815         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
8816         {0x20, AC_VERB_SET_PROC_COEF, 0x3050},
8817         /* enable unsolicited event */
8818         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8819         { }
8820 };
8821
8822 static void alc888_6st_dell_init_hook(struct hda_codec *codec)
8823 {
8824         struct alc_spec *spec = codec->spec;
8825
8826         spec->autocfg.hp_pins[0] = 0x1b;
8827         spec->autocfg.speaker_pins[0] = 0x14;
8828         spec->autocfg.speaker_pins[1] = 0x15;
8829         spec->autocfg.speaker_pins[2] = 0x16;
8830         spec->autocfg.speaker_pins[3] = 0x17;
8831         alc_automute_amp(codec);
8832 }
8833
8834 static void alc888_lenovo_sky_init_hook(struct hda_codec *codec)
8835 {
8836         struct alc_spec *spec = codec->spec;
8837
8838         spec->autocfg.hp_pins[0] = 0x1b;
8839         spec->autocfg.speaker_pins[0] = 0x14;
8840         spec->autocfg.speaker_pins[1] = 0x15;
8841         spec->autocfg.speaker_pins[2] = 0x16;
8842         spec->autocfg.speaker_pins[3] = 0x17;
8843         spec->autocfg.speaker_pins[4] = 0x1a;
8844         alc_automute_amp(codec);
8845 }
8846
8847 static void alc883_vaiott_init_hook(struct hda_codec *codec)
8848 {
8849         struct alc_spec *spec = codec->spec;
8850
8851         spec->autocfg.hp_pins[0] = 0x15;
8852         spec->autocfg.speaker_pins[0] = 0x14;
8853         spec->autocfg.speaker_pins[1] = 0x17;
8854         alc_automute_amp(codec);
8855 }
8856
8857 /*
8858  * generic initialization of ADC, input mixers and output mixers
8859  */
8860 static struct hda_verb alc883_auto_init_verbs[] = {
8861         /*
8862          * Unmute ADC0-2 and set the default input to mic-in
8863          */
8864         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8865         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8866         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8867         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8868
8869         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
8870          * mixer widget
8871          * Note: PASD motherboards uses the Line In 2 as the input for
8872          * front panel mic (mic 2)
8873          */
8874         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
8875         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8876         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8877         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8878         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8879         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8880
8881         /*
8882          * Set up output mixers (0x0c - 0x0f)
8883          */
8884         /* set vol=0 to output mixers */
8885         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8886         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8887         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8888         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8889         /* set up input amps for analog loopback */
8890         /* Amp Indices: DAC = 0, mixer = 1 */
8891         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8892         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8893         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8894         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8895         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8896         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8897         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8898         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8899         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8900         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8901
8902         /* FIXME: use matrix-type input source selection */
8903         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8904         /* Input mixer1 */
8905         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8906         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8907         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8908         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
8909         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
8910         /* Input mixer2 */
8911         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8912         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8913         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8914         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
8915         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
8916
8917         { }
8918 };
8919
8920 static struct hda_verb alc888_asus_m90v_verbs[] = {
8921         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8922         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8923         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8924         /* enable unsolicited event */
8925         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8926         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
8927         { } /* end */
8928 };
8929
8930 static void alc883_nb_mic_automute(struct hda_codec *codec)
8931 {
8932         unsigned int present;
8933
8934         present = snd_hda_codec_read(codec, 0x18, 0,
8935                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8936         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
8937                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
8938         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
8939                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
8940 }
8941
8942 static void alc883_M90V_init_hook(struct hda_codec *codec)
8943 {
8944         struct alc_spec *spec = codec->spec;
8945
8946         spec->autocfg.hp_pins[0] = 0x1b;
8947         spec->autocfg.speaker_pins[0] = 0x14;
8948         spec->autocfg.speaker_pins[1] = 0x15;
8949         spec->autocfg.speaker_pins[2] = 0x16;
8950         alc_automute_pin(codec);
8951 }
8952
8953 static void alc883_mode2_unsol_event(struct hda_codec *codec,
8954                                            unsigned int res)
8955 {
8956         switch (res >> 26) {
8957         case ALC880_MIC_EVENT:
8958                 alc883_nb_mic_automute(codec);
8959                 break;
8960         default:
8961                 alc_sku_unsol_event(codec, res);
8962                 break;
8963         }
8964 }
8965
8966 static void alc883_mode2_inithook(struct hda_codec *codec)
8967 {
8968         alc883_M90V_init_hook(codec);
8969         alc883_nb_mic_automute(codec);
8970 }
8971
8972 static struct hda_verb alc888_asus_eee1601_verbs[] = {
8973         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8974         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8975         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8976         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8977         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8978         {0x20, AC_VERB_SET_COEF_INDEX, 0x0b},
8979         {0x20, AC_VERB_SET_PROC_COEF,  0x0838},
8980         /* enable unsolicited event */
8981         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8982         { } /* end */
8983 };
8984
8985 static void alc883_eee1601_inithook(struct hda_codec *codec)
8986 {
8987         struct alc_spec *spec = codec->spec;
8988
8989         spec->autocfg.hp_pins[0] = 0x14;
8990         spec->autocfg.speaker_pins[0] = 0x1b;
8991         alc_automute_pin(codec);
8992 }
8993
8994 static struct hda_verb alc889A_mb31_verbs[] = {
8995         /* Init rear pin (used as headphone output) */
8996         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},    /* Apple Headphones */
8997         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},           /* Connect to front */
8998         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8999         /* Init line pin (used as output in 4ch and 6ch mode) */
9000         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x02},           /* Connect to CLFE */
9001         /* Init line 2 pin (used as headphone out by default) */
9002         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},  /* Use as input */
9003         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Mute output */
9004         { } /* end */
9005 };
9006
9007 /* Mute speakers according to the headphone jack state */
9008 static void alc889A_mb31_automute(struct hda_codec *codec)
9009 {
9010         unsigned int present;
9011
9012         /* Mute only in 2ch or 4ch mode */
9013         if (snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_CONNECT_SEL, 0)
9014             == 0x00) {
9015                 present = snd_hda_codec_read(codec, 0x15, 0,
9016                         AC_VERB_GET_PIN_SENSE, 0) & AC_PINSENSE_PRESENCE;
9017                 snd_hda_codec_amp_stereo(codec, 0x14,  HDA_OUTPUT, 0,
9018                         HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
9019                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
9020                         HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
9021         }
9022 }
9023
9024 static void alc889A_mb31_unsol_event(struct hda_codec *codec, unsigned int res)
9025 {
9026         if ((res >> 26) == ALC880_HP_EVENT)
9027                 alc889A_mb31_automute(codec);
9028 }
9029
9030 #ifdef CONFIG_SND_HDA_POWER_SAVE
9031 #define alc883_loopbacks        alc880_loopbacks
9032 #endif
9033
9034 /* pcm configuration: identical with ALC880 */
9035 #define alc883_pcm_analog_playback      alc880_pcm_analog_playback
9036 #define alc883_pcm_analog_capture       alc880_pcm_analog_capture
9037 #define alc883_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
9038 #define alc883_pcm_digital_playback     alc880_pcm_digital_playback
9039 #define alc883_pcm_digital_capture      alc880_pcm_digital_capture
9040
9041 /*
9042  * configuration and preset
9043  */
9044 static const char *alc883_models[ALC883_MODEL_LAST] = {
9045         [ALC883_3ST_2ch_DIG]    = "3stack-dig",
9046         [ALC883_3ST_6ch_DIG]    = "3stack-6ch-dig",
9047         [ALC883_3ST_6ch]        = "3stack-6ch",
9048         [ALC883_6ST_DIG]        = "6stack-dig",
9049         [ALC883_TARGA_DIG]      = "targa-dig",
9050         [ALC883_TARGA_2ch_DIG]  = "targa-2ch-dig",
9051         [ALC883_TARGA_8ch_DIG]  = "targa-8ch-dig",
9052         [ALC883_ACER]           = "acer",
9053         [ALC883_ACER_ASPIRE]    = "acer-aspire",
9054         [ALC888_ACER_ASPIRE_4930G]      = "acer-aspire-4930g",
9055         [ALC888_ACER_ASPIRE_6530G]      = "acer-aspire-6530g",
9056         [ALC888_ACER_ASPIRE_8930G]      = "acer-aspire-8930g",
9057         [ALC883_MEDION]         = "medion",
9058         [ALC883_MEDION_MD2]     = "medion-md2",
9059         [ALC883_LAPTOP_EAPD]    = "laptop-eapd",
9060         [ALC883_LENOVO_101E_2ch] = "lenovo-101e",
9061         [ALC883_LENOVO_NB0763]  = "lenovo-nb0763",
9062         [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
9063         [ALC888_LENOVO_SKY] = "lenovo-sky",
9064         [ALC883_HAIER_W66]      = "haier-w66",
9065         [ALC888_3ST_HP]         = "3stack-hp",
9066         [ALC888_6ST_DELL]       = "6stack-dell",
9067         [ALC883_MITAC]          = "mitac",
9068         [ALC883_CLEVO_M720]     = "clevo-m720",
9069         [ALC883_FUJITSU_PI2515] = "fujitsu-pi2515",
9070         [ALC888_FUJITSU_XA3530] = "fujitsu-xa3530",
9071         [ALC883_3ST_6ch_INTEL]  = "3stack-6ch-intel",
9072         [ALC1200_ASUS_P5Q]      = "asus-p5q",
9073         [ALC889A_MB31]          = "mb31",
9074         [ALC883_SONY_VAIO_TT]   = "sony-vaio-tt",
9075         [ALC883_AUTO]           = "auto",
9076 };
9077
9078 static struct snd_pci_quirk alc883_cfg_tbl[] = {
9079         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC883_3ST_6ch_DIG),
9080         SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE),
9081         SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_ACER_ASPIRE),
9082         SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_ACER_ASPIRE),
9083         SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE),
9084         SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE),
9085         SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_ACER_ASPIRE),
9086         SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
9087                 ALC888_ACER_ASPIRE_4930G),
9088         SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
9089                 ALC888_ACER_ASPIRE_4930G),
9090         SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
9091                 ALC888_ACER_ASPIRE_8930G),
9092         SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
9093                 ALC888_ACER_ASPIRE_8930G),
9094         SND_PCI_QUIRK(0x1025, 0x0157, "Acer X3200", ALC883_AUTO),
9095         SND_PCI_QUIRK(0x1025, 0x0158, "Acer AX1700-U3700A", ALC883_AUTO),
9096         SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
9097                 ALC888_ACER_ASPIRE_6530G),
9098         SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
9099                 ALC888_ACER_ASPIRE_6530G),
9100         /* default Acer -- disabled as it causes more problems.
9101          *    model=auto should work fine now
9102          */
9103         /* SND_PCI_QUIRK_VENDOR(0x1025, "Acer laptop", ALC883_ACER), */
9104         SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL),
9105         SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
9106         SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
9107         SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
9108         SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG),
9109         SND_PCI_QUIRK(0x103c, 0x2a66, "HP Acacia", ALC888_3ST_HP),
9110         SND_PCI_QUIRK(0x103c, 0x2a72, "HP Educ.ar", ALC888_3ST_HP),
9111         SND_PCI_QUIRK(0x1043, 0x1873, "Asus M90V", ALC888_ASUS_M90V),
9112         SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG),
9113         SND_PCI_QUIRK(0x1043, 0x8284, "Asus Z37E", ALC883_6ST_DIG),
9114         SND_PCI_QUIRK(0x1043, 0x82fe, "Asus P5Q-EM HDMI", ALC1200_ASUS_P5Q),
9115         SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_ASUS_EEE1601),
9116         SND_PCI_QUIRK(0x105b, 0x0ce8, "Foxconn P35AX-S", ALC883_6ST_DIG),
9117         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG),
9118         SND_PCI_QUIRK(0x1071, 0x8227, "Mitac 82801H", ALC883_MITAC),
9119         SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC),
9120         SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
9121         SND_PCI_QUIRK(0x10f1, 0x2350, "TYAN-S2350", ALC888_6ST_DELL),
9122         SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
9123         SND_PCI_QUIRK(0x1458, 0xa002, "MSI", ALC883_6ST_DIG),
9124         SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
9125         SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG),
9126         SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
9127         SND_PCI_QUIRK(0x1462, 0x2fb3, "MSI", ALC883_TARGA_2ch_DIG),
9128         SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
9129         SND_PCI_QUIRK(0x1462, 0x3783, "NEC S970", ALC883_TARGA_DIG),
9130         SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
9131         SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
9132         SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
9133         SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG),
9134         SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG),
9135         SND_PCI_QUIRK(0x1462, 0x3fdf, "MSI", ALC883_TARGA_DIG),
9136         SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
9137         SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
9138         SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
9139         SND_PCI_QUIRK(0x1462, 0x6510, "MSI GX620", ALC883_TARGA_8ch_DIG),
9140         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
9141         SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
9142         SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
9143         SND_PCI_QUIRK(0x1462, 0x7260, "MSI 7260", ALC883_TARGA_DIG),
9144         SND_PCI_QUIRK(0x1462, 0x7267, "MSI", ALC883_3ST_6ch_DIG),
9145         SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
9146         SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
9147         SND_PCI_QUIRK(0x1462, 0x7350, "MSI", ALC883_6ST_DIG),
9148         SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
9149         SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG),
9150         SND_PCI_QUIRK(0x1558, 0x0721, "Clevo laptop M720R", ALC883_CLEVO_M720),
9151         SND_PCI_QUIRK(0x1558, 0x0722, "Clevo laptop M720SR", ALC883_CLEVO_M720),
9152         SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC883_LAPTOP_EAPD),
9153         SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
9154         SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
9155         SND_PCI_QUIRK_MASK(0x1734, 0xfff0, 0x1100, "FSC AMILO Xi/Pi25xx",
9156                       ALC883_FUJITSU_PI2515),
9157         SND_PCI_QUIRK_MASK(0x1734, 0xfff0, 0x1130, "Fujitsu AMILO Xa35xx",
9158                 ALC888_FUJITSU_XA3530),
9159         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
9160         SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
9161         SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
9162         SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763),
9163         SND_PCI_QUIRK(0x17aa, 0x101d, "Lenovo Sky", ALC888_LENOVO_SKY),
9164         SND_PCI_QUIRK(0x17c0, 0x4071, "MEDION MD2", ALC883_MEDION_MD2),
9165         SND_PCI_QUIRK(0x17c0, 0x4085, "MEDION MD96630", ALC888_LENOVO_MS7195_DIG),
9166         SND_PCI_QUIRK(0x17f2, 0x5000, "Albatron KI690-AM2", ALC883_6ST_DIG),
9167         SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66),
9168         SND_PCI_QUIRK(0x8086, 0x0001, "DG33BUC", ALC883_3ST_6ch_INTEL),
9169         SND_PCI_QUIRK(0x8086, 0x0002, "DG33FBC", ALC883_3ST_6ch_INTEL),
9170         SND_PCI_QUIRK(0x8086, 0x2503, "82801H", ALC883_MITAC),
9171         SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC883_3ST_6ch_INTEL),
9172         SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch),
9173         SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC883_SONY_VAIO_TT),
9174         {}
9175 };
9176
9177 static hda_nid_t alc883_slave_dig_outs[] = {
9178         ALC1200_DIGOUT_NID, 0,
9179 };
9180
9181 static hda_nid_t alc1200_slave_dig_outs[] = {
9182         ALC883_DIGOUT_NID, 0,
9183 };
9184
9185 static struct alc_config_preset alc883_presets[] = {
9186         [ALC883_3ST_2ch_DIG] = {
9187                 .mixers = { alc883_3ST_2ch_mixer },
9188                 .init_verbs = { alc883_init_verbs },
9189                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9190                 .dac_nids = alc883_dac_nids,
9191                 .dig_out_nid = ALC883_DIGOUT_NID,
9192                 .dig_in_nid = ALC883_DIGIN_NID,
9193                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9194                 .channel_mode = alc883_3ST_2ch_modes,
9195                 .input_mux = &alc883_capture_source,
9196         },
9197         [ALC883_3ST_6ch_DIG] = {
9198                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9199                 .init_verbs = { alc883_init_verbs },
9200                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9201                 .dac_nids = alc883_dac_nids,
9202                 .dig_out_nid = ALC883_DIGOUT_NID,
9203                 .dig_in_nid = ALC883_DIGIN_NID,
9204                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9205                 .channel_mode = alc883_3ST_6ch_modes,
9206                 .need_dac_fix = 1,
9207                 .input_mux = &alc883_capture_source,
9208         },
9209         [ALC883_3ST_6ch] = {
9210                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9211                 .init_verbs = { alc883_init_verbs },
9212                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9213                 .dac_nids = alc883_dac_nids,
9214                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9215                 .channel_mode = alc883_3ST_6ch_modes,
9216                 .need_dac_fix = 1,
9217                 .input_mux = &alc883_capture_source,
9218         },
9219         [ALC883_3ST_6ch_INTEL] = {
9220                 .mixers = { alc883_3ST_6ch_intel_mixer, alc883_chmode_mixer },
9221                 .init_verbs = { alc883_init_verbs },
9222                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9223                 .dac_nids = alc883_dac_nids,
9224                 .dig_out_nid = ALC883_DIGOUT_NID,
9225                 .dig_in_nid = ALC883_DIGIN_NID,
9226                 .slave_dig_outs = alc883_slave_dig_outs,
9227                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_intel_modes),
9228                 .channel_mode = alc883_3ST_6ch_intel_modes,
9229                 .need_dac_fix = 1,
9230                 .input_mux = &alc883_3stack_6ch_intel,
9231         },
9232         [ALC883_6ST_DIG] = {
9233                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
9234                 .init_verbs = { alc883_init_verbs },
9235                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9236                 .dac_nids = alc883_dac_nids,
9237                 .dig_out_nid = ALC883_DIGOUT_NID,
9238                 .dig_in_nid = ALC883_DIGIN_NID,
9239                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9240                 .channel_mode = alc883_sixstack_modes,
9241                 .input_mux = &alc883_capture_source,
9242         },
9243         [ALC883_TARGA_DIG] = {
9244                 .mixers = { alc883_targa_mixer, alc883_chmode_mixer },
9245                 .init_verbs = { alc883_init_verbs, alc880_gpio3_init_verbs,
9246                                 alc883_targa_verbs},
9247                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9248                 .dac_nids = alc883_dac_nids,
9249                 .dig_out_nid = ALC883_DIGOUT_NID,
9250                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9251                 .channel_mode = alc883_3ST_6ch_modes,
9252                 .need_dac_fix = 1,
9253                 .input_mux = &alc883_capture_source,
9254                 .unsol_event = alc883_targa_unsol_event,
9255                 .init_hook = alc883_targa_init_hook,
9256         },
9257         [ALC883_TARGA_2ch_DIG] = {
9258                 .mixers = { alc883_targa_2ch_mixer},
9259                 .init_verbs = { alc883_init_verbs, alc880_gpio3_init_verbs,
9260                                 alc883_targa_verbs},
9261                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9262                 .dac_nids = alc883_dac_nids,
9263                 .adc_nids = alc883_adc_nids_alt,
9264                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
9265                 .dig_out_nid = ALC883_DIGOUT_NID,
9266                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9267                 .channel_mode = alc883_3ST_2ch_modes,
9268                 .input_mux = &alc883_capture_source,
9269                 .unsol_event = alc883_targa_unsol_event,
9270                 .init_hook = alc883_targa_init_hook,
9271         },
9272         [ALC883_TARGA_8ch_DIG] = {
9273                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
9274                 .init_verbs = { alc883_init_verbs, alc880_gpio3_init_verbs,
9275                                 alc883_targa_verbs },
9276                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9277                 .dac_nids = alc883_dac_nids,
9278                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
9279                 .adc_nids = alc883_adc_nids_rev,
9280                 .capsrc_nids = alc883_capsrc_nids_rev,
9281                 .dig_out_nid = ALC883_DIGOUT_NID,
9282                 .dig_in_nid = ALC883_DIGIN_NID,
9283                 .num_channel_mode = ARRAY_SIZE(alc883_4ST_8ch_modes),
9284                 .channel_mode = alc883_4ST_8ch_modes,
9285                 .need_dac_fix = 1,
9286                 .input_mux = &alc883_capture_source,
9287                 .unsol_event = alc883_targa_unsol_event,
9288                 .init_hook = alc883_targa_init_hook,
9289         },
9290         [ALC883_ACER] = {
9291                 .mixers = { alc883_base_mixer },
9292                 /* On TravelMate laptops, GPIO 0 enables the internal speaker
9293                  * and the headphone jack.  Turn this on and rely on the
9294                  * standard mute methods whenever the user wants to turn
9295                  * these outputs off.
9296                  */
9297                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
9298                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9299                 .dac_nids = alc883_dac_nids,
9300                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9301                 .channel_mode = alc883_3ST_2ch_modes,
9302                 .input_mux = &alc883_capture_source,
9303         },
9304         [ALC883_ACER_ASPIRE] = {
9305                 .mixers = { alc883_acer_aspire_mixer },
9306                 .init_verbs = { alc883_init_verbs, alc883_acer_eapd_verbs },
9307                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9308                 .dac_nids = alc883_dac_nids,
9309                 .dig_out_nid = ALC883_DIGOUT_NID,
9310                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9311                 .channel_mode = alc883_3ST_2ch_modes,
9312                 .input_mux = &alc883_capture_source,
9313                 .unsol_event = alc_automute_amp_unsol_event,
9314                 .init_hook = alc883_acer_aspire_init_hook,
9315         },
9316         [ALC888_ACER_ASPIRE_4930G] = {
9317                 .mixers = { alc888_base_mixer,
9318                                 alc883_chmode_mixer },
9319                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
9320                                 alc888_acer_aspire_4930g_verbs },
9321                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9322                 .dac_nids = alc883_dac_nids,
9323                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
9324                 .adc_nids = alc883_adc_nids_rev,
9325                 .capsrc_nids = alc883_capsrc_nids_rev,
9326                 .dig_out_nid = ALC883_DIGOUT_NID,
9327                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9328                 .channel_mode = alc883_3ST_6ch_modes,
9329                 .need_dac_fix = 1,
9330                 .num_mux_defs =
9331                         ARRAY_SIZE(alc888_2_capture_sources),
9332                 .input_mux = alc888_2_capture_sources,
9333                 .unsol_event = alc_automute_amp_unsol_event,
9334                 .init_hook = alc888_acer_aspire_4930g_init_hook,
9335         },
9336         [ALC888_ACER_ASPIRE_6530G] = {
9337                 .mixers = { alc888_acer_aspire_6530_mixer },
9338                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
9339                                 alc888_acer_aspire_6530g_verbs },
9340                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9341                 .dac_nids = alc883_dac_nids,
9342                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
9343                 .adc_nids = alc883_adc_nids_rev,
9344                 .capsrc_nids = alc883_capsrc_nids_rev,
9345                 .dig_out_nid = ALC883_DIGOUT_NID,
9346                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9347                 .channel_mode = alc883_3ST_2ch_modes,
9348                 .num_mux_defs =
9349                         ARRAY_SIZE(alc888_2_capture_sources),
9350                 .input_mux = alc888_acer_aspire_6530_sources,
9351                 .unsol_event = alc_automute_amp_unsol_event,
9352                 .init_hook = alc888_acer_aspire_6530g_init_hook,
9353         },
9354         [ALC888_ACER_ASPIRE_8930G] = {
9355                 .mixers = { alc888_base_mixer,
9356                                 alc883_chmode_mixer },
9357                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
9358                                 alc889_acer_aspire_8930g_verbs },
9359                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9360                 .dac_nids = alc883_dac_nids,
9361                 .num_adc_nids = ARRAY_SIZE(alc889_adc_nids),
9362                 .adc_nids = alc889_adc_nids,
9363                 .capsrc_nids = alc889_capsrc_nids,
9364                 .dig_out_nid = ALC883_DIGOUT_NID,
9365                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9366                 .channel_mode = alc883_3ST_6ch_modes,
9367                 .need_dac_fix = 1,
9368                 .const_channel_count = 6,
9369                 .num_mux_defs =
9370                         ARRAY_SIZE(alc889_capture_sources),
9371                 .input_mux = alc889_capture_sources,
9372                 .unsol_event = alc_automute_amp_unsol_event,
9373                 .init_hook = alc889_acer_aspire_8930g_init_hook,
9374         },
9375         [ALC883_MEDION] = {
9376                 .mixers = { alc883_fivestack_mixer,
9377                             alc883_chmode_mixer },
9378                 .init_verbs = { alc883_init_verbs,
9379                                 alc883_medion_eapd_verbs },
9380                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9381                 .dac_nids = alc883_dac_nids,
9382                 .adc_nids = alc883_adc_nids_alt,
9383                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
9384                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9385                 .channel_mode = alc883_sixstack_modes,
9386                 .input_mux = &alc883_capture_source,
9387         },
9388         [ALC883_MEDION_MD2] = {
9389                 .mixers = { alc883_medion_md2_mixer},
9390                 .init_verbs = { alc883_init_verbs, alc883_medion_md2_verbs},
9391                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9392                 .dac_nids = alc883_dac_nids,
9393                 .dig_out_nid = ALC883_DIGOUT_NID,
9394                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9395                 .channel_mode = alc883_3ST_2ch_modes,
9396                 .input_mux = &alc883_capture_source,
9397                 .unsol_event = alc_automute_amp_unsol_event,
9398                 .init_hook = alc883_medion_md2_init_hook,
9399         },
9400         [ALC883_LAPTOP_EAPD] = {
9401                 .mixers = { alc883_base_mixer },
9402                 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
9403                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9404                 .dac_nids = alc883_dac_nids,
9405                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9406                 .channel_mode = alc883_3ST_2ch_modes,
9407                 .input_mux = &alc883_capture_source,
9408         },
9409         [ALC883_CLEVO_M720] = {
9410                 .mixers = { alc883_clevo_m720_mixer },
9411                 .init_verbs = { alc883_init_verbs, alc883_clevo_m720_verbs },
9412                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9413                 .dac_nids = alc883_dac_nids,
9414                 .dig_out_nid = ALC883_DIGOUT_NID,
9415                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9416                 .channel_mode = alc883_3ST_2ch_modes,
9417                 .input_mux = &alc883_capture_source,
9418                 .unsol_event = alc883_clevo_m720_unsol_event,
9419                 .init_hook = alc883_clevo_m720_init_hook,
9420         },
9421         [ALC883_LENOVO_101E_2ch] = {
9422                 .mixers = { alc883_lenovo_101e_2ch_mixer},
9423                 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
9424                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9425                 .dac_nids = alc883_dac_nids,
9426                 .adc_nids = alc883_adc_nids_alt,
9427                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
9428                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9429                 .channel_mode = alc883_3ST_2ch_modes,
9430                 .input_mux = &alc883_lenovo_101e_capture_source,
9431                 .unsol_event = alc883_lenovo_101e_unsol_event,
9432                 .init_hook = alc883_lenovo_101e_all_automute,
9433         },
9434         [ALC883_LENOVO_NB0763] = {
9435                 .mixers = { alc883_lenovo_nb0763_mixer },
9436                 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs},
9437                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9438                 .dac_nids = alc883_dac_nids,
9439                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9440                 .channel_mode = alc883_3ST_2ch_modes,
9441                 .need_dac_fix = 1,
9442                 .input_mux = &alc883_lenovo_nb0763_capture_source,
9443                 .unsol_event = alc_automute_amp_unsol_event,
9444                 .init_hook = alc883_medion_md2_init_hook,
9445         },
9446         [ALC888_LENOVO_MS7195_DIG] = {
9447                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9448                 .init_verbs = { alc883_init_verbs, alc888_lenovo_ms7195_verbs},
9449                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9450                 .dac_nids = alc883_dac_nids,
9451                 .dig_out_nid = ALC883_DIGOUT_NID,
9452                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9453                 .channel_mode = alc883_3ST_6ch_modes,
9454                 .need_dac_fix = 1,
9455                 .input_mux = &alc883_capture_source,
9456                 .unsol_event = alc883_lenovo_ms7195_unsol_event,
9457                 .init_hook = alc888_lenovo_ms7195_front_automute,
9458         },
9459         [ALC883_HAIER_W66] = {
9460                 .mixers = { alc883_targa_2ch_mixer},
9461                 .init_verbs = { alc883_init_verbs, alc883_haier_w66_verbs},
9462                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9463                 .dac_nids = alc883_dac_nids,
9464                 .dig_out_nid = ALC883_DIGOUT_NID,
9465                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9466                 .channel_mode = alc883_3ST_2ch_modes,
9467                 .input_mux = &alc883_capture_source,
9468                 .unsol_event = alc_automute_amp_unsol_event,
9469                 .init_hook = alc883_haier_w66_init_hook,
9470         },
9471         [ALC888_3ST_HP] = {
9472                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9473                 .init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs },
9474                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9475                 .dac_nids = alc883_dac_nids,
9476                 .num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes),
9477                 .channel_mode = alc888_3st_hp_modes,
9478                 .need_dac_fix = 1,
9479                 .input_mux = &alc883_capture_source,
9480                 .unsol_event = alc_automute_amp_unsol_event,
9481                 .init_hook = alc888_3st_hp_init_hook,
9482         },
9483         [ALC888_6ST_DELL] = {
9484                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
9485                 .init_verbs = { alc883_init_verbs, alc888_6st_dell_verbs },
9486                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9487                 .dac_nids = alc883_dac_nids,
9488                 .dig_out_nid = ALC883_DIGOUT_NID,
9489                 .dig_in_nid = ALC883_DIGIN_NID,
9490                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9491                 .channel_mode = alc883_sixstack_modes,
9492                 .input_mux = &alc883_capture_source,
9493                 .unsol_event = alc_automute_amp_unsol_event,
9494                 .init_hook = alc888_6st_dell_init_hook,
9495         },
9496         [ALC883_MITAC] = {
9497                 .mixers = { alc883_mitac_mixer },
9498                 .init_verbs = { alc883_init_verbs, alc883_mitac_verbs },
9499                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9500                 .dac_nids = alc883_dac_nids,
9501                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9502                 .channel_mode = alc883_3ST_2ch_modes,
9503                 .input_mux = &alc883_capture_source,
9504                 .unsol_event = alc_automute_amp_unsol_event,
9505                 .init_hook = alc883_mitac_init_hook,
9506         },
9507         [ALC883_FUJITSU_PI2515] = {
9508                 .mixers = { alc883_2ch_fujitsu_pi2515_mixer },
9509                 .init_verbs = { alc883_init_verbs,
9510                                 alc883_2ch_fujitsu_pi2515_verbs},
9511                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9512                 .dac_nids = alc883_dac_nids,
9513                 .dig_out_nid = ALC883_DIGOUT_NID,
9514                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9515                 .channel_mode = alc883_3ST_2ch_modes,
9516                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
9517                 .unsol_event = alc_automute_amp_unsol_event,
9518                 .init_hook = alc883_2ch_fujitsu_pi2515_init_hook,
9519         },
9520         [ALC888_FUJITSU_XA3530] = {
9521                 .mixers = { alc888_base_mixer, alc883_chmode_mixer },
9522                 .init_verbs = { alc883_init_verbs,
9523                         alc888_fujitsu_xa3530_verbs },
9524                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9525                 .dac_nids = alc883_dac_nids,
9526                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
9527                 .adc_nids = alc883_adc_nids_rev,
9528                 .capsrc_nids = alc883_capsrc_nids_rev,
9529                 .dig_out_nid = ALC883_DIGOUT_NID,
9530                 .num_channel_mode = ARRAY_SIZE(alc888_4ST_8ch_intel_modes),
9531                 .channel_mode = alc888_4ST_8ch_intel_modes,
9532                 .num_mux_defs =
9533                         ARRAY_SIZE(alc888_2_capture_sources),
9534                 .input_mux = alc888_2_capture_sources,
9535                 .unsol_event = alc_automute_amp_unsol_event,
9536                 .init_hook = alc888_fujitsu_xa3530_init_hook,
9537         },
9538         [ALC888_LENOVO_SKY] = {
9539                 .mixers = { alc888_lenovo_sky_mixer, alc883_chmode_mixer },
9540                 .init_verbs = { alc883_init_verbs, alc888_lenovo_sky_verbs},
9541                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9542                 .dac_nids = alc883_dac_nids,
9543                 .dig_out_nid = ALC883_DIGOUT_NID,
9544                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9545                 .channel_mode = alc883_sixstack_modes,
9546                 .need_dac_fix = 1,
9547                 .input_mux = &alc883_lenovo_sky_capture_source,
9548                 .unsol_event = alc_automute_amp_unsol_event,
9549                 .init_hook = alc888_lenovo_sky_init_hook,
9550         },
9551         [ALC888_ASUS_M90V] = {
9552                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9553                 .init_verbs = { alc883_init_verbs, alc888_asus_m90v_verbs },
9554                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9555                 .dac_nids = alc883_dac_nids,
9556                 .dig_out_nid = ALC883_DIGOUT_NID,
9557                 .dig_in_nid = ALC883_DIGIN_NID,
9558                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9559                 .channel_mode = alc883_3ST_6ch_modes,
9560                 .need_dac_fix = 1,
9561                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
9562                 .unsol_event = alc883_mode2_unsol_event,
9563                 .init_hook = alc883_mode2_inithook,
9564         },
9565         [ALC888_ASUS_EEE1601] = {
9566                 .mixers = { alc883_asus_eee1601_mixer },
9567                 .cap_mixer = alc883_asus_eee1601_cap_mixer,
9568                 .init_verbs = { alc883_init_verbs, alc888_asus_eee1601_verbs },
9569                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9570                 .dac_nids = alc883_dac_nids,
9571                 .dig_out_nid = ALC883_DIGOUT_NID,
9572                 .dig_in_nid = ALC883_DIGIN_NID,
9573                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9574                 .channel_mode = alc883_3ST_2ch_modes,
9575                 .need_dac_fix = 1,
9576                 .input_mux = &alc883_asus_eee1601_capture_source,
9577                 .unsol_event = alc_sku_unsol_event,
9578                 .init_hook = alc883_eee1601_inithook,
9579         },
9580         [ALC1200_ASUS_P5Q] = {
9581                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
9582                 .init_verbs = { alc883_init_verbs },
9583                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9584                 .dac_nids = alc883_dac_nids,
9585                 .dig_out_nid = ALC1200_DIGOUT_NID,
9586                 .dig_in_nid = ALC883_DIGIN_NID,
9587                 .slave_dig_outs = alc1200_slave_dig_outs,
9588                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9589                 .channel_mode = alc883_sixstack_modes,
9590                 .input_mux = &alc883_capture_source,
9591         },
9592         [ALC889A_MB31] = {
9593                 .mixers = { alc889A_mb31_mixer, alc883_chmode_mixer},
9594                 .init_verbs = { alc883_init_verbs, alc889A_mb31_verbs,
9595                         alc880_gpio1_init_verbs },
9596                 .adc_nids = alc883_adc_nids,
9597                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
9598                 .dac_nids = alc883_dac_nids,
9599                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9600                 .channel_mode = alc889A_mb31_6ch_modes,
9601                 .num_channel_mode = ARRAY_SIZE(alc889A_mb31_6ch_modes),
9602                 .input_mux = &alc889A_mb31_capture_source,
9603                 .dig_out_nid = ALC883_DIGOUT_NID,
9604                 .unsol_event = alc889A_mb31_unsol_event,
9605                 .init_hook = alc889A_mb31_automute,
9606         },
9607         [ALC883_SONY_VAIO_TT] = {
9608                 .mixers = { alc883_vaiott_mixer },
9609                 .init_verbs = { alc883_init_verbs, alc883_vaiott_verbs },
9610                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9611                 .dac_nids = alc883_dac_nids,
9612                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9613                 .channel_mode = alc883_3ST_2ch_modes,
9614                 .input_mux = &alc883_capture_source,
9615                 .unsol_event = alc_automute_amp_unsol_event,
9616                 .init_hook = alc883_vaiott_init_hook,
9617         },
9618 };
9619
9620
9621 /*
9622  * BIOS auto configuration
9623  */
9624 static void alc883_auto_set_output_and_unmute(struct hda_codec *codec,
9625                                               hda_nid_t nid, int pin_type,
9626                                               int dac_idx)
9627 {
9628         /* set as output */
9629         struct alc_spec *spec = codec->spec;
9630         int idx;
9631
9632         alc_set_pin_output(codec, nid, pin_type);
9633         if (spec->multiout.dac_nids[dac_idx] == 0x25)
9634                 idx = 4;
9635         else
9636                 idx = spec->multiout.dac_nids[dac_idx] - 2;
9637         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
9638
9639 }
9640
9641 static void alc883_auto_init_multi_out(struct hda_codec *codec)
9642 {
9643         struct alc_spec *spec = codec->spec;
9644         int i;
9645
9646         for (i = 0; i <= HDA_SIDE; i++) {
9647                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
9648                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
9649                 if (nid)
9650                         alc883_auto_set_output_and_unmute(codec, nid, pin_type,
9651                                                           i);
9652         }
9653 }
9654
9655 static void alc883_auto_init_hp_out(struct hda_codec *codec)
9656 {
9657         struct alc_spec *spec = codec->spec;
9658         hda_nid_t pin;
9659
9660         pin = spec->autocfg.hp_pins[0];
9661         if (pin) /* connect to front */
9662                 /* use dac 0 */
9663                 alc883_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
9664         pin = spec->autocfg.speaker_pins[0];
9665         if (pin)
9666                 alc883_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
9667 }
9668
9669 #define alc883_is_input_pin(nid)        alc880_is_input_pin(nid)
9670 #define ALC883_PIN_CD_NID               ALC880_PIN_CD_NID
9671
9672 static void alc883_auto_init_analog_input(struct hda_codec *codec)
9673 {
9674         struct alc_spec *spec = codec->spec;
9675         int i;
9676
9677         for (i = 0; i < AUTO_PIN_LAST; i++) {
9678                 hda_nid_t nid = spec->autocfg.input_pins[i];
9679                 if (alc883_is_input_pin(nid)) {
9680                         alc_set_input_pin(codec, nid, i);
9681                         if (nid != ALC883_PIN_CD_NID &&
9682                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
9683                                 snd_hda_codec_write(codec, nid, 0,
9684                                                     AC_VERB_SET_AMP_GAIN_MUTE,
9685                                                     AMP_OUT_MUTE);
9686                 }
9687         }
9688 }
9689
9690 #define alc883_auto_init_input_src      alc882_auto_init_input_src
9691
9692 /* almost identical with ALC880 parser... */
9693 static int alc883_parse_auto_config(struct hda_codec *codec)
9694 {
9695         struct alc_spec *spec = codec->spec;
9696         int err = alc880_parse_auto_config(codec);
9697         struct auto_pin_cfg *cfg = &spec->autocfg;
9698         int i;
9699
9700         if (err < 0)
9701                 return err;
9702         else if (!err)
9703                 return 0; /* no config found */
9704
9705         err = alc_auto_add_mic_boost(codec);
9706         if (err < 0)
9707                 return err;
9708
9709         /* hack - override the init verbs */
9710         spec->init_verbs[0] = alc883_auto_init_verbs;
9711
9712         /* setup input_mux for ALC889 */
9713         if (codec->vendor_id == 0x10ec0889) {
9714                 /* digital-mic input pin is excluded in alc880_auto_create..()
9715                  * because it's under 0x18
9716                  */
9717                 if (cfg->input_pins[AUTO_PIN_MIC] == 0x12 ||
9718                     cfg->input_pins[AUTO_PIN_FRONT_MIC] == 0x12) {
9719                         struct hda_input_mux *imux = &spec->private_imux[0];
9720                         for (i = 1; i < 3; i++)
9721                                 memcpy(&spec->private_imux[i],
9722                                        &spec->private_imux[0],
9723                                        sizeof(spec->private_imux[0]));
9724                         imux->items[imux->num_items].label = "Int DMic";
9725                         imux->items[imux->num_items].index = 0x0b;
9726                         imux->num_items++;
9727                         spec->num_mux_defs = 3;
9728                         spec->input_mux = spec->private_imux;
9729                 }
9730         }
9731
9732         return 1; /* config found */
9733 }
9734
9735 /* additional initialization for auto-configuration model */
9736 static void alc883_auto_init(struct hda_codec *codec)
9737 {
9738         struct alc_spec *spec = codec->spec;
9739         alc883_auto_init_multi_out(codec);
9740         alc883_auto_init_hp_out(codec);
9741         alc883_auto_init_analog_input(codec);
9742         alc883_auto_init_input_src(codec);
9743         if (spec->unsol_event)
9744                 alc_inithook(codec);
9745 }
9746
9747 static int patch_alc883(struct hda_codec *codec)
9748 {
9749         struct alc_spec *spec;
9750         int err, board_config;
9751
9752         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
9753         if (spec == NULL)
9754                 return -ENOMEM;
9755
9756         codec->spec = spec;
9757
9758         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
9759
9760         board_config = snd_hda_check_board_config(codec, ALC883_MODEL_LAST,
9761                                                   alc883_models,
9762                                                   alc883_cfg_tbl);
9763         if (board_config < 0 || board_config >= ALC883_MODEL_LAST) {
9764                 /* Pick up systems that don't supply PCI SSID */
9765                 switch (codec->subsystem_id) {
9766                 case 0x106b3600: /* Macbook 3.1 */
9767                         board_config = ALC889A_MB31;
9768                         break;
9769                 default:
9770                         printk(KERN_INFO
9771                                 "hda_codec: Unknown model for %s, trying "
9772                                 "auto-probe from BIOS...\n", codec->chip_name);
9773                         board_config = ALC883_AUTO;
9774                 }
9775         }
9776
9777         if (board_config == ALC883_AUTO) {
9778                 /* automatic parse from the BIOS config */
9779                 err = alc883_parse_auto_config(codec);
9780                 if (err < 0) {
9781                         alc_free(codec);
9782                         return err;
9783                 } else if (!err) {
9784                         printk(KERN_INFO
9785                                "hda_codec: Cannot set up configuration "
9786                                "from BIOS.  Using base mode...\n");
9787                         board_config = ALC883_3ST_2ch_DIG;
9788                 }
9789         }
9790
9791         err = snd_hda_attach_beep_device(codec, 0x1);
9792         if (err < 0) {
9793                 alc_free(codec);
9794                 return err;
9795         }
9796
9797         if (board_config != ALC883_AUTO)
9798                 setup_preset(spec, &alc883_presets[board_config]);
9799
9800         switch (codec->vendor_id) {
9801         case 0x10ec0888:
9802                 if (!spec->num_adc_nids) {
9803                         spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
9804                         spec->adc_nids = alc883_adc_nids;
9805                 }
9806                 if (!spec->capsrc_nids)
9807                         spec->capsrc_nids = alc883_capsrc_nids;
9808                 spec->init_amp = ALC_INIT_DEFAULT; /* always initialize */
9809                 break;
9810         case 0x10ec0889:
9811                 if (!spec->num_adc_nids) {
9812                         spec->num_adc_nids = ARRAY_SIZE(alc889_adc_nids);
9813                         spec->adc_nids = alc889_adc_nids;
9814                 }
9815                 if (!spec->capsrc_nids)
9816                         spec->capsrc_nids = alc889_capsrc_nids;
9817                 break;
9818         default:
9819                 if (!spec->num_adc_nids) {
9820                         spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
9821                         spec->adc_nids = alc883_adc_nids;
9822                 }
9823                 if (!spec->capsrc_nids)
9824                         spec->capsrc_nids = alc883_capsrc_nids;
9825                 break;
9826         }
9827
9828         spec->stream_analog_playback = &alc883_pcm_analog_playback;
9829         spec->stream_analog_capture = &alc883_pcm_analog_capture;
9830         spec->stream_analog_alt_capture = &alc883_pcm_analog_alt_capture;
9831
9832         spec->stream_digital_playback = &alc883_pcm_digital_playback;
9833         spec->stream_digital_capture = &alc883_pcm_digital_capture;
9834
9835         if (!spec->cap_mixer)
9836                 set_capture_mixer(spec);
9837         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
9838
9839         spec->vmaster_nid = 0x0c;
9840
9841         codec->patch_ops = alc_patch_ops;
9842         if (board_config == ALC883_AUTO)
9843                 spec->init_hook = alc883_auto_init;
9844
9845 #ifdef CONFIG_SND_HDA_POWER_SAVE
9846         if (!spec->loopback.amplist)
9847                 spec->loopback.amplist = alc883_loopbacks;
9848 #endif
9849         codec->proc_widget_hook = print_realtek_coef;
9850
9851         return 0;
9852 }
9853
9854 /*
9855  * ALC262 support
9856  */
9857
9858 #define ALC262_DIGOUT_NID       ALC880_DIGOUT_NID
9859 #define ALC262_DIGIN_NID        ALC880_DIGIN_NID
9860
9861 #define alc262_dac_nids         alc260_dac_nids
9862 #define alc262_adc_nids         alc882_adc_nids
9863 #define alc262_adc_nids_alt     alc882_adc_nids_alt
9864 #define alc262_capsrc_nids      alc882_capsrc_nids
9865 #define alc262_capsrc_nids_alt  alc882_capsrc_nids_alt
9866
9867 #define alc262_modes            alc260_modes
9868 #define alc262_capture_source   alc882_capture_source
9869
9870 static hda_nid_t alc262_dmic_adc_nids[1] = {
9871         /* ADC0 */
9872         0x09
9873 };
9874
9875 static hda_nid_t alc262_dmic_capsrc_nids[1] = { 0x22 };
9876
9877 static struct snd_kcontrol_new alc262_base_mixer[] = {
9878         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9879         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9880         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9881         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9882         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9883         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9884         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9885         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9886         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9887         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9888         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9889         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9890         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
9891         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9892         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
9893         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
9894         { } /* end */
9895 };
9896
9897 /* update HP, line and mono-out pins according to the master switch */
9898 static void alc262_hp_master_update(struct hda_codec *codec)
9899 {
9900         struct alc_spec *spec = codec->spec;
9901         int val = spec->master_sw;
9902
9903         /* HP & line-out */
9904         snd_hda_codec_write_cache(codec, 0x1b, 0,
9905                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9906                                   val ? PIN_HP : 0);
9907         snd_hda_codec_write_cache(codec, 0x15, 0,
9908                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9909                                   val ? PIN_HP : 0);
9910         /* mono (speaker) depending on the HP jack sense */
9911         val = val && !spec->jack_present;
9912         snd_hda_codec_write_cache(codec, 0x16, 0,
9913                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9914                                   val ? PIN_OUT : 0);
9915 }
9916
9917 static void alc262_hp_bpc_automute(struct hda_codec *codec)
9918 {
9919         struct alc_spec *spec = codec->spec;
9920         unsigned int presence;
9921         presence = snd_hda_codec_read(codec, 0x1b, 0,
9922                                       AC_VERB_GET_PIN_SENSE, 0);
9923         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
9924         alc262_hp_master_update(codec);
9925 }
9926
9927 static void alc262_hp_bpc_unsol_event(struct hda_codec *codec, unsigned int res)
9928 {
9929         if ((res >> 26) != ALC880_HP_EVENT)
9930                 return;
9931         alc262_hp_bpc_automute(codec);
9932 }
9933
9934 static void alc262_hp_wildwest_automute(struct hda_codec *codec)
9935 {
9936         struct alc_spec *spec = codec->spec;
9937         unsigned int presence;
9938         presence = snd_hda_codec_read(codec, 0x15, 0,
9939                                       AC_VERB_GET_PIN_SENSE, 0);
9940         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
9941         alc262_hp_master_update(codec);
9942 }
9943
9944 static void alc262_hp_wildwest_unsol_event(struct hda_codec *codec,
9945                                            unsigned int res)
9946 {
9947         if ((res >> 26) != ALC880_HP_EVENT)
9948                 return;
9949         alc262_hp_wildwest_automute(codec);
9950 }
9951
9952 #define alc262_hp_master_sw_get         alc260_hp_master_sw_get
9953
9954 static int alc262_hp_master_sw_put(struct snd_kcontrol *kcontrol,
9955                                    struct snd_ctl_elem_value *ucontrol)
9956 {
9957         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9958         struct alc_spec *spec = codec->spec;
9959         int val = !!*ucontrol->value.integer.value;
9960
9961         if (val == spec->master_sw)
9962                 return 0;
9963         spec->master_sw = val;
9964         alc262_hp_master_update(codec);
9965         return 1;
9966 }
9967
9968 #define ALC262_HP_MASTER_SWITCH                                 \
9969         {                                                       \
9970                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,            \
9971                 .name = "Master Playback Switch",               \
9972                 .info = snd_ctl_boolean_mono_info,              \
9973                 .get = alc262_hp_master_sw_get,                 \
9974                 .put = alc262_hp_master_sw_put,                 \
9975         }
9976
9977 static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
9978         ALC262_HP_MASTER_SWITCH,
9979         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9980         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9981         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9982         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
9983                               HDA_OUTPUT),
9984         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
9985                             HDA_OUTPUT),
9986         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9987         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9988         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9989         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9990         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9991         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9992         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9993         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9994         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9995         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9996         HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
9997         HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
9998         { } /* end */
9999 };
10000
10001 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
10002         ALC262_HP_MASTER_SWITCH,
10003         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10004         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
10005         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
10006         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10007         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
10008                               HDA_OUTPUT),
10009         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
10010                             HDA_OUTPUT),
10011         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
10012         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
10013         HDA_CODEC_VOLUME("Front Mic Boost", 0x1a, 0, HDA_INPUT),
10014         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
10015         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
10016         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10017         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10018         { } /* end */
10019 };
10020
10021 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
10022         HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10023         HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10024         HDA_CODEC_VOLUME("Rear Mic Boost", 0x18, 0, HDA_INPUT),
10025         { } /* end */
10026 };
10027
10028 /* mute/unmute internal speaker according to the hp jack and mute state */
10029 static void alc262_hp_t5735_init_hook(struct hda_codec *codec)
10030 {
10031         struct alc_spec *spec = codec->spec;
10032
10033         spec->autocfg.hp_pins[0] = 0x15;
10034         spec->autocfg.speaker_pins[0] = 0x0c; /* HACK: not actually a pin */
10035         alc_automute_amp(codec);
10036 }
10037
10038 static struct snd_kcontrol_new alc262_hp_t5735_mixer[] = {
10039         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10040         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10041         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
10042         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10043         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10044         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10045         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10046         { } /* end */
10047 };
10048
10049 static struct hda_verb alc262_hp_t5735_verbs[] = {
10050         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10051         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10052
10053         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10054         { }
10055 };
10056
10057 static struct snd_kcontrol_new alc262_hp_rp5700_mixer[] = {
10058         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10059         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
10060         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
10061         HDA_CODEC_MUTE("Speaker Playback Switch", 0x16, 0x0, HDA_OUTPUT),
10062         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
10063         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
10064         { } /* end */
10065 };
10066
10067 static struct hda_verb alc262_hp_rp5700_verbs[] = {
10068         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10069         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10070         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10071         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10072         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10073         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10074         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10075         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10076         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
10077         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
10078         {}
10079 };
10080
10081 static struct hda_input_mux alc262_hp_rp5700_capture_source = {
10082         .num_items = 1,
10083         .items = {
10084                 { "Line", 0x1 },
10085         },
10086 };
10087
10088 /* bind hp and internal speaker mute (with plug check) as master switch */
10089 static void alc262_hippo_master_update(struct hda_codec *codec)
10090 {
10091         struct alc_spec *spec = codec->spec;
10092         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
10093         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
10094         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
10095         unsigned int mute;
10096
10097         /* HP */
10098         mute = spec->master_sw ? 0 : HDA_AMP_MUTE;
10099         snd_hda_codec_amp_stereo(codec, hp_nid, HDA_OUTPUT, 0,
10100                                  HDA_AMP_MUTE, mute);
10101         /* mute internal speaker per jack sense */
10102         if (spec->jack_present)
10103                 mute = HDA_AMP_MUTE;
10104         if (line_nid)
10105                 snd_hda_codec_amp_stereo(codec, line_nid, HDA_OUTPUT, 0,
10106                                          HDA_AMP_MUTE, mute);
10107         if (speaker_nid && speaker_nid != line_nid)
10108                 snd_hda_codec_amp_stereo(codec, speaker_nid, HDA_OUTPUT, 0,
10109                                          HDA_AMP_MUTE, mute);
10110 }
10111
10112 #define alc262_hippo_master_sw_get      alc262_hp_master_sw_get
10113
10114 static int alc262_hippo_master_sw_put(struct snd_kcontrol *kcontrol,
10115                                       struct snd_ctl_elem_value *ucontrol)
10116 {
10117         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10118         struct alc_spec *spec = codec->spec;
10119         int val = !!*ucontrol->value.integer.value;
10120
10121         if (val == spec->master_sw)
10122                 return 0;
10123         spec->master_sw = val;
10124         alc262_hippo_master_update(codec);
10125         return 1;
10126 }
10127
10128 #define ALC262_HIPPO_MASTER_SWITCH                              \
10129         {                                                       \
10130                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,            \
10131                 .name = "Master Playback Switch",               \
10132                 .info = snd_ctl_boolean_mono_info,              \
10133                 .get = alc262_hippo_master_sw_get,              \
10134                 .put = alc262_hippo_master_sw_put,              \
10135         }
10136
10137 static struct snd_kcontrol_new alc262_hippo_mixer[] = {
10138         ALC262_HIPPO_MASTER_SWITCH,
10139         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10140         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10141         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10142         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10143         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10144         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10145         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10146         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10147         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10148         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10149         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10150         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
10151         { } /* end */
10152 };
10153
10154 static struct snd_kcontrol_new alc262_hippo1_mixer[] = {
10155         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10156         ALC262_HIPPO_MASTER_SWITCH,
10157         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10158         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10159         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10160         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10161         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10162         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10163         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10164         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10165         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10166         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10167         { } /* end */
10168 };
10169
10170 /* mute/unmute internal speaker according to the hp jack and mute state */
10171 static void alc262_hippo_automute(struct hda_codec *codec)
10172 {
10173         struct alc_spec *spec = codec->spec;
10174         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
10175         unsigned int present;
10176
10177         /* need to execute and sync at first */
10178         snd_hda_codec_read(codec, hp_nid, 0, AC_VERB_SET_PIN_SENSE, 0);
10179         present = snd_hda_codec_read(codec, hp_nid, 0,
10180                                      AC_VERB_GET_PIN_SENSE, 0);
10181         spec->jack_present = (present & 0x80000000) != 0;
10182         alc262_hippo_master_update(codec);
10183 }
10184
10185 static void alc262_hippo_unsol_event(struct hda_codec *codec, unsigned int res)
10186 {
10187         if ((res >> 26) != ALC880_HP_EVENT)
10188                 return;
10189         alc262_hippo_automute(codec);
10190 }
10191
10192 static void alc262_hippo_init_hook(struct hda_codec *codec)
10193 {
10194         struct alc_spec *spec = codec->spec;
10195
10196         spec->autocfg.hp_pins[0] = 0x15;
10197         spec->autocfg.speaker_pins[0] = 0x14;
10198         alc262_hippo_automute(codec);
10199 }
10200
10201 static void alc262_hippo1_init_hook(struct hda_codec *codec)
10202 {
10203         struct alc_spec *spec = codec->spec;
10204
10205         spec->autocfg.hp_pins[0] = 0x1b;
10206         spec->autocfg.speaker_pins[0] = 0x14;
10207         alc262_hippo_automute(codec);
10208 }
10209
10210
10211 static struct snd_kcontrol_new alc262_sony_mixer[] = {
10212         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10213         ALC262_HIPPO_MASTER_SWITCH,
10214         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10215         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10216         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10217         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10218         { } /* end */
10219 };
10220
10221 static struct snd_kcontrol_new alc262_benq_t31_mixer[] = {
10222         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10223         ALC262_HIPPO_MASTER_SWITCH,
10224         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10225         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10226         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10227         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10228         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10229         { } /* end */
10230 };
10231
10232 static struct snd_kcontrol_new alc262_tyan_mixer[] = {
10233         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10234         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
10235         HDA_CODEC_VOLUME("Aux Playback Volume", 0x0b, 0x06, HDA_INPUT),
10236         HDA_CODEC_MUTE("Aux Playback Switch", 0x0b, 0x06, HDA_INPUT),
10237         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10238         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10239         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10240         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10241         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10242         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10243         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10244         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10245         { } /* end */
10246 };
10247
10248 static struct hda_verb alc262_tyan_verbs[] = {
10249         /* Headphone automute */
10250         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10251         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10252         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10253
10254         /* P11 AUX_IN, white 4-pin connector */
10255         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10256         {0x14, AC_VERB_SET_CONFIG_DEFAULT_BYTES_1, 0xe1},
10257         {0x14, AC_VERB_SET_CONFIG_DEFAULT_BYTES_2, 0x93},
10258         {0x14, AC_VERB_SET_CONFIG_DEFAULT_BYTES_3, 0x19},
10259
10260         {}
10261 };
10262
10263 /* unsolicited event for HP jack sensing */
10264 static void alc262_tyan_init_hook(struct hda_codec *codec)
10265 {
10266         struct alc_spec *spec = codec->spec;
10267
10268         spec->autocfg.hp_pins[0] = 0x1b;
10269         spec->autocfg.speaker_pins[0] = 0x15;
10270         alc_automute_amp(codec);
10271 }
10272
10273
10274 #define alc262_capture_mixer            alc882_capture_mixer
10275 #define alc262_capture_alt_mixer        alc882_capture_alt_mixer
10276
10277 /*
10278  * generic initialization of ADC, input mixers and output mixers
10279  */
10280 static struct hda_verb alc262_init_verbs[] = {
10281         /*
10282          * Unmute ADC0-2 and set the default input to mic-in
10283          */
10284         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10285         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10286         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10287         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10288         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10289         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10290
10291         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10292          * mixer widget
10293          * Note: PASD motherboards uses the Line In 2 as the input for
10294          * front panel mic (mic 2)
10295          */
10296         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10297         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10298         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10299         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10300         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10301         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10302
10303         /*
10304          * Set up output mixers (0x0c - 0x0e)
10305          */
10306         /* set vol=0 to output mixers */
10307         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10308         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10309         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10310         /* set up input amps for analog loopback */
10311         /* Amp Indices: DAC = 0, mixer = 1 */
10312         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10313         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10314         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10315         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10316         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10317         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10318
10319         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
10320         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
10321         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
10322         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10323         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10324         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10325
10326         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10327         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10328         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10329         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10330         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10331
10332         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
10333         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
10334
10335         /* FIXME: use matrix-type input source selection */
10336         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10337         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10338         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10339         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10340         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10341         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10342         /* Input mixer2 */
10343         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10344         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10345         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10346         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10347         /* Input mixer3 */
10348         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10349         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10350         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10351         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10352
10353         { }
10354 };
10355
10356 static struct hda_verb alc262_eapd_verbs[] = {
10357         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
10358         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
10359         { }
10360 };
10361
10362 static struct hda_verb alc262_hippo_unsol_verbs[] = {
10363         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10364         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10365         {}
10366 };
10367
10368 static struct hda_verb alc262_hippo1_unsol_verbs[] = {
10369         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
10370         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10371         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10372
10373         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10374         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10375         {}
10376 };
10377
10378 static struct hda_verb alc262_sony_unsol_verbs[] = {
10379         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
10380         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10381         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},   // Front Mic
10382
10383         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10384         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10385         {}
10386 };
10387
10388 static struct hda_input_mux alc262_dmic_capture_source = {
10389         .num_items = 2,
10390         .items = {
10391                 { "Int DMic", 0x9 },
10392                 { "Mic", 0x0 },
10393         },
10394 };
10395
10396 static struct snd_kcontrol_new alc262_toshiba_s06_mixer[] = {
10397         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10398         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10399         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10400         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10401         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10402         { } /* end */
10403 };
10404
10405 static struct hda_verb alc262_toshiba_s06_verbs[] = {
10406         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10407         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10408         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10409         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10410         {0x22, AC_VERB_SET_CONNECT_SEL, 0x09},
10411         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10412         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
10413         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10414         {}
10415 };
10416
10417 static void alc262_dmic_automute(struct hda_codec *codec)
10418 {
10419         unsigned int present;
10420
10421         present = snd_hda_codec_read(codec, 0x18, 0,
10422                                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
10423         snd_hda_codec_write(codec, 0x22, 0,
10424                                 AC_VERB_SET_CONNECT_SEL, present ? 0x0 : 0x09);
10425 }
10426
10427
10428 /* unsolicited event for HP jack sensing */
10429 static void alc262_toshiba_s06_unsol_event(struct hda_codec *codec,
10430                                        unsigned int res)
10431 {
10432         if ((res >> 26) == ALC880_MIC_EVENT)
10433                 alc262_dmic_automute(codec);
10434         else
10435                 alc_sku_unsol_event(codec, res);
10436 }
10437
10438 static void alc262_toshiba_s06_init_hook(struct hda_codec *codec)
10439 {
10440         struct alc_spec *spec = codec->spec;
10441
10442         spec->autocfg.hp_pins[0] = 0x15;
10443         spec->autocfg.speaker_pins[0] = 0x14;
10444         alc_automute_pin(codec);
10445         alc262_dmic_automute(codec);
10446 }
10447
10448 /*
10449  * nec model
10450  *  0x15 = headphone
10451  *  0x16 = internal speaker
10452  *  0x18 = external mic
10453  */
10454
10455 static struct snd_kcontrol_new alc262_nec_mixer[] = {
10456         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
10457         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 0, 0x0, HDA_OUTPUT),
10458
10459         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10460         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10461         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10462
10463         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
10464         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10465         { } /* end */
10466 };
10467
10468 static struct hda_verb alc262_nec_verbs[] = {
10469         /* Unmute Speaker */
10470         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10471
10472         /* Headphone */
10473         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10474         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10475
10476         /* External mic to headphone */
10477         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10478         /* External mic to speaker */
10479         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10480         {}
10481 };
10482
10483 /*
10484  * fujitsu model
10485  *  0x14 = headphone/spdif-out, 0x15 = internal speaker,
10486  *  0x1b = port replicator headphone out
10487  */
10488
10489 #define ALC_HP_EVENT    0x37
10490
10491 static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
10492         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
10493         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10494         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
10495         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10496         {}
10497 };
10498
10499 static struct hda_verb alc262_lenovo_3000_unsol_verbs[] = {
10500         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
10501         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10502         {}
10503 };
10504
10505 static struct hda_input_mux alc262_fujitsu_capture_source = {
10506         .num_items = 3,
10507         .items = {
10508                 { "Mic", 0x0 },
10509                 { "Int Mic", 0x1 },
10510                 { "CD", 0x4 },
10511         },
10512 };
10513
10514 static struct hda_input_mux alc262_HP_capture_source = {
10515         .num_items = 5,
10516         .items = {
10517                 { "Mic", 0x0 },
10518                 { "Front Mic", 0x1 },
10519                 { "Line", 0x2 },
10520                 { "CD", 0x4 },
10521                 { "AUX IN", 0x6 },
10522         },
10523 };
10524
10525 static struct hda_input_mux alc262_HP_D7000_capture_source = {
10526         .num_items = 4,
10527         .items = {
10528                 { "Mic", 0x0 },
10529                 { "Front Mic", 0x2 },
10530                 { "Line", 0x1 },
10531                 { "CD", 0x4 },
10532         },
10533 };
10534
10535 /* mute/unmute internal speaker according to the hp jacks and mute state */
10536 static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
10537 {
10538         struct alc_spec *spec = codec->spec;
10539         unsigned int mute;
10540
10541         if (force || !spec->sense_updated) {
10542                 unsigned int present;
10543                 /* need to execute and sync at first */
10544                 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
10545                 /* check laptop HP jack */
10546                 present = snd_hda_codec_read(codec, 0x14, 0,
10547                                              AC_VERB_GET_PIN_SENSE, 0);
10548                 /* need to execute and sync at first */
10549                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
10550                 /* check docking HP jack */
10551                 present |= snd_hda_codec_read(codec, 0x1b, 0,
10552                                               AC_VERB_GET_PIN_SENSE, 0);
10553                 if (present & AC_PINSENSE_PRESENCE)
10554                         spec->jack_present = 1;
10555                 else
10556                         spec->jack_present = 0;
10557                 spec->sense_updated = 1;
10558         }
10559         /* unmute internal speaker only if both HPs are unplugged and
10560          * master switch is on
10561          */
10562         if (spec->jack_present)
10563                 mute = HDA_AMP_MUTE;
10564         else
10565                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
10566         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
10567                                  HDA_AMP_MUTE, mute);
10568 }
10569
10570 /* unsolicited event for HP jack sensing */
10571 static void alc262_fujitsu_unsol_event(struct hda_codec *codec,
10572                                        unsigned int res)
10573 {
10574         if ((res >> 26) != ALC_HP_EVENT)
10575                 return;
10576         alc262_fujitsu_automute(codec, 1);
10577 }
10578
10579 static void alc262_fujitsu_init_hook(struct hda_codec *codec)
10580 {
10581         alc262_fujitsu_automute(codec, 1);
10582 }
10583
10584 /* bind volumes of both NID 0x0c and 0x0d */
10585 static struct hda_bind_ctls alc262_fujitsu_bind_master_vol = {
10586         .ops = &snd_hda_bind_vol,
10587         .values = {
10588                 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
10589                 HDA_COMPOSE_AMP_VAL(0x0d, 3, 0, HDA_OUTPUT),
10590                 0
10591         },
10592 };
10593
10594 /* mute/unmute internal speaker according to the hp jack and mute state */
10595 static void alc262_lenovo_3000_automute(struct hda_codec *codec, int force)
10596 {
10597         struct alc_spec *spec = codec->spec;
10598         unsigned int mute;
10599
10600         if (force || !spec->sense_updated) {
10601                 unsigned int present_int_hp;
10602                 /* need to execute and sync at first */
10603                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
10604                 present_int_hp = snd_hda_codec_read(codec, 0x1b, 0,
10605                                         AC_VERB_GET_PIN_SENSE, 0);
10606                 spec->jack_present = (present_int_hp & 0x80000000) != 0;
10607                 spec->sense_updated = 1;
10608         }
10609         if (spec->jack_present) {
10610                 /* mute internal speaker */
10611                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10612                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
10613                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
10614                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
10615         } else {
10616                 /* unmute internal speaker if necessary */
10617                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
10618                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10619                                          HDA_AMP_MUTE, mute);
10620                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
10621                                          HDA_AMP_MUTE, mute);
10622         }
10623 }
10624
10625 /* unsolicited event for HP jack sensing */
10626 static void alc262_lenovo_3000_unsol_event(struct hda_codec *codec,
10627                                        unsigned int res)
10628 {
10629         if ((res >> 26) != ALC_HP_EVENT)
10630                 return;
10631         alc262_lenovo_3000_automute(codec, 1);
10632 }
10633
10634 /* bind hp and internal speaker mute (with plug check) */
10635 static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
10636                                          struct snd_ctl_elem_value *ucontrol)
10637 {
10638         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10639         long *valp = ucontrol->value.integer.value;
10640         int change;
10641
10642         change = snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10643                                                  HDA_AMP_MUTE,
10644                                                  valp ? 0 : HDA_AMP_MUTE);
10645         change |= snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
10646                                                  HDA_AMP_MUTE,
10647                                                  valp ? 0 : HDA_AMP_MUTE);
10648
10649         if (change)
10650                 alc262_fujitsu_automute(codec, 0);
10651         return change;
10652 }
10653
10654 static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
10655         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
10656         {
10657                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10658                 .name = "Master Playback Switch",
10659                 .info = snd_hda_mixer_amp_switch_info,
10660                 .get = snd_hda_mixer_amp_switch_get,
10661                 .put = alc262_fujitsu_master_sw_put,
10662                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
10663         },
10664         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10665         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10666         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10667         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10668         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10669         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
10670         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
10671         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
10672         { } /* end */
10673 };
10674
10675 /* bind hp and internal speaker mute (with plug check) */
10676 static int alc262_lenovo_3000_master_sw_put(struct snd_kcontrol *kcontrol,
10677                                          struct snd_ctl_elem_value *ucontrol)
10678 {
10679         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10680         long *valp = ucontrol->value.integer.value;
10681         int change;
10682
10683         change = snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
10684                                                  HDA_AMP_MUTE,
10685                                                  valp ? 0 : HDA_AMP_MUTE);
10686
10687         if (change)
10688                 alc262_lenovo_3000_automute(codec, 0);
10689         return change;
10690 }
10691
10692 static struct snd_kcontrol_new alc262_lenovo_3000_mixer[] = {
10693         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
10694         {
10695                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10696                 .name = "Master Playback Switch",
10697                 .info = snd_hda_mixer_amp_switch_info,
10698                 .get = snd_hda_mixer_amp_switch_get,
10699                 .put = alc262_lenovo_3000_master_sw_put,
10700                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
10701         },
10702         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10703         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10704         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10705         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10706         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10707         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
10708         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
10709         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
10710         { } /* end */
10711 };
10712
10713 static struct snd_kcontrol_new alc262_toshiba_rx1_mixer[] = {
10714         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
10715         ALC262_HIPPO_MASTER_SWITCH,
10716         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10717         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10718         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10719         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10720         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10721         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10722         { } /* end */
10723 };
10724
10725 /* additional init verbs for Benq laptops */
10726 static struct hda_verb alc262_EAPD_verbs[] = {
10727         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
10728         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
10729         {}
10730 };
10731
10732 static struct hda_verb alc262_benq_t31_EAPD_verbs[] = {
10733         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10734         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10735
10736         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
10737         {0x20, AC_VERB_SET_PROC_COEF,  0x3050},
10738         {}
10739 };
10740
10741 /* Samsung Q1 Ultra Vista model setup */
10742 static struct snd_kcontrol_new alc262_ultra_mixer[] = {
10743         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10744         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
10745         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10746         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10747         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
10748         HDA_CODEC_VOLUME("Headphone Mic Boost", 0x15, 0, HDA_INPUT),
10749         { } /* end */
10750 };
10751
10752 static struct hda_verb alc262_ultra_verbs[] = {
10753         /* output mixer */
10754         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10755         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10756         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10757         /* speaker */
10758         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10759         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10760         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10761         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
10762         /* HP */
10763         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10764         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10765         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10766         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10767         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10768         /* internal mic */
10769         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10770         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10771         /* ADC, choose mic */
10772         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10773         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10774         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10775         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10776         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10777         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10778         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10779         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10780         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
10781         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(8)},
10782         {}
10783 };
10784
10785 /* mute/unmute internal speaker according to the hp jack and mute state */
10786 static void alc262_ultra_automute(struct hda_codec *codec)
10787 {
10788         struct alc_spec *spec = codec->spec;
10789         unsigned int mute;
10790
10791         mute = 0;
10792         /* auto-mute only when HP is used as HP */
10793         if (!spec->cur_mux[0]) {
10794                 unsigned int present;
10795                 /* need to execute and sync at first */
10796                 snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
10797                 present = snd_hda_codec_read(codec, 0x15, 0,
10798                                              AC_VERB_GET_PIN_SENSE, 0);
10799                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
10800                 if (spec->jack_present)
10801                         mute = HDA_AMP_MUTE;
10802         }
10803         /* mute/unmute internal speaker */
10804         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10805                                  HDA_AMP_MUTE, mute);
10806         /* mute/unmute HP */
10807         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
10808                                  HDA_AMP_MUTE, mute ? 0 : HDA_AMP_MUTE);
10809 }
10810
10811 /* unsolicited event for HP jack sensing */
10812 static void alc262_ultra_unsol_event(struct hda_codec *codec,
10813                                        unsigned int res)
10814 {
10815         if ((res >> 26) != ALC880_HP_EVENT)
10816                 return;
10817         alc262_ultra_automute(codec);
10818 }
10819
10820 static struct hda_input_mux alc262_ultra_capture_source = {
10821         .num_items = 2,
10822         .items = {
10823                 { "Mic", 0x1 },
10824                 { "Headphone", 0x7 },
10825         },
10826 };
10827
10828 static int alc262_ultra_mux_enum_put(struct snd_kcontrol *kcontrol,
10829                                      struct snd_ctl_elem_value *ucontrol)
10830 {
10831         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10832         struct alc_spec *spec = codec->spec;
10833         int ret;
10834
10835         ret = alc_mux_enum_put(kcontrol, ucontrol);
10836         if (!ret)
10837                 return 0;
10838         /* reprogram the HP pin as mic or HP according to the input source */
10839         snd_hda_codec_write_cache(codec, 0x15, 0,
10840                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
10841                                   spec->cur_mux[0] ? PIN_VREF80 : PIN_HP);
10842         alc262_ultra_automute(codec); /* mute/unmute HP */
10843         return ret;
10844 }
10845
10846 static struct snd_kcontrol_new alc262_ultra_capture_mixer[] = {
10847         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
10848         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
10849         {
10850                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10851                 .name = "Capture Source",
10852                 .info = alc_mux_enum_info,
10853                 .get = alc_mux_enum_get,
10854                 .put = alc262_ultra_mux_enum_put,
10855         },
10856         { } /* end */
10857 };
10858
10859 /* add playback controls from the parsed DAC table */
10860 static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
10861                                              const struct auto_pin_cfg *cfg)
10862 {
10863         hda_nid_t nid;
10864         int err;
10865
10866         spec->multiout.num_dacs = 1;    /* only use one dac */
10867         spec->multiout.dac_nids = spec->private_dac_nids;
10868         spec->multiout.dac_nids[0] = 2;
10869
10870         nid = cfg->line_out_pins[0];
10871         if (nid) {
10872                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
10873                                   "Front Playback Volume",
10874                                   HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT));
10875                 if (err < 0)
10876                         return err;
10877                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10878                                   "Front Playback Switch",
10879                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
10880                 if (err < 0)
10881                         return err;
10882         }
10883
10884         nid = cfg->speaker_pins[0];
10885         if (nid) {
10886                 if (nid == 0x16) {
10887                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
10888                                           "Speaker Playback Volume",
10889                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
10890                                                               HDA_OUTPUT));
10891                         if (err < 0)
10892                                 return err;
10893                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10894                                           "Speaker Playback Switch",
10895                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
10896                                                               HDA_OUTPUT));
10897                         if (err < 0)
10898                                 return err;
10899                 } else {
10900                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10901                                           "Speaker Playback Switch",
10902                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
10903                                                               HDA_OUTPUT));
10904                         if (err < 0)
10905                                 return err;
10906                 }
10907         }
10908         nid = cfg->hp_pins[0];
10909         if (nid) {
10910                 /* spec->multiout.hp_nid = 2; */
10911                 if (nid == 0x16) {
10912                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
10913                                           "Headphone Playback Volume",
10914                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
10915                                                               HDA_OUTPUT));
10916                         if (err < 0)
10917                                 return err;
10918                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10919                                           "Headphone Playback Switch",
10920                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
10921                                                               HDA_OUTPUT));
10922                         if (err < 0)
10923                                 return err;
10924                 } else {
10925                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10926                                           "Headphone Playback Switch",
10927                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
10928                                                               HDA_OUTPUT));
10929                         if (err < 0)
10930                                 return err;
10931                 }
10932         }
10933         return 0;
10934 }
10935
10936 static int alc262_auto_create_analog_input_ctls(struct alc_spec *spec,
10937                                                 const struct auto_pin_cfg *cfg)
10938 {
10939         int err;
10940
10941         err = alc880_auto_create_analog_input_ctls(spec, cfg);
10942         if (err < 0)
10943                 return err;
10944         /* digital-mic input pin is excluded in alc880_auto_create..()
10945          * because it's under 0x18
10946          */
10947         if (cfg->input_pins[AUTO_PIN_MIC] == 0x12 ||
10948             cfg->input_pins[AUTO_PIN_FRONT_MIC] == 0x12) {
10949                 struct hda_input_mux *imux = &spec->private_imux[0];
10950                 imux->items[imux->num_items].label = "Int Mic";
10951                 imux->items[imux->num_items].index = 0x09;
10952                 imux->num_items++;
10953         }
10954         return 0;
10955 }
10956
10957
10958 /*
10959  * generic initialization of ADC, input mixers and output mixers
10960  */
10961 static struct hda_verb alc262_volume_init_verbs[] = {
10962         /*
10963          * Unmute ADC0-2 and set the default input to mic-in
10964          */
10965         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10966         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10967         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10968         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10969         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10970         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10971
10972         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10973          * mixer widget
10974          * Note: PASD motherboards uses the Line In 2 as the input for
10975          * front panel mic (mic 2)
10976          */
10977         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10978         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10979         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10980         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10981         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10982         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10983
10984         /*
10985          * Set up output mixers (0x0c - 0x0f)
10986          */
10987         /* set vol=0 to output mixers */
10988         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10989         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10990         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10991
10992         /* set up input amps for analog loopback */
10993         /* Amp Indices: DAC = 0, mixer = 1 */
10994         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10995         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10996         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10997         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10998         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10999         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11000
11001         /* FIXME: use matrix-type input source selection */
11002         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
11003         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
11004         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11005         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11006         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11007         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11008         /* Input mixer2 */
11009         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11010         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11011         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11012         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11013         /* Input mixer3 */
11014         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11015         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11016         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11017         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11018
11019         { }
11020 };
11021
11022 static struct hda_verb alc262_HP_BPC_init_verbs[] = {
11023         /*
11024          * Unmute ADC0-2 and set the default input to mic-in
11025          */
11026         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
11027         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11028         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11029         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11030         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
11031         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11032
11033         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
11034          * mixer widget
11035          * Note: PASD motherboards uses the Line In 2 as the input for
11036          * front panel mic (mic 2)
11037          */
11038         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
11039         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11040         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11041         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11042         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11043         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
11044         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
11045         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
11046
11047         /*
11048          * Set up output mixers (0x0c - 0x0e)
11049          */
11050         /* set vol=0 to output mixers */
11051         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11052         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11053         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11054
11055         /* set up input amps for analog loopback */
11056         /* Amp Indices: DAC = 0, mixer = 1 */
11057         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11058         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11059         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11060         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11061         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11062         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11063
11064         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11065         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11066         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11067
11068         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11069         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11070
11071         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
11072         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
11073
11074         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11075         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11076         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11077         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11078         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11079
11080         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11081         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11082         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11083         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11084         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11085         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11086
11087
11088         /* FIXME: use matrix-type input source selection */
11089         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 0b, 12 */
11090         /* Input mixer1: only unmute Mic */
11091         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11092         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8))},
11093         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11094         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11095         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11096         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x05 << 8))},
11097         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x06 << 8))},
11098         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x07 << 8))},
11099         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x08 << 8))},
11100         /* Input mixer2 */
11101         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11102         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8))},
11103         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11104         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11105         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11106         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x05 << 8))},
11107         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x06 << 8))},
11108         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x07 << 8))},
11109         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x08 << 8))},
11110         /* Input mixer3 */
11111         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11112         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8))},
11113         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11114         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11115         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11116         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x05 << 8))},
11117         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x06 << 8))},
11118         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x07 << 8))},
11119         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x08 << 8))},
11120
11121         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11122
11123         { }
11124 };
11125
11126 static struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
11127         /*
11128          * Unmute ADC0-2 and set the default input to mic-in
11129          */
11130         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
11131         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11132         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11133         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11134         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
11135         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11136
11137         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
11138          * mixer widget
11139          * Note: PASD motherboards uses the Line In 2 as the input for front
11140          * panel mic (mic 2)
11141          */
11142         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
11143         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11144         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11145         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11146         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11147         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
11148         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
11149         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
11150         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
11151         /*
11152          * Set up output mixers (0x0c - 0x0e)
11153          */
11154         /* set vol=0 to output mixers */
11155         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11156         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11157         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11158
11159         /* set up input amps for analog loopback */
11160         /* Amp Indices: DAC = 0, mixer = 1 */
11161         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11162         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11163         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11164         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11165         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11166         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11167
11168
11169         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP */
11170         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Mono */
11171         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* rear MIC */
11172         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* Line in */
11173         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
11174         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Line out */
11175         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* CD in */
11176
11177         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11178         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11179
11180         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
11181         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
11182
11183         /* {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 }, */
11184         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11185         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11186         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
11187         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11188         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11189
11190         /* FIXME: use matrix-type input source selection */
11191         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
11192         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
11193         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, /*rear MIC*/
11194         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, /*Line in*/
11195         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))}, /*F MIC*/
11196         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))}, /*Front*/
11197         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))}, /*CD*/
11198         /* {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))},  */
11199         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))}, /*HP*/
11200         /* Input mixer2 */
11201         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11202         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
11203         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
11204         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
11205         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
11206         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
11207         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
11208         /* Input mixer3 */
11209         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11210         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
11211         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
11212         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
11213         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
11214         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
11215         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
11216
11217         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11218
11219         { }
11220 };
11221
11222 static struct hda_verb alc262_toshiba_rx1_unsol_verbs[] = {
11223
11224         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Front Speaker */
11225         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11226         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
11227
11228         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* MIC jack */
11229         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
11230         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
11231         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
11232
11233         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP  jack */
11234         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
11235         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
11236         {}
11237 };
11238
11239
11240 #ifdef CONFIG_SND_HDA_POWER_SAVE
11241 #define alc262_loopbacks        alc880_loopbacks
11242 #endif
11243
11244 /* pcm configuration: identical with ALC880 */
11245 #define alc262_pcm_analog_playback      alc880_pcm_analog_playback
11246 #define alc262_pcm_analog_capture       alc880_pcm_analog_capture
11247 #define alc262_pcm_digital_playback     alc880_pcm_digital_playback
11248 #define alc262_pcm_digital_capture      alc880_pcm_digital_capture
11249
11250 /*
11251  * BIOS auto configuration
11252  */
11253 static int alc262_parse_auto_config(struct hda_codec *codec)
11254 {
11255         struct alc_spec *spec = codec->spec;
11256         int err;
11257         static hda_nid_t alc262_ignore[] = { 0x1d, 0 };
11258
11259         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
11260                                            alc262_ignore);
11261         if (err < 0)
11262                 return err;
11263         if (!spec->autocfg.line_outs) {
11264                 if (spec->autocfg.dig_outs || spec->autocfg.dig_in_pin) {
11265                         spec->multiout.max_channels = 2;
11266                         spec->no_analog = 1;
11267                         goto dig_only;
11268                 }
11269                 return 0; /* can't find valid BIOS pin config */
11270         }
11271         err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
11272         if (err < 0)
11273                 return err;
11274         err = alc262_auto_create_analog_input_ctls(spec, &spec->autocfg);
11275         if (err < 0)
11276                 return err;
11277
11278         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
11279
11280  dig_only:
11281         if (spec->autocfg.dig_outs) {
11282                 spec->multiout.dig_out_nid = ALC262_DIGOUT_NID;
11283                 spec->dig_out_type = spec->autocfg.dig_out_type[0];
11284         }
11285         if (spec->autocfg.dig_in_pin)
11286                 spec->dig_in_nid = ALC262_DIGIN_NID;
11287
11288         if (spec->kctls.list)
11289                 add_mixer(spec, spec->kctls.list);
11290
11291         add_verb(spec, alc262_volume_init_verbs);
11292         spec->num_mux_defs = 1;
11293         spec->input_mux = &spec->private_imux[0];
11294
11295         err = alc_auto_add_mic_boost(codec);
11296         if (err < 0)
11297                 return err;
11298
11299         alc_ssid_check(codec, 0x15, 0x14, 0x1b);
11300
11301         return 1;
11302 }
11303
11304 #define alc262_auto_init_multi_out      alc882_auto_init_multi_out
11305 #define alc262_auto_init_hp_out         alc882_auto_init_hp_out
11306 #define alc262_auto_init_analog_input   alc882_auto_init_analog_input
11307 #define alc262_auto_init_input_src      alc882_auto_init_input_src
11308
11309
11310 /* init callback for auto-configuration model -- overriding the default init */
11311 static void alc262_auto_init(struct hda_codec *codec)
11312 {
11313         struct alc_spec *spec = codec->spec;
11314         alc262_auto_init_multi_out(codec);
11315         alc262_auto_init_hp_out(codec);
11316         alc262_auto_init_analog_input(codec);
11317         alc262_auto_init_input_src(codec);
11318         if (spec->unsol_event)
11319                 alc_inithook(codec);
11320 }
11321
11322 /*
11323  * configuration and preset
11324  */
11325 static const char *alc262_models[ALC262_MODEL_LAST] = {
11326         [ALC262_BASIC]          = "basic",
11327         [ALC262_HIPPO]          = "hippo",
11328         [ALC262_HIPPO_1]        = "hippo_1",
11329         [ALC262_FUJITSU]        = "fujitsu",
11330         [ALC262_HP_BPC]         = "hp-bpc",
11331         [ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000",
11332         [ALC262_HP_TC_T5735]    = "hp-tc-t5735",
11333         [ALC262_HP_RP5700]      = "hp-rp5700",
11334         [ALC262_BENQ_ED8]       = "benq",
11335         [ALC262_BENQ_T31]       = "benq-t31",
11336         [ALC262_SONY_ASSAMD]    = "sony-assamd",
11337         [ALC262_TOSHIBA_S06]    = "toshiba-s06",
11338         [ALC262_TOSHIBA_RX1]    = "toshiba-rx1",
11339         [ALC262_ULTRA]          = "ultra",
11340         [ALC262_LENOVO_3000]    = "lenovo-3000",
11341         [ALC262_NEC]            = "nec",
11342         [ALC262_TYAN]           = "tyan",
11343         [ALC262_AUTO]           = "auto",
11344 };
11345
11346 static struct snd_pci_quirk alc262_cfg_tbl[] = {
11347         SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
11348         SND_PCI_QUIRK(0x1033, 0x8895, "NEC Versa S9100", ALC262_NEC),
11349         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1200, "HP xw series",
11350                            ALC262_HP_BPC),
11351         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1300, "HP xw series",
11352                            ALC262_HP_BPC),
11353         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1700, "HP xw series",
11354                            ALC262_HP_BPC),
11355         SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
11356         SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
11357         SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
11358         SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF),
11359         SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL),
11360         SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF),
11361         SND_PCI_QUIRK(0x103c, 0x2806, "HP D7000", ALC262_HP_BPC_D7000_WL),
11362         SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF),
11363         SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC),
11364         SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC),
11365         SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC),
11366         SND_PCI_QUIRK(0x103c, 0x302f, "HP Thin Client T5735",
11367                       ALC262_HP_TC_T5735),
11368         SND_PCI_QUIRK(0x103c, 0x2817, "HP RP5700", ALC262_HP_RP5700),
11369         SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD),
11370         SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
11371         SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
11372         SND_PCI_QUIRK(0x104d, 0x9016, "Sony VAIO", ALC262_AUTO), /* dig-only */
11373         SND_PCI_QUIRK(0x104d, 0x9025, "Sony VAIO Z21MN", ALC262_TOSHIBA_S06),
11374         SND_PCI_QUIRK_MASK(0x104d, 0xff00, 0x9000, "Sony VAIO",
11375                            ALC262_SONY_ASSAMD),
11376         SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
11377                       ALC262_TOSHIBA_RX1),
11378         SND_PCI_QUIRK(0x1179, 0xff7b, "Toshiba S06", ALC262_TOSHIBA_S06),
11379         SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
11380         SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU),
11381         SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_TYAN),
11382         SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc032, "Samsung Q1",
11383                            ALC262_ULTRA),
11384         SND_PCI_QUIRK(0x144d, 0xc510, "Samsung Q45", ALC262_HIPPO),
11385         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 y410", ALC262_LENOVO_3000),
11386         SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
11387         SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
11388         SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
11389         {}
11390 };
11391
11392 static struct alc_config_preset alc262_presets[] = {
11393         [ALC262_BASIC] = {
11394                 .mixers = { alc262_base_mixer },
11395                 .init_verbs = { alc262_init_verbs },
11396                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11397                 .dac_nids = alc262_dac_nids,
11398                 .hp_nid = 0x03,
11399                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11400                 .channel_mode = alc262_modes,
11401                 .input_mux = &alc262_capture_source,
11402         },
11403         [ALC262_HIPPO] = {
11404                 .mixers = { alc262_hippo_mixer },
11405                 .init_verbs = { alc262_init_verbs, alc262_hippo_unsol_verbs},
11406                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11407                 .dac_nids = alc262_dac_nids,
11408                 .hp_nid = 0x03,
11409                 .dig_out_nid = ALC262_DIGOUT_NID,
11410                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11411                 .channel_mode = alc262_modes,
11412                 .input_mux = &alc262_capture_source,
11413                 .unsol_event = alc262_hippo_unsol_event,
11414                 .init_hook = alc262_hippo_init_hook,
11415         },
11416         [ALC262_HIPPO_1] = {
11417                 .mixers = { alc262_hippo1_mixer },
11418                 .init_verbs = { alc262_init_verbs, alc262_hippo1_unsol_verbs},
11419                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11420                 .dac_nids = alc262_dac_nids,
11421                 .hp_nid = 0x02,
11422                 .dig_out_nid = ALC262_DIGOUT_NID,
11423                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11424                 .channel_mode = alc262_modes,
11425                 .input_mux = &alc262_capture_source,
11426                 .unsol_event = alc262_hippo_unsol_event,
11427                 .init_hook = alc262_hippo1_init_hook,
11428         },
11429         [ALC262_FUJITSU] = {
11430                 .mixers = { alc262_fujitsu_mixer },
11431                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
11432                                 alc262_fujitsu_unsol_verbs },
11433                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11434                 .dac_nids = alc262_dac_nids,
11435                 .hp_nid = 0x03,
11436                 .dig_out_nid = ALC262_DIGOUT_NID,
11437                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11438                 .channel_mode = alc262_modes,
11439                 .input_mux = &alc262_fujitsu_capture_source,
11440                 .unsol_event = alc262_fujitsu_unsol_event,
11441                 .init_hook = alc262_fujitsu_init_hook,
11442         },
11443         [ALC262_HP_BPC] = {
11444                 .mixers = { alc262_HP_BPC_mixer },
11445                 .init_verbs = { alc262_HP_BPC_init_verbs },
11446                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11447                 .dac_nids = alc262_dac_nids,
11448                 .hp_nid = 0x03,
11449                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11450                 .channel_mode = alc262_modes,
11451                 .input_mux = &alc262_HP_capture_source,
11452                 .unsol_event = alc262_hp_bpc_unsol_event,
11453                 .init_hook = alc262_hp_bpc_automute,
11454         },
11455         [ALC262_HP_BPC_D7000_WF] = {
11456                 .mixers = { alc262_HP_BPC_WildWest_mixer },
11457                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
11458                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11459                 .dac_nids = alc262_dac_nids,
11460                 .hp_nid = 0x03,
11461                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11462                 .channel_mode = alc262_modes,
11463                 .input_mux = &alc262_HP_D7000_capture_source,
11464                 .unsol_event = alc262_hp_wildwest_unsol_event,
11465                 .init_hook = alc262_hp_wildwest_automute,
11466         },
11467         [ALC262_HP_BPC_D7000_WL] = {
11468                 .mixers = { alc262_HP_BPC_WildWest_mixer,
11469                             alc262_HP_BPC_WildWest_option_mixer },
11470                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
11471                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11472                 .dac_nids = alc262_dac_nids,
11473                 .hp_nid = 0x03,
11474                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11475                 .channel_mode = alc262_modes,
11476                 .input_mux = &alc262_HP_D7000_capture_source,
11477                 .unsol_event = alc262_hp_wildwest_unsol_event,
11478                 .init_hook = alc262_hp_wildwest_automute,
11479         },
11480         [ALC262_HP_TC_T5735] = {
11481                 .mixers = { alc262_hp_t5735_mixer },
11482                 .init_verbs = { alc262_init_verbs, alc262_hp_t5735_verbs },
11483                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11484                 .dac_nids = alc262_dac_nids,
11485                 .hp_nid = 0x03,
11486                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11487                 .channel_mode = alc262_modes,
11488                 .input_mux = &alc262_capture_source,
11489                 .unsol_event = alc_automute_amp_unsol_event,
11490                 .init_hook = alc262_hp_t5735_init_hook,
11491         },
11492         [ALC262_HP_RP5700] = {
11493                 .mixers = { alc262_hp_rp5700_mixer },
11494                 .init_verbs = { alc262_init_verbs, alc262_hp_rp5700_verbs },
11495                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11496                 .dac_nids = alc262_dac_nids,
11497                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11498                 .channel_mode = alc262_modes,
11499                 .input_mux = &alc262_hp_rp5700_capture_source,
11500         },
11501         [ALC262_BENQ_ED8] = {
11502                 .mixers = { alc262_base_mixer },
11503                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs },
11504                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11505                 .dac_nids = alc262_dac_nids,
11506                 .hp_nid = 0x03,
11507                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11508                 .channel_mode = alc262_modes,
11509                 .input_mux = &alc262_capture_source,
11510         },
11511         [ALC262_SONY_ASSAMD] = {
11512                 .mixers = { alc262_sony_mixer },
11513                 .init_verbs = { alc262_init_verbs, alc262_sony_unsol_verbs},
11514                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11515                 .dac_nids = alc262_dac_nids,
11516                 .hp_nid = 0x02,
11517                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11518                 .channel_mode = alc262_modes,
11519                 .input_mux = &alc262_capture_source,
11520                 .unsol_event = alc262_hippo_unsol_event,
11521                 .init_hook = alc262_hippo_init_hook,
11522         },
11523         [ALC262_BENQ_T31] = {
11524                 .mixers = { alc262_benq_t31_mixer },
11525                 .init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs, alc262_hippo_unsol_verbs },
11526                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11527                 .dac_nids = alc262_dac_nids,
11528                 .hp_nid = 0x03,
11529                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11530                 .channel_mode = alc262_modes,
11531                 .input_mux = &alc262_capture_source,
11532                 .unsol_event = alc262_hippo_unsol_event,
11533                 .init_hook = alc262_hippo_init_hook,
11534         },
11535         [ALC262_ULTRA] = {
11536                 .mixers = { alc262_ultra_mixer },
11537                 .cap_mixer = alc262_ultra_capture_mixer,
11538                 .init_verbs = { alc262_ultra_verbs },
11539                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11540                 .dac_nids = alc262_dac_nids,
11541                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11542                 .channel_mode = alc262_modes,
11543                 .input_mux = &alc262_ultra_capture_source,
11544                 .adc_nids = alc262_adc_nids, /* ADC0 */
11545                 .capsrc_nids = alc262_capsrc_nids,
11546                 .num_adc_nids = 1, /* single ADC */
11547                 .unsol_event = alc262_ultra_unsol_event,
11548                 .init_hook = alc262_ultra_automute,
11549         },
11550         [ALC262_LENOVO_3000] = {
11551                 .mixers = { alc262_lenovo_3000_mixer },
11552                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
11553                                 alc262_lenovo_3000_unsol_verbs },
11554                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11555                 .dac_nids = alc262_dac_nids,
11556                 .hp_nid = 0x03,
11557                 .dig_out_nid = ALC262_DIGOUT_NID,
11558                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11559                 .channel_mode = alc262_modes,
11560                 .input_mux = &alc262_fujitsu_capture_source,
11561                 .unsol_event = alc262_lenovo_3000_unsol_event,
11562         },
11563         [ALC262_NEC] = {
11564                 .mixers = { alc262_nec_mixer },
11565                 .init_verbs = { alc262_nec_verbs },
11566                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11567                 .dac_nids = alc262_dac_nids,
11568                 .hp_nid = 0x03,
11569                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11570                 .channel_mode = alc262_modes,
11571                 .input_mux = &alc262_capture_source,
11572         },
11573         [ALC262_TOSHIBA_S06] = {
11574                 .mixers = { alc262_toshiba_s06_mixer },
11575                 .init_verbs = { alc262_init_verbs, alc262_toshiba_s06_verbs,
11576                                                         alc262_eapd_verbs },
11577                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11578                 .capsrc_nids = alc262_dmic_capsrc_nids,
11579                 .dac_nids = alc262_dac_nids,
11580                 .adc_nids = alc262_dmic_adc_nids, /* ADC0 */
11581                 .num_adc_nids = 1, /* single ADC */
11582                 .dig_out_nid = ALC262_DIGOUT_NID,
11583                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11584                 .channel_mode = alc262_modes,
11585                 .input_mux = &alc262_dmic_capture_source,
11586                 .unsol_event = alc262_toshiba_s06_unsol_event,
11587                 .init_hook = alc262_toshiba_s06_init_hook,
11588         },
11589         [ALC262_TOSHIBA_RX1] = {
11590                 .mixers = { alc262_toshiba_rx1_mixer },
11591                 .init_verbs = { alc262_init_verbs, alc262_toshiba_rx1_unsol_verbs },
11592                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11593                 .dac_nids = alc262_dac_nids,
11594                 .hp_nid = 0x03,
11595                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11596                 .channel_mode = alc262_modes,
11597                 .input_mux = &alc262_capture_source,
11598                 .unsol_event = alc262_hippo_unsol_event,
11599                 .init_hook = alc262_hippo_init_hook,
11600         },
11601         [ALC262_TYAN] = {
11602                 .mixers = { alc262_tyan_mixer },
11603                 .init_verbs = { alc262_init_verbs, alc262_tyan_verbs},
11604                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11605                 .dac_nids = alc262_dac_nids,
11606                 .hp_nid = 0x02,
11607                 .dig_out_nid = ALC262_DIGOUT_NID,
11608                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11609                 .channel_mode = alc262_modes,
11610                 .input_mux = &alc262_capture_source,
11611                 .unsol_event = alc_automute_amp_unsol_event,
11612                 .init_hook = alc262_tyan_init_hook,
11613         },
11614 };
11615
11616 static int patch_alc262(struct hda_codec *codec)
11617 {
11618         struct alc_spec *spec;
11619         int board_config;
11620         int err;
11621
11622         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
11623         if (spec == NULL)
11624                 return -ENOMEM;
11625
11626         codec->spec = spec;
11627 #if 0
11628         /* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is
11629          * under-run
11630          */
11631         {
11632         int tmp;
11633         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
11634         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
11635         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
11636         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
11637         }
11638 #endif
11639
11640         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
11641
11642         board_config = snd_hda_check_board_config(codec, ALC262_MODEL_LAST,
11643                                                   alc262_models,
11644                                                   alc262_cfg_tbl);
11645
11646         if (board_config < 0) {
11647                 printk(KERN_INFO "hda_codec: Unknown model for %s, "
11648                        "trying auto-probe from BIOS...\n", codec->chip_name);
11649                 board_config = ALC262_AUTO;
11650         }
11651
11652         if (board_config == ALC262_AUTO) {
11653                 /* automatic parse from the BIOS config */
11654                 err = alc262_parse_auto_config(codec);
11655                 if (err < 0) {
11656                         alc_free(codec);
11657                         return err;
11658                 } else if (!err) {
11659                         printk(KERN_INFO
11660                                "hda_codec: Cannot set up configuration "
11661                                "from BIOS.  Using base mode...\n");
11662                         board_config = ALC262_BASIC;
11663                 }
11664         }
11665
11666         if (!spec->no_analog) {
11667                 err = snd_hda_attach_beep_device(codec, 0x1);
11668                 if (err < 0) {
11669                         alc_free(codec);
11670                         return err;
11671                 }
11672         }
11673
11674         if (board_config != ALC262_AUTO)
11675                 setup_preset(spec, &alc262_presets[board_config]);
11676
11677         spec->stream_analog_playback = &alc262_pcm_analog_playback;
11678         spec->stream_analog_capture = &alc262_pcm_analog_capture;
11679
11680         spec->stream_digital_playback = &alc262_pcm_digital_playback;
11681         spec->stream_digital_capture = &alc262_pcm_digital_capture;
11682
11683         if (!spec->adc_nids && spec->input_mux) {
11684                 int i;
11685                 /* check whether the digital-mic has to be supported */
11686                 for (i = 0; i < spec->input_mux->num_items; i++) {
11687                         if (spec->input_mux->items[i].index >= 9)
11688                                 break;
11689                 }
11690                 if (i < spec->input_mux->num_items) {
11691                         /* use only ADC0 */
11692                         spec->adc_nids = alc262_dmic_adc_nids;
11693                         spec->num_adc_nids = 1;
11694                         spec->capsrc_nids = alc262_dmic_capsrc_nids;
11695                 } else {
11696                         /* all analog inputs */
11697                         /* check whether NID 0x07 is valid */
11698                         unsigned int wcap = get_wcaps(codec, 0x07);
11699
11700                         /* get type */
11701                         wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
11702                         if (wcap != AC_WID_AUD_IN) {
11703                                 spec->adc_nids = alc262_adc_nids_alt;
11704                                 spec->num_adc_nids =
11705                                         ARRAY_SIZE(alc262_adc_nids_alt);
11706                                 spec->capsrc_nids = alc262_capsrc_nids_alt;
11707                         } else {
11708                                 spec->adc_nids = alc262_adc_nids;
11709                                 spec->num_adc_nids =
11710                                         ARRAY_SIZE(alc262_adc_nids);
11711                                 spec->capsrc_nids = alc262_capsrc_nids;
11712                         }
11713                 }
11714         }
11715         if (!spec->cap_mixer && !spec->no_analog)
11716                 set_capture_mixer(spec);
11717         if (!spec->no_analog)
11718                 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
11719
11720         spec->vmaster_nid = 0x0c;
11721
11722         codec->patch_ops = alc_patch_ops;
11723         if (board_config == ALC262_AUTO)
11724                 spec->init_hook = alc262_auto_init;
11725 #ifdef CONFIG_SND_HDA_POWER_SAVE
11726         if (!spec->loopback.amplist)
11727                 spec->loopback.amplist = alc262_loopbacks;
11728 #endif
11729         codec->proc_widget_hook = print_realtek_coef;
11730
11731         return 0;
11732 }
11733
11734 /*
11735  *  ALC268 channel source setting (2 channel)
11736  */
11737 #define ALC268_DIGOUT_NID       ALC880_DIGOUT_NID
11738 #define alc268_modes            alc260_modes
11739
11740 static hda_nid_t alc268_dac_nids[2] = {
11741         /* front, hp */
11742         0x02, 0x03
11743 };
11744
11745 static hda_nid_t alc268_adc_nids[2] = {
11746         /* ADC0-1 */
11747         0x08, 0x07
11748 };
11749
11750 static hda_nid_t alc268_adc_nids_alt[1] = {
11751         /* ADC0 */
11752         0x08
11753 };
11754
11755 static hda_nid_t alc268_capsrc_nids[2] = { 0x23, 0x24 };
11756
11757 static struct snd_kcontrol_new alc268_base_mixer[] = {
11758         /* output mixer control */
11759         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
11760         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11761         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
11762         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11763         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11764         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
11765         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11766         { }
11767 };
11768
11769 static struct snd_kcontrol_new alc268_toshiba_mixer[] = {
11770         /* output mixer control */
11771         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
11772         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
11773         ALC262_HIPPO_MASTER_SWITCH,
11774         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11775         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
11776         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11777         { }
11778 };
11779
11780 /* bind Beep switches of both NID 0x0f and 0x10 */
11781 static struct hda_bind_ctls alc268_bind_beep_sw = {
11782         .ops = &snd_hda_bind_sw,
11783         .values = {
11784                 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
11785                 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
11786                 0
11787         },
11788 };
11789
11790 static struct snd_kcontrol_new alc268_beep_mixer[] = {
11791         HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
11792         HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
11793         { }
11794 };
11795
11796 static struct hda_verb alc268_eapd_verbs[] = {
11797         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
11798         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
11799         { }
11800 };
11801
11802 /* Toshiba specific */
11803 static struct hda_verb alc268_toshiba_verbs[] = {
11804         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11805         { } /* end */
11806 };
11807
11808 static struct hda_input_mux alc268_acer_lc_capture_source = {
11809         .num_items = 2,
11810         .items = {
11811                 { "i-Mic", 0x6 },
11812                 { "E-Mic", 0x0 },
11813         },
11814 };
11815
11816 /* Acer specific */
11817 /* bind volumes of both NID 0x02 and 0x03 */
11818 static struct hda_bind_ctls alc268_acer_bind_master_vol = {
11819         .ops = &snd_hda_bind_vol,
11820         .values = {
11821                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
11822                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
11823                 0
11824         },
11825 };
11826
11827 /* mute/unmute internal speaker according to the hp jack and mute state */
11828 static void alc268_acer_automute(struct hda_codec *codec, int force)
11829 {
11830         struct alc_spec *spec = codec->spec;
11831         unsigned int mute;
11832
11833         if (force || !spec->sense_updated) {
11834                 unsigned int present;
11835                 present = snd_hda_codec_read(codec, 0x14, 0,
11836                                          AC_VERB_GET_PIN_SENSE, 0);
11837                 spec->jack_present = (present & 0x80000000) != 0;
11838                 spec->sense_updated = 1;
11839         }
11840         if (spec->jack_present)
11841                 mute = HDA_AMP_MUTE; /* mute internal speaker */
11842         else /* unmute internal speaker if necessary */
11843                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
11844         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
11845                                  HDA_AMP_MUTE, mute);
11846 }
11847
11848
11849 /* bind hp and internal speaker mute (with plug check) */
11850 static int alc268_acer_master_sw_put(struct snd_kcontrol *kcontrol,
11851                                      struct snd_ctl_elem_value *ucontrol)
11852 {
11853         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
11854         long *valp = ucontrol->value.integer.value;
11855         int change;
11856
11857         change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
11858                                           HDA_AMP_MUTE,
11859                                           valp[0] ? 0 : HDA_AMP_MUTE);
11860         change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
11861                                            HDA_AMP_MUTE,
11862                                            valp[1] ? 0 : HDA_AMP_MUTE);
11863         if (change)
11864                 alc268_acer_automute(codec, 0);
11865         return change;
11866 }
11867
11868 static struct snd_kcontrol_new alc268_acer_aspire_one_mixer[] = {
11869         /* output mixer control */
11870         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11871         {
11872                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11873                 .name = "Master Playback Switch",
11874                 .info = snd_hda_mixer_amp_switch_info,
11875                 .get = snd_hda_mixer_amp_switch_get,
11876                 .put = alc268_acer_master_sw_put,
11877                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11878         },
11879         HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x18, 0, HDA_INPUT),
11880         { }
11881 };
11882
11883 static struct snd_kcontrol_new alc268_acer_mixer[] = {
11884         /* output mixer control */
11885         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11886         {
11887                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11888                 .name = "Master Playback Switch",
11889                 .info = snd_hda_mixer_amp_switch_info,
11890                 .get = snd_hda_mixer_amp_switch_get,
11891                 .put = alc268_acer_master_sw_put,
11892                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11893         },
11894         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11895         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
11896         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11897         { }
11898 };
11899
11900 static struct snd_kcontrol_new alc268_acer_dmic_mixer[] = {
11901         /* output mixer control */
11902         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11903         {
11904                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11905                 .name = "Master Playback Switch",
11906                 .info = snd_hda_mixer_amp_switch_info,
11907                 .get = snd_hda_mixer_amp_switch_get,
11908                 .put = alc268_acer_master_sw_put,
11909                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11910         },
11911         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11912         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11913         { }
11914 };
11915
11916 static struct hda_verb alc268_acer_aspire_one_verbs[] = {
11917         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11918         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11919         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11920         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
11921         {0x23, AC_VERB_SET_CONNECT_SEL, 0x06},
11922         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, 0xa017},
11923         { }
11924 };
11925
11926 static struct hda_verb alc268_acer_verbs[] = {
11927         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* internal dmic? */
11928         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11929         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11930         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11931         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11932         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11933         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11934         { }
11935 };
11936
11937 /* unsolicited event for HP jack sensing */
11938 #define alc268_toshiba_unsol_event      alc262_hippo_unsol_event
11939 #define alc268_toshiba_init_hook        alc262_hippo_init_hook
11940
11941 static void alc268_acer_unsol_event(struct hda_codec *codec,
11942                                        unsigned int res)
11943 {
11944         if ((res >> 26) != ALC880_HP_EVENT)
11945                 return;
11946         alc268_acer_automute(codec, 1);
11947 }
11948
11949 static void alc268_acer_init_hook(struct hda_codec *codec)
11950 {
11951         alc268_acer_automute(codec, 1);
11952 }
11953
11954 /* toggle speaker-output according to the hp-jack state */
11955 static void alc268_aspire_one_speaker_automute(struct hda_codec *codec)
11956 {
11957         unsigned int present;
11958         unsigned char bits;
11959
11960         present = snd_hda_codec_read(codec, 0x15, 0,
11961                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11962         bits = present ? AMP_IN_MUTE(0) : 0;
11963         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 0,
11964                                 AMP_IN_MUTE(0), bits);
11965         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 1,
11966                                 AMP_IN_MUTE(0), bits);
11967 }
11968
11969
11970 static void alc268_acer_mic_automute(struct hda_codec *codec)
11971 {
11972         unsigned int present;
11973
11974         present = snd_hda_codec_read(codec, 0x18, 0,
11975                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11976         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_CONNECT_SEL,
11977                             present ? 0x0 : 0x6);
11978 }
11979
11980 static void alc268_acer_lc_unsol_event(struct hda_codec *codec,
11981                                     unsigned int res)
11982 {
11983         if ((res >> 26) == ALC880_HP_EVENT)
11984                 alc268_aspire_one_speaker_automute(codec);
11985         if ((res >> 26) == ALC880_MIC_EVENT)
11986                 alc268_acer_mic_automute(codec);
11987 }
11988
11989 static void alc268_acer_lc_init_hook(struct hda_codec *codec)
11990 {
11991         alc268_aspire_one_speaker_automute(codec);
11992         alc268_acer_mic_automute(codec);
11993 }
11994
11995 static struct snd_kcontrol_new alc268_dell_mixer[] = {
11996         /* output mixer control */
11997         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11998         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11999         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12000         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12001         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12002         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
12003         { }
12004 };
12005
12006 static struct hda_verb alc268_dell_verbs[] = {
12007         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12008         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12009         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12010         { }
12011 };
12012
12013 /* mute/unmute internal speaker according to the hp jack and mute state */
12014 static void alc268_dell_init_hook(struct hda_codec *codec)
12015 {
12016         struct alc_spec *spec = codec->spec;
12017
12018         spec->autocfg.hp_pins[0] = 0x15;
12019         spec->autocfg.speaker_pins[0] = 0x14;
12020         alc_automute_pin(codec);
12021 }
12022
12023 static struct snd_kcontrol_new alc267_quanta_il1_mixer[] = {
12024         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x2, 0x0, HDA_OUTPUT),
12025         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12026         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
12027         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12028         HDA_CODEC_VOLUME("Mic Capture Volume", 0x23, 0x0, HDA_OUTPUT),
12029         HDA_BIND_MUTE("Mic Capture Switch", 0x23, 2, HDA_OUTPUT),
12030         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
12031         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
12032         { }
12033 };
12034
12035 static struct hda_verb alc267_quanta_il1_verbs[] = {
12036         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12037         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
12038         { }
12039 };
12040
12041 static void alc267_quanta_il1_mic_automute(struct hda_codec *codec)
12042 {
12043         unsigned int present;
12044
12045         present = snd_hda_codec_read(codec, 0x18, 0,
12046                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12047         snd_hda_codec_write(codec, 0x23, 0,
12048                             AC_VERB_SET_CONNECT_SEL,
12049                             present ? 0x00 : 0x01);
12050 }
12051
12052 static void alc267_quanta_il1_init_hook(struct hda_codec *codec)
12053 {
12054         struct alc_spec *spec = codec->spec;
12055
12056         spec->autocfg.hp_pins[0] = 0x15;
12057         spec->autocfg.speaker_pins[0] = 0x14;
12058         alc_automute_pin(codec);
12059         alc267_quanta_il1_mic_automute(codec);
12060 }
12061
12062 static void alc267_quanta_il1_unsol_event(struct hda_codec *codec,
12063                                            unsigned int res)
12064 {
12065         switch (res >> 26) {
12066         case ALC880_MIC_EVENT:
12067                 alc267_quanta_il1_mic_automute(codec);
12068                 break;
12069         default:
12070                 alc_sku_unsol_event(codec, res);
12071                 break;
12072         }
12073 }
12074
12075 /*
12076  * generic initialization of ADC, input mixers and output mixers
12077  */
12078 static struct hda_verb alc268_base_init_verbs[] = {
12079         /* Unmute DAC0-1 and set vol = 0 */
12080         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12081         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12082
12083         /*
12084          * Set up output mixers (0x0c - 0x0e)
12085          */
12086         /* set vol=0 to output mixers */
12087         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12088         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
12089
12090         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12091         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12092
12093         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
12094         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
12095         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
12096         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
12097         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
12098         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12099         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12100         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12101
12102         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12103         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12104         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12105         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12106         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12107
12108         /* set PCBEEP vol = 0, mute connections */
12109         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12110         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12111         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12112
12113         /* Unmute Selector 23h,24h and set the default input to mic-in */
12114
12115         {0x23, AC_VERB_SET_CONNECT_SEL, 0x00},
12116         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12117         {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
12118         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12119
12120         { }
12121 };
12122
12123 /*
12124  * generic initialization of ADC, input mixers and output mixers
12125  */
12126 static struct hda_verb alc268_volume_init_verbs[] = {
12127         /* set output DAC */
12128         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12129         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12130
12131         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
12132         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
12133         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12134         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12135         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12136
12137         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12138         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12139         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12140
12141         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12142         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12143
12144         /* set PCBEEP vol = 0, mute connections */
12145         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12146         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12147         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12148
12149         { }
12150 };
12151
12152 static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
12153         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
12154         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
12155         {
12156                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12157                 /* The multiple "Capture Source" controls confuse alsamixer
12158                  * So call somewhat different..
12159                  */
12160                 /* .name = "Capture Source", */
12161                 .name = "Input Source",
12162                 .count = 1,
12163                 .info = alc_mux_enum_info,
12164                 .get = alc_mux_enum_get,
12165                 .put = alc_mux_enum_put,
12166         },
12167         { } /* end */
12168 };
12169
12170 static struct snd_kcontrol_new alc268_capture_mixer[] = {
12171         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
12172         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
12173         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
12174         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
12175         {
12176                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12177                 /* The multiple "Capture Source" controls confuse alsamixer
12178                  * So call somewhat different..
12179                  */
12180                 /* .name = "Capture Source", */
12181                 .name = "Input Source",
12182                 .count = 2,
12183                 .info = alc_mux_enum_info,
12184                 .get = alc_mux_enum_get,
12185                 .put = alc_mux_enum_put,
12186         },
12187         { } /* end */
12188 };
12189
12190 static struct hda_input_mux alc268_capture_source = {
12191         .num_items = 4,
12192         .items = {
12193                 { "Mic", 0x0 },
12194                 { "Front Mic", 0x1 },
12195                 { "Line", 0x2 },
12196                 { "CD", 0x3 },
12197         },
12198 };
12199
12200 static struct hda_input_mux alc268_acer_capture_source = {
12201         .num_items = 3,
12202         .items = {
12203                 { "Mic", 0x0 },
12204                 { "Internal Mic", 0x1 },
12205                 { "Line", 0x2 },
12206         },
12207 };
12208
12209 static struct hda_input_mux alc268_acer_dmic_capture_source = {
12210         .num_items = 3,
12211         .items = {
12212                 { "Mic", 0x0 },
12213                 { "Internal Mic", 0x6 },
12214                 { "Line", 0x2 },
12215         },
12216 };
12217
12218 #ifdef CONFIG_SND_DEBUG
12219 static struct snd_kcontrol_new alc268_test_mixer[] = {
12220         /* Volume widgets */
12221         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12222         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12223         HDA_BIND_MUTE_MONO("Mono sum Playback Switch", 0x0e, 1, 2, HDA_INPUT),
12224         HDA_BIND_MUTE("LINE-OUT sum Playback Switch", 0x0f, 2, HDA_INPUT),
12225         HDA_BIND_MUTE("HP-OUT sum Playback Switch", 0x10, 2, HDA_INPUT),
12226         HDA_BIND_MUTE("LINE-OUT Playback Switch", 0x14, 2, HDA_OUTPUT),
12227         HDA_BIND_MUTE("HP-OUT Playback Switch", 0x15, 2, HDA_OUTPUT),
12228         HDA_BIND_MUTE("Mono Playback Switch", 0x16, 2, HDA_OUTPUT),
12229         HDA_CODEC_VOLUME("MIC1 Capture Volume", 0x18, 0x0, HDA_INPUT),
12230         HDA_BIND_MUTE("MIC1 Capture Switch", 0x18, 2, HDA_OUTPUT),
12231         HDA_CODEC_VOLUME("MIC2 Capture Volume", 0x19, 0x0, HDA_INPUT),
12232         HDA_CODEC_VOLUME("LINE1 Capture Volume", 0x1a, 0x0, HDA_INPUT),
12233         HDA_BIND_MUTE("LINE1 Capture Switch", 0x1a, 2, HDA_OUTPUT),
12234         /* The below appears problematic on some hardwares */
12235         /*HDA_CODEC_VOLUME("PCBEEP Playback Volume", 0x1d, 0x0, HDA_INPUT),*/
12236         HDA_CODEC_VOLUME("PCM-IN1 Capture Volume", 0x23, 0x0, HDA_OUTPUT),
12237         HDA_BIND_MUTE("PCM-IN1 Capture Switch", 0x23, 2, HDA_OUTPUT),
12238         HDA_CODEC_VOLUME("PCM-IN2 Capture Volume", 0x24, 0x0, HDA_OUTPUT),
12239         HDA_BIND_MUTE("PCM-IN2 Capture Switch", 0x24, 2, HDA_OUTPUT),
12240
12241         /* Modes for retasking pin widgets */
12242         ALC_PIN_MODE("LINE-OUT pin mode", 0x14, ALC_PIN_DIR_INOUT),
12243         ALC_PIN_MODE("HP-OUT pin mode", 0x15, ALC_PIN_DIR_INOUT),
12244         ALC_PIN_MODE("MIC1 pin mode", 0x18, ALC_PIN_DIR_INOUT),
12245         ALC_PIN_MODE("LINE1 pin mode", 0x1a, ALC_PIN_DIR_INOUT),
12246
12247         /* Controls for GPIO pins, assuming they are configured as outputs */
12248         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
12249         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
12250         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
12251         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
12252
12253         /* Switches to allow the digital SPDIF output pin to be enabled.
12254          * The ALC268 does not have an SPDIF input.
12255          */
12256         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x06, 0x01),
12257
12258         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
12259          * this output to turn on an external amplifier.
12260          */
12261         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
12262         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
12263
12264         { } /* end */
12265 };
12266 #endif
12267
12268 /* create input playback/capture controls for the given pin */
12269 static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
12270                                     const char *ctlname, int idx)
12271 {
12272         char name[32];
12273         int err;
12274
12275         sprintf(name, "%s Playback Volume", ctlname);
12276         if (nid == 0x14) {
12277                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
12278                                   HDA_COMPOSE_AMP_VAL(0x02, 3, idx,
12279                                                       HDA_OUTPUT));
12280                 if (err < 0)
12281                         return err;
12282         } else if (nid == 0x15) {
12283                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
12284                                   HDA_COMPOSE_AMP_VAL(0x03, 3, idx,
12285                                                       HDA_OUTPUT));
12286                 if (err < 0)
12287                         return err;
12288         } else
12289                 return -1;
12290         sprintf(name, "%s Playback Switch", ctlname);
12291         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
12292                           HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
12293         if (err < 0)
12294                 return err;
12295         return 0;
12296 }
12297
12298 /* add playback controls from the parsed DAC table */
12299 static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
12300                                              const struct auto_pin_cfg *cfg)
12301 {
12302         hda_nid_t nid;
12303         int err;
12304
12305         spec->multiout.num_dacs = 2;    /* only use one dac */
12306         spec->multiout.dac_nids = spec->private_dac_nids;
12307         spec->multiout.dac_nids[0] = 2;
12308         spec->multiout.dac_nids[1] = 3;
12309
12310         nid = cfg->line_out_pins[0];
12311         if (nid)
12312                 alc268_new_analog_output(spec, nid, "Front", 0);
12313
12314         nid = cfg->speaker_pins[0];
12315         if (nid == 0x1d) {
12316                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
12317                                   "Speaker Playback Volume",
12318                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
12319                 if (err < 0)
12320                         return err;
12321         }
12322         nid = cfg->hp_pins[0];
12323         if (nid)
12324                 alc268_new_analog_output(spec, nid, "Headphone", 0);
12325
12326         nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
12327         if (nid == 0x16) {
12328                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12329                                   "Mono Playback Switch",
12330                                   HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_INPUT));
12331                 if (err < 0)
12332                         return err;
12333         }
12334         return 0;
12335 }
12336
12337 /* create playback/capture controls for input pins */
12338 static int alc268_auto_create_analog_input_ctls(struct alc_spec *spec,
12339                                                 const struct auto_pin_cfg *cfg)
12340 {
12341         struct hda_input_mux *imux = &spec->private_imux[0];
12342         int i, idx1;
12343
12344         for (i = 0; i < AUTO_PIN_LAST; i++) {
12345                 switch(cfg->input_pins[i]) {
12346                 case 0x18:
12347                         idx1 = 0;       /* Mic 1 */
12348                         break;
12349                 case 0x19:
12350                         idx1 = 1;       /* Mic 2 */
12351                         break;
12352                 case 0x1a:
12353                         idx1 = 2;       /* Line In */
12354                         break;
12355                 case 0x1c:
12356                         idx1 = 3;       /* CD */
12357                         break;
12358                 case 0x12:
12359                 case 0x13:
12360                         idx1 = 6;       /* digital mics */
12361                         break;
12362                 default:
12363                         continue;
12364                 }
12365                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
12366                 imux->items[imux->num_items].index = idx1;
12367                 imux->num_items++;
12368         }
12369         return 0;
12370 }
12371
12372 static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
12373 {
12374         struct alc_spec *spec = codec->spec;
12375         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
12376         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
12377         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
12378         unsigned int    dac_vol1, dac_vol2;
12379
12380         if (speaker_nid) {
12381                 snd_hda_codec_write(codec, speaker_nid, 0,
12382                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
12383                 snd_hda_codec_write(codec, 0x0f, 0,
12384                                     AC_VERB_SET_AMP_GAIN_MUTE,
12385                                     AMP_IN_UNMUTE(1));
12386                 snd_hda_codec_write(codec, 0x10, 0,
12387                                     AC_VERB_SET_AMP_GAIN_MUTE,
12388                                     AMP_IN_UNMUTE(1));
12389         } else {
12390                 snd_hda_codec_write(codec, 0x0f, 0,
12391                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
12392                 snd_hda_codec_write(codec, 0x10, 0,
12393                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
12394         }
12395
12396         dac_vol1 = dac_vol2 = 0xb000 | 0x40;    /* set max volume  */
12397         if (line_nid == 0x14)
12398                 dac_vol2 = AMP_OUT_ZERO;
12399         else if (line_nid == 0x15)
12400                 dac_vol1 = AMP_OUT_ZERO;
12401         if (hp_nid == 0x14)
12402                 dac_vol2 = AMP_OUT_ZERO;
12403         else if (hp_nid == 0x15)
12404                 dac_vol1 = AMP_OUT_ZERO;
12405         if (line_nid != 0x16 || hp_nid != 0x16 ||
12406             spec->autocfg.line_out_pins[1] != 0x16 ||
12407             spec->autocfg.line_out_pins[2] != 0x16)
12408                 dac_vol1 = dac_vol2 = AMP_OUT_ZERO;
12409
12410         snd_hda_codec_write(codec, 0x02, 0,
12411                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol1);
12412         snd_hda_codec_write(codec, 0x03, 0,
12413                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol2);
12414 }
12415
12416 /* pcm configuration: identical with ALC880 */
12417 #define alc268_pcm_analog_playback      alc880_pcm_analog_playback
12418 #define alc268_pcm_analog_capture       alc880_pcm_analog_capture
12419 #define alc268_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
12420 #define alc268_pcm_digital_playback     alc880_pcm_digital_playback
12421
12422 /*
12423  * BIOS auto configuration
12424  */
12425 static int alc268_parse_auto_config(struct hda_codec *codec)
12426 {
12427         struct alc_spec *spec = codec->spec;
12428         int err;
12429         static hda_nid_t alc268_ignore[] = { 0 };
12430
12431         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
12432                                            alc268_ignore);
12433         if (err < 0)
12434                 return err;
12435         if (!spec->autocfg.line_outs) {
12436                 if (spec->autocfg.dig_outs || spec->autocfg.dig_in_pin) {
12437                         spec->multiout.max_channels = 2;
12438                         spec->no_analog = 1;
12439                         goto dig_only;
12440                 }
12441                 return 0; /* can't find valid BIOS pin config */
12442         }
12443         err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
12444         if (err < 0)
12445                 return err;
12446         err = alc268_auto_create_analog_input_ctls(spec, &spec->autocfg);
12447         if (err < 0)
12448                 return err;
12449
12450         spec->multiout.max_channels = 2;
12451
12452  dig_only:
12453         /* digital only support output */
12454         if (spec->autocfg.dig_outs) {
12455                 spec->multiout.dig_out_nid = ALC268_DIGOUT_NID;
12456                 spec->dig_out_type = spec->autocfg.dig_out_type[0];
12457         }
12458         if (spec->kctls.list)
12459                 add_mixer(spec, spec->kctls.list);
12460
12461         if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d)
12462                 add_mixer(spec, alc268_beep_mixer);
12463
12464         add_verb(spec, alc268_volume_init_verbs);
12465         spec->num_mux_defs = 1;
12466         spec->input_mux = &spec->private_imux[0];
12467
12468         err = alc_auto_add_mic_boost(codec);
12469         if (err < 0)
12470                 return err;
12471
12472         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
12473
12474         return 1;
12475 }
12476
12477 #define alc268_auto_init_multi_out      alc882_auto_init_multi_out
12478 #define alc268_auto_init_hp_out         alc882_auto_init_hp_out
12479 #define alc268_auto_init_analog_input   alc882_auto_init_analog_input
12480
12481 /* init callback for auto-configuration model -- overriding the default init */
12482 static void alc268_auto_init(struct hda_codec *codec)
12483 {
12484         struct alc_spec *spec = codec->spec;
12485         alc268_auto_init_multi_out(codec);
12486         alc268_auto_init_hp_out(codec);
12487         alc268_auto_init_mono_speaker_out(codec);
12488         alc268_auto_init_analog_input(codec);
12489         if (spec->unsol_event)
12490                 alc_inithook(codec);
12491 }
12492
12493 /*
12494  * configuration and preset
12495  */
12496 static const char *alc268_models[ALC268_MODEL_LAST] = {
12497         [ALC267_QUANTA_IL1]     = "quanta-il1",
12498         [ALC268_3ST]            = "3stack",
12499         [ALC268_TOSHIBA]        = "toshiba",
12500         [ALC268_ACER]           = "acer",
12501         [ALC268_ACER_DMIC]      = "acer-dmic",
12502         [ALC268_ACER_ASPIRE_ONE]        = "acer-aspire",
12503         [ALC268_DELL]           = "dell",
12504         [ALC268_ZEPTO]          = "zepto",
12505 #ifdef CONFIG_SND_DEBUG
12506         [ALC268_TEST]           = "test",
12507 #endif
12508         [ALC268_AUTO]           = "auto",
12509 };
12510
12511 static struct snd_pci_quirk alc268_cfg_tbl[] = {
12512         SND_PCI_QUIRK(0x1025, 0x011e, "Acer Aspire 5720z", ALC268_ACER),
12513         SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
12514         SND_PCI_QUIRK(0x1025, 0x012e, "Acer Aspire 5310", ALC268_ACER),
12515         SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
12516         SND_PCI_QUIRK(0x1025, 0x0136, "Acer Aspire 5315", ALC268_ACER),
12517         SND_PCI_QUIRK(0x1025, 0x015b, "Acer Aspire One",
12518                                                 ALC268_ACER_ASPIRE_ONE),
12519         SND_PCI_QUIRK(0x1028, 0x0253, "Dell OEM", ALC268_DELL),
12520         SND_PCI_QUIRK(0x1028, 0x02b0, "Dell Inspiron Mini9", ALC268_DELL),
12521         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP TX25xx series",
12522                            ALC268_TOSHIBA),
12523         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
12524         SND_PCI_QUIRK(0x1170, 0x0040, "ZEPTO", ALC268_ZEPTO),
12525         SND_PCI_QUIRK_MASK(0x1179, 0xff00, 0xff00, "TOSHIBA A/Lx05",
12526                            ALC268_TOSHIBA),
12527         SND_PCI_QUIRK(0x14c0, 0x0025, "COMPAL IFL90/JFL-92", ALC268_TOSHIBA),
12528         SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER),
12529         SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1),
12530         SND_PCI_QUIRK(0x1854, 0x1775, "LG R510", ALC268_DELL),
12531         {}
12532 };
12533
12534 static struct alc_config_preset alc268_presets[] = {
12535         [ALC267_QUANTA_IL1] = {
12536                 .mixers = { alc267_quanta_il1_mixer, alc268_beep_mixer },
12537                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12538                                 alc267_quanta_il1_verbs },
12539                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12540                 .dac_nids = alc268_dac_nids,
12541                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12542                 .adc_nids = alc268_adc_nids_alt,
12543                 .hp_nid = 0x03,
12544                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12545                 .channel_mode = alc268_modes,
12546                 .input_mux = &alc268_capture_source,
12547                 .unsol_event = alc267_quanta_il1_unsol_event,
12548                 .init_hook = alc267_quanta_il1_init_hook,
12549         },
12550         [ALC268_3ST] = {
12551                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
12552                             alc268_beep_mixer },
12553                 .init_verbs = { alc268_base_init_verbs },
12554                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12555                 .dac_nids = alc268_dac_nids,
12556                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12557                 .adc_nids = alc268_adc_nids_alt,
12558                 .capsrc_nids = alc268_capsrc_nids,
12559                 .hp_nid = 0x03,
12560                 .dig_out_nid = ALC268_DIGOUT_NID,
12561                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12562                 .channel_mode = alc268_modes,
12563                 .input_mux = &alc268_capture_source,
12564         },
12565         [ALC268_TOSHIBA] = {
12566                 .mixers = { alc268_toshiba_mixer, alc268_capture_alt_mixer,
12567                             alc268_beep_mixer },
12568                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12569                                 alc268_toshiba_verbs },
12570                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12571                 .dac_nids = alc268_dac_nids,
12572                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12573                 .adc_nids = alc268_adc_nids_alt,
12574                 .capsrc_nids = alc268_capsrc_nids,
12575                 .hp_nid = 0x03,
12576                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12577                 .channel_mode = alc268_modes,
12578                 .input_mux = &alc268_capture_source,
12579                 .unsol_event = alc268_toshiba_unsol_event,
12580                 .init_hook = alc268_toshiba_init_hook,
12581         },
12582         [ALC268_ACER] = {
12583                 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer,
12584                             alc268_beep_mixer },
12585                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12586                                 alc268_acer_verbs },
12587                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12588                 .dac_nids = alc268_dac_nids,
12589                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12590                 .adc_nids = alc268_adc_nids_alt,
12591                 .capsrc_nids = alc268_capsrc_nids,
12592                 .hp_nid = 0x02,
12593                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12594                 .channel_mode = alc268_modes,
12595                 .input_mux = &alc268_acer_capture_source,
12596                 .unsol_event = alc268_acer_unsol_event,
12597                 .init_hook = alc268_acer_init_hook,
12598         },
12599         [ALC268_ACER_DMIC] = {
12600                 .mixers = { alc268_acer_dmic_mixer, alc268_capture_alt_mixer,
12601                             alc268_beep_mixer },
12602                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12603                                 alc268_acer_verbs },
12604                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12605                 .dac_nids = alc268_dac_nids,
12606                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12607                 .adc_nids = alc268_adc_nids_alt,
12608                 .capsrc_nids = alc268_capsrc_nids,
12609                 .hp_nid = 0x02,
12610                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12611                 .channel_mode = alc268_modes,
12612                 .input_mux = &alc268_acer_dmic_capture_source,
12613                 .unsol_event = alc268_acer_unsol_event,
12614                 .init_hook = alc268_acer_init_hook,
12615         },
12616         [ALC268_ACER_ASPIRE_ONE] = {
12617                 .mixers = { alc268_acer_aspire_one_mixer,
12618                             alc268_beep_mixer,
12619                             alc268_capture_alt_mixer },
12620                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12621                                 alc268_acer_aspire_one_verbs },
12622                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12623                 .dac_nids = alc268_dac_nids,
12624                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12625                 .adc_nids = alc268_adc_nids_alt,
12626                 .capsrc_nids = alc268_capsrc_nids,
12627                 .hp_nid = 0x03,
12628                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12629                 .channel_mode = alc268_modes,
12630                 .input_mux = &alc268_acer_lc_capture_source,
12631                 .unsol_event = alc268_acer_lc_unsol_event,
12632                 .init_hook = alc268_acer_lc_init_hook,
12633         },
12634         [ALC268_DELL] = {
12635                 .mixers = { alc268_dell_mixer, alc268_beep_mixer },
12636                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12637                                 alc268_dell_verbs },
12638                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12639                 .dac_nids = alc268_dac_nids,
12640                 .hp_nid = 0x02,
12641                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12642                 .channel_mode = alc268_modes,
12643                 .unsol_event = alc_sku_unsol_event,
12644                 .init_hook = alc268_dell_init_hook,
12645                 .input_mux = &alc268_capture_source,
12646         },
12647         [ALC268_ZEPTO] = {
12648                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
12649                             alc268_beep_mixer },
12650                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12651                                 alc268_toshiba_verbs },
12652                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12653                 .dac_nids = alc268_dac_nids,
12654                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12655                 .adc_nids = alc268_adc_nids_alt,
12656                 .capsrc_nids = alc268_capsrc_nids,
12657                 .hp_nid = 0x03,
12658                 .dig_out_nid = ALC268_DIGOUT_NID,
12659                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12660                 .channel_mode = alc268_modes,
12661                 .input_mux = &alc268_capture_source,
12662                 .unsol_event = alc268_toshiba_unsol_event,
12663                 .init_hook = alc268_toshiba_init_hook
12664         },
12665 #ifdef CONFIG_SND_DEBUG
12666         [ALC268_TEST] = {
12667                 .mixers = { alc268_test_mixer, alc268_capture_mixer },
12668                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12669                                 alc268_volume_init_verbs },
12670                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12671                 .dac_nids = alc268_dac_nids,
12672                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12673                 .adc_nids = alc268_adc_nids_alt,
12674                 .capsrc_nids = alc268_capsrc_nids,
12675                 .hp_nid = 0x03,
12676                 .dig_out_nid = ALC268_DIGOUT_NID,
12677                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12678                 .channel_mode = alc268_modes,
12679                 .input_mux = &alc268_capture_source,
12680         },
12681 #endif
12682 };
12683
12684 static int patch_alc268(struct hda_codec *codec)
12685 {
12686         struct alc_spec *spec;
12687         int board_config;
12688         int i, has_beep, err;
12689
12690         spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
12691         if (spec == NULL)
12692                 return -ENOMEM;
12693
12694         codec->spec = spec;
12695
12696         board_config = snd_hda_check_board_config(codec, ALC268_MODEL_LAST,
12697                                                   alc268_models,
12698                                                   alc268_cfg_tbl);
12699
12700         if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
12701                 printk(KERN_INFO "hda_codec: Unknown model for %s, "
12702                        "trying auto-probe from BIOS...\n", codec->chip_name);
12703                 board_config = ALC268_AUTO;
12704         }
12705
12706         if (board_config == ALC268_AUTO) {
12707                 /* automatic parse from the BIOS config */
12708                 err = alc268_parse_auto_config(codec);
12709                 if (err < 0) {
12710                         alc_free(codec);
12711                         return err;
12712                 } else if (!err) {
12713                         printk(KERN_INFO
12714                                "hda_codec: Cannot set up configuration "
12715                                "from BIOS.  Using base mode...\n");
12716                         board_config = ALC268_3ST;
12717                 }
12718         }
12719
12720         if (board_config != ALC268_AUTO)
12721                 setup_preset(spec, &alc268_presets[board_config]);
12722
12723         spec->stream_analog_playback = &alc268_pcm_analog_playback;
12724         spec->stream_analog_capture = &alc268_pcm_analog_capture;
12725         spec->stream_analog_alt_capture = &alc268_pcm_analog_alt_capture;
12726
12727         spec->stream_digital_playback = &alc268_pcm_digital_playback;
12728
12729         has_beep = 0;
12730         for (i = 0; i < spec->num_mixers; i++) {
12731                 if (spec->mixers[i] == alc268_beep_mixer) {
12732                         has_beep = 1;
12733                         break;
12734                 }
12735         }
12736
12737         if (has_beep) {
12738                 err = snd_hda_attach_beep_device(codec, 0x1);
12739                 if (err < 0) {
12740                         alc_free(codec);
12741                         return err;
12742                 }
12743                 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
12744                         /* override the amp caps for beep generator */
12745                         snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
12746                                           (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
12747                                           (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
12748                                           (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
12749                                           (0 << AC_AMPCAP_MUTE_SHIFT));
12750         }
12751
12752         if (!spec->no_analog && !spec->adc_nids && spec->input_mux) {
12753                 /* check whether NID 0x07 is valid */
12754                 unsigned int wcap = get_wcaps(codec, 0x07);
12755                 int i;
12756
12757                 /* get type */
12758                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
12759                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
12760                         spec->adc_nids = alc268_adc_nids_alt;
12761                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt);
12762                         add_mixer(spec, alc268_capture_alt_mixer);
12763                 } else {
12764                         spec->adc_nids = alc268_adc_nids;
12765                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids);
12766                         add_mixer(spec, alc268_capture_mixer);
12767                 }
12768                 spec->capsrc_nids = alc268_capsrc_nids;
12769                 /* set default input source */
12770                 for (i = 0; i < spec->num_adc_nids; i++)
12771                         snd_hda_codec_write_cache(codec, alc268_capsrc_nids[i],
12772                                 0, AC_VERB_SET_CONNECT_SEL,
12773                                 spec->input_mux->items[0].index);
12774         }
12775
12776         spec->vmaster_nid = 0x02;
12777
12778         codec->patch_ops = alc_patch_ops;
12779         if (board_config == ALC268_AUTO)
12780                 spec->init_hook = alc268_auto_init;
12781
12782         codec->proc_widget_hook = print_realtek_coef;
12783
12784         return 0;
12785 }
12786
12787 /*
12788  *  ALC269 channel source setting (2 channel)
12789  */
12790 #define ALC269_DIGOUT_NID       ALC880_DIGOUT_NID
12791
12792 #define alc269_dac_nids         alc260_dac_nids
12793
12794 static hda_nid_t alc269_adc_nids[1] = {
12795         /* ADC1 */
12796         0x08,
12797 };
12798
12799 static hda_nid_t alc269_capsrc_nids[1] = {
12800         0x23,
12801 };
12802
12803 /* NOTE: ADC2 (0x07) is connected from a recording *MIXER* (0x24),
12804  *       not a mux!
12805  */
12806
12807 static struct hda_input_mux alc269_eeepc_dmic_capture_source = {
12808         .num_items = 2,
12809         .items = {
12810                 { "i-Mic", 0x5 },
12811                 { "e-Mic", 0x0 },
12812         },
12813 };
12814
12815 static struct hda_input_mux alc269_eeepc_amic_capture_source = {
12816         .num_items = 2,
12817         .items = {
12818                 { "i-Mic", 0x1 },
12819                 { "e-Mic", 0x0 },
12820         },
12821 };
12822
12823 #define alc269_modes            alc260_modes
12824 #define alc269_capture_source   alc880_lg_lw_capture_source
12825
12826 static struct snd_kcontrol_new alc269_base_mixer[] = {
12827         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12828         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12829         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
12830         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
12831         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12832         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12833         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12834         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12835         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12836         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
12837         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12838         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
12839         { } /* end */
12840 };
12841
12842 static struct snd_kcontrol_new alc269_quanta_fl1_mixer[] = {
12843         /* output mixer control */
12844         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
12845         {
12846                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12847                 .name = "Master Playback Switch",
12848                 .info = snd_hda_mixer_amp_switch_info,
12849                 .get = snd_hda_mixer_amp_switch_get,
12850                 .put = alc268_acer_master_sw_put,
12851                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
12852         },
12853         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12854         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12855         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12856         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12857         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12858         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
12859         { }
12860 };
12861
12862 static struct snd_kcontrol_new alc269_lifebook_mixer[] = {
12863         /* output mixer control */
12864         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
12865         {
12866                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12867                 .name = "Master Playback Switch",
12868                 .info = snd_hda_mixer_amp_switch_info,
12869                 .get = snd_hda_mixer_amp_switch_get,
12870                 .put = alc268_acer_master_sw_put,
12871                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
12872         },
12873         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12874         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12875         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12876         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12877         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12878         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
12879         HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x0b, 0x03, HDA_INPUT),
12880         HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x0b, 0x03, HDA_INPUT),
12881         HDA_CODEC_VOLUME("Dock Mic Boost", 0x1b, 0, HDA_INPUT),
12882         { }
12883 };
12884
12885 static struct snd_kcontrol_new alc269_eeepc_mixer[] = {
12886         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12887         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12888         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12889         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12890         { } /* end */
12891 };
12892
12893 /* capture mixer elements */
12894 static struct snd_kcontrol_new alc269_epc_capture_mixer[] = {
12895         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
12896         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
12897         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12898         { } /* end */
12899 };
12900
12901 /* FSC amilo */
12902 #define alc269_fujitsu_mixer    alc269_eeepc_mixer
12903
12904 static struct hda_verb alc269_quanta_fl1_verbs[] = {
12905         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12906         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12907         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12908         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12909         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12910         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12911         { }
12912 };
12913
12914 static struct hda_verb alc269_lifebook_verbs[] = {
12915         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12916         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
12917         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12918         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12919         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12920         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12921         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12922         {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12923         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12924         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12925         { }
12926 };
12927
12928 /* toggle speaker-output according to the hp-jack state */
12929 static void alc269_quanta_fl1_speaker_automute(struct hda_codec *codec)
12930 {
12931         unsigned int present;
12932         unsigned char bits;
12933
12934         present = snd_hda_codec_read(codec, 0x15, 0,
12935                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12936         bits = present ? AMP_IN_MUTE(0) : 0;
12937         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
12938                         AMP_IN_MUTE(0), bits);
12939         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
12940                         AMP_IN_MUTE(0), bits);
12941
12942         snd_hda_codec_write(codec, 0x20, 0,
12943                         AC_VERB_SET_COEF_INDEX, 0x0c);
12944         snd_hda_codec_write(codec, 0x20, 0,
12945                         AC_VERB_SET_PROC_COEF, 0x680);
12946
12947         snd_hda_codec_write(codec, 0x20, 0,
12948                         AC_VERB_SET_COEF_INDEX, 0x0c);
12949         snd_hda_codec_write(codec, 0x20, 0,
12950                         AC_VERB_SET_PROC_COEF, 0x480);
12951 }
12952
12953 /* toggle speaker-output according to the hp-jacks state */
12954 static void alc269_lifebook_speaker_automute(struct hda_codec *codec)
12955 {
12956         unsigned int present;
12957         unsigned char bits;
12958
12959         /* Check laptop headphone socket */
12960         present = snd_hda_codec_read(codec, 0x15, 0,
12961                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12962
12963         /* Check port replicator headphone socket */
12964         present |= snd_hda_codec_read(codec, 0x1a, 0,
12965                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12966
12967         bits = present ? AMP_IN_MUTE(0) : 0;
12968         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
12969                         AMP_IN_MUTE(0), bits);
12970         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
12971                         AMP_IN_MUTE(0), bits);
12972
12973         snd_hda_codec_write(codec, 0x20, 0,
12974                         AC_VERB_SET_COEF_INDEX, 0x0c);
12975         snd_hda_codec_write(codec, 0x20, 0,
12976                         AC_VERB_SET_PROC_COEF, 0x680);
12977
12978         snd_hda_codec_write(codec, 0x20, 0,
12979                         AC_VERB_SET_COEF_INDEX, 0x0c);
12980         snd_hda_codec_write(codec, 0x20, 0,
12981                         AC_VERB_SET_PROC_COEF, 0x480);
12982 }
12983
12984 static void alc269_quanta_fl1_mic_automute(struct hda_codec *codec)
12985 {
12986         unsigned int present;
12987
12988         present = snd_hda_codec_read(codec, 0x18, 0,
12989                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12990         snd_hda_codec_write(codec, 0x23, 0,
12991                             AC_VERB_SET_CONNECT_SEL, present ? 0x0 : 0x1);
12992 }
12993
12994 static void alc269_lifebook_mic_autoswitch(struct hda_codec *codec)
12995 {
12996         unsigned int present_laptop;
12997         unsigned int present_dock;
12998
12999         present_laptop = snd_hda_codec_read(codec, 0x18, 0,
13000                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13001
13002         present_dock = snd_hda_codec_read(codec, 0x1b, 0,
13003                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13004
13005         /* Laptop mic port overrides dock mic port, design decision */
13006         if (present_dock)
13007                 snd_hda_codec_write(codec, 0x23, 0,
13008                                 AC_VERB_SET_CONNECT_SEL, 0x3);
13009         if (present_laptop)
13010                 snd_hda_codec_write(codec, 0x23, 0,
13011                                 AC_VERB_SET_CONNECT_SEL, 0x0);
13012         if (!present_dock && !present_laptop)
13013                 snd_hda_codec_write(codec, 0x23, 0,
13014                                 AC_VERB_SET_CONNECT_SEL, 0x1);
13015 }
13016
13017 static void alc269_quanta_fl1_unsol_event(struct hda_codec *codec,
13018                                     unsigned int res)
13019 {
13020         if ((res >> 26) == ALC880_HP_EVENT)
13021                 alc269_quanta_fl1_speaker_automute(codec);
13022         if ((res >> 26) == ALC880_MIC_EVENT)
13023                 alc269_quanta_fl1_mic_automute(codec);
13024 }
13025
13026 static void alc269_lifebook_unsol_event(struct hda_codec *codec,
13027                                         unsigned int res)
13028 {
13029         if ((res >> 26) == ALC880_HP_EVENT)
13030                 alc269_lifebook_speaker_automute(codec);
13031         if ((res >> 26) == ALC880_MIC_EVENT)
13032                 alc269_lifebook_mic_autoswitch(codec);
13033 }
13034
13035 static void alc269_quanta_fl1_init_hook(struct hda_codec *codec)
13036 {
13037         alc269_quanta_fl1_speaker_automute(codec);
13038         alc269_quanta_fl1_mic_automute(codec);
13039 }
13040
13041 static void alc269_lifebook_init_hook(struct hda_codec *codec)
13042 {
13043         alc269_lifebook_speaker_automute(codec);
13044         alc269_lifebook_mic_autoswitch(codec);
13045 }
13046
13047 static struct hda_verb alc269_eeepc_dmic_init_verbs[] = {
13048         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
13049         {0x23, AC_VERB_SET_CONNECT_SEL, 0x05},
13050         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
13051         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))},
13052         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13053         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
13054         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13055         {}
13056 };
13057
13058 static struct hda_verb alc269_eeepc_amic_init_verbs[] = {
13059         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
13060         {0x23, AC_VERB_SET_CONNECT_SEL, 0x01},
13061         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
13062         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x701b | (0x00 << 8))},
13063         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
13064         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13065         {}
13066 };
13067
13068 /* toggle speaker-output according to the hp-jack state */
13069 static void alc269_speaker_automute(struct hda_codec *codec)
13070 {
13071         unsigned int present;
13072         unsigned char bits;
13073
13074         present = snd_hda_codec_read(codec, 0x15, 0,
13075                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13076         bits = present ? AMP_IN_MUTE(0) : 0;
13077         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
13078                                 AMP_IN_MUTE(0), bits);
13079         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
13080                                 AMP_IN_MUTE(0), bits);
13081 }
13082
13083 static void alc269_eeepc_dmic_automute(struct hda_codec *codec)
13084 {
13085         unsigned int present;
13086
13087         present = snd_hda_codec_read(codec, 0x18, 0,
13088                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13089         snd_hda_codec_write(codec, 0x23, 0,
13090                                 AC_VERB_SET_CONNECT_SEL,  (present ? 0 : 5));
13091 }
13092
13093 static void alc269_eeepc_amic_automute(struct hda_codec *codec)
13094 {
13095         unsigned int present;
13096
13097         present = snd_hda_codec_read(codec, 0x18, 0,
13098                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13099         snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
13100                                 0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
13101         snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
13102                                 0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
13103 }
13104
13105 /* unsolicited event for HP jack sensing */
13106 static void alc269_eeepc_dmic_unsol_event(struct hda_codec *codec,
13107                                      unsigned int res)
13108 {
13109         if ((res >> 26) == ALC880_HP_EVENT)
13110                 alc269_speaker_automute(codec);
13111
13112         if ((res >> 26) == ALC880_MIC_EVENT)
13113                 alc269_eeepc_dmic_automute(codec);
13114 }
13115
13116 static void alc269_eeepc_dmic_inithook(struct hda_codec *codec)
13117 {
13118         alc269_speaker_automute(codec);
13119         alc269_eeepc_dmic_automute(codec);
13120 }
13121
13122 /* unsolicited event for HP jack sensing */
13123 static void alc269_eeepc_amic_unsol_event(struct hda_codec *codec,
13124                                      unsigned int res)
13125 {
13126         if ((res >> 26) == ALC880_HP_EVENT)
13127                 alc269_speaker_automute(codec);
13128
13129         if ((res >> 26) == ALC880_MIC_EVENT)
13130                 alc269_eeepc_amic_automute(codec);
13131 }
13132
13133 static void alc269_eeepc_amic_inithook(struct hda_codec *codec)
13134 {
13135         alc269_speaker_automute(codec);
13136         alc269_eeepc_amic_automute(codec);
13137 }
13138
13139 /*
13140  * generic initialization of ADC, input mixers and output mixers
13141  */
13142 static struct hda_verb alc269_init_verbs[] = {
13143         /*
13144          * Unmute ADC0 and set the default input to mic-in
13145          */
13146         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13147
13148         /* Mute input amps (PCBeep, Line In, Mic 1 & Mic 2) of the
13149          * analog-loopback mixer widget
13150          * Note: PASD motherboards uses the Line In 2 as the input for
13151          * front panel mic (mic 2)
13152          */
13153         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
13154         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13155         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13156         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
13157         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
13158         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
13159
13160         /*
13161          * Set up output mixers (0x0c - 0x0e)
13162          */
13163         /* set vol=0 to output mixers */
13164         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13165         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13166
13167         /* set up input amps for analog loopback */
13168         /* Amp Indices: DAC = 0, mixer = 1 */
13169         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13170         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13171         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13172         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13173         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13174         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13175
13176         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13177         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13178         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13179         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13180         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13181         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13182         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13183
13184         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13185         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13186         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13187         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13188         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13189         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13190         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13191
13192         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
13193         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
13194
13195         /* FIXME: use matrix-type input source selection */
13196         /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
13197         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
13198         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13199         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13200         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
13201         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
13202
13203         /* set EAPD */
13204         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
13205         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
13206         { }
13207 };
13208
13209 /* add playback controls from the parsed DAC table */
13210 static int alc269_auto_create_multi_out_ctls(struct alc_spec *spec,
13211                                              const struct auto_pin_cfg *cfg)
13212 {
13213         hda_nid_t nid;
13214         int err;
13215
13216         spec->multiout.num_dacs = 1;    /* only use one dac */
13217         spec->multiout.dac_nids = spec->private_dac_nids;
13218         spec->multiout.dac_nids[0] = 2;
13219
13220         nid = cfg->line_out_pins[0];
13221         if (nid) {
13222                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
13223                                   "Front Playback Volume",
13224                                   HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT));
13225                 if (err < 0)
13226                         return err;
13227                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
13228                                   "Front Playback Switch",
13229                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
13230                 if (err < 0)
13231                         return err;
13232         }
13233
13234         nid = cfg->speaker_pins[0];
13235         if (nid) {
13236                 if (!cfg->line_out_pins[0]) {
13237                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
13238                                           "Speaker Playback Volume",
13239                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
13240                                                               HDA_OUTPUT));
13241                         if (err < 0)
13242                                 return err;
13243                 }
13244                 if (nid == 0x16) {
13245                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
13246                                           "Speaker Playback Switch",
13247                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
13248                                                               HDA_OUTPUT));
13249                         if (err < 0)
13250                                 return err;
13251                 } else {
13252                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
13253                                           "Speaker Playback Switch",
13254                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
13255                                                               HDA_OUTPUT));
13256                         if (err < 0)
13257                                 return err;
13258                 }
13259         }
13260         nid = cfg->hp_pins[0];
13261         if (nid) {
13262                 /* spec->multiout.hp_nid = 2; */
13263                 if (!cfg->line_out_pins[0] && !cfg->speaker_pins[0]) {
13264                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
13265                                           "Headphone Playback Volume",
13266                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
13267                                                               HDA_OUTPUT));
13268                         if (err < 0)
13269                                 return err;
13270                 }
13271                 if (nid == 0x16) {
13272                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
13273                                           "Headphone Playback Switch",
13274                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
13275                                                               HDA_OUTPUT));
13276                         if (err < 0)
13277                                 return err;
13278                 } else {
13279                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
13280                                           "Headphone Playback Switch",
13281                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
13282                                                               HDA_OUTPUT));
13283                         if (err < 0)
13284                                 return err;
13285                 }
13286         }
13287         return 0;
13288 }
13289
13290 #define alc269_auto_create_analog_input_ctls \
13291         alc262_auto_create_analog_input_ctls
13292
13293 #ifdef CONFIG_SND_HDA_POWER_SAVE
13294 #define alc269_loopbacks        alc880_loopbacks
13295 #endif
13296
13297 /* pcm configuration: identical with ALC880 */
13298 #define alc269_pcm_analog_playback      alc880_pcm_analog_playback
13299 #define alc269_pcm_analog_capture       alc880_pcm_analog_capture
13300 #define alc269_pcm_digital_playback     alc880_pcm_digital_playback
13301 #define alc269_pcm_digital_capture      alc880_pcm_digital_capture
13302
13303 static struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
13304         .substreams = 1,
13305         .channels_min = 2,
13306         .channels_max = 8,
13307         .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
13308         /* NID is set in alc_build_pcms */
13309         .ops = {
13310                 .open = alc880_playback_pcm_open,
13311                 .prepare = alc880_playback_pcm_prepare,
13312                 .cleanup = alc880_playback_pcm_cleanup
13313         },
13314 };
13315
13316 static struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
13317         .substreams = 1,
13318         .channels_min = 2,
13319         .channels_max = 2,
13320         .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
13321         /* NID is set in alc_build_pcms */
13322 };
13323
13324 /*
13325  * BIOS auto configuration
13326  */
13327 static int alc269_parse_auto_config(struct hda_codec *codec)
13328 {
13329         struct alc_spec *spec = codec->spec;
13330         int err;
13331         static hda_nid_t alc269_ignore[] = { 0x1d, 0 };
13332
13333         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
13334                                            alc269_ignore);
13335         if (err < 0)
13336                 return err;
13337
13338         err = alc269_auto_create_multi_out_ctls(spec, &spec->autocfg);
13339         if (err < 0)
13340                 return err;
13341         err = alc269_auto_create_analog_input_ctls(spec, &spec->autocfg);
13342         if (err < 0)
13343                 return err;
13344
13345         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
13346
13347         if (spec->autocfg.dig_outs)
13348                 spec->multiout.dig_out_nid = ALC269_DIGOUT_NID;
13349
13350         if (spec->kctls.list)
13351                 add_mixer(spec, spec->kctls.list);
13352
13353         add_verb(spec, alc269_init_verbs);
13354         spec->num_mux_defs = 1;
13355         spec->input_mux = &spec->private_imux[0];
13356         /* set default input source */
13357         snd_hda_codec_write_cache(codec, alc269_capsrc_nids[0],
13358                                   0, AC_VERB_SET_CONNECT_SEL,
13359                                   spec->input_mux->items[0].index);
13360
13361         err = alc_auto_add_mic_boost(codec);
13362         if (err < 0)
13363                 return err;
13364
13365         if (!spec->cap_mixer && !spec->no_analog)
13366                 set_capture_mixer(spec);
13367
13368         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
13369
13370         return 1;
13371 }
13372
13373 #define alc269_auto_init_multi_out      alc882_auto_init_multi_out
13374 #define alc269_auto_init_hp_out         alc882_auto_init_hp_out
13375 #define alc269_auto_init_analog_input   alc882_auto_init_analog_input
13376
13377
13378 /* init callback for auto-configuration model -- overriding the default init */
13379 static void alc269_auto_init(struct hda_codec *codec)
13380 {
13381         struct alc_spec *spec = codec->spec;
13382         alc269_auto_init_multi_out(codec);
13383         alc269_auto_init_hp_out(codec);
13384         alc269_auto_init_analog_input(codec);
13385         if (spec->unsol_event)
13386                 alc_inithook(codec);
13387 }
13388
13389 /*
13390  * configuration and preset
13391  */
13392 static const char *alc269_models[ALC269_MODEL_LAST] = {
13393         [ALC269_BASIC]                  = "basic",
13394         [ALC269_QUANTA_FL1]             = "quanta",
13395         [ALC269_ASUS_EEEPC_P703]        = "eeepc-p703",
13396         [ALC269_ASUS_EEEPC_P901]        = "eeepc-p901",
13397         [ALC269_FUJITSU]                = "fujitsu",
13398         [ALC269_LIFEBOOK]               = "lifebook"
13399 };
13400
13401 static struct snd_pci_quirk alc269_cfg_tbl[] = {
13402         SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_QUANTA_FL1),
13403         SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
13404                       ALC269_ASUS_EEEPC_P703),
13405         SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_ASUS_EEEPC_P703),
13406         SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_ASUS_EEEPC_P703),
13407         SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_ASUS_EEEPC_P703),
13408         SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_ASUS_EEEPC_P703),
13409         SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_ASUS_EEEPC_P703),
13410         SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_ASUS_EEEPC_P703),
13411         SND_PCI_QUIRK(0x1043, 0x831a, "ASUS Eeepc P901",
13412                       ALC269_ASUS_EEEPC_P901),
13413         SND_PCI_QUIRK(0x1043, 0x834a, "ASUS Eeepc S101",
13414                       ALC269_ASUS_EEEPC_P901),
13415         SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_ASUS_EEEPC_P901),
13416         SND_PCI_QUIRK(0x1734, 0x115d, "FSC Amilo", ALC269_FUJITSU),
13417         SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook ICH9M-based", ALC269_LIFEBOOK),
13418         {}
13419 };
13420
13421 static struct alc_config_preset alc269_presets[] = {
13422         [ALC269_BASIC] = {
13423                 .mixers = { alc269_base_mixer },
13424                 .init_verbs = { alc269_init_verbs },
13425                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13426                 .dac_nids = alc269_dac_nids,
13427                 .hp_nid = 0x03,
13428                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13429                 .channel_mode = alc269_modes,
13430                 .input_mux = &alc269_capture_source,
13431         },
13432         [ALC269_QUANTA_FL1] = {
13433                 .mixers = { alc269_quanta_fl1_mixer },
13434                 .init_verbs = { alc269_init_verbs, alc269_quanta_fl1_verbs },
13435                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13436                 .dac_nids = alc269_dac_nids,
13437                 .hp_nid = 0x03,
13438                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13439                 .channel_mode = alc269_modes,
13440                 .input_mux = &alc269_capture_source,
13441                 .unsol_event = alc269_quanta_fl1_unsol_event,
13442                 .init_hook = alc269_quanta_fl1_init_hook,
13443         },
13444         [ALC269_ASUS_EEEPC_P703] = {
13445                 .mixers = { alc269_eeepc_mixer },
13446                 .cap_mixer = alc269_epc_capture_mixer,
13447                 .init_verbs = { alc269_init_verbs,
13448                                 alc269_eeepc_amic_init_verbs },
13449                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13450                 .dac_nids = alc269_dac_nids,
13451                 .hp_nid = 0x03,
13452                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13453                 .channel_mode = alc269_modes,
13454                 .input_mux = &alc269_eeepc_amic_capture_source,
13455                 .unsol_event = alc269_eeepc_amic_unsol_event,
13456                 .init_hook = alc269_eeepc_amic_inithook,
13457         },
13458         [ALC269_ASUS_EEEPC_P901] = {
13459                 .mixers = { alc269_eeepc_mixer },
13460                 .cap_mixer = alc269_epc_capture_mixer,
13461                 .init_verbs = { alc269_init_verbs,
13462                                 alc269_eeepc_dmic_init_verbs },
13463                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13464                 .dac_nids = alc269_dac_nids,
13465                 .hp_nid = 0x03,
13466                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13467                 .channel_mode = alc269_modes,
13468                 .input_mux = &alc269_eeepc_dmic_capture_source,
13469                 .unsol_event = alc269_eeepc_dmic_unsol_event,
13470                 .init_hook = alc269_eeepc_dmic_inithook,
13471         },
13472         [ALC269_FUJITSU] = {
13473                 .mixers = { alc269_fujitsu_mixer },
13474                 .cap_mixer = alc269_epc_capture_mixer,
13475                 .init_verbs = { alc269_init_verbs,
13476                                 alc269_eeepc_dmic_init_verbs },
13477                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13478                 .dac_nids = alc269_dac_nids,
13479                 .hp_nid = 0x03,
13480                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13481                 .channel_mode = alc269_modes,
13482                 .input_mux = &alc269_eeepc_dmic_capture_source,
13483                 .unsol_event = alc269_eeepc_dmic_unsol_event,
13484                 .init_hook = alc269_eeepc_dmic_inithook,
13485         },
13486         [ALC269_LIFEBOOK] = {
13487                 .mixers = { alc269_lifebook_mixer },
13488                 .init_verbs = { alc269_init_verbs, alc269_lifebook_verbs },
13489                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13490                 .dac_nids = alc269_dac_nids,
13491                 .hp_nid = 0x03,
13492                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13493                 .channel_mode = alc269_modes,
13494                 .input_mux = &alc269_capture_source,
13495                 .unsol_event = alc269_lifebook_unsol_event,
13496                 .init_hook = alc269_lifebook_init_hook,
13497         },
13498 };
13499
13500 static int patch_alc269(struct hda_codec *codec)
13501 {
13502         struct alc_spec *spec;
13503         int board_config;
13504         int err;
13505
13506         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
13507         if (spec == NULL)
13508                 return -ENOMEM;
13509
13510         codec->spec = spec;
13511
13512         alc_fix_pll_init(codec, 0x20, 0x04, 15);
13513
13514         board_config = snd_hda_check_board_config(codec, ALC269_MODEL_LAST,
13515                                                   alc269_models,
13516                                                   alc269_cfg_tbl);
13517
13518         if (board_config < 0) {
13519                 printk(KERN_INFO "hda_codec: Unknown model for %s, "
13520                        "trying auto-probe from BIOS...\n", codec->chip_name);
13521                 board_config = ALC269_AUTO;
13522         }
13523
13524         if (board_config == ALC269_AUTO) {
13525                 /* automatic parse from the BIOS config */
13526                 err = alc269_parse_auto_config(codec);
13527                 if (err < 0) {
13528                         alc_free(codec);
13529                         return err;
13530                 } else if (!err) {
13531                         printk(KERN_INFO
13532                                "hda_codec: Cannot set up configuration "
13533                                "from BIOS.  Using base mode...\n");
13534                         board_config = ALC269_BASIC;
13535                 }
13536         }
13537
13538         err = snd_hda_attach_beep_device(codec, 0x1);
13539         if (err < 0) {
13540                 alc_free(codec);
13541                 return err;
13542         }
13543
13544         if (board_config != ALC269_AUTO)
13545                 setup_preset(spec, &alc269_presets[board_config]);
13546
13547         if (codec->subsystem_id == 0x17aa3bf8) {
13548                 /* Due to a hardware problem on Lenovo Ideadpad, we need to
13549                  * fix the sample rate of analog I/O to 44.1kHz
13550                  */
13551                 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
13552                 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
13553         } else {
13554                 spec->stream_analog_playback = &alc269_pcm_analog_playback;
13555                 spec->stream_analog_capture = &alc269_pcm_analog_capture;
13556         }
13557         spec->stream_digital_playback = &alc269_pcm_digital_playback;
13558         spec->stream_digital_capture = &alc269_pcm_digital_capture;
13559
13560         spec->adc_nids = alc269_adc_nids;
13561         spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids);
13562         spec->capsrc_nids = alc269_capsrc_nids;
13563         if (!spec->cap_mixer)
13564                 set_capture_mixer(spec);
13565         set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
13566
13567         codec->patch_ops = alc_patch_ops;
13568         if (board_config == ALC269_AUTO)
13569                 spec->init_hook = alc269_auto_init;
13570 #ifdef CONFIG_SND_HDA_POWER_SAVE
13571         if (!spec->loopback.amplist)
13572                 spec->loopback.amplist = alc269_loopbacks;
13573 #endif
13574         codec->proc_widget_hook = print_realtek_coef;
13575
13576         return 0;
13577 }
13578
13579 /*
13580  *  ALC861 channel source setting (2/6 channel selection for 3-stack)
13581  */
13582
13583 /*
13584  * set the path ways for 2 channel output
13585  * need to set the codec line out and mic 1 pin widgets to inputs
13586  */
13587 static struct hda_verb alc861_threestack_ch2_init[] = {
13588         /* set pin widget 1Ah (line in) for input */
13589         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13590         /* set pin widget 18h (mic1/2) for input, for mic also enable
13591          * the vref
13592          */
13593         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13594
13595         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
13596 #if 0
13597         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
13598         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
13599 #endif
13600         { } /* end */
13601 };
13602 /*
13603  * 6ch mode
13604  * need to set the codec line out and mic 1 pin widgets to outputs
13605  */
13606 static struct hda_verb alc861_threestack_ch6_init[] = {
13607         /* set pin widget 1Ah (line in) for output (Back Surround)*/
13608         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13609         /* set pin widget 18h (mic1) for output (CLFE)*/
13610         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13611
13612         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
13613         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
13614
13615         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
13616 #if 0
13617         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
13618         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
13619 #endif
13620         { } /* end */
13621 };
13622
13623 static struct hda_channel_mode alc861_threestack_modes[2] = {
13624         { 2, alc861_threestack_ch2_init },
13625         { 6, alc861_threestack_ch6_init },
13626 };
13627 /* Set mic1 as input and unmute the mixer */
13628 static struct hda_verb alc861_uniwill_m31_ch2_init[] = {
13629         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13630         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
13631         { } /* end */
13632 };
13633 /* Set mic1 as output and mute mixer */
13634 static struct hda_verb alc861_uniwill_m31_ch4_init[] = {
13635         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13636         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
13637         { } /* end */
13638 };
13639
13640 static struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
13641         { 2, alc861_uniwill_m31_ch2_init },
13642         { 4, alc861_uniwill_m31_ch4_init },
13643 };
13644
13645 /* Set mic1 and line-in as input and unmute the mixer */
13646 static struct hda_verb alc861_asus_ch2_init[] = {
13647         /* set pin widget 1Ah (line in) for input */
13648         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13649         /* set pin widget 18h (mic1/2) for input, for mic also enable
13650          * the vref
13651          */
13652         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13653
13654         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
13655 #if 0
13656         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
13657         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
13658 #endif
13659         { } /* end */
13660 };
13661 /* Set mic1 nad line-in as output and mute mixer */
13662 static struct hda_verb alc861_asus_ch6_init[] = {
13663         /* set pin widget 1Ah (line in) for output (Back Surround)*/
13664         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13665         /* { 0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
13666         /* set pin widget 18h (mic1) for output (CLFE)*/
13667         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13668         /* { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
13669         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
13670         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
13671
13672         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
13673 #if 0
13674         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
13675         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
13676 #endif
13677         { } /* end */
13678 };
13679
13680 static struct hda_channel_mode alc861_asus_modes[2] = {
13681         { 2, alc861_asus_ch2_init },
13682         { 6, alc861_asus_ch6_init },
13683 };
13684
13685 /* patch-ALC861 */
13686
13687 static struct snd_kcontrol_new alc861_base_mixer[] = {
13688         /* output mixer control */
13689         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13690         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
13691         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
13692         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13693         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
13694
13695         /*Input mixer control */
13696         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13697            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
13698         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13699         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13700         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13701         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13702         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13703         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13704         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13705         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
13706
13707         { } /* end */
13708 };
13709
13710 static struct snd_kcontrol_new alc861_3ST_mixer[] = {
13711         /* output mixer control */
13712         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13713         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
13714         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
13715         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13716         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
13717
13718         /* Input mixer control */
13719         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13720            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
13721         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13722         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13723         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13724         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13725         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13726         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13727         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13728         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
13729
13730         {
13731                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13732                 .name = "Channel Mode",
13733                 .info = alc_ch_mode_info,
13734                 .get = alc_ch_mode_get,
13735                 .put = alc_ch_mode_put,
13736                 .private_value = ARRAY_SIZE(alc861_threestack_modes),
13737         },
13738         { } /* end */
13739 };
13740
13741 static struct snd_kcontrol_new alc861_toshiba_mixer[] = {
13742         /* output mixer control */
13743         HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13744         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13745         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13746
13747         { } /* end */
13748 };
13749
13750 static struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
13751         /* output mixer control */
13752         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13753         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
13754         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
13755         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13756         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
13757
13758         /* Input mixer control */
13759         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13760            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
13761         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13762         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13763         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13764         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13765         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13766         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13767         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13768         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
13769
13770         {
13771                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13772                 .name = "Channel Mode",
13773                 .info = alc_ch_mode_info,
13774                 .get = alc_ch_mode_get,
13775                 .put = alc_ch_mode_put,
13776                 .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
13777         },
13778         { } /* end */
13779 };
13780
13781 static struct snd_kcontrol_new alc861_asus_mixer[] = {
13782         /* output mixer control */
13783         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13784         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
13785         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
13786         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13787         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
13788
13789         /* Input mixer control */
13790         HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13791         HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT),
13792         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13793         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13794         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13795         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13796         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13797         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13798         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13799         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT),
13800
13801         {
13802                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13803                 .name = "Channel Mode",
13804                 .info = alc_ch_mode_info,
13805                 .get = alc_ch_mode_get,
13806                 .put = alc_ch_mode_put,
13807                 .private_value = ARRAY_SIZE(alc861_asus_modes),
13808         },
13809         { }
13810 };
13811
13812 /* additional mixer */
13813 static struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
13814         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13815         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13816         { }
13817 };
13818
13819 /*
13820  * generic initialization of ADC, input mixers and output mixers
13821  */
13822 static struct hda_verb alc861_base_init_verbs[] = {
13823         /*
13824          * Unmute ADC0 and set the default input to mic-in
13825          */
13826         /* port-A for surround (rear panel) */
13827         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13828         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
13829         /* port-B for mic-in (rear panel) with vref */
13830         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13831         /* port-C for line-in (rear panel) */
13832         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13833         /* port-D for Front */
13834         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13835         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13836         /* port-E for HP out (front panel) */
13837         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
13838         /* route front PCM to HP */
13839         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13840         /* port-F for mic-in (front panel) with vref */
13841         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13842         /* port-G for CLFE (rear panel) */
13843         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13844         { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13845         /* port-H for side (rear panel) */
13846         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13847         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
13848         /* CD-in */
13849         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13850         /* route front mic to ADC1*/
13851         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13852         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13853
13854         /* Unmute DAC0~3 & spdif out*/
13855         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13856         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13857         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13858         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13859         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13860
13861         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13862         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13863         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13864         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13865         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13866
13867         /* Unmute Stereo Mixer 15 */
13868         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13869         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13870         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13871         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13872
13873         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13874         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13875         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13876         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13877         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13878         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13879         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13880         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13881         /* hp used DAC 3 (Front) */
13882         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13883         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13884
13885         { }
13886 };
13887
13888 static struct hda_verb alc861_threestack_init_verbs[] = {
13889         /*
13890          * Unmute ADC0 and set the default input to mic-in
13891          */
13892         /* port-A for surround (rear panel) */
13893         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13894         /* port-B for mic-in (rear panel) with vref */
13895         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13896         /* port-C for line-in (rear panel) */
13897         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13898         /* port-D for Front */
13899         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13900         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13901         /* port-E for HP out (front panel) */
13902         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
13903         /* route front PCM to HP */
13904         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13905         /* port-F for mic-in (front panel) with vref */
13906         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13907         /* port-G for CLFE (rear panel) */
13908         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13909         /* port-H for side (rear panel) */
13910         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13911         /* CD-in */
13912         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13913         /* route front mic to ADC1*/
13914         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13915         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13916         /* Unmute DAC0~3 & spdif out*/
13917         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13918         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13919         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13920         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13921         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13922
13923         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13924         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13925         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13926         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13927         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13928
13929         /* Unmute Stereo Mixer 15 */
13930         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13931         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13932         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13933         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13934
13935         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13936         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13937         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13938         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13939         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13940         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13941         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13942         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13943         /* hp used DAC 3 (Front) */
13944         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13945         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13946         { }
13947 };
13948
13949 static struct hda_verb alc861_uniwill_m31_init_verbs[] = {
13950         /*
13951          * Unmute ADC0 and set the default input to mic-in
13952          */
13953         /* port-A for surround (rear panel) */
13954         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13955         /* port-B for mic-in (rear panel) with vref */
13956         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13957         /* port-C for line-in (rear panel) */
13958         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13959         /* port-D for Front */
13960         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13961         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13962         /* port-E for HP out (front panel) */
13963         /* this has to be set to VREF80 */
13964         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13965         /* route front PCM to HP */
13966         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13967         /* port-F for mic-in (front panel) with vref */
13968         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13969         /* port-G for CLFE (rear panel) */
13970         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13971         /* port-H for side (rear panel) */
13972         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13973         /* CD-in */
13974         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13975         /* route front mic to ADC1*/
13976         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13977         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13978         /* Unmute DAC0~3 & spdif out*/
13979         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13980         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13981         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13982         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13983         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13984
13985         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13986         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13987         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13988         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13989         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13990
13991         /* Unmute Stereo Mixer 15 */
13992         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13993         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13994         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13995         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13996
13997         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13998         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13999         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14000         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14001         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14002         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14003         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14004         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14005         /* hp used DAC 3 (Front) */
14006         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
14007         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14008         { }
14009 };
14010
14011 static struct hda_verb alc861_asus_init_verbs[] = {
14012         /*
14013          * Unmute ADC0 and set the default input to mic-in
14014          */
14015         /* port-A for surround (rear panel)
14016          * according to codec#0 this is the HP jack
14017          */
14018         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, /* was 0x00 */
14019         /* route front PCM to HP */
14020         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x01 },
14021         /* port-B for mic-in (rear panel) with vref */
14022         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
14023         /* port-C for line-in (rear panel) */
14024         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
14025         /* port-D for Front */
14026         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
14027         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
14028         /* port-E for HP out (front panel) */
14029         /* this has to be set to VREF80 */
14030         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
14031         /* route front PCM to HP */
14032         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
14033         /* port-F for mic-in (front panel) with vref */
14034         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
14035         /* port-G for CLFE (rear panel) */
14036         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
14037         /* port-H for side (rear panel) */
14038         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
14039         /* CD-in */
14040         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
14041         /* route front mic to ADC1*/
14042         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
14043         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14044         /* Unmute DAC0~3 & spdif out*/
14045         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14046         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14047         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14048         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14049         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14050         /* Unmute Mixer 14 (mic) 1c (Line in)*/
14051         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14052         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14053         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14054         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14055
14056         /* Unmute Stereo Mixer 15 */
14057         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14058         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14059         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14060         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
14061
14062         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14063         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14064         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14065         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14066         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14067         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14068         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14069         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14070         /* hp used DAC 3 (Front) */
14071         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
14072         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14073         { }
14074 };
14075
14076 /* additional init verbs for ASUS laptops */
14077 static struct hda_verb alc861_asus_laptop_init_verbs[] = {
14078         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x45 }, /* HP-out */
14079         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2) }, /* mute line-in */
14080         { }
14081 };
14082
14083 /*
14084  * generic initialization of ADC, input mixers and output mixers
14085  */
14086 static struct hda_verb alc861_auto_init_verbs[] = {
14087         /*
14088          * Unmute ADC0 and set the default input to mic-in
14089          */
14090         /* {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, */
14091         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14092
14093         /* Unmute DAC0~3 & spdif out*/
14094         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14095         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14096         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14097         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14098         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14099
14100         /* Unmute Mixer 14 (mic) 1c (Line in)*/
14101         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14102         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14103         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14104         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14105
14106         /* Unmute Stereo Mixer 15 */
14107         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14108         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14109         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14110         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c},
14111
14112         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14113         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14114         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14115         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14116         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14117         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14118         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14119         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14120
14121         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14122         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14123         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14124         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
14125         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14126         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14127         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14128         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
14129
14130         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},  /* set Mic 1 */
14131
14132         { }
14133 };
14134
14135 static struct hda_verb alc861_toshiba_init_verbs[] = {
14136         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14137
14138         { }
14139 };
14140
14141 /* toggle speaker-output according to the hp-jack state */
14142 static void alc861_toshiba_automute(struct hda_codec *codec)
14143 {
14144         unsigned int present;
14145
14146         present = snd_hda_codec_read(codec, 0x0f, 0,
14147                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14148         snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
14149                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
14150         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
14151                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
14152 }
14153
14154 static void alc861_toshiba_unsol_event(struct hda_codec *codec,
14155                                        unsigned int res)
14156 {
14157         if ((res >> 26) == ALC880_HP_EVENT)
14158                 alc861_toshiba_automute(codec);
14159 }
14160
14161 /* pcm configuration: identical with ALC880 */
14162 #define alc861_pcm_analog_playback      alc880_pcm_analog_playback
14163 #define alc861_pcm_analog_capture       alc880_pcm_analog_capture
14164 #define alc861_pcm_digital_playback     alc880_pcm_digital_playback
14165 #define alc861_pcm_digital_capture      alc880_pcm_digital_capture
14166
14167
14168 #define ALC861_DIGOUT_NID       0x07
14169
14170 static struct hda_channel_mode alc861_8ch_modes[1] = {
14171         { 8, NULL }
14172 };
14173
14174 static hda_nid_t alc861_dac_nids[4] = {
14175         /* front, surround, clfe, side */
14176         0x03, 0x06, 0x05, 0x04
14177 };
14178
14179 static hda_nid_t alc660_dac_nids[3] = {
14180         /* front, clfe, surround */
14181         0x03, 0x05, 0x06
14182 };
14183
14184 static hda_nid_t alc861_adc_nids[1] = {
14185         /* ADC0-2 */
14186         0x08,
14187 };
14188
14189 static struct hda_input_mux alc861_capture_source = {
14190         .num_items = 5,
14191         .items = {
14192                 { "Mic", 0x0 },
14193                 { "Front Mic", 0x3 },
14194                 { "Line", 0x1 },
14195                 { "CD", 0x4 },
14196                 { "Mixer", 0x5 },
14197         },
14198 };
14199
14200 /* fill in the dac_nids table from the parsed pin configuration */
14201 static int alc861_auto_fill_dac_nids(struct alc_spec *spec,
14202                                      const struct auto_pin_cfg *cfg)
14203 {
14204         int i;
14205         hda_nid_t nid;
14206
14207         spec->multiout.dac_nids = spec->private_dac_nids;
14208         for (i = 0; i < cfg->line_outs; i++) {
14209                 nid = cfg->line_out_pins[i];
14210                 if (nid) {
14211                         if (i >= ARRAY_SIZE(alc861_dac_nids))
14212                                 continue;
14213                         spec->multiout.dac_nids[i] = alc861_dac_nids[i];
14214                 }
14215         }
14216         spec->multiout.num_dacs = cfg->line_outs;
14217         return 0;
14218 }
14219
14220 /* add playback controls from the parsed DAC table */
14221 static int alc861_auto_create_multi_out_ctls(struct alc_spec *spec,
14222                                              const struct auto_pin_cfg *cfg)
14223 {
14224         char name[32];
14225         static const char *chname[4] = {
14226                 "Front", "Surround", NULL /*CLFE*/, "Side"
14227         };
14228         hda_nid_t nid;
14229         int i, idx, err;
14230
14231         for (i = 0; i < cfg->line_outs; i++) {
14232                 nid = spec->multiout.dac_nids[i];
14233                 if (!nid)
14234                         continue;
14235                 if (nid == 0x05) {
14236                         /* Center/LFE */
14237                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14238                                           "Center Playback Switch",
14239                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
14240                                                               HDA_OUTPUT));
14241                         if (err < 0)
14242                                 return err;
14243                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14244                                           "LFE Playback Switch",
14245                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
14246                                                               HDA_OUTPUT));
14247                         if (err < 0)
14248                                 return err;
14249                 } else {
14250                         for (idx = 0; idx < ARRAY_SIZE(alc861_dac_nids) - 1;
14251                              idx++)
14252                                 if (nid == alc861_dac_nids[idx])
14253                                         break;
14254                         sprintf(name, "%s Playback Switch", chname[idx]);
14255                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
14256                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
14257                                                               HDA_OUTPUT));
14258                         if (err < 0)
14259                                 return err;
14260                 }
14261         }
14262         return 0;
14263 }
14264
14265 static int alc861_auto_create_hp_ctls(struct alc_spec *spec, hda_nid_t pin)
14266 {
14267         int err;
14268         hda_nid_t nid;
14269
14270         if (!pin)
14271                 return 0;
14272
14273         if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
14274                 nid = 0x03;
14275                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
14276                                   "Headphone Playback Switch",
14277                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
14278                 if (err < 0)
14279                         return err;
14280                 spec->multiout.hp_nid = nid;
14281         }
14282         return 0;
14283 }
14284
14285 /* create playback/capture controls for input pins */
14286 static int alc861_auto_create_analog_input_ctls(struct alc_spec *spec,
14287                                                 const struct auto_pin_cfg *cfg)
14288 {
14289         struct hda_input_mux *imux = &spec->private_imux[0];
14290         int i, err, idx, idx1;
14291
14292         for (i = 0; i < AUTO_PIN_LAST; i++) {
14293                 switch (cfg->input_pins[i]) {
14294                 case 0x0c:
14295                         idx1 = 1;
14296                         idx = 2;        /* Line In */
14297                         break;
14298                 case 0x0f:
14299                         idx1 = 2;
14300                         idx = 2;        /* Line In */
14301                         break;
14302                 case 0x0d:
14303                         idx1 = 0;
14304                         idx = 1;        /* Mic In */
14305                         break;
14306                 case 0x10:
14307                         idx1 = 3;
14308                         idx = 1;        /* Mic In */
14309                         break;
14310                 case 0x11:
14311                         idx1 = 4;
14312                         idx = 0;        /* CD */
14313                         break;
14314                 default:
14315                         continue;
14316                 }
14317
14318                 err = new_analog_input(spec, cfg->input_pins[i],
14319                                        auto_pin_cfg_labels[i], idx, 0x15);
14320                 if (err < 0)
14321                         return err;
14322
14323                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
14324                 imux->items[imux->num_items].index = idx1;
14325                 imux->num_items++;
14326         }
14327         return 0;
14328 }
14329
14330 static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
14331                                               hda_nid_t nid,
14332                                               int pin_type, int dac_idx)
14333 {
14334         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
14335                             pin_type);
14336         snd_hda_codec_write(codec, dac_idx, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14337                             AMP_OUT_UNMUTE);
14338 }
14339
14340 static void alc861_auto_init_multi_out(struct hda_codec *codec)
14341 {
14342         struct alc_spec *spec = codec->spec;
14343         int i;
14344
14345         for (i = 0; i < spec->autocfg.line_outs; i++) {
14346                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
14347                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
14348                 if (nid)
14349                         alc861_auto_set_output_and_unmute(codec, nid, pin_type,
14350                                                           spec->multiout.dac_nids[i]);
14351         }
14352 }
14353
14354 static void alc861_auto_init_hp_out(struct hda_codec *codec)
14355 {
14356         struct alc_spec *spec = codec->spec;
14357         hda_nid_t pin;
14358
14359         pin = spec->autocfg.hp_pins[0];
14360         if (pin) /* connect to front */
14361                 alc861_auto_set_output_and_unmute(codec, pin, PIN_HP,
14362                                                   spec->multiout.dac_nids[0]);
14363         pin = spec->autocfg.speaker_pins[0];
14364         if (pin)
14365                 alc861_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
14366 }
14367
14368 static void alc861_auto_init_analog_input(struct hda_codec *codec)
14369 {
14370         struct alc_spec *spec = codec->spec;
14371         int i;
14372
14373         for (i = 0; i < AUTO_PIN_LAST; i++) {
14374                 hda_nid_t nid = spec->autocfg.input_pins[i];
14375                 if (nid >= 0x0c && nid <= 0x11)
14376                         alc_set_input_pin(codec, nid, i);
14377         }
14378 }
14379
14380 /* parse the BIOS configuration and set up the alc_spec */
14381 /* return 1 if successful, 0 if the proper config is not found,
14382  * or a negative error code
14383  */
14384 static int alc861_parse_auto_config(struct hda_codec *codec)
14385 {
14386         struct alc_spec *spec = codec->spec;
14387         int err;
14388         static hda_nid_t alc861_ignore[] = { 0x1d, 0 };
14389
14390         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
14391                                            alc861_ignore);
14392         if (err < 0)
14393                 return err;
14394         if (!spec->autocfg.line_outs)
14395                 return 0; /* can't find valid BIOS pin config */
14396
14397         err = alc861_auto_fill_dac_nids(spec, &spec->autocfg);
14398         if (err < 0)
14399                 return err;
14400         err = alc861_auto_create_multi_out_ctls(spec, &spec->autocfg);
14401         if (err < 0)
14402                 return err;
14403         err = alc861_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
14404         if (err < 0)
14405                 return err;
14406         err = alc861_auto_create_analog_input_ctls(spec, &spec->autocfg);
14407         if (err < 0)
14408                 return err;
14409
14410         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
14411
14412         if (spec->autocfg.dig_outs)
14413                 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;
14414
14415         if (spec->kctls.list)
14416                 add_mixer(spec, spec->kctls.list);
14417
14418         add_verb(spec, alc861_auto_init_verbs);
14419
14420         spec->num_mux_defs = 1;
14421         spec->input_mux = &spec->private_imux[0];
14422
14423         spec->adc_nids = alc861_adc_nids;
14424         spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
14425         set_capture_mixer(spec);
14426
14427         alc_ssid_check(codec, 0x0e, 0x0f, 0x0b);
14428
14429         return 1;
14430 }
14431
14432 /* additional initialization for auto-configuration model */
14433 static void alc861_auto_init(struct hda_codec *codec)
14434 {
14435         struct alc_spec *spec = codec->spec;
14436         alc861_auto_init_multi_out(codec);
14437         alc861_auto_init_hp_out(codec);
14438         alc861_auto_init_analog_input(codec);
14439         if (spec->unsol_event)
14440                 alc_inithook(codec);
14441 }
14442
14443 #ifdef CONFIG_SND_HDA_POWER_SAVE
14444 static struct hda_amp_list alc861_loopbacks[] = {
14445         { 0x15, HDA_INPUT, 0 },
14446         { 0x15, HDA_INPUT, 1 },
14447         { 0x15, HDA_INPUT, 2 },
14448         { 0x15, HDA_INPUT, 3 },
14449         { } /* end */
14450 };
14451 #endif
14452
14453
14454 /*
14455  * configuration and preset
14456  */
14457 static const char *alc861_models[ALC861_MODEL_LAST] = {
14458         [ALC861_3ST]            = "3stack",
14459         [ALC660_3ST]            = "3stack-660",
14460         [ALC861_3ST_DIG]        = "3stack-dig",
14461         [ALC861_6ST_DIG]        = "6stack-dig",
14462         [ALC861_UNIWILL_M31]    = "uniwill-m31",
14463         [ALC861_TOSHIBA]        = "toshiba",
14464         [ALC861_ASUS]           = "asus",
14465         [ALC861_ASUS_LAPTOP]    = "asus-laptop",
14466         [ALC861_AUTO]           = "auto",
14467 };
14468
14469 static struct snd_pci_quirk alc861_cfg_tbl[] = {
14470         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC861_3ST),
14471         SND_PCI_QUIRK(0x1043, 0x1335, "ASUS F2/3", ALC861_ASUS_LAPTOP),
14472         SND_PCI_QUIRK(0x1043, 0x1338, "ASUS F2/3", ALC861_ASUS_LAPTOP),
14473         SND_PCI_QUIRK(0x1043, 0x1393, "ASUS", ALC861_ASUS),
14474         SND_PCI_QUIRK(0x1043, 0x13d7, "ASUS A9rp", ALC861_ASUS_LAPTOP),
14475         SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS P1-AH2", ALC861_3ST_DIG),
14476         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba", ALC861_TOSHIBA),
14477         /* FIXME: the entry below breaks Toshiba A100 (model=auto works!)
14478          *        Any other models that need this preset?
14479          */
14480         /* SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba", ALC861_TOSHIBA), */
14481         SND_PCI_QUIRK(0x1462, 0x7254, "HP dx2200 (MSI MS-7254)", ALC861_3ST),
14482         SND_PCI_QUIRK(0x1462, 0x7297, "HP dx2250 (MSI MS-7297)", ALC861_3ST),
14483         SND_PCI_QUIRK(0x1584, 0x2b01, "Uniwill X40AIx", ALC861_UNIWILL_M31),
14484         SND_PCI_QUIRK(0x1584, 0x9072, "Uniwill m31", ALC861_UNIWILL_M31),
14485         SND_PCI_QUIRK(0x1584, 0x9075, "Airis Praxis N1212", ALC861_ASUS_LAPTOP),
14486         /* FIXME: the below seems conflict */
14487         /* SND_PCI_QUIRK(0x1584, 0x9075, "Uniwill", ALC861_UNIWILL_M31), */
14488         SND_PCI_QUIRK(0x1849, 0x0660, "Asrock 939SLI32", ALC660_3ST),
14489         SND_PCI_QUIRK(0x8086, 0xd600, "Intel", ALC861_3ST),
14490         {}
14491 };
14492
14493 static struct alc_config_preset alc861_presets[] = {
14494         [ALC861_3ST] = {
14495                 .mixers = { alc861_3ST_mixer },
14496                 .init_verbs = { alc861_threestack_init_verbs },
14497                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14498                 .dac_nids = alc861_dac_nids,
14499                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
14500                 .channel_mode = alc861_threestack_modes,
14501                 .need_dac_fix = 1,
14502                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14503                 .adc_nids = alc861_adc_nids,
14504                 .input_mux = &alc861_capture_source,
14505         },
14506         [ALC861_3ST_DIG] = {
14507                 .mixers = { alc861_base_mixer },
14508                 .init_verbs = { alc861_threestack_init_verbs },
14509                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14510                 .dac_nids = alc861_dac_nids,
14511                 .dig_out_nid = ALC861_DIGOUT_NID,
14512                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
14513                 .channel_mode = alc861_threestack_modes,
14514                 .need_dac_fix = 1,
14515                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14516                 .adc_nids = alc861_adc_nids,
14517                 .input_mux = &alc861_capture_source,
14518         },
14519         [ALC861_6ST_DIG] = {
14520                 .mixers = { alc861_base_mixer },
14521                 .init_verbs = { alc861_base_init_verbs },
14522                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14523                 .dac_nids = alc861_dac_nids,
14524                 .dig_out_nid = ALC861_DIGOUT_NID,
14525                 .num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
14526                 .channel_mode = alc861_8ch_modes,
14527                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14528                 .adc_nids = alc861_adc_nids,
14529                 .input_mux = &alc861_capture_source,
14530         },
14531         [ALC660_3ST] = {
14532                 .mixers = { alc861_3ST_mixer },
14533                 .init_verbs = { alc861_threestack_init_verbs },
14534                 .num_dacs = ARRAY_SIZE(alc660_dac_nids),
14535                 .dac_nids = alc660_dac_nids,
14536                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
14537                 .channel_mode = alc861_threestack_modes,
14538                 .need_dac_fix = 1,
14539                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14540                 .adc_nids = alc861_adc_nids,
14541                 .input_mux = &alc861_capture_source,
14542         },
14543         [ALC861_UNIWILL_M31] = {
14544                 .mixers = { alc861_uniwill_m31_mixer },
14545                 .init_verbs = { alc861_uniwill_m31_init_verbs },
14546                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14547                 .dac_nids = alc861_dac_nids,
14548                 .dig_out_nid = ALC861_DIGOUT_NID,
14549                 .num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
14550                 .channel_mode = alc861_uniwill_m31_modes,
14551                 .need_dac_fix = 1,
14552                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14553                 .adc_nids = alc861_adc_nids,
14554                 .input_mux = &alc861_capture_source,
14555         },
14556         [ALC861_TOSHIBA] = {
14557                 .mixers = { alc861_toshiba_mixer },
14558                 .init_verbs = { alc861_base_init_verbs,
14559                                 alc861_toshiba_init_verbs },
14560                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14561                 .dac_nids = alc861_dac_nids,
14562                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
14563                 .channel_mode = alc883_3ST_2ch_modes,
14564                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14565                 .adc_nids = alc861_adc_nids,
14566                 .input_mux = &alc861_capture_source,
14567                 .unsol_event = alc861_toshiba_unsol_event,
14568                 .init_hook = alc861_toshiba_automute,
14569         },
14570         [ALC861_ASUS] = {
14571                 .mixers = { alc861_asus_mixer },
14572                 .init_verbs = { alc861_asus_init_verbs },
14573                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14574                 .dac_nids = alc861_dac_nids,
14575                 .dig_out_nid = ALC861_DIGOUT_NID,
14576                 .num_channel_mode = ARRAY_SIZE(alc861_asus_modes),
14577                 .channel_mode = alc861_asus_modes,
14578                 .need_dac_fix = 1,
14579                 .hp_nid = 0x06,
14580                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14581                 .adc_nids = alc861_adc_nids,
14582                 .input_mux = &alc861_capture_source,
14583         },
14584         [ALC861_ASUS_LAPTOP] = {
14585                 .mixers = { alc861_toshiba_mixer, alc861_asus_laptop_mixer },
14586                 .init_verbs = { alc861_asus_init_verbs,
14587                                 alc861_asus_laptop_init_verbs },
14588                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14589                 .dac_nids = alc861_dac_nids,
14590                 .dig_out_nid = ALC861_DIGOUT_NID,
14591                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
14592                 .channel_mode = alc883_3ST_2ch_modes,
14593                 .need_dac_fix = 1,
14594                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14595                 .adc_nids = alc861_adc_nids,
14596                 .input_mux = &alc861_capture_source,
14597         },
14598 };
14599
14600
14601 static int patch_alc861(struct hda_codec *codec)
14602 {
14603         struct alc_spec *spec;
14604         int board_config;
14605         int err;
14606
14607         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
14608         if (spec == NULL)
14609                 return -ENOMEM;
14610
14611         codec->spec = spec;
14612
14613         board_config = snd_hda_check_board_config(codec, ALC861_MODEL_LAST,
14614                                                   alc861_models,
14615                                                   alc861_cfg_tbl);
14616
14617         if (board_config < 0) {
14618                 printk(KERN_INFO "hda_codec: Unknown model for %s, "
14619                        "trying auto-probe from BIOS...\n", codec->chip_name);
14620                 board_config = ALC861_AUTO;
14621         }
14622
14623         if (board_config == ALC861_AUTO) {
14624                 /* automatic parse from the BIOS config */
14625                 err = alc861_parse_auto_config(codec);
14626                 if (err < 0) {
14627                         alc_free(codec);
14628                         return err;
14629                 } else if (!err) {
14630                         printk(KERN_INFO
14631                                "hda_codec: Cannot set up configuration "
14632                                "from BIOS.  Using base mode...\n");
14633                    board_config = ALC861_3ST_DIG;
14634                 }
14635         }
14636
14637         err = snd_hda_attach_beep_device(codec, 0x23);
14638         if (err < 0) {
14639                 alc_free(codec);
14640                 return err;
14641         }
14642
14643         if (board_config != ALC861_AUTO)
14644                 setup_preset(spec, &alc861_presets[board_config]);
14645
14646         spec->stream_analog_playback = &alc861_pcm_analog_playback;
14647         spec->stream_analog_capture = &alc861_pcm_analog_capture;
14648
14649         spec->stream_digital_playback = &alc861_pcm_digital_playback;
14650         spec->stream_digital_capture = &alc861_pcm_digital_capture;
14651
14652         set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
14653
14654         spec->vmaster_nid = 0x03;
14655
14656         codec->patch_ops = alc_patch_ops;
14657         if (board_config == ALC861_AUTO)
14658                 spec->init_hook = alc861_auto_init;
14659 #ifdef CONFIG_SND_HDA_POWER_SAVE
14660         if (!spec->loopback.amplist)
14661                 spec->loopback.amplist = alc861_loopbacks;
14662 #endif
14663         codec->proc_widget_hook = print_realtek_coef;
14664
14665         return 0;
14666 }
14667
14668 /*
14669  * ALC861-VD support
14670  *
14671  * Based on ALC882
14672  *
14673  * In addition, an independent DAC
14674  */
14675 #define ALC861VD_DIGOUT_NID     0x06
14676
14677 static hda_nid_t alc861vd_dac_nids[4] = {
14678         /* front, surr, clfe, side surr */
14679         0x02, 0x03, 0x04, 0x05
14680 };
14681
14682 /* dac_nids for ALC660vd are in a different order - according to
14683  * Realtek's driver.
14684  * This should probably result in a different mixer for 6stack models
14685  * of ALC660vd codecs, but for now there is only 3stack mixer
14686  * - and it is the same as in 861vd.
14687  * adc_nids in ALC660vd are (is) the same as in 861vd
14688  */
14689 static hda_nid_t alc660vd_dac_nids[3] = {
14690         /* front, rear, clfe, rear_surr */
14691         0x02, 0x04, 0x03
14692 };
14693
14694 static hda_nid_t alc861vd_adc_nids[1] = {
14695         /* ADC0 */
14696         0x09,
14697 };
14698
14699 static hda_nid_t alc861vd_capsrc_nids[1] = { 0x22 };
14700
14701 /* input MUX */
14702 /* FIXME: should be a matrix-type input source selection */
14703 static struct hda_input_mux alc861vd_capture_source = {
14704         .num_items = 4,
14705         .items = {
14706                 { "Mic", 0x0 },
14707                 { "Front Mic", 0x1 },
14708                 { "Line", 0x2 },
14709                 { "CD", 0x4 },
14710         },
14711 };
14712
14713 static struct hda_input_mux alc861vd_dallas_capture_source = {
14714         .num_items = 2,
14715         .items = {
14716                 { "Ext Mic", 0x0 },
14717                 { "Int Mic", 0x1 },
14718         },
14719 };
14720
14721 static struct hda_input_mux alc861vd_hp_capture_source = {
14722         .num_items = 2,
14723         .items = {
14724                 { "Front Mic", 0x0 },
14725                 { "ATAPI Mic", 0x1 },
14726         },
14727 };
14728
14729 /*
14730  * 2ch mode
14731  */
14732 static struct hda_channel_mode alc861vd_3stack_2ch_modes[1] = {
14733         { 2, NULL }
14734 };
14735
14736 /*
14737  * 6ch mode
14738  */
14739 static struct hda_verb alc861vd_6stack_ch6_init[] = {
14740         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
14741         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14742         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14743         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14744         { } /* end */
14745 };
14746
14747 /*
14748  * 8ch mode
14749  */
14750 static struct hda_verb alc861vd_6stack_ch8_init[] = {
14751         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14752         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14753         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14754         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14755         { } /* end */
14756 };
14757
14758 static struct hda_channel_mode alc861vd_6stack_modes[2] = {
14759         { 6, alc861vd_6stack_ch6_init },
14760         { 8, alc861vd_6stack_ch8_init },
14761 };
14762
14763 static struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
14764         {
14765                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
14766                 .name = "Channel Mode",
14767                 .info = alc_ch_mode_info,
14768                 .get = alc_ch_mode_get,
14769                 .put = alc_ch_mode_put,
14770         },
14771         { } /* end */
14772 };
14773
14774 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
14775  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
14776  */
14777 static struct snd_kcontrol_new alc861vd_6st_mixer[] = {
14778         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14779         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14780
14781         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14782         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
14783
14784         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0,
14785                                 HDA_OUTPUT),
14786         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0,
14787                                 HDA_OUTPUT),
14788         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
14789         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
14790
14791         HDA_CODEC_VOLUME("Side Playback Volume", 0x05, 0x0, HDA_OUTPUT),
14792         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
14793
14794         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14795
14796         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
14797         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14798         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14799
14800         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
14801         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14802         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14803
14804         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14805         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14806
14807         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14808         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14809
14810         { } /* end */
14811 };
14812
14813 static struct snd_kcontrol_new alc861vd_3st_mixer[] = {
14814         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14815         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14816
14817         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14818
14819         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
14820         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14821         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14822
14823         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
14824         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14825         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14826
14827         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14828         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14829
14830         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14831         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14832
14833         { } /* end */
14834 };
14835
14836 static struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
14837         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14838         /*HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),*/
14839         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14840
14841         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14842
14843         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
14844         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14845         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14846
14847         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
14848         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14849         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14850
14851         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14852         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14853
14854         { } /* end */
14855 };
14856
14857 /* Pin assignment: Speaker=0x14, HP = 0x15,
14858  *                 Ext Mic=0x18, Int Mic = 0x19, CD = 0x1c, PC Beep = 0x1d
14859  */
14860 static struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
14861         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14862         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
14863         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14864         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
14865         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
14866         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14867         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14868         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
14869         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14870         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14871         { } /* end */
14872 };
14873
14874 /* Pin assignment: Speaker=0x14, Line-out = 0x15,
14875  *                 Front Mic=0x18, ATAPI Mic = 0x19,
14876  */
14877 static struct snd_kcontrol_new alc861vd_hp_mixer[] = {
14878         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14879         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14880         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14881         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
14882         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14883         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14884         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14885         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14886
14887         { } /* end */
14888 };
14889
14890 /*
14891  * generic initialization of ADC, input mixers and output mixers
14892  */
14893 static struct hda_verb alc861vd_volume_init_verbs[] = {
14894         /*
14895          * Unmute ADC0 and set the default input to mic-in
14896          */
14897         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
14898         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14899
14900         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of
14901          * the analog-loopback mixer widget
14902          */
14903         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
14904         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14905         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14906         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14907         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14908         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14909
14910         /* Capture mixer: unmute Mic, F-Mic, Line, CD inputs */
14911         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14912         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14913         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14914         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
14915
14916         /*
14917          * Set up output mixers (0x02 - 0x05)
14918          */
14919         /* set vol=0 to output mixers */
14920         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14921         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14922         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14923         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14924
14925         /* set up input amps for analog loopback */
14926         /* Amp Indices: DAC = 0, mixer = 1 */
14927         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14928         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14929         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14930         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14931         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14932         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14933         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14934         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14935
14936         { }
14937 };
14938
14939 /*
14940  * 3-stack pin configuration:
14941  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
14942  */
14943 static struct hda_verb alc861vd_3stack_init_verbs[] = {
14944         /*
14945          * Set pin mode and muting
14946          */
14947         /* set front pin widgets 0x14 for output */
14948         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14949         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14950         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
14951
14952         /* Mic (rear) pin: input vref at 80% */
14953         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14954         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14955         /* Front Mic pin: input vref at 80% */
14956         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14957         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14958         /* Line In pin: input */
14959         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14960         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14961         /* Line-2 In: Headphone output (output 0 - 0x0c) */
14962         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14963         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14964         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
14965         /* CD pin widget for input */
14966         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14967
14968         { }
14969 };
14970
14971 /*
14972  * 6-stack pin configuration:
14973  */
14974 static struct hda_verb alc861vd_6stack_init_verbs[] = {
14975         /*
14976          * Set pin mode and muting
14977          */
14978         /* set front pin widgets 0x14 for output */
14979         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14980         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14981         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
14982
14983         /* Rear Pin: output 1 (0x0d) */
14984         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14985         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14986         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
14987         /* CLFE Pin: output 2 (0x0e) */
14988         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14989         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14990         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
14991         /* Side Pin: output 3 (0x0f) */
14992         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14993         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14994         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
14995
14996         /* Mic (rear) pin: input vref at 80% */
14997         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14998         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14999         /* Front Mic pin: input vref at 80% */
15000         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
15001         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15002         /* Line In pin: input */
15003         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15004         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15005         /* Line-2 In: Headphone output (output 0 - 0x0c) */
15006         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15007         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15008         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
15009         /* CD pin widget for input */
15010         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15011
15012         { }
15013 };
15014
15015 static struct hda_verb alc861vd_eapd_verbs[] = {
15016         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
15017         { }
15018 };
15019
15020 static struct hda_verb alc660vd_eapd_verbs[] = {
15021         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
15022         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
15023         { }
15024 };
15025
15026 static struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
15027         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15028         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15029         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
15030         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15031         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15032         {}
15033 };
15034
15035 static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
15036 {
15037         unsigned int present;
15038         unsigned char bits;
15039
15040         present = snd_hda_codec_read(codec, 0x18, 0,
15041                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15042         bits = present ? HDA_AMP_MUTE : 0;
15043         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
15044                                  HDA_AMP_MUTE, bits);
15045 }
15046
15047 static void alc861vd_lenovo_init_hook(struct hda_codec *codec)
15048 {
15049         struct alc_spec *spec = codec->spec;
15050
15051         spec->autocfg.hp_pins[0] = 0x1b;
15052         spec->autocfg.speaker_pins[0] = 0x14;
15053         alc_automute_amp(codec);
15054         alc861vd_lenovo_mic_automute(codec);
15055 }
15056
15057 static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
15058                                         unsigned int res)
15059 {
15060         switch (res >> 26) {
15061         case ALC880_MIC_EVENT:
15062                 alc861vd_lenovo_mic_automute(codec);
15063                 break;
15064         default:
15065                 alc_automute_amp_unsol_event(codec, res);
15066                 break;
15067         }
15068 }
15069
15070 static struct hda_verb alc861vd_dallas_verbs[] = {
15071         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15072         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15073         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15074         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15075
15076         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15077         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15078         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15079         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15080         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15081         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15082         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15083         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15084
15085         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15086         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15087         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15088         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15089         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15090         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15091         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15092         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15093
15094         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
15095         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15096         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
15097         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15098         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15099         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15100         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15101         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15102
15103         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15104         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
15105         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
15106         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
15107
15108         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15109         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
15110         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15111
15112         { } /* end */
15113 };
15114
15115 /* toggle speaker-output according to the hp-jack state */
15116 static void alc861vd_dallas_init_hook(struct hda_codec *codec)
15117 {
15118         struct alc_spec *spec = codec->spec;
15119
15120         spec->autocfg.hp_pins[0] = 0x15;
15121         spec->autocfg.speaker_pins[0] = 0x14;
15122         alc_automute_amp(codec);
15123 }
15124
15125 #ifdef CONFIG_SND_HDA_POWER_SAVE
15126 #define alc861vd_loopbacks      alc880_loopbacks
15127 #endif
15128
15129 /* pcm configuration: identical with ALC880 */
15130 #define alc861vd_pcm_analog_playback    alc880_pcm_analog_playback
15131 #define alc861vd_pcm_analog_capture     alc880_pcm_analog_capture
15132 #define alc861vd_pcm_digital_playback   alc880_pcm_digital_playback
15133 #define alc861vd_pcm_digital_capture    alc880_pcm_digital_capture
15134
15135 /*
15136  * configuration and preset
15137  */
15138 static const char *alc861vd_models[ALC861VD_MODEL_LAST] = {
15139         [ALC660VD_3ST]          = "3stack-660",
15140         [ALC660VD_3ST_DIG]      = "3stack-660-digout",
15141         [ALC660VD_ASUS_V1S]     = "asus-v1s",
15142         [ALC861VD_3ST]          = "3stack",
15143         [ALC861VD_3ST_DIG]      = "3stack-digout",
15144         [ALC861VD_6ST_DIG]      = "6stack-digout",
15145         [ALC861VD_LENOVO]       = "lenovo",
15146         [ALC861VD_DALLAS]       = "dallas",
15147         [ALC861VD_HP]           = "hp",
15148         [ALC861VD_AUTO]         = "auto",
15149 };
15150
15151 static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
15152         SND_PCI_QUIRK(0x1019, 0xa88d, "Realtek ALC660 demo", ALC660VD_3ST),
15153         SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_HP),
15154         SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST),
15155         SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),
15156         SND_PCI_QUIRK(0x1043, 0x1633, "Asus V1Sn", ALC660VD_ASUS_V1S),
15157         SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG),
15158         SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
15159         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
15160         /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
15161         SND_PCI_QUIRK(0x1179, 0xff01, "DALLAS", ALC861VD_DALLAS),
15162         SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
15163         SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_DALLAS),
15164         SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
15165         SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", ALC861VD_LENOVO),
15166         SND_PCI_QUIRK(0x1849, 0x0862, "ASRock K8NF6G-VSTA", ALC861VD_6ST_DIG),
15167         {}
15168 };
15169
15170 static struct alc_config_preset alc861vd_presets[] = {
15171         [ALC660VD_3ST] = {
15172                 .mixers = { alc861vd_3st_mixer },
15173                 .init_verbs = { alc861vd_volume_init_verbs,
15174                                  alc861vd_3stack_init_verbs },
15175                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
15176                 .dac_nids = alc660vd_dac_nids,
15177                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15178                 .channel_mode = alc861vd_3stack_2ch_modes,
15179                 .input_mux = &alc861vd_capture_source,
15180         },
15181         [ALC660VD_3ST_DIG] = {
15182                 .mixers = { alc861vd_3st_mixer },
15183                 .init_verbs = { alc861vd_volume_init_verbs,
15184                                  alc861vd_3stack_init_verbs },
15185                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
15186                 .dac_nids = alc660vd_dac_nids,
15187                 .dig_out_nid = ALC861VD_DIGOUT_NID,
15188                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15189                 .channel_mode = alc861vd_3stack_2ch_modes,
15190                 .input_mux = &alc861vd_capture_source,
15191         },
15192         [ALC861VD_3ST] = {
15193                 .mixers = { alc861vd_3st_mixer },
15194                 .init_verbs = { alc861vd_volume_init_verbs,
15195                                  alc861vd_3stack_init_verbs },
15196                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
15197                 .dac_nids = alc861vd_dac_nids,
15198                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15199                 .channel_mode = alc861vd_3stack_2ch_modes,
15200                 .input_mux = &alc861vd_capture_source,
15201         },
15202         [ALC861VD_3ST_DIG] = {
15203                 .mixers = { alc861vd_3st_mixer },
15204                 .init_verbs = { alc861vd_volume_init_verbs,
15205                                  alc861vd_3stack_init_verbs },
15206                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
15207                 .dac_nids = alc861vd_dac_nids,
15208                 .dig_out_nid = ALC861VD_DIGOUT_NID,
15209                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15210                 .channel_mode = alc861vd_3stack_2ch_modes,
15211                 .input_mux = &alc861vd_capture_source,
15212         },
15213         [ALC861VD_6ST_DIG] = {
15214                 .mixers = { alc861vd_6st_mixer, alc861vd_chmode_mixer },
15215                 .init_verbs = { alc861vd_volume_init_verbs,
15216                                 alc861vd_6stack_init_verbs },
15217                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
15218                 .dac_nids = alc861vd_dac_nids,
15219                 .dig_out_nid = ALC861VD_DIGOUT_NID,
15220                 .num_channel_mode = ARRAY_SIZE(alc861vd_6stack_modes),
15221                 .channel_mode = alc861vd_6stack_modes,
15222                 .input_mux = &alc861vd_capture_source,
15223         },
15224         [ALC861VD_LENOVO] = {
15225                 .mixers = { alc861vd_lenovo_mixer },
15226                 .init_verbs = { alc861vd_volume_init_verbs,
15227                                 alc861vd_3stack_init_verbs,
15228                                 alc861vd_eapd_verbs,
15229                                 alc861vd_lenovo_unsol_verbs },
15230                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
15231                 .dac_nids = alc660vd_dac_nids,
15232                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15233                 .channel_mode = alc861vd_3stack_2ch_modes,
15234                 .input_mux = &alc861vd_capture_source,
15235                 .unsol_event = alc861vd_lenovo_unsol_event,
15236                 .init_hook = alc861vd_lenovo_init_hook,
15237         },
15238         [ALC861VD_DALLAS] = {
15239                 .mixers = { alc861vd_dallas_mixer },
15240                 .init_verbs = { alc861vd_dallas_verbs },
15241                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
15242                 .dac_nids = alc861vd_dac_nids,
15243                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15244                 .channel_mode = alc861vd_3stack_2ch_modes,
15245                 .input_mux = &alc861vd_dallas_capture_source,
15246                 .unsol_event = alc_automute_amp_unsol_event,
15247                 .init_hook = alc861vd_dallas_init_hook,
15248         },
15249         [ALC861VD_HP] = {
15250                 .mixers = { alc861vd_hp_mixer },
15251                 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs },
15252                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
15253                 .dac_nids = alc861vd_dac_nids,
15254                 .dig_out_nid = ALC861VD_DIGOUT_NID,
15255                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15256                 .channel_mode = alc861vd_3stack_2ch_modes,
15257                 .input_mux = &alc861vd_hp_capture_source,
15258                 .unsol_event = alc_automute_amp_unsol_event,
15259                 .init_hook = alc861vd_dallas_init_hook,
15260         },
15261         [ALC660VD_ASUS_V1S] = {
15262                 .mixers = { alc861vd_lenovo_mixer },
15263                 .init_verbs = { alc861vd_volume_init_verbs,
15264                                 alc861vd_3stack_init_verbs,
15265                                 alc861vd_eapd_verbs,
15266                                 alc861vd_lenovo_unsol_verbs },
15267                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
15268                 .dac_nids = alc660vd_dac_nids,
15269                 .dig_out_nid = ALC861VD_DIGOUT_NID,
15270                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15271                 .channel_mode = alc861vd_3stack_2ch_modes,
15272                 .input_mux = &alc861vd_capture_source,
15273                 .unsol_event = alc861vd_lenovo_unsol_event,
15274                 .init_hook = alc861vd_lenovo_init_hook,
15275         },
15276 };
15277
15278 /*
15279  * BIOS auto configuration
15280  */
15281 static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
15282                                 hda_nid_t nid, int pin_type, int dac_idx)
15283 {
15284         alc_set_pin_output(codec, nid, pin_type);
15285 }
15286
15287 static void alc861vd_auto_init_multi_out(struct hda_codec *codec)
15288 {
15289         struct alc_spec *spec = codec->spec;
15290         int i;
15291
15292         for (i = 0; i <= HDA_SIDE; i++) {
15293                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
15294                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
15295                 if (nid)
15296                         alc861vd_auto_set_output_and_unmute(codec, nid,
15297                                                             pin_type, i);
15298         }
15299 }
15300
15301
15302 static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
15303 {
15304         struct alc_spec *spec = codec->spec;
15305         hda_nid_t pin;
15306
15307         pin = spec->autocfg.hp_pins[0];
15308         if (pin) /* connect to front and use dac 0 */
15309                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
15310         pin = spec->autocfg.speaker_pins[0];
15311         if (pin)
15312                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
15313 }
15314
15315 #define alc861vd_is_input_pin(nid)      alc880_is_input_pin(nid)
15316 #define ALC861VD_PIN_CD_NID             ALC880_PIN_CD_NID
15317
15318 static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
15319 {
15320         struct alc_spec *spec = codec->spec;
15321         int i;
15322
15323         for (i = 0; i < AUTO_PIN_LAST; i++) {
15324                 hda_nid_t nid = spec->autocfg.input_pins[i];
15325                 if (alc861vd_is_input_pin(nid)) {
15326                         alc_set_input_pin(codec, nid, i);
15327                         if (nid != ALC861VD_PIN_CD_NID &&
15328                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
15329                                 snd_hda_codec_write(codec, nid, 0,
15330                                                 AC_VERB_SET_AMP_GAIN_MUTE,
15331                                                 AMP_OUT_MUTE);
15332                 }
15333         }
15334 }
15335
15336 #define alc861vd_auto_init_input_src    alc882_auto_init_input_src
15337
15338 #define alc861vd_idx_to_mixer_vol(nid)          ((nid) + 0x02)
15339 #define alc861vd_idx_to_mixer_switch(nid)       ((nid) + 0x0c)
15340
15341 /* add playback controls from the parsed DAC table */
15342 /* Based on ALC880 version. But ALC861VD has separate,
15343  * different NIDs for mute/unmute switch and volume control */
15344 static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
15345                                              const struct auto_pin_cfg *cfg)
15346 {
15347         char name[32];
15348         static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"};
15349         hda_nid_t nid_v, nid_s;
15350         int i, err;
15351
15352         for (i = 0; i < cfg->line_outs; i++) {
15353                 if (!spec->multiout.dac_nids[i])
15354                         continue;
15355                 nid_v = alc861vd_idx_to_mixer_vol(
15356                                 alc880_dac_to_idx(
15357                                         spec->multiout.dac_nids[i]));
15358                 nid_s = alc861vd_idx_to_mixer_switch(
15359                                 alc880_dac_to_idx(
15360                                         spec->multiout.dac_nids[i]));
15361
15362                 if (i == 2) {
15363                         /* Center/LFE */
15364                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
15365                                           "Center Playback Volume",
15366                                           HDA_COMPOSE_AMP_VAL(nid_v, 1, 0,
15367                                                               HDA_OUTPUT));
15368                         if (err < 0)
15369                                 return err;
15370                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
15371                                           "LFE Playback Volume",
15372                                           HDA_COMPOSE_AMP_VAL(nid_v, 2, 0,
15373                                                               HDA_OUTPUT));
15374                         if (err < 0)
15375                                 return err;
15376                         err = add_control(spec, ALC_CTL_BIND_MUTE,
15377                                           "Center Playback Switch",
15378                                           HDA_COMPOSE_AMP_VAL(nid_s, 1, 2,
15379                                                               HDA_INPUT));
15380                         if (err < 0)
15381                                 return err;
15382                         err = add_control(spec, ALC_CTL_BIND_MUTE,
15383                                           "LFE Playback Switch",
15384                                           HDA_COMPOSE_AMP_VAL(nid_s, 2, 2,
15385                                                               HDA_INPUT));
15386                         if (err < 0)
15387                                 return err;
15388                 } else {
15389                         sprintf(name, "%s Playback Volume", chname[i]);
15390                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
15391                                           HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
15392                                                               HDA_OUTPUT));
15393                         if (err < 0)
15394                                 return err;
15395                         sprintf(name, "%s Playback Switch", chname[i]);
15396                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
15397                                           HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
15398                                                               HDA_INPUT));
15399                         if (err < 0)
15400                                 return err;
15401                 }
15402         }
15403         return 0;
15404 }
15405
15406 /* add playback controls for speaker and HP outputs */
15407 /* Based on ALC880 version. But ALC861VD has separate,
15408  * different NIDs for mute/unmute switch and volume control */
15409 static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
15410                                         hda_nid_t pin, const char *pfx)
15411 {
15412         hda_nid_t nid_v, nid_s;
15413         int err;
15414         char name[32];
15415
15416         if (!pin)
15417                 return 0;
15418
15419         if (alc880_is_fixed_pin(pin)) {
15420                 nid_v = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
15421                 /* specify the DAC as the extra output */
15422                 if (!spec->multiout.hp_nid)
15423                         spec->multiout.hp_nid = nid_v;
15424                 else
15425                         spec->multiout.extra_out_nid[0] = nid_v;
15426                 /* control HP volume/switch on the output mixer amp */
15427                 nid_v = alc861vd_idx_to_mixer_vol(
15428                                 alc880_fixed_pin_idx(pin));
15429                 nid_s = alc861vd_idx_to_mixer_switch(
15430                                 alc880_fixed_pin_idx(pin));
15431
15432                 sprintf(name, "%s Playback Volume", pfx);
15433                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
15434                                   HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT));
15435                 if (err < 0)
15436                         return err;
15437                 sprintf(name, "%s Playback Switch", pfx);
15438                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
15439                                   HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT));
15440                 if (err < 0)
15441                         return err;
15442         } else if (alc880_is_multi_pin(pin)) {
15443                 /* set manual connection */
15444                 /* we have only a switch on HP-out PIN */
15445                 sprintf(name, "%s Playback Switch", pfx);
15446                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
15447                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
15448                 if (err < 0)
15449                         return err;
15450         }
15451         return 0;
15452 }
15453
15454 /* parse the BIOS configuration and set up the alc_spec
15455  * return 1 if successful, 0 if the proper config is not found,
15456  * or a negative error code
15457  * Based on ALC880 version - had to change it to override
15458  * alc880_auto_create_extra_out and alc880_auto_create_multi_out_ctls */
15459 static int alc861vd_parse_auto_config(struct hda_codec *codec)
15460 {
15461         struct alc_spec *spec = codec->spec;
15462         int err;
15463         static hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
15464
15465         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
15466                                            alc861vd_ignore);
15467         if (err < 0)
15468                 return err;
15469         if (!spec->autocfg.line_outs)
15470                 return 0; /* can't find valid BIOS pin config */
15471
15472         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
15473         if (err < 0)
15474                 return err;
15475         err = alc861vd_auto_create_multi_out_ctls(spec, &spec->autocfg);
15476         if (err < 0)
15477                 return err;
15478         err = alc861vd_auto_create_extra_out(spec,
15479                                              spec->autocfg.speaker_pins[0],
15480                                              "Speaker");
15481         if (err < 0)
15482                 return err;
15483         err = alc861vd_auto_create_extra_out(spec,
15484                                              spec->autocfg.hp_pins[0],
15485                                              "Headphone");
15486         if (err < 0)
15487                 return err;
15488         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
15489         if (err < 0)
15490                 return err;
15491
15492         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
15493
15494         if (spec->autocfg.dig_outs)
15495                 spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID;
15496
15497         if (spec->kctls.list)
15498                 add_mixer(spec, spec->kctls.list);
15499
15500         add_verb(spec, alc861vd_volume_init_verbs);
15501
15502         spec->num_mux_defs = 1;
15503         spec->input_mux = &spec->private_imux[0];
15504
15505         err = alc_auto_add_mic_boost(codec);
15506         if (err < 0)
15507                 return err;
15508
15509         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
15510
15511         return 1;
15512 }
15513
15514 /* additional initialization for auto-configuration model */
15515 static void alc861vd_auto_init(struct hda_codec *codec)
15516 {
15517         struct alc_spec *spec = codec->spec;
15518         alc861vd_auto_init_multi_out(codec);
15519         alc861vd_auto_init_hp_out(codec);
15520         alc861vd_auto_init_analog_input(codec);
15521         alc861vd_auto_init_input_src(codec);
15522         if (spec->unsol_event)
15523                 alc_inithook(codec);
15524 }
15525
15526 static int patch_alc861vd(struct hda_codec *codec)
15527 {
15528         struct alc_spec *spec;
15529         int err, board_config;
15530
15531         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
15532         if (spec == NULL)
15533                 return -ENOMEM;
15534
15535         codec->spec = spec;
15536
15537         board_config = snd_hda_check_board_config(codec, ALC861VD_MODEL_LAST,
15538                                                   alc861vd_models,
15539                                                   alc861vd_cfg_tbl);
15540
15541         if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) {
15542                 printk(KERN_INFO "hda_codec: Unknown model for %s, "
15543                        "trying auto-probe from BIOS...\n", codec->chip_name);
15544                 board_config = ALC861VD_AUTO;
15545         }
15546
15547         if (board_config == ALC861VD_AUTO) {
15548                 /* automatic parse from the BIOS config */
15549                 err = alc861vd_parse_auto_config(codec);
15550                 if (err < 0) {
15551                         alc_free(codec);
15552                         return err;
15553                 } else if (!err) {
15554                         printk(KERN_INFO
15555                                "hda_codec: Cannot set up configuration "
15556                                "from BIOS.  Using base mode...\n");
15557                         board_config = ALC861VD_3ST;
15558                 }
15559         }
15560
15561         err = snd_hda_attach_beep_device(codec, 0x23);
15562         if (err < 0) {
15563                 alc_free(codec);
15564                 return err;
15565         }
15566
15567         if (board_config != ALC861VD_AUTO)
15568                 setup_preset(spec, &alc861vd_presets[board_config]);
15569
15570         if (codec->vendor_id == 0x10ec0660) {
15571                 /* always turn on EAPD */
15572                 add_verb(spec, alc660vd_eapd_verbs);
15573         }
15574
15575         spec->stream_analog_playback = &alc861vd_pcm_analog_playback;
15576         spec->stream_analog_capture = &alc861vd_pcm_analog_capture;
15577
15578         spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
15579         spec->stream_digital_capture = &alc861vd_pcm_digital_capture;
15580
15581         spec->adc_nids = alc861vd_adc_nids;
15582         spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
15583         spec->capsrc_nids = alc861vd_capsrc_nids;
15584
15585         set_capture_mixer(spec);
15586         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
15587
15588         spec->vmaster_nid = 0x02;
15589
15590         codec->patch_ops = alc_patch_ops;
15591
15592         if (board_config == ALC861VD_AUTO)
15593                 spec->init_hook = alc861vd_auto_init;
15594 #ifdef CONFIG_SND_HDA_POWER_SAVE
15595         if (!spec->loopback.amplist)
15596                 spec->loopback.amplist = alc861vd_loopbacks;
15597 #endif
15598         codec->proc_widget_hook = print_realtek_coef;
15599
15600         return 0;
15601 }
15602
15603 /*
15604  * ALC662 support
15605  *
15606  * ALC662 is almost identical with ALC880 but has cleaner and more flexible
15607  * configuration.  Each pin widget can choose any input DACs and a mixer.
15608  * Each ADC is connected from a mixer of all inputs.  This makes possible
15609  * 6-channel independent captures.
15610  *
15611  * In addition, an independent DAC for the multi-playback (not used in this
15612  * driver yet).
15613  */
15614 #define ALC662_DIGOUT_NID       0x06
15615 #define ALC662_DIGIN_NID        0x0a
15616
15617 static hda_nid_t alc662_dac_nids[4] = {
15618         /* front, rear, clfe, rear_surr */
15619         0x02, 0x03, 0x04
15620 };
15621
15622 static hda_nid_t alc272_dac_nids[2] = {
15623         0x02, 0x03
15624 };
15625
15626 static hda_nid_t alc662_adc_nids[1] = {
15627         /* ADC1-2 */
15628         0x09,
15629 };
15630
15631 static hda_nid_t alc272_adc_nids[1] = {
15632         /* ADC1-2 */
15633         0x08,
15634 };
15635
15636 static hda_nid_t alc662_capsrc_nids[1] = { 0x22 };
15637 static hda_nid_t alc272_capsrc_nids[1] = { 0x23 };
15638
15639
15640 /* input MUX */
15641 /* FIXME: should be a matrix-type input source selection */
15642 static struct hda_input_mux alc662_capture_source = {
15643         .num_items = 4,
15644         .items = {
15645                 { "Mic", 0x0 },
15646                 { "Front Mic", 0x1 },
15647                 { "Line", 0x2 },
15648                 { "CD", 0x4 },
15649         },
15650 };
15651
15652 static struct hda_input_mux alc662_lenovo_101e_capture_source = {
15653         .num_items = 2,
15654         .items = {
15655                 { "Mic", 0x1 },
15656                 { "Line", 0x2 },
15657         },
15658 };
15659
15660 static struct hda_input_mux alc662_eeepc_capture_source = {
15661         .num_items = 2,
15662         .items = {
15663                 { "i-Mic", 0x1 },
15664                 { "e-Mic", 0x0 },
15665         },
15666 };
15667
15668 static struct hda_input_mux alc663_capture_source = {
15669         .num_items = 3,
15670         .items = {
15671                 { "Mic", 0x0 },
15672                 { "Front Mic", 0x1 },
15673                 { "Line", 0x2 },
15674         },
15675 };
15676
15677 static struct hda_input_mux alc663_m51va_capture_source = {
15678         .num_items = 2,
15679         .items = {
15680                 { "Ext-Mic", 0x0 },
15681                 { "D-Mic", 0x9 },
15682         },
15683 };
15684
15685 #if 1 /* set to 0 for testing other input sources below */
15686 static struct hda_input_mux alc272_nc10_capture_source = {
15687         .num_items = 2,
15688         .items = {
15689                 { "Autoselect Mic", 0x0 },
15690                 { "Internal Mic", 0x1 },
15691         },
15692 };
15693 #else
15694 static struct hda_input_mux alc272_nc10_capture_source = {
15695         .num_items = 16,
15696         .items = {
15697                 { "Autoselect Mic", 0x0 },
15698                 { "Internal Mic", 0x1 },
15699                 { "In-0x02", 0x2 },
15700                 { "In-0x03", 0x3 },
15701                 { "In-0x04", 0x4 },
15702                 { "In-0x05", 0x5 },
15703                 { "In-0x06", 0x6 },
15704                 { "In-0x07", 0x7 },
15705                 { "In-0x08", 0x8 },
15706                 { "In-0x09", 0x9 },
15707                 { "In-0x0a", 0x0a },
15708                 { "In-0x0b", 0x0b },
15709                 { "In-0x0c", 0x0c },
15710                 { "In-0x0d", 0x0d },
15711                 { "In-0x0e", 0x0e },
15712                 { "In-0x0f", 0x0f },
15713         },
15714 };
15715 #endif
15716
15717 /*
15718  * 2ch mode
15719  */
15720 static struct hda_channel_mode alc662_3ST_2ch_modes[1] = {
15721         { 2, NULL }
15722 };
15723
15724 /*
15725  * 2ch mode
15726  */
15727 static struct hda_verb alc662_3ST_ch2_init[] = {
15728         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
15729         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
15730         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
15731         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
15732         { } /* end */
15733 };
15734
15735 /*
15736  * 6ch mode
15737  */
15738 static struct hda_verb alc662_3ST_ch6_init[] = {
15739         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15740         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
15741         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
15742         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15743         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
15744         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
15745         { } /* end */
15746 };
15747
15748 static struct hda_channel_mode alc662_3ST_6ch_modes[2] = {
15749         { 2, alc662_3ST_ch2_init },
15750         { 6, alc662_3ST_ch6_init },
15751 };
15752
15753 /*
15754  * 2ch mode
15755  */
15756 static struct hda_verb alc662_sixstack_ch6_init[] = {
15757         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
15758         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
15759         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15760         { } /* end */
15761 };
15762
15763 /*
15764  * 6ch mode
15765  */
15766 static struct hda_verb alc662_sixstack_ch8_init[] = {
15767         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15768         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15769         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15770         { } /* end */
15771 };
15772
15773 static struct hda_channel_mode alc662_5stack_modes[2] = {
15774         { 2, alc662_sixstack_ch6_init },
15775         { 6, alc662_sixstack_ch8_init },
15776 };
15777
15778 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
15779  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
15780  */
15781
15782 static struct snd_kcontrol_new alc662_base_mixer[] = {
15783         /* output mixer control */
15784         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
15785         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
15786         HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
15787         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
15788         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15789         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15790         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
15791         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
15792         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15793
15794         /*Input mixer control */
15795         HDA_CODEC_VOLUME("CD Playback Volume", 0xb, 0x4, HDA_INPUT),
15796         HDA_CODEC_MUTE("CD Playback Switch", 0xb, 0x4, HDA_INPUT),
15797         HDA_CODEC_VOLUME("Line Playback Volume", 0xb, 0x02, HDA_INPUT),
15798         HDA_CODEC_MUTE("Line Playback Switch", 0xb, 0x02, HDA_INPUT),
15799         HDA_CODEC_VOLUME("Mic Playback Volume", 0xb, 0x0, HDA_INPUT),
15800         HDA_CODEC_MUTE("Mic Playback Switch", 0xb, 0x0, HDA_INPUT),
15801         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0xb, 0x01, HDA_INPUT),
15802         HDA_CODEC_MUTE("Front Mic Playback Switch", 0xb, 0x01, HDA_INPUT),
15803         { } /* end */
15804 };
15805
15806 static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
15807         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15808         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
15809         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15810         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
15811         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
15812         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15813         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15814         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15815         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15816         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15817         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15818         { } /* end */
15819 };
15820
15821 static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
15822         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15823         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
15824         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15825         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
15826         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15827         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15828         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
15829         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
15830         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15831         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
15832         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
15833         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15834         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15835         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15836         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15837         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15838         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15839         { } /* end */
15840 };
15841
15842 static struct snd_kcontrol_new alc662_lenovo_101e_mixer[] = {
15843         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15844         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
15845         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15846         HDA_BIND_MUTE("Speaker Playback Switch", 0x03, 2, HDA_INPUT),
15847         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15848         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15849         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15850         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15851         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15852         { } /* end */
15853 };
15854
15855 static struct snd_kcontrol_new alc662_eeepc_p701_mixer[] = {
15856         HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15857         ALC262_HIPPO_MASTER_SWITCH,
15858
15859         HDA_CODEC_VOLUME("e-Mic Boost", 0x18, 0, HDA_INPUT),
15860         HDA_CODEC_VOLUME("e-Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15861         HDA_CODEC_MUTE("e-Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15862
15863         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
15864         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15865         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15866         { } /* end */
15867 };
15868
15869 static struct snd_kcontrol_new alc662_eeepc_ep20_mixer[] = {
15870         ALC262_HIPPO_MASTER_SWITCH,
15871         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15872         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15873         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15874         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15875         HDA_BIND_MUTE("MuteCtrl Playback Switch", 0x0c, 2, HDA_INPUT),
15876         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15877         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15878         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15879         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15880         { } /* end */
15881 };
15882
15883 static struct hda_bind_ctls alc663_asus_bind_master_vol = {
15884         .ops = &snd_hda_bind_vol,
15885         .values = {
15886                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
15887                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
15888                 0
15889         },
15890 };
15891
15892 static struct hda_bind_ctls alc663_asus_one_bind_switch = {
15893         .ops = &snd_hda_bind_sw,
15894         .values = {
15895                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15896                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
15897                 0
15898         },
15899 };
15900
15901 static struct snd_kcontrol_new alc663_m51va_mixer[] = {
15902         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15903         HDA_BIND_SW("Master Playback Switch", &alc663_asus_one_bind_switch),
15904         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15905         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15906         { } /* end */
15907 };
15908
15909 static struct hda_bind_ctls alc663_asus_tree_bind_switch = {
15910         .ops = &snd_hda_bind_sw,
15911         .values = {
15912                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15913                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
15914                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
15915                 0
15916         },
15917 };
15918
15919 static struct snd_kcontrol_new alc663_two_hp_m1_mixer[] = {
15920         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15921         HDA_BIND_SW("Master Playback Switch", &alc663_asus_tree_bind_switch),
15922         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15923         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15924         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15925         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15926
15927         { } /* end */
15928 };
15929
15930 static struct hda_bind_ctls alc663_asus_four_bind_switch = {
15931         .ops = &snd_hda_bind_sw,
15932         .values = {
15933                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15934                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
15935                 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
15936                 0
15937         },
15938 };
15939
15940 static struct snd_kcontrol_new alc663_two_hp_m2_mixer[] = {
15941         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15942         HDA_BIND_SW("Master Playback Switch", &alc663_asus_four_bind_switch),
15943         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15944         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15945         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15946         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15947         { } /* end */
15948 };
15949
15950 static struct snd_kcontrol_new alc662_1bjd_mixer[] = {
15951         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15952         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15953         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15954         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15955         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15956         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15957         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15958         { } /* end */
15959 };
15960
15961 static struct hda_bind_ctls alc663_asus_two_bind_master_vol = {
15962         .ops = &snd_hda_bind_vol,
15963         .values = {
15964                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
15965                 HDA_COMPOSE_AMP_VAL(0x04, 3, 0, HDA_OUTPUT),
15966                 0
15967         },
15968 };
15969
15970 static struct hda_bind_ctls alc663_asus_two_bind_switch = {
15971         .ops = &snd_hda_bind_sw,
15972         .values = {
15973                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15974                 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT),
15975                 0
15976         },
15977 };
15978
15979 static struct snd_kcontrol_new alc663_asus_21jd_clfe_mixer[] = {
15980         HDA_BIND_VOL("Master Playback Volume",
15981                                 &alc663_asus_two_bind_master_vol),
15982         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
15983         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15984         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
15985         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15986         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15987         { } /* end */
15988 };
15989
15990 static struct snd_kcontrol_new alc663_asus_15jd_clfe_mixer[] = {
15991         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15992         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
15993         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15994         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
15995         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15996         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15997         { } /* end */
15998 };
15999
16000 static struct snd_kcontrol_new alc663_g71v_mixer[] = {
16001         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16002         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
16003         HDA_CODEC_VOLUME("Front Playback Volume", 0x03, 0x0, HDA_OUTPUT),
16004         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
16005         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
16006
16007         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16008         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16009         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16010         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16011         { } /* end */
16012 };
16013
16014 static struct snd_kcontrol_new alc663_g50v_mixer[] = {
16015         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16016         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
16017         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
16018
16019         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16020         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16021         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16022         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16023         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
16024         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
16025         { } /* end */
16026 };
16027
16028 static struct snd_kcontrol_new alc662_chmode_mixer[] = {
16029         {
16030                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
16031                 .name = "Channel Mode",
16032                 .info = alc_ch_mode_info,
16033                 .get = alc_ch_mode_get,
16034                 .put = alc_ch_mode_put,
16035         },
16036         { } /* end */
16037 };
16038
16039 static struct hda_verb alc662_init_verbs[] = {
16040         /* ADC: mute amp left and right */
16041         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16042         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
16043         /* Front mixer: unmute input/output amp left and right (volume = 0) */
16044
16045         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16046         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
16047         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
16048         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
16049         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
16050
16051         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16052         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16053         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16054         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16055         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16056         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16057
16058         /* Front Pin: output 0 (0x0c) */
16059         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16060         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16061
16062         /* Rear Pin: output 1 (0x0d) */
16063         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16064         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16065
16066         /* CLFE Pin: output 2 (0x0e) */
16067         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16068         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16069
16070         /* Mic (rear) pin: input vref at 80% */
16071         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
16072         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16073         /* Front Mic pin: input vref at 80% */
16074         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
16075         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16076         /* Line In pin: input */
16077         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16078         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16079         /* Line-2 In: Headphone output (output 0 - 0x0c) */
16080         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16081         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16082         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
16083         /* CD pin widget for input */
16084         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16085
16086         /* FIXME: use matrix-type input source selection */
16087         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
16088         /* Input mixer */
16089         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16090         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16091
16092         /* always trun on EAPD */
16093         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
16094         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
16095
16096         { }
16097 };
16098
16099 static struct hda_verb alc662_sue_init_verbs[] = {
16100         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
16101         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
16102         {}
16103 };
16104
16105 static struct hda_verb alc662_eeepc_sue_init_verbs[] = {
16106         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16107         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16108         {}
16109 };
16110
16111 /* Set Unsolicited Event*/
16112 static struct hda_verb alc662_eeepc_ep20_sue_init_verbs[] = {
16113         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16114         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16115         {}
16116 };
16117
16118 /*
16119  * generic initialization of ADC, input mixers and output mixers
16120  */
16121 static struct hda_verb alc662_auto_init_verbs[] = {
16122         /*
16123          * Unmute ADC and set the default input to mic-in
16124          */
16125         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
16126         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16127
16128         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
16129          * mixer widget
16130          * Note: PASD motherboards uses the Line In 2 as the input for front
16131          * panel mic (mic 2)
16132          */
16133         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
16134         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16135         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
16136         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
16137         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
16138         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
16139
16140         /*
16141          * Set up output mixers (0x0c - 0x0f)
16142          */
16143         /* set vol=0 to output mixers */
16144         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
16145         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
16146         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
16147
16148         /* set up input amps for analog loopback */
16149         /* Amp Indices: DAC = 0, mixer = 1 */
16150         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16151         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16152         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16153         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16154         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16155         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16156
16157
16158         /* FIXME: use matrix-type input source selection */
16159         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
16160         /* Input mixer */
16161         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16162         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16163         { }
16164 };
16165
16166 /* additional verbs for ALC663 */
16167 static struct hda_verb alc663_auto_init_verbs[] = {
16168         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16169         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16170         { }
16171 };
16172
16173 static struct hda_verb alc663_m51va_init_verbs[] = {
16174         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16175         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16176         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16177         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16178         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16179         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16180         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
16181         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16182         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16183         {}
16184 };
16185
16186 static struct hda_verb alc663_21jd_amic_init_verbs[] = {
16187         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16188         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16189         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16190         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16191         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16192         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16193         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16194         {}
16195 };
16196
16197 static struct hda_verb alc662_1bjd_amic_init_verbs[] = {
16198         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16199         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16200         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16201         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
16202         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16203         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16204         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16205         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16206         {}
16207 };
16208
16209 static struct hda_verb alc663_15jd_amic_init_verbs[] = {
16210         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16211         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16212         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16213         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16214         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16215         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16216         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16217         {}
16218 };
16219
16220 static struct hda_verb alc663_two_hp_amic_m1_init_verbs[] = {
16221         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16222         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16223         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16224         {0x21, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
16225         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16226         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16227         {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
16228         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16229         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16230         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16231         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16232         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16233         {}
16234 };
16235
16236 static struct hda_verb alc663_two_hp_amic_m2_init_verbs[] = {
16237         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16238         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16239         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16240         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16241         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16242         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16243         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16244         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16245         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16246         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16247         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16248         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16249         {}
16250 };
16251
16252 static struct hda_verb alc663_g71v_init_verbs[] = {
16253         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16254         /* {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
16255         /* {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, */ /* Headphone */
16256
16257         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16258         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16259         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
16260
16261         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
16262         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_MIC_EVENT},
16263         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
16264         {}
16265 };
16266
16267 static struct hda_verb alc663_g50v_init_verbs[] = {
16268         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16269         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16270         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
16271
16272         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16273         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16274         {}
16275 };
16276
16277 static struct hda_verb alc662_ecs_init_verbs[] = {
16278         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0x701f},
16279         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16280         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16281         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16282         {}
16283 };
16284
16285 static struct hda_verb alc272_dell_zm1_init_verbs[] = {
16286         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16287         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16288         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16289         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16290         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16291         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16292         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16293         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16294         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
16295         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16296         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16297         {}
16298 };
16299
16300 static struct hda_verb alc272_dell_init_verbs[] = {
16301         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16302         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16303         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16304         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16305         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16306         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16307         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16308         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16309         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
16310         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16311         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16312         {}
16313 };
16314
16315 static struct snd_kcontrol_new alc662_auto_capture_mixer[] = {
16316         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
16317         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
16318         { } /* end */
16319 };
16320
16321 static struct snd_kcontrol_new alc272_auto_capture_mixer[] = {
16322         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
16323         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
16324         { } /* end */
16325 };
16326
16327 static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
16328 {
16329         unsigned int present;
16330         unsigned char bits;
16331
16332         present = snd_hda_codec_read(codec, 0x14, 0,
16333                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
16334         bits = present ? HDA_AMP_MUTE : 0;
16335         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
16336                                  HDA_AMP_MUTE, bits);
16337 }
16338
16339 static void alc662_lenovo_101e_all_automute(struct hda_codec *codec)
16340 {
16341         unsigned int present;
16342         unsigned char bits;
16343
16344         present = snd_hda_codec_read(codec, 0x1b, 0,
16345                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
16346         bits = present ? HDA_AMP_MUTE : 0;
16347         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
16348                                  HDA_AMP_MUTE, bits);
16349         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
16350                                  HDA_AMP_MUTE, bits);
16351 }
16352
16353 static void alc662_lenovo_101e_unsol_event(struct hda_codec *codec,
16354                                            unsigned int res)
16355 {
16356         if ((res >> 26) == ALC880_HP_EVENT)
16357                 alc662_lenovo_101e_all_automute(codec);
16358         if ((res >> 26) == ALC880_FRONT_EVENT)
16359                 alc662_lenovo_101e_ispeaker_automute(codec);
16360 }
16361
16362 static void alc662_eeepc_mic_automute(struct hda_codec *codec)
16363 {
16364         unsigned int present;
16365
16366         present = snd_hda_codec_read(codec, 0x18, 0,
16367                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
16368         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16369                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
16370         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16371                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
16372         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16373                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
16374         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16375                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
16376 }
16377
16378 /* unsolicited event for HP jack sensing */
16379 static void alc662_eeepc_unsol_event(struct hda_codec *codec,
16380                                      unsigned int res)
16381 {
16382         if ((res >> 26) == ALC880_MIC_EVENT)
16383                 alc662_eeepc_mic_automute(codec);
16384         else
16385                 alc262_hippo_unsol_event(codec, res);
16386 }
16387
16388 static void alc662_eeepc_inithook(struct hda_codec *codec)
16389 {
16390         alc262_hippo1_init_hook(codec);
16391         alc662_eeepc_mic_automute(codec);
16392 }
16393
16394 static void alc662_eeepc_ep20_inithook(struct hda_codec *codec)
16395 {
16396         struct alc_spec *spec = codec->spec;
16397
16398         spec->autocfg.hp_pins[0] = 0x14;
16399         spec->autocfg.speaker_pins[0] = 0x1b;
16400         alc262_hippo_master_update(codec);
16401 }
16402
16403 static void alc663_m51va_speaker_automute(struct hda_codec *codec)
16404 {
16405         unsigned int present;
16406         unsigned char bits;
16407
16408         present = snd_hda_codec_read(codec, 0x21, 0,
16409                         AC_VERB_GET_PIN_SENSE, 0)
16410                         & AC_PINSENSE_PRESENCE;
16411         bits = present ? HDA_AMP_MUTE : 0;
16412         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16413                                 AMP_IN_MUTE(0), bits);
16414         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16415                                 AMP_IN_MUTE(0), bits);
16416 }
16417
16418 static void alc663_21jd_two_speaker_automute(struct hda_codec *codec)
16419 {
16420         unsigned int present;
16421         unsigned char bits;
16422
16423         present = snd_hda_codec_read(codec, 0x21, 0,
16424                         AC_VERB_GET_PIN_SENSE, 0)
16425                         & AC_PINSENSE_PRESENCE;
16426         bits = present ? HDA_AMP_MUTE : 0;
16427         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16428                                 AMP_IN_MUTE(0), bits);
16429         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16430                                 AMP_IN_MUTE(0), bits);
16431         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
16432                                 AMP_IN_MUTE(0), bits);
16433         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
16434                                 AMP_IN_MUTE(0), bits);
16435 }
16436
16437 static void alc663_15jd_two_speaker_automute(struct hda_codec *codec)
16438 {
16439         unsigned int present;
16440         unsigned char bits;
16441
16442         present = snd_hda_codec_read(codec, 0x15, 0,
16443                         AC_VERB_GET_PIN_SENSE, 0)
16444                         & AC_PINSENSE_PRESENCE;
16445         bits = present ? HDA_AMP_MUTE : 0;
16446         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16447                                 AMP_IN_MUTE(0), bits);
16448         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16449                                 AMP_IN_MUTE(0), bits);
16450         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
16451                                 AMP_IN_MUTE(0), bits);
16452         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
16453                                 AMP_IN_MUTE(0), bits);
16454 }
16455
16456 static void alc662_f5z_speaker_automute(struct hda_codec *codec)
16457 {
16458         unsigned int present;
16459         unsigned char bits;
16460
16461         present = snd_hda_codec_read(codec, 0x1b, 0,
16462                         AC_VERB_GET_PIN_SENSE, 0)
16463                         & AC_PINSENSE_PRESENCE;
16464         bits = present ? 0 : PIN_OUT;
16465         snd_hda_codec_write(codec, 0x14, 0,
16466                          AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
16467 }
16468
16469 static void alc663_two_hp_m1_speaker_automute(struct hda_codec *codec)
16470 {
16471         unsigned int present1, present2;
16472
16473         present1 = snd_hda_codec_read(codec, 0x21, 0,
16474                         AC_VERB_GET_PIN_SENSE, 0)
16475                         & AC_PINSENSE_PRESENCE;
16476         present2 = snd_hda_codec_read(codec, 0x15, 0,
16477                         AC_VERB_GET_PIN_SENSE, 0)
16478                         & AC_PINSENSE_PRESENCE;
16479
16480         if (present1 || present2) {
16481                 snd_hda_codec_write_cache(codec, 0x14, 0,
16482                         AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
16483         } else {
16484                 snd_hda_codec_write_cache(codec, 0x14, 0,
16485                         AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
16486         }
16487 }
16488
16489 static void alc663_two_hp_m2_speaker_automute(struct hda_codec *codec)
16490 {
16491         unsigned int present1, present2;
16492
16493         present1 = snd_hda_codec_read(codec, 0x1b, 0,
16494                                 AC_VERB_GET_PIN_SENSE, 0)
16495                                 & AC_PINSENSE_PRESENCE;
16496         present2 = snd_hda_codec_read(codec, 0x15, 0,
16497                                 AC_VERB_GET_PIN_SENSE, 0)
16498                                 & AC_PINSENSE_PRESENCE;
16499
16500         if (present1 || present2) {
16501                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16502                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
16503                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16504                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
16505         } else {
16506                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16507                                 AMP_IN_MUTE(0), 0);
16508                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16509                                 AMP_IN_MUTE(0), 0);
16510         }
16511 }
16512
16513 static void alc663_m51va_mic_automute(struct hda_codec *codec)
16514 {
16515         unsigned int present;
16516
16517         present = snd_hda_codec_read(codec, 0x18, 0,
16518                         AC_VERB_GET_PIN_SENSE, 0)
16519                         & AC_PINSENSE_PRESENCE;
16520         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16521                         0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
16522         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16523                         0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
16524         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16525                         0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
16526         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16527                         0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
16528 }
16529
16530 static void alc663_m51va_unsol_event(struct hda_codec *codec,
16531                                            unsigned int res)
16532 {
16533         switch (res >> 26) {
16534         case ALC880_HP_EVENT:
16535                 alc663_m51va_speaker_automute(codec);
16536                 break;
16537         case ALC880_MIC_EVENT:
16538                 alc663_m51va_mic_automute(codec);
16539                 break;
16540         }
16541 }
16542
16543 static void alc663_m51va_inithook(struct hda_codec *codec)
16544 {
16545         alc663_m51va_speaker_automute(codec);
16546         alc663_m51va_mic_automute(codec);
16547 }
16548
16549 /* ***************** Mode1 ******************************/
16550 static void alc663_mode1_unsol_event(struct hda_codec *codec,
16551                                            unsigned int res)
16552 {
16553         switch (res >> 26) {
16554         case ALC880_HP_EVENT:
16555                 alc663_m51va_speaker_automute(codec);
16556                 break;
16557         case ALC880_MIC_EVENT:
16558                 alc662_eeepc_mic_automute(codec);
16559                 break;
16560         }
16561 }
16562
16563 static void alc663_mode1_inithook(struct hda_codec *codec)
16564 {
16565         alc663_m51va_speaker_automute(codec);
16566         alc662_eeepc_mic_automute(codec);
16567 }
16568 /* ***************** Mode2 ******************************/
16569 static void alc662_mode2_unsol_event(struct hda_codec *codec,
16570                                            unsigned int res)
16571 {
16572         switch (res >> 26) {
16573         case ALC880_HP_EVENT:
16574                 alc662_f5z_speaker_automute(codec);
16575                 break;
16576         case ALC880_MIC_EVENT:
16577                 alc662_eeepc_mic_automute(codec);
16578                 break;
16579         }
16580 }
16581
16582 static void alc662_mode2_inithook(struct hda_codec *codec)
16583 {
16584         alc662_f5z_speaker_automute(codec);
16585         alc662_eeepc_mic_automute(codec);
16586 }
16587 /* ***************** Mode3 ******************************/
16588 static void alc663_mode3_unsol_event(struct hda_codec *codec,
16589                                            unsigned int res)
16590 {
16591         switch (res >> 26) {
16592         case ALC880_HP_EVENT:
16593                 alc663_two_hp_m1_speaker_automute(codec);
16594                 break;
16595         case ALC880_MIC_EVENT:
16596                 alc662_eeepc_mic_automute(codec);
16597                 break;
16598         }
16599 }
16600
16601 static void alc663_mode3_inithook(struct hda_codec *codec)
16602 {
16603         alc663_two_hp_m1_speaker_automute(codec);
16604         alc662_eeepc_mic_automute(codec);
16605 }
16606 /* ***************** Mode4 ******************************/
16607 static void alc663_mode4_unsol_event(struct hda_codec *codec,
16608                                            unsigned int res)
16609 {
16610         switch (res >> 26) {
16611         case ALC880_HP_EVENT:
16612                 alc663_21jd_two_speaker_automute(codec);
16613                 break;
16614         case ALC880_MIC_EVENT:
16615                 alc662_eeepc_mic_automute(codec);
16616                 break;
16617         }
16618 }
16619
16620 static void alc663_mode4_inithook(struct hda_codec *codec)
16621 {
16622         alc663_21jd_two_speaker_automute(codec);
16623         alc662_eeepc_mic_automute(codec);
16624 }
16625 /* ***************** Mode5 ******************************/
16626 static void alc663_mode5_unsol_event(struct hda_codec *codec,
16627                                            unsigned int res)
16628 {
16629         switch (res >> 26) {
16630         case ALC880_HP_EVENT:
16631                 alc663_15jd_two_speaker_automute(codec);
16632                 break;
16633         case ALC880_MIC_EVENT:
16634                 alc662_eeepc_mic_automute(codec);
16635                 break;
16636         }
16637 }
16638
16639 static void alc663_mode5_inithook(struct hda_codec *codec)
16640 {
16641         alc663_15jd_two_speaker_automute(codec);
16642         alc662_eeepc_mic_automute(codec);
16643 }
16644 /* ***************** Mode6 ******************************/
16645 static void alc663_mode6_unsol_event(struct hda_codec *codec,
16646                                            unsigned int res)
16647 {
16648         switch (res >> 26) {
16649         case ALC880_HP_EVENT:
16650                 alc663_two_hp_m2_speaker_automute(codec);
16651                 break;
16652         case ALC880_MIC_EVENT:
16653                 alc662_eeepc_mic_automute(codec);
16654                 break;
16655         }
16656 }
16657
16658 static void alc663_mode6_inithook(struct hda_codec *codec)
16659 {
16660         alc663_two_hp_m2_speaker_automute(codec);
16661         alc662_eeepc_mic_automute(codec);
16662 }
16663
16664 static void alc663_g71v_hp_automute(struct hda_codec *codec)
16665 {
16666         unsigned int present;
16667         unsigned char bits;
16668
16669         present = snd_hda_codec_read(codec, 0x21, 0,
16670                                      AC_VERB_GET_PIN_SENSE, 0)
16671                 & AC_PINSENSE_PRESENCE;
16672         bits = present ? HDA_AMP_MUTE : 0;
16673         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
16674                                  HDA_AMP_MUTE, bits);
16675         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
16676                                  HDA_AMP_MUTE, bits);
16677 }
16678
16679 static void alc663_g71v_front_automute(struct hda_codec *codec)
16680 {
16681         unsigned int present;
16682         unsigned char bits;
16683
16684         present = snd_hda_codec_read(codec, 0x15, 0,
16685                                      AC_VERB_GET_PIN_SENSE, 0)
16686                 & AC_PINSENSE_PRESENCE;
16687         bits = present ? HDA_AMP_MUTE : 0;
16688         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
16689                                  HDA_AMP_MUTE, bits);
16690 }
16691
16692 static void alc663_g71v_unsol_event(struct hda_codec *codec,
16693                                            unsigned int res)
16694 {
16695         switch (res >> 26) {
16696         case ALC880_HP_EVENT:
16697                 alc663_g71v_hp_automute(codec);
16698                 break;
16699         case ALC880_FRONT_EVENT:
16700                 alc663_g71v_front_automute(codec);
16701                 break;
16702         case ALC880_MIC_EVENT:
16703                 alc662_eeepc_mic_automute(codec);
16704                 break;
16705         }
16706 }
16707
16708 static void alc663_g71v_inithook(struct hda_codec *codec)
16709 {
16710         alc663_g71v_front_automute(codec);
16711         alc663_g71v_hp_automute(codec);
16712         alc662_eeepc_mic_automute(codec);
16713 }
16714
16715 static void alc663_g50v_unsol_event(struct hda_codec *codec,
16716                                            unsigned int res)
16717 {
16718         switch (res >> 26) {
16719         case ALC880_HP_EVENT:
16720                 alc663_m51va_speaker_automute(codec);
16721                 break;
16722         case ALC880_MIC_EVENT:
16723                 alc662_eeepc_mic_automute(codec);
16724                 break;
16725         }
16726 }
16727
16728 static void alc663_g50v_inithook(struct hda_codec *codec)
16729 {
16730         alc663_m51va_speaker_automute(codec);
16731         alc662_eeepc_mic_automute(codec);
16732 }
16733
16734 static struct snd_kcontrol_new alc662_ecs_mixer[] = {
16735         HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16736         ALC262_HIPPO_MASTER_SWITCH,
16737
16738         HDA_CODEC_VOLUME("e-Mic/LineIn Boost", 0x18, 0, HDA_INPUT),
16739         HDA_CODEC_VOLUME("e-Mic/LineIn Playback Volume", 0x0b, 0x0, HDA_INPUT),
16740         HDA_CODEC_MUTE("e-Mic/LineIn Playback Switch", 0x0b, 0x0, HDA_INPUT),
16741
16742         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
16743         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16744         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16745         { } /* end */
16746 };
16747
16748 static struct snd_kcontrol_new alc272_nc10_mixer[] = {
16749         /* Master Playback automatically created from Speaker and Headphone */
16750         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16751         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
16752         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
16753         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
16754
16755         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16756         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16757         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
16758
16759         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16760         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16761         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
16762         { } /* end */
16763 };
16764
16765 #ifdef CONFIG_SND_HDA_POWER_SAVE
16766 #define alc662_loopbacks        alc880_loopbacks
16767 #endif
16768
16769
16770 /* pcm configuration: identical with ALC880 */
16771 #define alc662_pcm_analog_playback      alc880_pcm_analog_playback
16772 #define alc662_pcm_analog_capture       alc880_pcm_analog_capture
16773 #define alc662_pcm_digital_playback     alc880_pcm_digital_playback
16774 #define alc662_pcm_digital_capture      alc880_pcm_digital_capture
16775
16776 /*
16777  * configuration and preset
16778  */
16779 static const char *alc662_models[ALC662_MODEL_LAST] = {
16780         [ALC662_3ST_2ch_DIG]    = "3stack-dig",
16781         [ALC662_3ST_6ch_DIG]    = "3stack-6ch-dig",
16782         [ALC662_3ST_6ch]        = "3stack-6ch",
16783         [ALC662_5ST_DIG]        = "6stack-dig",
16784         [ALC662_LENOVO_101E]    = "lenovo-101e",
16785         [ALC662_ASUS_EEEPC_P701] = "eeepc-p701",
16786         [ALC662_ASUS_EEEPC_EP20] = "eeepc-ep20",
16787         [ALC662_ECS] = "ecs",
16788         [ALC663_ASUS_M51VA] = "m51va",
16789         [ALC663_ASUS_G71V] = "g71v",
16790         [ALC663_ASUS_H13] = "h13",
16791         [ALC663_ASUS_G50V] = "g50v",
16792         [ALC663_ASUS_MODE1] = "asus-mode1",
16793         [ALC662_ASUS_MODE2] = "asus-mode2",
16794         [ALC663_ASUS_MODE3] = "asus-mode3",
16795         [ALC663_ASUS_MODE4] = "asus-mode4",
16796         [ALC663_ASUS_MODE5] = "asus-mode5",
16797         [ALC663_ASUS_MODE6] = "asus-mode6",
16798         [ALC272_DELL]           = "dell",
16799         [ALC272_DELL_ZM1]       = "dell-zm1",
16800         [ALC272_SAMSUNG_NC10]   = "samsung-nc10",
16801         [ALC662_AUTO]           = "auto",
16802 };
16803
16804 static struct snd_pci_quirk alc662_cfg_tbl[] = {
16805         SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_ECS),
16806         SND_PCI_QUIRK(0x1028, 0x02d6, "DELL", ALC272_DELL),
16807         SND_PCI_QUIRK(0x1028, 0x02f4, "DELL ZM1", ALC272_DELL_ZM1),
16808         SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC663_ASUS_MODE1),
16809         SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC663_ASUS_MODE3),
16810         SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC663_ASUS_MODE3),
16811         SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC663_ASUS_MODE1),
16812         SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_ASUS_MODE2),
16813         SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC663_ASUS_MODE1),
16814         SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_ASUS_MODE2),
16815         SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_ASUS_MODE2),
16816         SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_ASUS_MODE2),
16817         SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC663_ASUS_MODE6),
16818         SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC663_ASUS_MODE6),
16819         SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_ASUS_MODE2),
16820         SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC663_ASUS_MODE3),
16821         SND_PCI_QUIRK(0x1043, 0x17c3, "ASUS UX20", ALC663_ASUS_M51VA),
16822         SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_ASUS_MODE2),
16823         SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_ASUS_MODE2),
16824         SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC663_ASUS_MODE5),
16825         SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC663_ASUS_MODE6),
16826         SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_ASUS_MODE2),
16827         SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC663_ASUS_MODE1),
16828         SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_ASUS_MODE2),
16829         SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_ASUS_MODE2),
16830         SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M51VA", ALC663_ASUS_M51VA),
16831         /*SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M50Vr", ALC663_ASUS_MODE1),*/
16832         SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC663_ASUS_MODE3),
16833         SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC663_ASUS_MODE3),
16834         SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC663_ASUS_MODE1),
16835         SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC663_ASUS_MODE1),
16836         SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC663_ASUS_MODE1),
16837         SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC663_ASUS_MODE1),
16838         SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_ASUS_MODE2),
16839         SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_ASUS_MODE2),
16840         SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC663_ASUS_MODE1),
16841         SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC663_ASUS_MODE1),
16842         SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC663_ASUS_MODE3),
16843         SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC663_ASUS_MODE1),
16844         SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC663_ASUS_MODE1),
16845         SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS G50V", ALC663_ASUS_G50V),
16846         /*SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS NB", ALC663_ASUS_MODE1),*/
16847         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC663_ASUS_MODE1),
16848         SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_ASUS_MODE2),
16849         SND_PCI_QUIRK(0x1043, 0x19d3, "ASUS NB", ALC663_ASUS_M51VA),
16850         SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC663_ASUS_MODE1),
16851         SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC663_ASUS_MODE4),
16852         SND_PCI_QUIRK(0x1043, 0x8290, "ASUS P5GC-MX", ALC662_3ST_6ch_DIG),
16853         SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
16854         SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20),
16855         SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_ECS),
16856         SND_PCI_QUIRK(0x105b, 0x0d47, "Foxconn 45CMX/45GMX/45CMX-K",
16857                       ALC662_3ST_6ch_DIG),
16858         SND_PCI_QUIRK(0x144d, 0xca00, "Samsung NC10", ALC272_SAMSUNG_NC10),
16859         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte 945GCM-S2L",
16860                       ALC662_3ST_6ch_DIG),
16861         SND_PCI_QUIRK(0x1565, 0x820f, "Biostar TA780G M2+", ALC662_3ST_6ch_DIG),
16862         SND_PCI_QUIRK(0x1631, 0xc10c, "PB RS65", ALC663_ASUS_M51VA),
16863         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
16864         SND_PCI_QUIRK(0x1849, 0x3662, "ASROCK K10N78FullHD-hSLI R3.0",
16865                                         ALC662_3ST_6ch_DIG),
16866         SND_PCI_QUIRK_MASK(0x1854, 0xf000, 0x2000, "ASUS H13-200x",
16867                            ALC663_ASUS_H13),
16868         {}
16869 };
16870
16871 static struct alc_config_preset alc662_presets[] = {
16872         [ALC662_3ST_2ch_DIG] = {
16873                 .mixers = { alc662_3ST_2ch_mixer },
16874                 .init_verbs = { alc662_init_verbs },
16875                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16876                 .dac_nids = alc662_dac_nids,
16877                 .dig_out_nid = ALC662_DIGOUT_NID,
16878                 .dig_in_nid = ALC662_DIGIN_NID,
16879                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16880                 .channel_mode = alc662_3ST_2ch_modes,
16881                 .input_mux = &alc662_capture_source,
16882         },
16883         [ALC662_3ST_6ch_DIG] = {
16884                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
16885                 .init_verbs = { alc662_init_verbs },
16886                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16887                 .dac_nids = alc662_dac_nids,
16888                 .dig_out_nid = ALC662_DIGOUT_NID,
16889                 .dig_in_nid = ALC662_DIGIN_NID,
16890                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16891                 .channel_mode = alc662_3ST_6ch_modes,
16892                 .need_dac_fix = 1,
16893                 .input_mux = &alc662_capture_source,
16894         },
16895         [ALC662_3ST_6ch] = {
16896                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
16897                 .init_verbs = { alc662_init_verbs },
16898                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16899                 .dac_nids = alc662_dac_nids,
16900                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16901                 .channel_mode = alc662_3ST_6ch_modes,
16902                 .need_dac_fix = 1,
16903                 .input_mux = &alc662_capture_source,
16904         },
16905         [ALC662_5ST_DIG] = {
16906                 .mixers = { alc662_base_mixer, alc662_chmode_mixer },
16907                 .init_verbs = { alc662_init_verbs },
16908                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16909                 .dac_nids = alc662_dac_nids,
16910                 .dig_out_nid = ALC662_DIGOUT_NID,
16911                 .dig_in_nid = ALC662_DIGIN_NID,
16912                 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
16913                 .channel_mode = alc662_5stack_modes,
16914                 .input_mux = &alc662_capture_source,
16915         },
16916         [ALC662_LENOVO_101E] = {
16917                 .mixers = { alc662_lenovo_101e_mixer },
16918                 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs },
16919                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16920                 .dac_nids = alc662_dac_nids,
16921                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16922                 .channel_mode = alc662_3ST_2ch_modes,
16923                 .input_mux = &alc662_lenovo_101e_capture_source,
16924                 .unsol_event = alc662_lenovo_101e_unsol_event,
16925                 .init_hook = alc662_lenovo_101e_all_automute,
16926         },
16927         [ALC662_ASUS_EEEPC_P701] = {
16928                 .mixers = { alc662_eeepc_p701_mixer },
16929                 .init_verbs = { alc662_init_verbs,
16930                                 alc662_eeepc_sue_init_verbs },
16931                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16932                 .dac_nids = alc662_dac_nids,
16933                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16934                 .channel_mode = alc662_3ST_2ch_modes,
16935                 .input_mux = &alc662_eeepc_capture_source,
16936                 .unsol_event = alc662_eeepc_unsol_event,
16937                 .init_hook = alc662_eeepc_inithook,
16938         },
16939         [ALC662_ASUS_EEEPC_EP20] = {
16940                 .mixers = { alc662_eeepc_ep20_mixer,
16941                             alc662_chmode_mixer },
16942                 .init_verbs = { alc662_init_verbs,
16943                                 alc662_eeepc_ep20_sue_init_verbs },
16944                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16945                 .dac_nids = alc662_dac_nids,
16946                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16947                 .channel_mode = alc662_3ST_6ch_modes,
16948                 .input_mux = &alc662_lenovo_101e_capture_source,
16949                 .unsol_event = alc662_eeepc_unsol_event,
16950                 .init_hook = alc662_eeepc_ep20_inithook,
16951         },
16952         [ALC662_ECS] = {
16953                 .mixers = { alc662_ecs_mixer },
16954                 .init_verbs = { alc662_init_verbs,
16955                                 alc662_ecs_init_verbs },
16956                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16957                 .dac_nids = alc662_dac_nids,
16958                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16959                 .channel_mode = alc662_3ST_2ch_modes,
16960                 .input_mux = &alc662_eeepc_capture_source,
16961                 .unsol_event = alc662_eeepc_unsol_event,
16962                 .init_hook = alc662_eeepc_inithook,
16963         },
16964         [ALC663_ASUS_M51VA] = {
16965                 .mixers = { alc663_m51va_mixer },
16966                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
16967                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16968                 .dac_nids = alc662_dac_nids,
16969                 .dig_out_nid = ALC662_DIGOUT_NID,
16970                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16971                 .channel_mode = alc662_3ST_2ch_modes,
16972                 .input_mux = &alc663_m51va_capture_source,
16973                 .unsol_event = alc663_m51va_unsol_event,
16974                 .init_hook = alc663_m51va_inithook,
16975         },
16976         [ALC663_ASUS_G71V] = {
16977                 .mixers = { alc663_g71v_mixer },
16978                 .init_verbs = { alc662_init_verbs, alc663_g71v_init_verbs },
16979                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16980                 .dac_nids = alc662_dac_nids,
16981                 .dig_out_nid = ALC662_DIGOUT_NID,
16982                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16983                 .channel_mode = alc662_3ST_2ch_modes,
16984                 .input_mux = &alc662_eeepc_capture_source,
16985                 .unsol_event = alc663_g71v_unsol_event,
16986                 .init_hook = alc663_g71v_inithook,
16987         },
16988         [ALC663_ASUS_H13] = {
16989                 .mixers = { alc663_m51va_mixer },
16990                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
16991                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16992                 .dac_nids = alc662_dac_nids,
16993                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16994                 .channel_mode = alc662_3ST_2ch_modes,
16995                 .input_mux = &alc663_m51va_capture_source,
16996                 .unsol_event = alc663_m51va_unsol_event,
16997                 .init_hook = alc663_m51va_inithook,
16998         },
16999         [ALC663_ASUS_G50V] = {
17000                 .mixers = { alc663_g50v_mixer },
17001                 .init_verbs = { alc662_init_verbs, alc663_g50v_init_verbs },
17002                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17003                 .dac_nids = alc662_dac_nids,
17004                 .dig_out_nid = ALC662_DIGOUT_NID,
17005                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
17006                 .channel_mode = alc662_3ST_6ch_modes,
17007                 .input_mux = &alc663_capture_source,
17008                 .unsol_event = alc663_g50v_unsol_event,
17009                 .init_hook = alc663_g50v_inithook,
17010         },
17011         [ALC663_ASUS_MODE1] = {
17012                 .mixers = { alc663_m51va_mixer },
17013                 .cap_mixer = alc662_auto_capture_mixer,
17014                 .init_verbs = { alc662_init_verbs,
17015                                 alc663_21jd_amic_init_verbs },
17016                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17017                 .hp_nid = 0x03,
17018                 .dac_nids = alc662_dac_nids,
17019                 .dig_out_nid = ALC662_DIGOUT_NID,
17020                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17021                 .channel_mode = alc662_3ST_2ch_modes,
17022                 .input_mux = &alc662_eeepc_capture_source,
17023                 .unsol_event = alc663_mode1_unsol_event,
17024                 .init_hook = alc663_mode1_inithook,
17025         },
17026         [ALC662_ASUS_MODE2] = {
17027                 .mixers = { alc662_1bjd_mixer },
17028                 .cap_mixer = alc662_auto_capture_mixer,
17029                 .init_verbs = { alc662_init_verbs,
17030                                 alc662_1bjd_amic_init_verbs },
17031                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17032                 .dac_nids = alc662_dac_nids,
17033                 .dig_out_nid = ALC662_DIGOUT_NID,
17034                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17035                 .channel_mode = alc662_3ST_2ch_modes,
17036                 .input_mux = &alc662_eeepc_capture_source,
17037                 .unsol_event = alc662_mode2_unsol_event,
17038                 .init_hook = alc662_mode2_inithook,
17039         },
17040         [ALC663_ASUS_MODE3] = {
17041                 .mixers = { alc663_two_hp_m1_mixer },
17042                 .cap_mixer = alc662_auto_capture_mixer,
17043                 .init_verbs = { alc662_init_verbs,
17044                                 alc663_two_hp_amic_m1_init_verbs },
17045                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17046                 .hp_nid = 0x03,
17047                 .dac_nids = alc662_dac_nids,
17048                 .dig_out_nid = ALC662_DIGOUT_NID,
17049                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17050                 .channel_mode = alc662_3ST_2ch_modes,
17051                 .input_mux = &alc662_eeepc_capture_source,
17052                 .unsol_event = alc663_mode3_unsol_event,
17053                 .init_hook = alc663_mode3_inithook,
17054         },
17055         [ALC663_ASUS_MODE4] = {
17056                 .mixers = { alc663_asus_21jd_clfe_mixer },
17057                 .cap_mixer = alc662_auto_capture_mixer,
17058                 .init_verbs = { alc662_init_verbs,
17059                                 alc663_21jd_amic_init_verbs},
17060                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17061                 .hp_nid = 0x03,
17062                 .dac_nids = alc662_dac_nids,
17063                 .dig_out_nid = ALC662_DIGOUT_NID,
17064                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17065                 .channel_mode = alc662_3ST_2ch_modes,
17066                 .input_mux = &alc662_eeepc_capture_source,
17067                 .unsol_event = alc663_mode4_unsol_event,
17068                 .init_hook = alc663_mode4_inithook,
17069         },
17070         [ALC663_ASUS_MODE5] = {
17071                 .mixers = { alc663_asus_15jd_clfe_mixer },
17072                 .cap_mixer = alc662_auto_capture_mixer,
17073                 .init_verbs = { alc662_init_verbs,
17074                                 alc663_15jd_amic_init_verbs },
17075                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17076                 .hp_nid = 0x03,
17077                 .dac_nids = alc662_dac_nids,
17078                 .dig_out_nid = ALC662_DIGOUT_NID,
17079                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17080                 .channel_mode = alc662_3ST_2ch_modes,
17081                 .input_mux = &alc662_eeepc_capture_source,
17082                 .unsol_event = alc663_mode5_unsol_event,
17083                 .init_hook = alc663_mode5_inithook,
17084         },
17085         [ALC663_ASUS_MODE6] = {
17086                 .mixers = { alc663_two_hp_m2_mixer },
17087                 .cap_mixer = alc662_auto_capture_mixer,
17088                 .init_verbs = { alc662_init_verbs,
17089                                 alc663_two_hp_amic_m2_init_verbs },
17090                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17091                 .hp_nid = 0x03,
17092                 .dac_nids = alc662_dac_nids,
17093                 .dig_out_nid = ALC662_DIGOUT_NID,
17094                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17095                 .channel_mode = alc662_3ST_2ch_modes,
17096                 .input_mux = &alc662_eeepc_capture_source,
17097                 .unsol_event = alc663_mode6_unsol_event,
17098                 .init_hook = alc663_mode6_inithook,
17099         },
17100         [ALC272_DELL] = {
17101                 .mixers = { alc663_m51va_mixer },
17102                 .cap_mixer = alc272_auto_capture_mixer,
17103                 .init_verbs = { alc662_init_verbs, alc272_dell_init_verbs },
17104                 .num_dacs = ARRAY_SIZE(alc272_dac_nids),
17105                 .dac_nids = alc662_dac_nids,
17106                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17107                 .adc_nids = alc272_adc_nids,
17108                 .num_adc_nids = ARRAY_SIZE(alc272_adc_nids),
17109                 .capsrc_nids = alc272_capsrc_nids,
17110                 .channel_mode = alc662_3ST_2ch_modes,
17111                 .input_mux = &alc663_m51va_capture_source,
17112                 .unsol_event = alc663_m51va_unsol_event,
17113                 .init_hook = alc663_m51va_inithook,
17114         },
17115         [ALC272_DELL_ZM1] = {
17116                 .mixers = { alc663_m51va_mixer },
17117                 .cap_mixer = alc662_auto_capture_mixer,
17118                 .init_verbs = { alc662_init_verbs, alc272_dell_zm1_init_verbs },
17119                 .num_dacs = ARRAY_SIZE(alc272_dac_nids),
17120                 .dac_nids = alc662_dac_nids,
17121                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17122                 .adc_nids = alc662_adc_nids,
17123                 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
17124                 .capsrc_nids = alc662_capsrc_nids,
17125                 .channel_mode = alc662_3ST_2ch_modes,
17126                 .input_mux = &alc663_m51va_capture_source,
17127                 .unsol_event = alc663_m51va_unsol_event,
17128                 .init_hook = alc663_m51va_inithook,
17129         },
17130         [ALC272_SAMSUNG_NC10] = {
17131                 .mixers = { alc272_nc10_mixer },
17132                 .init_verbs = { alc662_init_verbs,
17133                                 alc663_21jd_amic_init_verbs },
17134                 .num_dacs = ARRAY_SIZE(alc272_dac_nids),
17135                 .dac_nids = alc272_dac_nids,
17136                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17137                 .channel_mode = alc662_3ST_2ch_modes,
17138                 .input_mux = &alc272_nc10_capture_source,
17139                 .unsol_event = alc663_mode4_unsol_event,
17140                 .init_hook = alc663_mode4_inithook,
17141         },
17142 };
17143
17144
17145 /*
17146  * BIOS auto configuration
17147  */
17148
17149 /* add playback controls from the parsed DAC table */
17150 static int alc662_auto_create_multi_out_ctls(struct alc_spec *spec,
17151                                              const struct auto_pin_cfg *cfg)
17152 {
17153         char name[32];
17154         static const char *chname[4] = {
17155                 "Front", "Surround", NULL /*CLFE*/, "Side"
17156         };
17157         hda_nid_t nid;
17158         int i, err;
17159
17160         for (i = 0; i < cfg->line_outs; i++) {
17161                 if (!spec->multiout.dac_nids[i])
17162                         continue;
17163                 nid = alc880_idx_to_dac(i);
17164                 if (i == 2) {
17165                         /* Center/LFE */
17166                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
17167                                           "Center Playback Volume",
17168                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
17169                                                               HDA_OUTPUT));
17170                         if (err < 0)
17171                                 return err;
17172                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
17173                                           "LFE Playback Volume",
17174                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
17175                                                               HDA_OUTPUT));
17176                         if (err < 0)
17177                                 return err;
17178                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
17179                                           "Center Playback Switch",
17180                                           HDA_COMPOSE_AMP_VAL(0x0e, 1, 0,
17181                                                               HDA_INPUT));
17182                         if (err < 0)
17183                                 return err;
17184                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
17185                                           "LFE Playback Switch",
17186                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
17187                                                               HDA_INPUT));
17188                         if (err < 0)
17189                                 return err;
17190                 } else {
17191                         sprintf(name, "%s Playback Volume", chname[i]);
17192                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
17193                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
17194                                                               HDA_OUTPUT));
17195                         if (err < 0)
17196                                 return err;
17197                         sprintf(name, "%s Playback Switch", chname[i]);
17198                         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
17199                                 HDA_COMPOSE_AMP_VAL(alc880_idx_to_mixer(i),
17200                                                     3, 0, HDA_INPUT));
17201                         if (err < 0)
17202                                 return err;
17203                 }
17204         }
17205         return 0;
17206 }
17207
17208 /* add playback controls for speaker and HP outputs */
17209 static int alc662_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
17210                                         const char *pfx)
17211 {
17212         hda_nid_t nid;
17213         int err;
17214         char name[32];
17215
17216         if (!pin)
17217                 return 0;
17218
17219         if (pin == 0x17) {
17220                 /* ALC663 has a mono output pin on 0x17 */
17221                 sprintf(name, "%s Playback Switch", pfx);
17222                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
17223                                   HDA_COMPOSE_AMP_VAL(pin, 2, 0, HDA_OUTPUT));
17224                 return err;
17225         }
17226
17227         if (alc880_is_fixed_pin(pin)) {
17228                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
17229                 /* printk(KERN_DEBUG "DAC nid=%x\n",nid); */
17230                 /* specify the DAC as the extra output */
17231                 if (!spec->multiout.hp_nid)
17232                         spec->multiout.hp_nid = nid;
17233                 else
17234                         spec->multiout.extra_out_nid[0] = nid;
17235                 /* control HP volume/switch on the output mixer amp */
17236                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
17237                 sprintf(name, "%s Playback Volume", pfx);
17238                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
17239                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
17240                 if (err < 0)
17241                         return err;
17242                 sprintf(name, "%s Playback Switch", pfx);
17243                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
17244                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
17245                 if (err < 0)
17246                         return err;
17247         } else if (alc880_is_multi_pin(pin)) {
17248                 /* set manual connection */
17249                 /* we have only a switch on HP-out PIN */
17250                 sprintf(name, "%s Playback Switch", pfx);
17251                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
17252                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
17253                 if (err < 0)
17254                         return err;
17255         }
17256         return 0;
17257 }
17258
17259 /* return the index of the src widget from the connection list of the nid.
17260  * return -1 if not found
17261  */
17262 static int alc662_input_pin_idx(struct hda_codec *codec, hda_nid_t nid,
17263                                 hda_nid_t src)
17264 {
17265         hda_nid_t conn_list[HDA_MAX_CONNECTIONS];
17266         int i, conns;
17267
17268         conns = snd_hda_get_connections(codec, nid, conn_list,
17269                                         ARRAY_SIZE(conn_list));
17270         if (conns < 0)
17271                 return -1;
17272         for (i = 0; i < conns; i++)
17273                 if (conn_list[i] == src)
17274                         return i;
17275         return -1;
17276 }
17277
17278 static int alc662_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
17279 {
17280         unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
17281         return (pincap & AC_PINCAP_IN) != 0;
17282 }
17283
17284 /* create playback/capture controls for input pins */
17285 static int alc662_auto_create_analog_input_ctls(struct hda_codec *codec,
17286                                                 const struct auto_pin_cfg *cfg)
17287 {
17288         struct alc_spec *spec = codec->spec;
17289         struct hda_input_mux *imux = &spec->private_imux[0];
17290         int i, err, idx;
17291
17292         for (i = 0; i < AUTO_PIN_LAST; i++) {
17293                 if (alc662_is_input_pin(codec, cfg->input_pins[i])) {
17294                         idx = alc662_input_pin_idx(codec, 0x0b,
17295                                                    cfg->input_pins[i]);
17296                         if (idx >= 0) {
17297                                 err = new_analog_input(spec, cfg->input_pins[i],
17298                                                        auto_pin_cfg_labels[i],
17299                                                        idx, 0x0b);
17300                                 if (err < 0)
17301                                         return err;
17302                         }
17303                         idx = alc662_input_pin_idx(codec, 0x22,
17304                                                    cfg->input_pins[i]);
17305                         if (idx >= 0) {
17306                                 imux->items[imux->num_items].label =
17307                                         auto_pin_cfg_labels[i];
17308                                 imux->items[imux->num_items].index = idx;
17309                                 imux->num_items++;
17310                         }
17311                 }
17312         }
17313         return 0;
17314 }
17315
17316 static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
17317                                               hda_nid_t nid, int pin_type,
17318                                               int dac_idx)
17319 {
17320         alc_set_pin_output(codec, nid, pin_type);
17321         /* need the manual connection? */
17322         if (alc880_is_multi_pin(nid)) {
17323                 struct alc_spec *spec = codec->spec;
17324                 int idx = alc880_multi_pin_idx(nid);
17325                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
17326                                     AC_VERB_SET_CONNECT_SEL,
17327                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
17328         }
17329 }
17330
17331 static void alc662_auto_init_multi_out(struct hda_codec *codec)
17332 {
17333         struct alc_spec *spec = codec->spec;
17334         int i;
17335
17336         for (i = 0; i <= HDA_SIDE; i++) {
17337                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
17338                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
17339                 if (nid)
17340                         alc662_auto_set_output_and_unmute(codec, nid, pin_type,
17341                                                           i);
17342         }
17343 }
17344
17345 static void alc662_auto_init_hp_out(struct hda_codec *codec)
17346 {
17347         struct alc_spec *spec = codec->spec;
17348         hda_nid_t pin;
17349
17350         pin = spec->autocfg.hp_pins[0];
17351         if (pin) /* connect to front */
17352                 /* use dac 0 */
17353                 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
17354         pin = spec->autocfg.speaker_pins[0];
17355         if (pin)
17356                 alc662_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
17357 }
17358
17359 #define ALC662_PIN_CD_NID               ALC880_PIN_CD_NID
17360
17361 static void alc662_auto_init_analog_input(struct hda_codec *codec)
17362 {
17363         struct alc_spec *spec = codec->spec;
17364         int i;
17365
17366         for (i = 0; i < AUTO_PIN_LAST; i++) {
17367                 hda_nid_t nid = spec->autocfg.input_pins[i];
17368                 if (alc662_is_input_pin(codec, nid)) {
17369                         alc_set_input_pin(codec, nid, i);
17370                         if (nid != ALC662_PIN_CD_NID &&
17371                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
17372                                 snd_hda_codec_write(codec, nid, 0,
17373                                                     AC_VERB_SET_AMP_GAIN_MUTE,
17374                                                     AMP_OUT_MUTE);
17375                 }
17376         }
17377 }
17378
17379 #define alc662_auto_init_input_src      alc882_auto_init_input_src
17380
17381 static int alc662_parse_auto_config(struct hda_codec *codec)
17382 {
17383         struct alc_spec *spec = codec->spec;
17384         int err;
17385         static hda_nid_t alc662_ignore[] = { 0x1d, 0 };
17386
17387         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
17388                                            alc662_ignore);
17389         if (err < 0)
17390                 return err;
17391         if (!spec->autocfg.line_outs)
17392                 return 0; /* can't find valid BIOS pin config */
17393
17394         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
17395         if (err < 0)
17396                 return err;
17397         err = alc662_auto_create_multi_out_ctls(spec, &spec->autocfg);
17398         if (err < 0)
17399                 return err;
17400         err = alc662_auto_create_extra_out(spec,
17401                                            spec->autocfg.speaker_pins[0],
17402                                            "Speaker");
17403         if (err < 0)
17404                 return err;
17405         err = alc662_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
17406                                            "Headphone");
17407         if (err < 0)
17408                 return err;
17409         err = alc662_auto_create_analog_input_ctls(codec, &spec->autocfg);
17410         if (err < 0)
17411                 return err;
17412
17413         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
17414
17415         if (spec->autocfg.dig_outs)
17416                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
17417
17418         if (spec->kctls.list)
17419                 add_mixer(spec, spec->kctls.list);
17420
17421         spec->num_mux_defs = 1;
17422         spec->input_mux = &spec->private_imux[0];
17423
17424         add_verb(spec, alc662_auto_init_verbs);
17425         if (codec->vendor_id == 0x10ec0663)
17426                 add_verb(spec, alc663_auto_init_verbs);
17427
17428         err = alc_auto_add_mic_boost(codec);
17429         if (err < 0)
17430                 return err;
17431
17432         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
17433
17434         return 1;
17435 }
17436
17437 /* additional initialization for auto-configuration model */
17438 static void alc662_auto_init(struct hda_codec *codec)
17439 {
17440         struct alc_spec *spec = codec->spec;
17441         alc662_auto_init_multi_out(codec);
17442         alc662_auto_init_hp_out(codec);
17443         alc662_auto_init_analog_input(codec);
17444         alc662_auto_init_input_src(codec);
17445         if (spec->unsol_event)
17446                 alc_inithook(codec);
17447 }
17448
17449 static int patch_alc662(struct hda_codec *codec)
17450 {
17451         struct alc_spec *spec;
17452         int err, board_config;
17453
17454         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
17455         if (!spec)
17456                 return -ENOMEM;
17457
17458         codec->spec = spec;
17459
17460         alc_fix_pll_init(codec, 0x20, 0x04, 15);
17461
17462         board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
17463                                                   alc662_models,
17464                                                   alc662_cfg_tbl);
17465         if (board_config < 0) {
17466                 printk(KERN_INFO "hda_codec: Unknown model for %s, "
17467                        "trying auto-probe from BIOS...\n", codec->chip_name);
17468                 board_config = ALC662_AUTO;
17469         }
17470
17471         if (board_config == ALC662_AUTO) {
17472                 /* automatic parse from the BIOS config */
17473                 err = alc662_parse_auto_config(codec);
17474                 if (err < 0) {
17475                         alc_free(codec);
17476                         return err;
17477                 } else if (!err) {
17478                         printk(KERN_INFO
17479                                "hda_codec: Cannot set up configuration "
17480                                "from BIOS.  Using base mode...\n");
17481                         board_config = ALC662_3ST_2ch_DIG;
17482                 }
17483         }
17484
17485         err = snd_hda_attach_beep_device(codec, 0x1);
17486         if (err < 0) {
17487                 alc_free(codec);
17488                 return err;
17489         }
17490
17491         if (board_config != ALC662_AUTO)
17492                 setup_preset(spec, &alc662_presets[board_config]);
17493
17494         spec->stream_analog_playback = &alc662_pcm_analog_playback;
17495         spec->stream_analog_capture = &alc662_pcm_analog_capture;
17496
17497         spec->stream_digital_playback = &alc662_pcm_digital_playback;
17498         spec->stream_digital_capture = &alc662_pcm_digital_capture;
17499
17500         spec->adc_nids = alc662_adc_nids;
17501         spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
17502         spec->capsrc_nids = alc662_capsrc_nids;
17503
17504         if (!spec->cap_mixer)
17505                 set_capture_mixer(spec);
17506         if (codec->vendor_id == 0x10ec0662)
17507                 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
17508         else
17509                 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
17510
17511         spec->vmaster_nid = 0x02;
17512
17513         codec->patch_ops = alc_patch_ops;
17514         if (board_config == ALC662_AUTO)
17515                 spec->init_hook = alc662_auto_init;
17516 #ifdef CONFIG_SND_HDA_POWER_SAVE
17517         if (!spec->loopback.amplist)
17518                 spec->loopback.amplist = alc662_loopbacks;
17519 #endif
17520         codec->proc_widget_hook = print_realtek_coef;
17521
17522         return 0;
17523 }
17524
17525 /*
17526  * patch entries
17527  */
17528 static struct hda_codec_preset snd_hda_preset_realtek[] = {
17529         { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
17530         { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
17531         { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
17532         { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
17533         { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
17534         { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
17535         { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
17536           .patch = patch_alc861 },
17537         { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
17538         { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
17539         { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
17540         { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
17541           .patch = patch_alc883 },
17542         { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
17543           .patch = patch_alc662 },
17544         { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
17545         { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
17546         { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
17547         { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 },
17548         { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
17549           .patch = patch_alc882 }, /* should be patch_alc883() in future */
17550         { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
17551           .patch = patch_alc882 }, /* should be patch_alc883() in future */
17552         { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
17553         { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc883 },
17554         { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
17555           .patch = patch_alc883 },
17556         { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc883 },
17557         { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc883 },
17558         {} /* terminator */
17559 };
17560
17561 MODULE_ALIAS("snd-hda-codec-id:10ec*");
17562
17563 MODULE_LICENSE("GPL");
17564 MODULE_DESCRIPTION("Realtek HD-audio codec");
17565
17566 static struct hda_codec_preset_list realtek_list = {
17567         .preset = snd_hda_preset_realtek,
17568         .owner = THIS_MODULE,
17569 };
17570
17571 static int __init patch_realtek_init(void)
17572 {
17573         return snd_hda_add_codec_preset(&realtek_list);
17574 }
17575
17576 static void __exit patch_realtek_exit(void)
17577 {
17578         snd_hda_delete_codec_preset(&realtek_list);
17579 }
17580
17581 module_init(patch_realtek_init)
17582 module_exit(patch_realtek_exit)