ALSA: hda - Add missing initializations for ALC268 and ALC269
[pandora-kernel.git] / sound / pci / hda / patch_realtek.c
1 /*
2  * Universal Interface for Intel High Definition Audio Codec
3  *
4  * HD audio interface patch for ALC 260/880/882 codecs
5  *
6  * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7  *                    PeiSen Hou <pshou@realtek.com.tw>
8  *                    Takashi Iwai <tiwai@suse.de>
9  *                    Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
10  *
11  *  This driver is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This driver is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
24  */
25
26 #include <linux/init.h>
27 #include <linux/delay.h>
28 #include <linux/slab.h>
29 #include <linux/pci.h>
30 #include <sound/core.h>
31 #include "hda_codec.h"
32 #include "hda_local.h"
33 #include "hda_beep.h"
34
35 #define ALC880_FRONT_EVENT              0x01
36 #define ALC880_DCVOL_EVENT              0x02
37 #define ALC880_HP_EVENT                 0x04
38 #define ALC880_MIC_EVENT                0x08
39
40 /* ALC880 board config type */
41 enum {
42         ALC880_3ST,
43         ALC880_3ST_DIG,
44         ALC880_5ST,
45         ALC880_5ST_DIG,
46         ALC880_W810,
47         ALC880_Z71V,
48         ALC880_6ST,
49         ALC880_6ST_DIG,
50         ALC880_F1734,
51         ALC880_ASUS,
52         ALC880_ASUS_DIG,
53         ALC880_ASUS_W1V,
54         ALC880_ASUS_DIG2,
55         ALC880_FUJITSU,
56         ALC880_UNIWILL_DIG,
57         ALC880_UNIWILL,
58         ALC880_UNIWILL_P53,
59         ALC880_CLEVO,
60         ALC880_TCL_S700,
61         ALC880_LG,
62         ALC880_LG_LW,
63         ALC880_MEDION_RIM,
64 #ifdef CONFIG_SND_DEBUG
65         ALC880_TEST,
66 #endif
67         ALC880_AUTO,
68         ALC880_MODEL_LAST /* last tag */
69 };
70
71 /* ALC260 models */
72 enum {
73         ALC260_BASIC,
74         ALC260_HP,
75         ALC260_HP_DC7600,
76         ALC260_HP_3013,
77         ALC260_FUJITSU_S702X,
78         ALC260_ACER,
79         ALC260_WILL,
80         ALC260_REPLACER_672V,
81         ALC260_FAVORIT100,
82 #ifdef CONFIG_SND_DEBUG
83         ALC260_TEST,
84 #endif
85         ALC260_AUTO,
86         ALC260_MODEL_LAST /* last tag */
87 };
88
89 /* ALC262 models */
90 enum {
91         ALC262_BASIC,
92         ALC262_HIPPO,
93         ALC262_HIPPO_1,
94         ALC262_FUJITSU,
95         ALC262_HP_BPC,
96         ALC262_HP_BPC_D7000_WL,
97         ALC262_HP_BPC_D7000_WF,
98         ALC262_HP_TC_T5735,
99         ALC262_HP_RP5700,
100         ALC262_BENQ_ED8,
101         ALC262_SONY_ASSAMD,
102         ALC262_BENQ_T31,
103         ALC262_ULTRA,
104         ALC262_LENOVO_3000,
105         ALC262_NEC,
106         ALC262_TOSHIBA_S06,
107         ALC262_TOSHIBA_RX1,
108         ALC262_TYAN,
109         ALC262_AUTO,
110         ALC262_MODEL_LAST /* last tag */
111 };
112
113 /* ALC268 models */
114 enum {
115         ALC267_QUANTA_IL1,
116         ALC268_3ST,
117         ALC268_TOSHIBA,
118         ALC268_ACER,
119         ALC268_ACER_DMIC,
120         ALC268_ACER_ASPIRE_ONE,
121         ALC268_DELL,
122         ALC268_ZEPTO,
123 #ifdef CONFIG_SND_DEBUG
124         ALC268_TEST,
125 #endif
126         ALC268_AUTO,
127         ALC268_MODEL_LAST /* last tag */
128 };
129
130 /* ALC269 models */
131 enum {
132         ALC269_BASIC,
133         ALC269_QUANTA_FL1,
134         ALC269_ASUS_EEEPC_P703,
135         ALC269_ASUS_EEEPC_P901,
136         ALC269_FUJITSU,
137         ALC269_LIFEBOOK,
138         ALC269_AUTO,
139         ALC269_MODEL_LAST /* last tag */
140 };
141
142 /* ALC861 models */
143 enum {
144         ALC861_3ST,
145         ALC660_3ST,
146         ALC861_3ST_DIG,
147         ALC861_6ST_DIG,
148         ALC861_UNIWILL_M31,
149         ALC861_TOSHIBA,
150         ALC861_ASUS,
151         ALC861_ASUS_LAPTOP,
152         ALC861_AUTO,
153         ALC861_MODEL_LAST,
154 };
155
156 /* ALC861-VD models */
157 enum {
158         ALC660VD_3ST,
159         ALC660VD_3ST_DIG,
160         ALC660VD_ASUS_V1S,
161         ALC861VD_3ST,
162         ALC861VD_3ST_DIG,
163         ALC861VD_6ST_DIG,
164         ALC861VD_LENOVO,
165         ALC861VD_DALLAS,
166         ALC861VD_HP,
167         ALC861VD_AUTO,
168         ALC861VD_MODEL_LAST,
169 };
170
171 /* ALC662 models */
172 enum {
173         ALC662_3ST_2ch_DIG,
174         ALC662_3ST_6ch_DIG,
175         ALC662_3ST_6ch,
176         ALC662_5ST_DIG,
177         ALC662_LENOVO_101E,
178         ALC662_ASUS_EEEPC_P701,
179         ALC662_ASUS_EEEPC_EP20,
180         ALC663_ASUS_M51VA,
181         ALC663_ASUS_G71V,
182         ALC663_ASUS_H13,
183         ALC663_ASUS_G50V,
184         ALC662_ECS,
185         ALC663_ASUS_MODE1,
186         ALC662_ASUS_MODE2,
187         ALC663_ASUS_MODE3,
188         ALC663_ASUS_MODE4,
189         ALC663_ASUS_MODE5,
190         ALC663_ASUS_MODE6,
191         ALC272_DELL,
192         ALC272_DELL_ZM1,
193         ALC272_SAMSUNG_NC10,
194         ALC662_AUTO,
195         ALC662_MODEL_LAST,
196 };
197
198 /* ALC882 models */
199 enum {
200         ALC882_3ST_DIG,
201         ALC882_6ST_DIG,
202         ALC882_ARIMA,
203         ALC882_W2JC,
204         ALC882_TARGA,
205         ALC882_ASUS_A7J,
206         ALC882_ASUS_A7M,
207         ALC885_MACPRO,
208         ALC885_MBP3,
209         ALC885_MB5,
210         ALC885_IMAC24,
211         ALC882_AUTO,
212         ALC882_MODEL_LAST,
213 };
214
215 /* ALC883 models */
216 enum {
217         ALC883_3ST_2ch_DIG,
218         ALC883_3ST_6ch_DIG,
219         ALC883_3ST_6ch,
220         ALC883_6ST_DIG,
221         ALC883_TARGA_DIG,
222         ALC883_TARGA_2ch_DIG,
223         ALC883_TARGA_8ch_DIG,
224         ALC883_ACER,
225         ALC883_ACER_ASPIRE,
226         ALC888_ACER_ASPIRE_4930G,
227         ALC888_ACER_ASPIRE_6530G,
228         ALC888_ACER_ASPIRE_8930G,
229         ALC883_MEDION,
230         ALC883_MEDION_MD2,
231         ALC883_LAPTOP_EAPD,
232         ALC883_LENOVO_101E_2ch,
233         ALC883_LENOVO_NB0763,
234         ALC888_LENOVO_MS7195_DIG,
235         ALC888_LENOVO_SKY,
236         ALC883_HAIER_W66,
237         ALC888_3ST_HP,
238         ALC888_6ST_DELL,
239         ALC883_MITAC,
240         ALC883_CLEVO_M720,
241         ALC883_FUJITSU_PI2515,
242         ALC888_FUJITSU_XA3530,
243         ALC883_3ST_6ch_INTEL,
244         ALC888_ASUS_M90V,
245         ALC888_ASUS_EEE1601,
246         ALC889A_MB31,
247         ALC1200_ASUS_P5Q,
248         ALC883_SONY_VAIO_TT,
249         ALC883_AUTO,
250         ALC883_MODEL_LAST,
251 };
252
253 /* for GPIO Poll */
254 #define GPIO_MASK       0x03
255
256 /* extra amp-initialization sequence types */
257 enum {
258         ALC_INIT_NONE,
259         ALC_INIT_DEFAULT,
260         ALC_INIT_GPIO1,
261         ALC_INIT_GPIO2,
262         ALC_INIT_GPIO3,
263 };
264
265 struct alc_spec {
266         /* codec parameterization */
267         struct snd_kcontrol_new *mixers[5];     /* mixer arrays */
268         unsigned int num_mixers;
269         struct snd_kcontrol_new *cap_mixer;     /* capture mixer */
270         unsigned int beep_amp;  /* beep amp value, set via set_beep_amp() */
271
272         const struct hda_verb *init_verbs[5];   /* initialization verbs
273                                                  * don't forget NULL
274                                                  * termination!
275                                                  */
276         unsigned int num_init_verbs;
277
278         char stream_name_analog[16];    /* analog PCM stream */
279         struct hda_pcm_stream *stream_analog_playback;
280         struct hda_pcm_stream *stream_analog_capture;
281         struct hda_pcm_stream *stream_analog_alt_playback;
282         struct hda_pcm_stream *stream_analog_alt_capture;
283
284         char stream_name_digital[16];   /* digital PCM stream */
285         struct hda_pcm_stream *stream_digital_playback;
286         struct hda_pcm_stream *stream_digital_capture;
287
288         /* playback */
289         struct hda_multi_out multiout;  /* playback set-up
290                                          * max_channels, dacs must be set
291                                          * dig_out_nid and hp_nid are optional
292                                          */
293         hda_nid_t alt_dac_nid;
294         hda_nid_t slave_dig_outs[3];    /* optional - for auto-parsing */
295         int dig_out_type;
296
297         /* capture */
298         unsigned int num_adc_nids;
299         hda_nid_t *adc_nids;
300         hda_nid_t *capsrc_nids;
301         hda_nid_t dig_in_nid;           /* digital-in NID; optional */
302
303         /* capture source */
304         unsigned int num_mux_defs;
305         const struct hda_input_mux *input_mux;
306         unsigned int cur_mux[3];
307
308         /* channel model */
309         const struct hda_channel_mode *channel_mode;
310         int num_channel_mode;
311         int need_dac_fix;
312         int const_channel_count;
313         int ext_channel_count;
314
315         /* PCM information */
316         struct hda_pcm pcm_rec[3];      /* used in alc_build_pcms() */
317
318         /* dynamic controls, init_verbs and input_mux */
319         struct auto_pin_cfg autocfg;
320         struct snd_array kctls;
321         struct hda_input_mux private_imux[3];
322         hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
323
324         /* hooks */
325         void (*init_hook)(struct hda_codec *codec);
326         void (*unsol_event)(struct hda_codec *codec, unsigned int res);
327
328         /* for pin sensing */
329         unsigned int sense_updated: 1;
330         unsigned int jack_present: 1;
331         unsigned int master_sw: 1;
332
333         /* other flags */
334         unsigned int no_analog :1; /* digital I/O only */
335         int init_amp;
336
337         /* for virtual master */
338         hda_nid_t vmaster_nid;
339 #ifdef CONFIG_SND_HDA_POWER_SAVE
340         struct hda_loopback_check loopback;
341 #endif
342
343         /* for PLL fix */
344         hda_nid_t pll_nid;
345         unsigned int pll_coef_idx, pll_coef_bit;
346 };
347
348 /*
349  * configuration template - to be copied to the spec instance
350  */
351 struct alc_config_preset {
352         struct snd_kcontrol_new *mixers[5]; /* should be identical size
353                                              * with spec
354                                              */
355         struct snd_kcontrol_new *cap_mixer; /* capture mixer */
356         const struct hda_verb *init_verbs[5];
357         unsigned int num_dacs;
358         hda_nid_t *dac_nids;
359         hda_nid_t dig_out_nid;          /* optional */
360         hda_nid_t hp_nid;               /* optional */
361         hda_nid_t *slave_dig_outs;
362         unsigned int num_adc_nids;
363         hda_nid_t *adc_nids;
364         hda_nid_t *capsrc_nids;
365         hda_nid_t dig_in_nid;
366         unsigned int num_channel_mode;
367         const struct hda_channel_mode *channel_mode;
368         int need_dac_fix;
369         int const_channel_count;
370         unsigned int num_mux_defs;
371         const struct hda_input_mux *input_mux;
372         void (*unsol_event)(struct hda_codec *, unsigned int);
373         void (*init_hook)(struct hda_codec *);
374 #ifdef CONFIG_SND_HDA_POWER_SAVE
375         struct hda_amp_list *loopbacks;
376 #endif
377 };
378
379
380 /*
381  * input MUX handling
382  */
383 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
384                              struct snd_ctl_elem_info *uinfo)
385 {
386         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
387         struct alc_spec *spec = codec->spec;
388         unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
389         if (mux_idx >= spec->num_mux_defs)
390                 mux_idx = 0;
391         return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
392 }
393
394 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
395                             struct snd_ctl_elem_value *ucontrol)
396 {
397         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
398         struct alc_spec *spec = codec->spec;
399         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
400
401         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
402         return 0;
403 }
404
405 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
406                             struct snd_ctl_elem_value *ucontrol)
407 {
408         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
409         struct alc_spec *spec = codec->spec;
410         const struct hda_input_mux *imux;
411         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
412         unsigned int mux_idx;
413         hda_nid_t nid = spec->capsrc_nids ?
414                 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
415         unsigned int type;
416
417         mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
418         imux = &spec->input_mux[mux_idx];
419
420         type = (get_wcaps(codec, nid) & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
421         if (type == AC_WID_AUD_MIX) {
422                 /* Matrix-mixer style (e.g. ALC882) */
423                 unsigned int *cur_val = &spec->cur_mux[adc_idx];
424                 unsigned int i, idx;
425
426                 idx = ucontrol->value.enumerated.item[0];
427                 if (idx >= imux->num_items)
428                         idx = imux->num_items - 1;
429                 if (*cur_val == idx)
430                         return 0;
431                 for (i = 0; i < imux->num_items; i++) {
432                         unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
433                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
434                                                  imux->items[i].index,
435                                                  HDA_AMP_MUTE, v);
436                 }
437                 *cur_val = idx;
438                 return 1;
439         } else {
440                 /* MUX style (e.g. ALC880) */
441                 return snd_hda_input_mux_put(codec, imux, ucontrol, nid,
442                                              &spec->cur_mux[adc_idx]);
443         }
444 }
445
446 /*
447  * channel mode setting
448  */
449 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
450                             struct snd_ctl_elem_info *uinfo)
451 {
452         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
453         struct alc_spec *spec = codec->spec;
454         return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
455                                     spec->num_channel_mode);
456 }
457
458 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
459                            struct snd_ctl_elem_value *ucontrol)
460 {
461         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
462         struct alc_spec *spec = codec->spec;
463         return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
464                                    spec->num_channel_mode,
465                                    spec->ext_channel_count);
466 }
467
468 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
469                            struct snd_ctl_elem_value *ucontrol)
470 {
471         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
472         struct alc_spec *spec = codec->spec;
473         int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
474                                       spec->num_channel_mode,
475                                       &spec->ext_channel_count);
476         if (err >= 0 && !spec->const_channel_count) {
477                 spec->multiout.max_channels = spec->ext_channel_count;
478                 if (spec->need_dac_fix)
479                         spec->multiout.num_dacs = spec->multiout.max_channels / 2;
480         }
481         return err;
482 }
483
484 /*
485  * Control the mode of pin widget settings via the mixer.  "pc" is used
486  * instead of "%" to avoid consequences of accidently treating the % as
487  * being part of a format specifier.  Maximum allowed length of a value is
488  * 63 characters plus NULL terminator.
489  *
490  * Note: some retasking pin complexes seem to ignore requests for input
491  * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
492  * are requested.  Therefore order this list so that this behaviour will not
493  * cause problems when mixer clients move through the enum sequentially.
494  * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
495  * March 2006.
496  */
497 static char *alc_pin_mode_names[] = {
498         "Mic 50pc bias", "Mic 80pc bias",
499         "Line in", "Line out", "Headphone out",
500 };
501 static unsigned char alc_pin_mode_values[] = {
502         PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
503 };
504 /* The control can present all 5 options, or it can limit the options based
505  * in the pin being assumed to be exclusively an input or an output pin.  In
506  * addition, "input" pins may or may not process the mic bias option
507  * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
508  * accept requests for bias as of chip versions up to March 2006) and/or
509  * wiring in the computer.
510  */
511 #define ALC_PIN_DIR_IN              0x00
512 #define ALC_PIN_DIR_OUT             0x01
513 #define ALC_PIN_DIR_INOUT           0x02
514 #define ALC_PIN_DIR_IN_NOMICBIAS    0x03
515 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
516
517 /* Info about the pin modes supported by the different pin direction modes.
518  * For each direction the minimum and maximum values are given.
519  */
520 static signed char alc_pin_mode_dir_info[5][2] = {
521         { 0, 2 },    /* ALC_PIN_DIR_IN */
522         { 3, 4 },    /* ALC_PIN_DIR_OUT */
523         { 0, 4 },    /* ALC_PIN_DIR_INOUT */
524         { 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
525         { 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
526 };
527 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
528 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
529 #define alc_pin_mode_n_items(_dir) \
530         (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
531
532 static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
533                              struct snd_ctl_elem_info *uinfo)
534 {
535         unsigned int item_num = uinfo->value.enumerated.item;
536         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
537
538         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
539         uinfo->count = 1;
540         uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
541
542         if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
543                 item_num = alc_pin_mode_min(dir);
544         strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
545         return 0;
546 }
547
548 static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
549                             struct snd_ctl_elem_value *ucontrol)
550 {
551         unsigned int i;
552         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
553         hda_nid_t nid = kcontrol->private_value & 0xffff;
554         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
555         long *valp = ucontrol->value.integer.value;
556         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
557                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
558                                                  0x00);
559
560         /* Find enumerated value for current pinctl setting */
561         i = alc_pin_mode_min(dir);
562         while (alc_pin_mode_values[i] != pinctl && i <= alc_pin_mode_max(dir))
563                 i++;
564         *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
565         return 0;
566 }
567
568 static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
569                             struct snd_ctl_elem_value *ucontrol)
570 {
571         signed int change;
572         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
573         hda_nid_t nid = kcontrol->private_value & 0xffff;
574         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
575         long val = *ucontrol->value.integer.value;
576         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
577                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
578                                                  0x00);
579
580         if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
581                 val = alc_pin_mode_min(dir);
582
583         change = pinctl != alc_pin_mode_values[val];
584         if (change) {
585                 /* Set pin mode to that requested */
586                 snd_hda_codec_write_cache(codec, nid, 0,
587                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
588                                           alc_pin_mode_values[val]);
589
590                 /* Also enable the retasking pin's input/output as required
591                  * for the requested pin mode.  Enum values of 2 or less are
592                  * input modes.
593                  *
594                  * Dynamically switching the input/output buffers probably
595                  * reduces noise slightly (particularly on input) so we'll
596                  * do it.  However, having both input and output buffers
597                  * enabled simultaneously doesn't seem to be problematic if
598                  * this turns out to be necessary in the future.
599                  */
600                 if (val <= 2) {
601                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
602                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
603                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
604                                                  HDA_AMP_MUTE, 0);
605                 } else {
606                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
607                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
608                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
609                                                  HDA_AMP_MUTE, 0);
610                 }
611         }
612         return change;
613 }
614
615 #define ALC_PIN_MODE(xname, nid, dir) \
616         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
617           .info = alc_pin_mode_info, \
618           .get = alc_pin_mode_get, \
619           .put = alc_pin_mode_put, \
620           .private_value = nid | (dir<<16) }
621
622 /* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
623  * together using a mask with more than one bit set.  This control is
624  * currently used only by the ALC260 test model.  At this stage they are not
625  * needed for any "production" models.
626  */
627 #ifdef CONFIG_SND_DEBUG
628 #define alc_gpio_data_info      snd_ctl_boolean_mono_info
629
630 static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
631                              struct snd_ctl_elem_value *ucontrol)
632 {
633         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
634         hda_nid_t nid = kcontrol->private_value & 0xffff;
635         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
636         long *valp = ucontrol->value.integer.value;
637         unsigned int val = snd_hda_codec_read(codec, nid, 0,
638                                               AC_VERB_GET_GPIO_DATA, 0x00);
639
640         *valp = (val & mask) != 0;
641         return 0;
642 }
643 static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
644                              struct snd_ctl_elem_value *ucontrol)
645 {
646         signed int change;
647         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
648         hda_nid_t nid = kcontrol->private_value & 0xffff;
649         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
650         long val = *ucontrol->value.integer.value;
651         unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
652                                                     AC_VERB_GET_GPIO_DATA,
653                                                     0x00);
654
655         /* Set/unset the masked GPIO bit(s) as needed */
656         change = (val == 0 ? 0 : mask) != (gpio_data & mask);
657         if (val == 0)
658                 gpio_data &= ~mask;
659         else
660                 gpio_data |= mask;
661         snd_hda_codec_write_cache(codec, nid, 0,
662                                   AC_VERB_SET_GPIO_DATA, gpio_data);
663
664         return change;
665 }
666 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
667         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
668           .info = alc_gpio_data_info, \
669           .get = alc_gpio_data_get, \
670           .put = alc_gpio_data_put, \
671           .private_value = nid | (mask<<16) }
672 #endif   /* CONFIG_SND_DEBUG */
673
674 /* A switch control to allow the enabling of the digital IO pins on the
675  * ALC260.  This is incredibly simplistic; the intention of this control is
676  * to provide something in the test model allowing digital outputs to be
677  * identified if present.  If models are found which can utilise these
678  * outputs a more complete mixer control can be devised for those models if
679  * necessary.
680  */
681 #ifdef CONFIG_SND_DEBUG
682 #define alc_spdif_ctrl_info     snd_ctl_boolean_mono_info
683
684 static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
685                               struct snd_ctl_elem_value *ucontrol)
686 {
687         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
688         hda_nid_t nid = kcontrol->private_value & 0xffff;
689         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
690         long *valp = ucontrol->value.integer.value;
691         unsigned int val = snd_hda_codec_read(codec, nid, 0,
692                                               AC_VERB_GET_DIGI_CONVERT_1, 0x00);
693
694         *valp = (val & mask) != 0;
695         return 0;
696 }
697 static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
698                               struct snd_ctl_elem_value *ucontrol)
699 {
700         signed int change;
701         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
702         hda_nid_t nid = kcontrol->private_value & 0xffff;
703         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
704         long val = *ucontrol->value.integer.value;
705         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
706                                                     AC_VERB_GET_DIGI_CONVERT_1,
707                                                     0x00);
708
709         /* Set/unset the masked control bit(s) as needed */
710         change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
711         if (val==0)
712                 ctrl_data &= ~mask;
713         else
714                 ctrl_data |= mask;
715         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
716                                   ctrl_data);
717
718         return change;
719 }
720 #define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
721         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
722           .info = alc_spdif_ctrl_info, \
723           .get = alc_spdif_ctrl_get, \
724           .put = alc_spdif_ctrl_put, \
725           .private_value = nid | (mask<<16) }
726 #endif   /* CONFIG_SND_DEBUG */
727
728 /* A switch control to allow the enabling EAPD digital outputs on the ALC26x.
729  * Again, this is only used in the ALC26x test models to help identify when
730  * the EAPD line must be asserted for features to work.
731  */
732 #ifdef CONFIG_SND_DEBUG
733 #define alc_eapd_ctrl_info      snd_ctl_boolean_mono_info
734
735 static int alc_eapd_ctrl_get(struct snd_kcontrol *kcontrol,
736                               struct snd_ctl_elem_value *ucontrol)
737 {
738         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
739         hda_nid_t nid = kcontrol->private_value & 0xffff;
740         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
741         long *valp = ucontrol->value.integer.value;
742         unsigned int val = snd_hda_codec_read(codec, nid, 0,
743                                               AC_VERB_GET_EAPD_BTLENABLE, 0x00);
744
745         *valp = (val & mask) != 0;
746         return 0;
747 }
748
749 static int alc_eapd_ctrl_put(struct snd_kcontrol *kcontrol,
750                               struct snd_ctl_elem_value *ucontrol)
751 {
752         int change;
753         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
754         hda_nid_t nid = kcontrol->private_value & 0xffff;
755         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
756         long val = *ucontrol->value.integer.value;
757         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
758                                                     AC_VERB_GET_EAPD_BTLENABLE,
759                                                     0x00);
760
761         /* Set/unset the masked control bit(s) as needed */
762         change = (!val ? 0 : mask) != (ctrl_data & mask);
763         if (!val)
764                 ctrl_data &= ~mask;
765         else
766                 ctrl_data |= mask;
767         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
768                                   ctrl_data);
769
770         return change;
771 }
772
773 #define ALC_EAPD_CTRL_SWITCH(xname, nid, mask) \
774         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
775           .info = alc_eapd_ctrl_info, \
776           .get = alc_eapd_ctrl_get, \
777           .put = alc_eapd_ctrl_put, \
778           .private_value = nid | (mask<<16) }
779 #endif   /* CONFIG_SND_DEBUG */
780
781 /*
782  * set up the input pin config (depending on the given auto-pin type)
783  */
784 static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
785                               int auto_pin_type)
786 {
787         unsigned int val = PIN_IN;
788
789         if (auto_pin_type <= AUTO_PIN_FRONT_MIC) {
790                 unsigned int pincap;
791                 pincap = snd_hda_query_pin_caps(codec, nid);
792                 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
793                 if (pincap & AC_PINCAP_VREF_80)
794                         val = PIN_VREF80;
795                 else if (pincap & AC_PINCAP_VREF_50)
796                         val = PIN_VREF50;
797                 else if (pincap & AC_PINCAP_VREF_100)
798                         val = PIN_VREF100;
799                 else if (pincap & AC_PINCAP_VREF_GRD)
800                         val = PIN_VREFGRD;
801         }
802         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
803 }
804
805 /*
806  */
807 static void add_mixer(struct alc_spec *spec, struct snd_kcontrol_new *mix)
808 {
809         if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
810                 return;
811         spec->mixers[spec->num_mixers++] = mix;
812 }
813
814 static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
815 {
816         if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
817                 return;
818         spec->init_verbs[spec->num_init_verbs++] = verb;
819 }
820
821 #ifdef CONFIG_PROC_FS
822 /*
823  * hook for proc
824  */
825 static void print_realtek_coef(struct snd_info_buffer *buffer,
826                                struct hda_codec *codec, hda_nid_t nid)
827 {
828         int coeff;
829
830         if (nid != 0x20)
831                 return;
832         coeff = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PROC_COEF, 0);
833         snd_iprintf(buffer, "  Processing Coefficient: 0x%02x\n", coeff);
834         coeff = snd_hda_codec_read(codec, nid, 0,
835                                    AC_VERB_GET_COEF_INDEX, 0);
836         snd_iprintf(buffer, "  Coefficient Index: 0x%02x\n", coeff);
837 }
838 #else
839 #define print_realtek_coef      NULL
840 #endif
841
842 /*
843  * set up from the preset table
844  */
845 static void setup_preset(struct alc_spec *spec,
846                          const struct alc_config_preset *preset)
847 {
848         int i;
849
850         for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
851                 add_mixer(spec, preset->mixers[i]);
852         spec->cap_mixer = preset->cap_mixer;
853         for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
854              i++)
855                 add_verb(spec, preset->init_verbs[i]);
856
857         spec->channel_mode = preset->channel_mode;
858         spec->num_channel_mode = preset->num_channel_mode;
859         spec->need_dac_fix = preset->need_dac_fix;
860         spec->const_channel_count = preset->const_channel_count;
861
862         if (preset->const_channel_count)
863                 spec->multiout.max_channels = preset->const_channel_count;
864         else
865                 spec->multiout.max_channels = spec->channel_mode[0].channels;
866         spec->ext_channel_count = spec->channel_mode[0].channels;
867
868         spec->multiout.num_dacs = preset->num_dacs;
869         spec->multiout.dac_nids = preset->dac_nids;
870         spec->multiout.dig_out_nid = preset->dig_out_nid;
871         spec->multiout.slave_dig_outs = preset->slave_dig_outs;
872         spec->multiout.hp_nid = preset->hp_nid;
873
874         spec->num_mux_defs = preset->num_mux_defs;
875         if (!spec->num_mux_defs)
876                 spec->num_mux_defs = 1;
877         spec->input_mux = preset->input_mux;
878
879         spec->num_adc_nids = preset->num_adc_nids;
880         spec->adc_nids = preset->adc_nids;
881         spec->capsrc_nids = preset->capsrc_nids;
882         spec->dig_in_nid = preset->dig_in_nid;
883
884         spec->unsol_event = preset->unsol_event;
885         spec->init_hook = preset->init_hook;
886 #ifdef CONFIG_SND_HDA_POWER_SAVE
887         spec->loopback.amplist = preset->loopbacks;
888 #endif
889 }
890
891 /* Enable GPIO mask and set output */
892 static struct hda_verb alc_gpio1_init_verbs[] = {
893         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
894         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
895         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
896         { }
897 };
898
899 static struct hda_verb alc_gpio2_init_verbs[] = {
900         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
901         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
902         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
903         { }
904 };
905
906 static struct hda_verb alc_gpio3_init_verbs[] = {
907         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
908         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
909         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
910         { }
911 };
912
913 /*
914  * Fix hardware PLL issue
915  * On some codecs, the analog PLL gating control must be off while
916  * the default value is 1.
917  */
918 static void alc_fix_pll(struct hda_codec *codec)
919 {
920         struct alc_spec *spec = codec->spec;
921         unsigned int val;
922
923         if (!spec->pll_nid)
924                 return;
925         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
926                             spec->pll_coef_idx);
927         val = snd_hda_codec_read(codec, spec->pll_nid, 0,
928                                  AC_VERB_GET_PROC_COEF, 0);
929         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
930                             spec->pll_coef_idx);
931         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
932                             val & ~(1 << spec->pll_coef_bit));
933 }
934
935 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
936                              unsigned int coef_idx, unsigned int coef_bit)
937 {
938         struct alc_spec *spec = codec->spec;
939         spec->pll_nid = nid;
940         spec->pll_coef_idx = coef_idx;
941         spec->pll_coef_bit = coef_bit;
942         alc_fix_pll(codec);
943 }
944
945 static void alc_automute_pin(struct hda_codec *codec)
946 {
947         struct alc_spec *spec = codec->spec;
948         unsigned int present, pincap;
949         unsigned int nid = spec->autocfg.hp_pins[0];
950         int i;
951
952         pincap = snd_hda_query_pin_caps(codec, nid);
953         if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */
954                 snd_hda_codec_read(codec, nid, 0, AC_VERB_SET_PIN_SENSE, 0);
955         present = snd_hda_codec_read(codec, nid, 0,
956                                      AC_VERB_GET_PIN_SENSE, 0);
957         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
958         for (i = 0; i < ARRAY_SIZE(spec->autocfg.speaker_pins); i++) {
959                 nid = spec->autocfg.speaker_pins[i];
960                 if (!nid)
961                         break;
962                 snd_hda_codec_write(codec, nid, 0,
963                                     AC_VERB_SET_PIN_WIDGET_CONTROL,
964                                     spec->jack_present ? 0 : PIN_OUT);
965         }
966 }
967
968 #if 0 /* it's broken in some cases -- temporarily disabled */
969 static void alc_mic_automute(struct hda_codec *codec)
970 {
971         struct alc_spec *spec = codec->spec;
972         unsigned int present;
973         unsigned int mic_nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
974         unsigned int fmic_nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
975         unsigned int mix_nid = spec->capsrc_nids[0];
976         unsigned int capsrc_idx_mic, capsrc_idx_fmic;
977
978         capsrc_idx_mic = mic_nid - 0x18;
979         capsrc_idx_fmic = fmic_nid - 0x18;
980         present = snd_hda_codec_read(codec, mic_nid, 0,
981                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
982         snd_hda_codec_write(codec, mix_nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
983                     0x7000 | (capsrc_idx_mic << 8) | (present ? 0 : 0x80));
984         snd_hda_codec_write(codec, mix_nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
985                     0x7000 | (capsrc_idx_fmic << 8) | (present ? 0x80 : 0));
986         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, capsrc_idx_fmic,
987                          HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
988 }
989 #else
990 #define alc_mic_automute(codec) do {} while(0) /* NOP */
991 #endif /* disabled */
992
993 /* unsolicited event for HP jack sensing */
994 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
995 {
996         if (codec->vendor_id == 0x10ec0880)
997                 res >>= 28;
998         else
999                 res >>= 26;
1000         switch (res) {
1001         case ALC880_HP_EVENT:
1002                 alc_automute_pin(codec);
1003                 break;
1004         case ALC880_MIC_EVENT:
1005                 alc_mic_automute(codec);
1006                 break;
1007         }
1008 }
1009
1010 static void alc_inithook(struct hda_codec *codec)
1011 {
1012         alc_automute_pin(codec);
1013         alc_mic_automute(codec);
1014 }
1015
1016 /* additional initialization for ALC888 variants */
1017 static void alc888_coef_init(struct hda_codec *codec)
1018 {
1019         unsigned int tmp;
1020
1021         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
1022         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
1023         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
1024         if ((tmp & 0xf0) == 0x20)
1025                 /* alc888S-VC */
1026                 snd_hda_codec_read(codec, 0x20, 0,
1027                                    AC_VERB_SET_PROC_COEF, 0x830);
1028          else
1029                  /* alc888-VB */
1030                  snd_hda_codec_read(codec, 0x20, 0,
1031                                     AC_VERB_SET_PROC_COEF, 0x3030);
1032 }
1033
1034 static void alc_auto_init_amp(struct hda_codec *codec, int type)
1035 {
1036         unsigned int tmp;
1037
1038         switch (type) {
1039         case ALC_INIT_GPIO1:
1040                 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
1041                 break;
1042         case ALC_INIT_GPIO2:
1043                 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
1044                 break;
1045         case ALC_INIT_GPIO3:
1046                 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
1047                 break;
1048         case ALC_INIT_DEFAULT:
1049                 switch (codec->vendor_id) {
1050                 case 0x10ec0260:
1051                         snd_hda_codec_write(codec, 0x0f, 0,
1052                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1053                         snd_hda_codec_write(codec, 0x10, 0,
1054                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1055                         break;
1056                 case 0x10ec0262:
1057                 case 0x10ec0267:
1058                 case 0x10ec0268:
1059                 case 0x10ec0269:
1060                 case 0x10ec0272:
1061                 case 0x10ec0660:
1062                 case 0x10ec0662:
1063                 case 0x10ec0663:
1064                 case 0x10ec0862:
1065                 case 0x10ec0889:
1066                         snd_hda_codec_write(codec, 0x14, 0,
1067                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1068                         snd_hda_codec_write(codec, 0x15, 0,
1069                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1070                         break;
1071                 }
1072                 switch (codec->vendor_id) {
1073                 case 0x10ec0260:
1074                         snd_hda_codec_write(codec, 0x1a, 0,
1075                                             AC_VERB_SET_COEF_INDEX, 7);
1076                         tmp = snd_hda_codec_read(codec, 0x1a, 0,
1077                                                  AC_VERB_GET_PROC_COEF, 0);
1078                         snd_hda_codec_write(codec, 0x1a, 0,
1079                                             AC_VERB_SET_COEF_INDEX, 7);
1080                         snd_hda_codec_write(codec, 0x1a, 0,
1081                                             AC_VERB_SET_PROC_COEF,
1082                                             tmp | 0x2010);
1083                         break;
1084                 case 0x10ec0262:
1085                 case 0x10ec0880:
1086                 case 0x10ec0882:
1087                 case 0x10ec0883:
1088                 case 0x10ec0885:
1089                 case 0x10ec0887:
1090                 case 0x10ec0889:
1091                         snd_hda_codec_write(codec, 0x20, 0,
1092                                             AC_VERB_SET_COEF_INDEX, 7);
1093                         tmp = snd_hda_codec_read(codec, 0x20, 0,
1094                                                  AC_VERB_GET_PROC_COEF, 0);
1095                         snd_hda_codec_write(codec, 0x20, 0,
1096                                             AC_VERB_SET_COEF_INDEX, 7);
1097                         snd_hda_codec_write(codec, 0x20, 0,
1098                                             AC_VERB_SET_PROC_COEF,
1099                                             tmp | 0x2010);
1100                         break;
1101                 case 0x10ec0888:
1102                         alc888_coef_init(codec);
1103                         break;
1104                 case 0x10ec0267:
1105                 case 0x10ec0268:
1106                         snd_hda_codec_write(codec, 0x20, 0,
1107                                             AC_VERB_SET_COEF_INDEX, 7);
1108                         tmp = snd_hda_codec_read(codec, 0x20, 0,
1109                                                  AC_VERB_GET_PROC_COEF, 0);
1110                         snd_hda_codec_write(codec, 0x20, 0,
1111                                             AC_VERB_SET_COEF_INDEX, 7);
1112                         snd_hda_codec_write(codec, 0x20, 0,
1113                                             AC_VERB_SET_PROC_COEF,
1114                                             tmp | 0x3000);
1115                         break;
1116                 }
1117                 break;
1118         }
1119 }
1120
1121 static void alc_init_auto_hp(struct hda_codec *codec)
1122 {
1123         struct alc_spec *spec = codec->spec;
1124
1125         if (!spec->autocfg.hp_pins[0])
1126                 return;
1127
1128         if (!spec->autocfg.speaker_pins[0]) {
1129                 if (spec->autocfg.line_out_pins[0] &&
1130                     spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
1131                         spec->autocfg.speaker_pins[0] =
1132                                 spec->autocfg.line_out_pins[0];
1133                 else
1134                         return;
1135         }
1136
1137         snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
1138                     spec->autocfg.hp_pins[0]);
1139         snd_hda_codec_write_cache(codec, spec->autocfg.hp_pins[0], 0,
1140                                   AC_VERB_SET_UNSOLICITED_ENABLE,
1141                                   AC_USRSP_EN | ALC880_HP_EVENT);
1142         spec->unsol_event = alc_sku_unsol_event;
1143 }
1144
1145 /* check subsystem ID and set up device-specific initialization;
1146  * return 1 if initialized, 0 if invalid SSID
1147  */
1148 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1149  *      31 ~ 16 :       Manufacture ID
1150  *      15 ~ 8  :       SKU ID
1151  *      7  ~ 0  :       Assembly ID
1152  *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1153  */
1154 static int alc_subsystem_id(struct hda_codec *codec,
1155                             hda_nid_t porta, hda_nid_t porte,
1156                             hda_nid_t portd)
1157 {
1158         unsigned int ass, tmp, i;
1159         unsigned nid;
1160         struct alc_spec *spec = codec->spec;
1161
1162         ass = codec->subsystem_id & 0xffff;
1163         if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1164                 goto do_sku;
1165
1166         /* invalid SSID, check the special NID pin defcfg instead */
1167         /*
1168          * 31~30        : port connectivity
1169          * 29~21        : reserve
1170          * 20           : PCBEEP input
1171          * 19~16        : Check sum (15:1)
1172          * 15~1         : Custom
1173          * 0            : override
1174         */
1175         nid = 0x1d;
1176         if (codec->vendor_id == 0x10ec0260)
1177                 nid = 0x17;
1178         ass = snd_hda_codec_get_pincfg(codec, nid);
1179         snd_printd("realtek: No valid SSID, "
1180                    "checking pincfg 0x%08x for NID 0x%x\n",
1181                    ass, nid);
1182         if (!(ass & 1) && !(ass & 0x100000))
1183                 return 0;
1184         if ((ass >> 30) != 1)   /* no physical connection */
1185                 return 0;
1186
1187         /* check sum */
1188         tmp = 0;
1189         for (i = 1; i < 16; i++) {
1190                 if ((ass >> i) & 1)
1191                         tmp++;
1192         }
1193         if (((ass >> 16) & 0xf) != tmp)
1194                 return 0;
1195 do_sku:
1196         snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1197                    ass & 0xffff, codec->vendor_id);
1198         /*
1199          * 0 : override
1200          * 1 :  Swap Jack
1201          * 2 : 0 --> Desktop, 1 --> Laptop
1202          * 3~5 : External Amplifier control
1203          * 7~6 : Reserved
1204         */
1205         tmp = (ass & 0x38) >> 3;        /* external Amp control */
1206         switch (tmp) {
1207         case 1:
1208                 spec->init_amp = ALC_INIT_GPIO1;
1209                 break;
1210         case 3:
1211                 spec->init_amp = ALC_INIT_GPIO2;
1212                 break;
1213         case 7:
1214                 spec->init_amp = ALC_INIT_GPIO3;
1215                 break;
1216         case 5:
1217                 spec->init_amp = ALC_INIT_DEFAULT;
1218                 break;
1219         }
1220
1221         /* is laptop or Desktop and enable the function "Mute internal speaker
1222          * when the external headphone out jack is plugged"
1223          */
1224         if (!(ass & 0x8000))
1225                 return 1;
1226         /*
1227          * 10~8 : Jack location
1228          * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1229          * 14~13: Resvered
1230          * 15   : 1 --> enable the function "Mute internal speaker
1231          *              when the external headphone out jack is plugged"
1232          */
1233         if (!spec->autocfg.hp_pins[0]) {
1234                 tmp = (ass >> 11) & 0x3;        /* HP to chassis */
1235                 if (tmp == 0)
1236                         spec->autocfg.hp_pins[0] = porta;
1237                 else if (tmp == 1)
1238                         spec->autocfg.hp_pins[0] = porte;
1239                 else if (tmp == 2)
1240                         spec->autocfg.hp_pins[0] = portd;
1241                 else
1242                         return 1;
1243         }
1244
1245         alc_init_auto_hp(codec);
1246         return 1;
1247 }
1248
1249 static void alc_ssid_check(struct hda_codec *codec,
1250                            hda_nid_t porta, hda_nid_t porte, hda_nid_t portd)
1251 {
1252         if (!alc_subsystem_id(codec, porta, porte, portd)) {
1253                 struct alc_spec *spec = codec->spec;
1254                 snd_printd("realtek: "
1255                            "Enable default setup for auto mode as fallback\n");
1256                 spec->init_amp = ALC_INIT_DEFAULT;
1257                 alc_init_auto_hp(codec);
1258         }
1259 }
1260
1261 /*
1262  * Fix-up pin default configurations
1263  */
1264
1265 struct alc_pincfg {
1266         hda_nid_t nid;
1267         u32 val;
1268 };
1269
1270 static void alc_fix_pincfg(struct hda_codec *codec,
1271                            const struct snd_pci_quirk *quirk,
1272                            const struct alc_pincfg **pinfix)
1273 {
1274         const struct alc_pincfg *cfg;
1275
1276         quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1277         if (!quirk)
1278                 return;
1279
1280         cfg = pinfix[quirk->value];
1281         for (; cfg->nid; cfg++)
1282                 snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val);
1283 }
1284
1285 /*
1286  * ALC888
1287  */
1288
1289 /*
1290  * 2ch mode
1291  */
1292 static struct hda_verb alc888_4ST_ch2_intel_init[] = {
1293 /* Mic-in jack as mic in */
1294         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1295         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1296 /* Line-in jack as Line in */
1297         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1298         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1299 /* Line-Out as Front */
1300         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1301         { } /* end */
1302 };
1303
1304 /*
1305  * 4ch mode
1306  */
1307 static struct hda_verb alc888_4ST_ch4_intel_init[] = {
1308 /* Mic-in jack as mic in */
1309         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1310         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1311 /* Line-in jack as Surround */
1312         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1313         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1314 /* Line-Out as Front */
1315         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1316         { } /* end */
1317 };
1318
1319 /*
1320  * 6ch mode
1321  */
1322 static struct hda_verb alc888_4ST_ch6_intel_init[] = {
1323 /* Mic-in jack as CLFE */
1324         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1325         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1326 /* Line-in jack as Surround */
1327         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1328         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1329 /* Line-Out as CLFE (workaround because Mic-in is not loud enough) */
1330         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1331         { } /* end */
1332 };
1333
1334 /*
1335  * 8ch mode
1336  */
1337 static struct hda_verb alc888_4ST_ch8_intel_init[] = {
1338 /* Mic-in jack as CLFE */
1339         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1340         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1341 /* Line-in jack as Surround */
1342         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1343         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1344 /* Line-Out as Side */
1345         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1346         { } /* end */
1347 };
1348
1349 static struct hda_channel_mode alc888_4ST_8ch_intel_modes[4] = {
1350         { 2, alc888_4ST_ch2_intel_init },
1351         { 4, alc888_4ST_ch4_intel_init },
1352         { 6, alc888_4ST_ch6_intel_init },
1353         { 8, alc888_4ST_ch8_intel_init },
1354 };
1355
1356 /*
1357  * ALC888 Fujitsu Siemens Amillo xa3530
1358  */
1359
1360 static struct hda_verb alc888_fujitsu_xa3530_verbs[] = {
1361 /* Front Mic: set to PIN_IN (empty by default) */
1362         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1363 /* Connect Internal HP to Front */
1364         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1365         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1366         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1367 /* Connect Bass HP to Front */
1368         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1369         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1370         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1371 /* Connect Line-Out side jack (SPDIF) to Side */
1372         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1373         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1374         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1375 /* Connect Mic jack to CLFE */
1376         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1377         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1378         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},
1379 /* Connect Line-in jack to Surround */
1380         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1381         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1382         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
1383 /* Connect HP out jack to Front */
1384         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1385         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1386         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1387 /* Enable unsolicited event for HP jack and Line-out jack */
1388         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1389         {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1390         {}
1391 };
1392
1393 static void alc_automute_amp(struct hda_codec *codec)
1394 {
1395         struct alc_spec *spec = codec->spec;
1396         unsigned int val, mute, pincap;
1397         hda_nid_t nid;
1398         int i;
1399
1400         spec->jack_present = 0;
1401         for (i = 0; i < ARRAY_SIZE(spec->autocfg.hp_pins); i++) {
1402                 nid = spec->autocfg.hp_pins[i];
1403                 if (!nid)
1404                         break;
1405                 pincap = snd_hda_query_pin_caps(codec, nid);
1406                 if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */
1407                         snd_hda_codec_read(codec, nid, 0,
1408                                            AC_VERB_SET_PIN_SENSE, 0);
1409                 val = snd_hda_codec_read(codec, nid, 0,
1410                                          AC_VERB_GET_PIN_SENSE, 0);
1411                 if (val & AC_PINSENSE_PRESENCE) {
1412                         spec->jack_present = 1;
1413                         break;
1414                 }
1415         }
1416
1417         mute = spec->jack_present ? HDA_AMP_MUTE : 0;
1418         /* Toggle internal speakers muting */
1419         for (i = 0; i < ARRAY_SIZE(spec->autocfg.speaker_pins); i++) {
1420                 nid = spec->autocfg.speaker_pins[i];
1421                 if (!nid)
1422                         break;
1423                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
1424                                          HDA_AMP_MUTE, mute);
1425         }
1426 }
1427
1428 static void alc_automute_amp_unsol_event(struct hda_codec *codec,
1429                                          unsigned int res)
1430 {
1431         if (codec->vendor_id == 0x10ec0880)
1432                 res >>= 28;
1433         else
1434                 res >>= 26;
1435         if (res == ALC880_HP_EVENT)
1436                 alc_automute_amp(codec);
1437 }
1438
1439 static void alc888_fujitsu_xa3530_init_hook(struct hda_codec *codec)
1440 {
1441         struct alc_spec *spec = codec->spec;
1442
1443         spec->autocfg.hp_pins[0] = 0x17; /* line-out */
1444         spec->autocfg.hp_pins[1] = 0x1b; /* hp */
1445         spec->autocfg.speaker_pins[0] = 0x14; /* speaker */
1446         spec->autocfg.speaker_pins[1] = 0x15; /* bass */
1447         alc_automute_amp(codec);
1448 }
1449
1450 /*
1451  * ALC888 Acer Aspire 4930G model
1452  */
1453
1454 static struct hda_verb alc888_acer_aspire_4930g_verbs[] = {
1455 /* Front Mic: set to PIN_IN (empty by default) */
1456         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1457 /* Unselect Front Mic by default in input mixer 3 */
1458         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1459 /* Enable unsolicited event for HP jack */
1460         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1461 /* Connect Internal HP to front */
1462         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1463         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1464         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1465 /* Connect HP out to front */
1466         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1467         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1468         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1469         { }
1470 };
1471
1472 /*
1473  * ALC888 Acer Aspire 6530G model
1474  */
1475
1476 static struct hda_verb alc888_acer_aspire_6530g_verbs[] = {
1477 /* Bias voltage on for external mic port */
1478         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN | PIN_VREF80},
1479 /* Front Mic: set to PIN_IN (empty by default) */
1480         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1481 /* Unselect Front Mic by default in input mixer 3 */
1482         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1483 /* Enable unsolicited event for HP jack */
1484         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1485 /* Enable speaker output */
1486         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1487         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1488 /* Enable headphone output */
1489         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | PIN_HP},
1490         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1491         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1492         { }
1493 };
1494
1495 /*
1496  * ALC889 Acer Aspire 8930G model
1497  */
1498
1499 static struct hda_verb alc889_acer_aspire_8930g_verbs[] = {
1500 /* Front Mic: set to PIN_IN (empty by default) */
1501         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1502 /* Unselect Front Mic by default in input mixer 3 */
1503         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1504 /* Enable unsolicited event for HP jack */
1505         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1506 /* Connect Internal Front to Front */
1507         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1508         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1509         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1510 /* Connect Internal Rear to Rear */
1511         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1512         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1513         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},
1514 /* Connect Internal CLFE to CLFE */
1515         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1516         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1517         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
1518 /* Connect HP out to Front */
1519         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | PIN_HP},
1520         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1521         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1522 /* Enable all DACs */
1523 /*  DAC DISABLE/MUTE 1? */
1524 /*  setting bits 1-5 disables DAC nids 0x02-0x06 apparently. Init=0x38 */
1525         {0x20, AC_VERB_SET_COEF_INDEX, 0x03},
1526         {0x20, AC_VERB_SET_PROC_COEF, 0x0000},
1527 /*  DAC DISABLE/MUTE 2? */
1528 /*  some bit here disables the other DACs. Init=0x4900 */
1529         {0x20, AC_VERB_SET_COEF_INDEX, 0x08},
1530         {0x20, AC_VERB_SET_PROC_COEF, 0x0000},
1531 /* Enable amplifiers */
1532         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
1533         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
1534 /* DMIC fix
1535  * This laptop has a stereo digital microphone. The mics are only 1cm apart
1536  * which makes the stereo useless. However, either the mic or the ALC889
1537  * makes the signal become a difference/sum signal instead of standard
1538  * stereo, which is annoying. So instead we flip this bit which makes the
1539  * codec replicate the sum signal to both channels, turning it into a
1540  * normal mono mic.
1541  */
1542 /*  DMIC_CONTROL? Init value = 0x0001 */
1543         {0x20, AC_VERB_SET_COEF_INDEX, 0x0b},
1544         {0x20, AC_VERB_SET_PROC_COEF, 0x0003},
1545         { }
1546 };
1547
1548 static struct hda_input_mux alc888_2_capture_sources[2] = {
1549         /* Front mic only available on one ADC */
1550         {
1551                 .num_items = 4,
1552                 .items = {
1553                         { "Mic", 0x0 },
1554                         { "Line", 0x2 },
1555                         { "CD", 0x4 },
1556                         { "Front Mic", 0xb },
1557                 },
1558         },
1559         {
1560                 .num_items = 3,
1561                 .items = {
1562                         { "Mic", 0x0 },
1563                         { "Line", 0x2 },
1564                         { "CD", 0x4 },
1565                 },
1566         }
1567 };
1568
1569 static struct hda_input_mux alc888_acer_aspire_6530_sources[2] = {
1570         /* Interal mic only available on one ADC */
1571         {
1572                 .num_items = 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 (!i)
4509                         spec->multiout.dig_out_nid = dig_nid;
4510                 else {
4511                         spec->multiout.slave_dig_outs = spec->slave_dig_outs;
4512                         spec->slave_dig_outs[i - 1] = dig_nid;
4513                         if (i == ARRAY_SIZE(spec->slave_dig_outs) - 1)
4514                                 break;
4515                 }
4516         }
4517         if (spec->autocfg.dig_in_pin)
4518                 spec->dig_in_nid = ALC880_DIGIN_NID;
4519
4520         if (spec->kctls.list)
4521                 add_mixer(spec, spec->kctls.list);
4522
4523         add_verb(spec, alc880_volume_init_verbs);
4524
4525         spec->num_mux_defs = 1;
4526         spec->input_mux = &spec->private_imux[0];
4527
4528         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
4529
4530         return 1;
4531 }
4532
4533 /* additional initialization for auto-configuration model */
4534 static void alc880_auto_init(struct hda_codec *codec)
4535 {
4536         struct alc_spec *spec = codec->spec;
4537         alc880_auto_init_multi_out(codec);
4538         alc880_auto_init_extra_out(codec);
4539         alc880_auto_init_analog_input(codec);
4540         if (spec->unsol_event)
4541                 alc_inithook(codec);
4542 }
4543
4544 static void set_capture_mixer(struct alc_spec *spec)
4545 {
4546         static struct snd_kcontrol_new *caps[2][3] = {
4547                 { alc_capture_mixer_nosrc1,
4548                   alc_capture_mixer_nosrc2,
4549                   alc_capture_mixer_nosrc3 },
4550                 { alc_capture_mixer1,
4551                   alc_capture_mixer2,
4552                   alc_capture_mixer3 },
4553         };
4554         if (spec->num_adc_nids > 0 && spec->num_adc_nids <= 3) {
4555                 int mux;
4556                 if (spec->input_mux && spec->input_mux->num_items > 1)
4557                         mux = 1;
4558                 else
4559                         mux = 0;
4560                 spec->cap_mixer = caps[mux][spec->num_adc_nids - 1];
4561         }
4562 }
4563
4564 #define set_beep_amp(spec, nid, idx, dir) \
4565         ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4566
4567 /*
4568  * OK, here we have finally the patch for ALC880
4569  */
4570
4571 static int patch_alc880(struct hda_codec *codec)
4572 {
4573         struct alc_spec *spec;
4574         int board_config;
4575         int err;
4576
4577         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4578         if (spec == NULL)
4579                 return -ENOMEM;
4580
4581         codec->spec = spec;
4582
4583         board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
4584                                                   alc880_models,
4585                                                   alc880_cfg_tbl);
4586         if (board_config < 0) {
4587                 printk(KERN_INFO "hda_codec: Unknown model for %s, "
4588                        "trying auto-probe from BIOS...\n", codec->chip_name);
4589                 board_config = ALC880_AUTO;
4590         }
4591
4592         if (board_config == ALC880_AUTO) {
4593                 /* automatic parse from the BIOS config */
4594                 err = alc880_parse_auto_config(codec);
4595                 if (err < 0) {
4596                         alc_free(codec);
4597                         return err;
4598                 } else if (!err) {
4599                         printk(KERN_INFO
4600                                "hda_codec: Cannot set up configuration "
4601                                "from BIOS.  Using 3-stack mode...\n");
4602                         board_config = ALC880_3ST;
4603                 }
4604         }
4605
4606         err = snd_hda_attach_beep_device(codec, 0x1);
4607         if (err < 0) {
4608                 alc_free(codec);
4609                 return err;
4610         }
4611
4612         if (board_config != ALC880_AUTO)
4613                 setup_preset(spec, &alc880_presets[board_config]);
4614
4615         spec->stream_analog_playback = &alc880_pcm_analog_playback;
4616         spec->stream_analog_capture = &alc880_pcm_analog_capture;
4617         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
4618
4619         spec->stream_digital_playback = &alc880_pcm_digital_playback;
4620         spec->stream_digital_capture = &alc880_pcm_digital_capture;
4621
4622         if (!spec->adc_nids && spec->input_mux) {
4623                 /* check whether NID 0x07 is valid */
4624                 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
4625                 /* get type */
4626                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
4627                 if (wcap != AC_WID_AUD_IN) {
4628                         spec->adc_nids = alc880_adc_nids_alt;
4629                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
4630                 } else {
4631                         spec->adc_nids = alc880_adc_nids;
4632                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
4633                 }
4634         }
4635         set_capture_mixer(spec);
4636         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4637
4638         spec->vmaster_nid = 0x0c;
4639
4640         codec->patch_ops = alc_patch_ops;
4641         if (board_config == ALC880_AUTO)
4642                 spec->init_hook = alc880_auto_init;
4643 #ifdef CONFIG_SND_HDA_POWER_SAVE
4644         if (!spec->loopback.amplist)
4645                 spec->loopback.amplist = alc880_loopbacks;
4646 #endif
4647         codec->proc_widget_hook = print_realtek_coef;
4648
4649         return 0;
4650 }
4651
4652
4653 /*
4654  * ALC260 support
4655  */
4656
4657 static hda_nid_t alc260_dac_nids[1] = {
4658         /* front */
4659         0x02,
4660 };
4661
4662 static hda_nid_t alc260_adc_nids[1] = {
4663         /* ADC0 */
4664         0x04,
4665 };
4666
4667 static hda_nid_t alc260_adc_nids_alt[1] = {
4668         /* ADC1 */
4669         0x05,
4670 };
4671
4672 /* NIDs used when simultaneous access to both ADCs makes sense.  Note that
4673  * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
4674  */
4675 static hda_nid_t alc260_dual_adc_nids[2] = {
4676         /* ADC0, ADC1 */
4677         0x04, 0x05
4678 };
4679
4680 #define ALC260_DIGOUT_NID       0x03
4681 #define ALC260_DIGIN_NID        0x06
4682
4683 static struct hda_input_mux alc260_capture_source = {
4684         .num_items = 4,
4685         .items = {
4686                 { "Mic", 0x0 },
4687                 { "Front Mic", 0x1 },
4688                 { "Line", 0x2 },
4689                 { "CD", 0x4 },
4690         },
4691 };
4692
4693 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
4694  * headphone jack and the internal CD lines since these are the only pins at
4695  * which audio can appear.  For flexibility, also allow the option of
4696  * recording the mixer output on the second ADC (ADC0 doesn't have a
4697  * connection to the mixer output).
4698  */
4699 static struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
4700         {
4701                 .num_items = 3,
4702                 .items = {
4703                         { "Mic/Line", 0x0 },
4704                         { "CD", 0x4 },
4705                         { "Headphone", 0x2 },
4706                 },
4707         },
4708         {
4709                 .num_items = 4,
4710                 .items = {
4711                         { "Mic/Line", 0x0 },
4712                         { "CD", 0x4 },
4713                         { "Headphone", 0x2 },
4714                         { "Mixer", 0x5 },
4715                 },
4716         },
4717
4718 };
4719
4720 /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
4721  * the Fujitsu S702x, but jacks are marked differently.
4722  */
4723 static struct hda_input_mux alc260_acer_capture_sources[2] = {
4724         {
4725                 .num_items = 4,
4726                 .items = {
4727                         { "Mic", 0x0 },
4728                         { "Line", 0x2 },
4729                         { "CD", 0x4 },
4730                         { "Headphone", 0x5 },
4731                 },
4732         },
4733         {
4734                 .num_items = 5,
4735                 .items = {
4736                         { "Mic", 0x0 },
4737                         { "Line", 0x2 },
4738                         { "CD", 0x4 },
4739                         { "Headphone", 0x6 },
4740                         { "Mixer", 0x5 },
4741                 },
4742         },
4743 };
4744
4745 /* Maxdata Favorit 100XS */
4746 static struct hda_input_mux alc260_favorit100_capture_sources[2] = {
4747         {
4748                 .num_items = 2,
4749                 .items = {
4750                         { "Line/Mic", 0x0 },
4751                         { "CD", 0x4 },
4752                 },
4753         },
4754         {
4755                 .num_items = 3,
4756                 .items = {
4757                         { "Line/Mic", 0x0 },
4758                         { "CD", 0x4 },
4759                         { "Mixer", 0x5 },
4760                 },
4761         },
4762 };
4763
4764 /*
4765  * This is just place-holder, so there's something for alc_build_pcms to look
4766  * at when it calculates the maximum number of channels. ALC260 has no mixer
4767  * element which allows changing the channel mode, so the verb list is
4768  * never used.
4769  */
4770 static struct hda_channel_mode alc260_modes[1] = {
4771         { 2, NULL },
4772 };
4773
4774
4775 /* Mixer combinations
4776  *
4777  * basic: base_output + input + pc_beep + capture
4778  * HP: base_output + input + capture_alt
4779  * HP_3013: hp_3013 + input + capture
4780  * fujitsu: fujitsu + capture
4781  * acer: acer + capture
4782  */
4783
4784 static struct snd_kcontrol_new alc260_base_output_mixer[] = {
4785         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4786         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
4787         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4788         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
4789         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4790         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4791         { } /* end */
4792 };
4793
4794 static struct snd_kcontrol_new alc260_input_mixer[] = {
4795         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4796         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4797         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4798         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4799         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4800         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4801         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
4802         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
4803         { } /* end */
4804 };
4805
4806 /* update HP, line and mono out pins according to the master switch */
4807 static void alc260_hp_master_update(struct hda_codec *codec,
4808                                     hda_nid_t hp, hda_nid_t line,
4809                                     hda_nid_t mono)
4810 {
4811         struct alc_spec *spec = codec->spec;
4812         unsigned int val = spec->master_sw ? PIN_HP : 0;
4813         /* change HP and line-out pins */
4814         snd_hda_codec_write(codec, hp, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4815                             val);
4816         snd_hda_codec_write(codec, line, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4817                             val);
4818         /* mono (speaker) depending on the HP jack sense */
4819         val = (val && !spec->jack_present) ? PIN_OUT : 0;
4820         snd_hda_codec_write(codec, mono, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4821                             val);
4822 }
4823
4824 static int alc260_hp_master_sw_get(struct snd_kcontrol *kcontrol,
4825                                    struct snd_ctl_elem_value *ucontrol)
4826 {
4827         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4828         struct alc_spec *spec = codec->spec;
4829         *ucontrol->value.integer.value = spec->master_sw;
4830         return 0;
4831 }
4832
4833 static int alc260_hp_master_sw_put(struct snd_kcontrol *kcontrol,
4834                                    struct snd_ctl_elem_value *ucontrol)
4835 {
4836         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4837         struct alc_spec *spec = codec->spec;
4838         int val = !!*ucontrol->value.integer.value;
4839         hda_nid_t hp, line, mono;
4840
4841         if (val == spec->master_sw)
4842                 return 0;
4843         spec->master_sw = val;
4844         hp = (kcontrol->private_value >> 16) & 0xff;
4845         line = (kcontrol->private_value >> 8) & 0xff;
4846         mono = kcontrol->private_value & 0xff;
4847         alc260_hp_master_update(codec, hp, line, mono);
4848         return 1;
4849 }
4850
4851 static struct snd_kcontrol_new alc260_hp_output_mixer[] = {
4852         {
4853                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4854                 .name = "Master Playback Switch",
4855                 .info = snd_ctl_boolean_mono_info,
4856                 .get = alc260_hp_master_sw_get,
4857                 .put = alc260_hp_master_sw_put,
4858                 .private_value = (0x0f << 16) | (0x10 << 8) | 0x11
4859         },
4860         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4861         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
4862         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4863         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
4864         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4865                               HDA_OUTPUT),
4866         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4867         { } /* end */
4868 };
4869
4870 static struct hda_verb alc260_hp_unsol_verbs[] = {
4871         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4872         {},
4873 };
4874
4875 static void alc260_hp_automute(struct hda_codec *codec)
4876 {
4877         struct alc_spec *spec = codec->spec;
4878         unsigned int present;
4879
4880         present = snd_hda_codec_read(codec, 0x10, 0,
4881                                      AC_VERB_GET_PIN_SENSE, 0);
4882         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4883         alc260_hp_master_update(codec, 0x0f, 0x10, 0x11);
4884 }
4885
4886 static void alc260_hp_unsol_event(struct hda_codec *codec, unsigned int res)
4887 {
4888         if ((res >> 26) == ALC880_HP_EVENT)
4889                 alc260_hp_automute(codec);
4890 }
4891
4892 static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
4893         {
4894                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4895                 .name = "Master Playback Switch",
4896                 .info = snd_ctl_boolean_mono_info,
4897                 .get = alc260_hp_master_sw_get,
4898                 .put = alc260_hp_master_sw_put,
4899                 .private_value = (0x15 << 16) | (0x10 << 8) | 0x11
4900         },
4901         HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4902         HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
4903         HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
4904         HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
4905         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4906         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
4907         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4908         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
4909         { } /* end */
4910 };
4911
4912 static struct hda_bind_ctls alc260_dc7600_bind_master_vol = {
4913         .ops = &snd_hda_bind_vol,
4914         .values = {
4915                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_OUTPUT),
4916                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
4917                 HDA_COMPOSE_AMP_VAL(0x0a, 3, 0, HDA_OUTPUT),
4918                 0
4919         },
4920 };
4921
4922 static struct hda_bind_ctls alc260_dc7600_bind_switch = {
4923         .ops = &snd_hda_bind_sw,
4924         .values = {
4925                 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
4926                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
4927                 0
4928         },
4929 };
4930
4931 static struct snd_kcontrol_new alc260_hp_dc7600_mixer[] = {
4932         HDA_BIND_VOL("Master Playback Volume", &alc260_dc7600_bind_master_vol),
4933         HDA_BIND_SW("LineOut Playback Switch", &alc260_dc7600_bind_switch),
4934         HDA_CODEC_MUTE("Speaker Playback Switch", 0x0f, 0x0, HDA_OUTPUT),
4935         HDA_CODEC_MUTE("Headphone Playback Switch", 0x10, 0x0, HDA_OUTPUT),
4936         { } /* end */
4937 };
4938
4939 static struct hda_verb alc260_hp_3013_unsol_verbs[] = {
4940         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4941         {},
4942 };
4943
4944 static void alc260_hp_3013_automute(struct hda_codec *codec)
4945 {
4946         struct alc_spec *spec = codec->spec;
4947         unsigned int present;
4948
4949         present = snd_hda_codec_read(codec, 0x15, 0,
4950                                      AC_VERB_GET_PIN_SENSE, 0);
4951         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4952         alc260_hp_master_update(codec, 0x15, 0x10, 0x11);
4953 }
4954
4955 static void alc260_hp_3013_unsol_event(struct hda_codec *codec,
4956                                        unsigned int res)
4957 {
4958         if ((res >> 26) == ALC880_HP_EVENT)
4959                 alc260_hp_3013_automute(codec);
4960 }
4961
4962 static void alc260_hp_3012_automute(struct hda_codec *codec)
4963 {
4964         unsigned int present, bits;
4965
4966         present = snd_hda_codec_read(codec, 0x10, 0,
4967                         AC_VERB_GET_PIN_SENSE, 0) & AC_PINSENSE_PRESENCE;
4968
4969         bits = present ? 0 : PIN_OUT;
4970         snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4971                             bits);
4972         snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4973                             bits);
4974         snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4975                             bits);
4976 }
4977
4978 static void alc260_hp_3012_unsol_event(struct hda_codec *codec,
4979                                        unsigned int res)
4980 {
4981         if ((res >> 26) == ALC880_HP_EVENT)
4982                 alc260_hp_3012_automute(codec);
4983 }
4984
4985 /* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12,
4986  * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
4987  */
4988 static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
4989         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4990         HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
4991         ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4992         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4993         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4994         HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
4995         HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
4996         ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
4997         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4998         HDA_BIND_MUTE("Speaker Playback Switch", 0x09, 2, HDA_INPUT),
4999         { } /* end */
5000 };
5001
5002 /* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks.  Note that current
5003  * versions of the ALC260 don't act on requests to enable mic bias from NID
5004  * 0x0f (used to drive the headphone jack in these laptops).  The ALC260
5005  * datasheet doesn't mention this restriction.  At this stage it's not clear
5006  * whether this behaviour is intentional or is a hardware bug in chip
5007  * revisions available in early 2006.  Therefore for now allow the
5008  * "Headphone Jack Mode" control to span all choices, but if it turns out
5009  * that the lack of mic bias for this NID is intentional we could change the
5010  * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
5011  *
5012  * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
5013  * don't appear to make the mic bias available from the "line" jack, even
5014  * though the NID used for this jack (0x14) can supply it.  The theory is
5015  * that perhaps Acer have included blocking capacitors between the ALC260
5016  * and the output jack.  If this turns out to be the case for all such
5017  * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
5018  * to ALC_PIN_DIR_INOUT_NOMICBIAS.
5019  *
5020  * The C20x Tablet series have a mono internal speaker which is controlled
5021  * via the chip's Mono sum widget and pin complex, so include the necessary
5022  * controls for such models.  On models without a "mono speaker" the control
5023  * won't do anything.
5024  */
5025 static struct snd_kcontrol_new alc260_acer_mixer[] = {
5026         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5027         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
5028         ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
5029         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
5030                               HDA_OUTPUT),
5031         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2,
5032                            HDA_INPUT),
5033         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5034         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5035         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
5036         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
5037         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
5038         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
5039         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
5040         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
5041         { } /* end */
5042 };
5043
5044 /* Maxdata Favorit 100XS: one output and one input (0x12) jack
5045  */
5046 static struct snd_kcontrol_new alc260_favorit100_mixer[] = {
5047         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5048         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
5049         ALC_PIN_MODE("Output Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
5050         HDA_CODEC_VOLUME("Line/Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
5051         HDA_CODEC_MUTE("Line/Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
5052         ALC_PIN_MODE("Line/Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
5053         { } /* end */
5054 };
5055
5056 /* Packard bell V7900  ALC260 pin usage: HP = 0x0f, Mic jack = 0x12,
5057  * Line In jack = 0x14, CD audio =  0x16, pc beep = 0x17.
5058  */
5059 static struct snd_kcontrol_new alc260_will_mixer[] = {
5060         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5061         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
5062         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
5063         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
5064         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
5065         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
5066         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
5067         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
5068         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5069         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5070         { } /* end */
5071 };
5072
5073 /* Replacer 672V ALC260 pin usage: Mic jack = 0x12,
5074  * Line In jack = 0x14, ATAPI Mic = 0x13, speaker = 0x0f.
5075  */
5076 static struct snd_kcontrol_new alc260_replacer_672v_mixer[] = {
5077         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5078         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
5079         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
5080         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
5081         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
5082         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x07, 0x1, HDA_INPUT),
5083         HDA_CODEC_MUTE("ATATI Mic Playback Switch", 0x07, 0x1, HDA_INPUT),
5084         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
5085         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
5086         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
5087         { } /* end */
5088 };
5089
5090 /*
5091  * initialization verbs
5092  */
5093 static struct hda_verb alc260_init_verbs[] = {
5094         /* Line In pin widget for input */
5095         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5096         /* CD pin widget for input */
5097         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5098         /* Mic1 (rear panel) pin widget for input and vref at 80% */
5099         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5100         /* Mic2 (front panel) pin widget for input and vref at 80% */
5101         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5102         /* LINE-2 is used for line-out in rear */
5103         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5104         /* select line-out */
5105         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
5106         /* LINE-OUT pin */
5107         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5108         /* enable HP */
5109         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5110         /* enable Mono */
5111         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5112         /* mute capture amp left and right */
5113         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5114         /* set connection select to line in (default select for this ADC) */
5115         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
5116         /* mute capture amp left and right */
5117         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5118         /* set connection select to line in (default select for this ADC) */
5119         {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
5120         /* set vol=0 Line-Out mixer amp left and right */
5121         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5122         /* unmute pin widget amp left and right (no gain on this amp) */
5123         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5124         /* set vol=0 HP mixer amp left and right */
5125         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5126         /* unmute pin widget amp left and right (no gain on this amp) */
5127         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5128         /* set vol=0 Mono mixer amp left and right */
5129         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5130         /* unmute pin widget amp left and right (no gain on this amp) */
5131         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5132         /* unmute LINE-2 out pin */
5133         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5134         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
5135          * Line In 2 = 0x03
5136          */
5137         /* mute analog inputs */
5138         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5139         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5140         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5141         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5142         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5143         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
5144         /* mute Front out path */
5145         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5146         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5147         /* mute Headphone out path */
5148         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5149         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5150         /* mute Mono out path */
5151         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5152         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5153         { }
5154 };
5155
5156 #if 0 /* should be identical with alc260_init_verbs? */
5157 static struct hda_verb alc260_hp_init_verbs[] = {
5158         /* Headphone and output */
5159         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
5160         /* mono output */
5161         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5162         /* Mic1 (rear panel) pin widget for input and vref at 80% */
5163         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
5164         /* Mic2 (front panel) pin widget for input and vref at 80% */
5165         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
5166         /* Line In pin widget for input */
5167         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
5168         /* Line-2 pin widget for output */
5169         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5170         /* CD pin widget for input */
5171         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
5172         /* unmute amp left and right */
5173         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
5174         /* set connection select to line in (default select for this ADC) */
5175         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
5176         /* unmute Line-Out mixer amp left and right (volume = 0) */
5177         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5178         /* mute pin widget amp left and right (no gain on this amp) */
5179         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5180         /* unmute HP mixer amp left and right (volume = 0) */
5181         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5182         /* mute pin widget amp left and right (no gain on this amp) */
5183         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5184         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
5185          * Line In 2 = 0x03
5186          */
5187         /* mute analog inputs */
5188         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5189         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5190         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5191         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5192         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5193         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
5194         /* Unmute Front out path */
5195         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5196         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5197         /* Unmute Headphone out path */
5198         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5199         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5200         /* Unmute Mono out path */
5201         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5202         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5203         { }
5204 };
5205 #endif
5206
5207 static struct hda_verb alc260_hp_3013_init_verbs[] = {
5208         /* Line out and output */
5209         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5210         /* mono output */
5211         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
5212         /* Mic1 (rear panel) pin widget for input and vref at 80% */
5213         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
5214         /* Mic2 (front panel) pin widget for input and vref at 80% */
5215         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
5216         /* Line In pin widget for input */
5217         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
5218         /* Headphone pin widget for output */
5219         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
5220         /* CD pin widget for input */
5221         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
5222         /* unmute amp left and right */
5223         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
5224         /* set connection select to line in (default select for this ADC) */
5225         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
5226         /* unmute Line-Out mixer amp left and right (volume = 0) */
5227         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5228         /* mute pin widget amp left and right (no gain on this amp) */
5229         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5230         /* unmute HP mixer amp left and right (volume = 0) */
5231         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5232         /* mute pin widget amp left and right (no gain on this amp) */
5233         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5234         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
5235          * Line In 2 = 0x03
5236          */
5237         /* mute analog inputs */
5238         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5239         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5240         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5241         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5242         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5243         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
5244         /* Unmute Front out path */
5245         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5246         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5247         /* Unmute Headphone out path */
5248         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5249         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5250         /* Unmute Mono out path */
5251         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5252         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5253         { }
5254 };
5255
5256 /* Initialisation sequence for ALC260 as configured in Fujitsu S702x
5257  * laptops.  ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
5258  * audio = 0x16, internal speaker = 0x10.
5259  */
5260 static struct hda_verb alc260_fujitsu_init_verbs[] = {
5261         /* Disable all GPIOs */
5262         {0x01, AC_VERB_SET_GPIO_MASK, 0},
5263         /* Internal speaker is connected to headphone pin */
5264         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5265         /* Headphone/Line-out jack connects to Line1 pin; make it an output */
5266         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5267         /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
5268         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5269         /* Ensure all other unused pins are disabled and muted. */
5270         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5271         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5272         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5273         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5274         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5275         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5276         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5277         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5278
5279         /* Disable digital (SPDIF) pins */
5280         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5281         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5282
5283         /* Ensure Line1 pin widget takes its input from the OUT1 sum bus
5284          * when acting as an output.
5285          */
5286         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5287
5288         /* Start with output sum widgets muted and their output gains at min */
5289         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5290         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5291         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5292         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5293         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5294         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5295         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5296         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5297         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5298
5299         /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
5300         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5301         /* Unmute Line1 pin widget output buffer since it starts as an output.
5302          * If the pin mode is changed by the user the pin mode control will
5303          * take care of enabling the pin's input/output buffers as needed.
5304          * Therefore there's no need to enable the input buffer at this
5305          * stage.
5306          */
5307         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5308         /* Unmute input buffer of pin widget used for Line-in (no equiv
5309          * mixer ctrl)
5310          */
5311         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5312
5313         /* Mute capture amp left and right */
5314         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5315         /* Set ADC connection select to match default mixer setting - line
5316          * in (on mic1 pin)
5317          */
5318         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5319
5320         /* Do the same for the second ADC: mute capture input amp and
5321          * set ADC connection to line in (on mic1 pin)
5322          */
5323         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5324         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5325
5326         /* Mute all inputs to mixer widget (even unconnected ones) */
5327         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5328         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5329         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5330         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5331         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5332         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5333         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5334         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5335
5336         { }
5337 };
5338
5339 /* Initialisation sequence for ALC260 as configured in Acer TravelMate and
5340  * similar laptops (adapted from Fujitsu init verbs).
5341  */
5342 static struct hda_verb alc260_acer_init_verbs[] = {
5343         /* On TravelMate laptops, GPIO 0 enables the internal speaker and
5344          * the headphone jack.  Turn this on and rely on the standard mute
5345          * methods whenever the user wants to turn these outputs off.
5346          */
5347         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5348         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5349         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5350         /* Internal speaker/Headphone jack is connected to Line-out pin */
5351         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5352         /* Internal microphone/Mic jack is connected to Mic1 pin */
5353         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
5354         /* Line In jack is connected to Line1 pin */
5355         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5356         /* Some Acers (eg: C20x Tablets) use Mono pin for internal speaker */
5357         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5358         /* Ensure all other unused pins are disabled and muted. */
5359         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5360         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5361         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5362         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5363         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5364         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5365         /* Disable digital (SPDIF) pins */
5366         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5367         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5368
5369         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
5370          * bus when acting as outputs.
5371          */
5372         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5373         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5374
5375         /* Start with output sum widgets muted and their output gains at min */
5376         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5377         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5378         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5379         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5380         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5381         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5382         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5383         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5384         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5385
5386         /* Unmute Line-out pin widget amp left and right
5387          * (no equiv mixer ctrl)
5388          */
5389         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5390         /* Unmute mono pin widget amp output (no equiv mixer ctrl) */
5391         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5392         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
5393          * inputs. If the pin mode is changed by the user the pin mode control
5394          * will take care of enabling the pin's input/output buffers as needed.
5395          * Therefore there's no need to enable the input buffer at this
5396          * stage.
5397          */
5398         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5399         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5400
5401         /* Mute capture amp left and right */
5402         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5403         /* Set ADC connection select to match default mixer setting - mic
5404          * (on mic1 pin)
5405          */
5406         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5407
5408         /* Do similar with the second ADC: mute capture input amp and
5409          * set ADC connection to mic to match ALSA's default state.
5410          */
5411         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5412         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5413
5414         /* Mute all inputs to mixer widget (even unconnected ones) */
5415         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5416         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5417         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5418         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5419         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5420         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5421         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5422         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5423
5424         { }
5425 };
5426
5427 /* Initialisation sequence for Maxdata Favorit 100XS
5428  * (adapted from Acer init verbs).
5429  */
5430 static struct hda_verb alc260_favorit100_init_verbs[] = {
5431         /* GPIO 0 enables the output jack.
5432          * Turn this on and rely on the standard mute
5433          * methods whenever the user wants to turn these outputs off.
5434          */
5435         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5436         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5437         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5438         /* Line/Mic input jack is connected to Mic1 pin */
5439         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
5440         /* Ensure all other unused pins are disabled and muted. */
5441         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5442         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5443         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5444         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5445         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5446         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5447         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5448         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5449         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5450         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5451         /* Disable digital (SPDIF) pins */
5452         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5453         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5454
5455         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
5456          * bus when acting as outputs.
5457          */
5458         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5459         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5460
5461         /* Start with output sum widgets muted and their output gains at min */
5462         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5463         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5464         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5465         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5466         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5467         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5468         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5469         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5470         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5471
5472         /* Unmute Line-out pin widget amp left and right
5473          * (no equiv mixer ctrl)
5474          */
5475         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5476         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
5477          * inputs. If the pin mode is changed by the user the pin mode control
5478          * will take care of enabling the pin's input/output buffers as needed.
5479          * Therefore there's no need to enable the input buffer at this
5480          * stage.
5481          */
5482         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5483
5484         /* Mute capture amp left and right */
5485         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5486         /* Set ADC connection select to match default mixer setting - mic
5487          * (on mic1 pin)
5488          */
5489         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5490
5491         /* Do similar with the second ADC: mute capture input amp and
5492          * set ADC connection to mic to match ALSA's default state.
5493          */
5494         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5495         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5496
5497         /* Mute all inputs to mixer widget (even unconnected ones) */
5498         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5499         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5500         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5501         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5502         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5503         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5504         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5505         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5506
5507         { }
5508 };
5509
5510 static struct hda_verb alc260_will_verbs[] = {
5511         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5512         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x00},
5513         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
5514         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
5515         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
5516         {0x1a, AC_VERB_SET_PROC_COEF, 0x3040},
5517         {}
5518 };
5519
5520 static struct hda_verb alc260_replacer_672v_verbs[] = {
5521         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
5522         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
5523         {0x1a, AC_VERB_SET_PROC_COEF, 0x3050},
5524
5525         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5526         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5527         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5528
5529         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5530         {}
5531 };
5532
5533 /* toggle speaker-output according to the hp-jack state */
5534 static void alc260_replacer_672v_automute(struct hda_codec *codec)
5535 {
5536         unsigned int present;
5537
5538         /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
5539         present = snd_hda_codec_read(codec, 0x0f, 0,
5540                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5541         if (present) {
5542                 snd_hda_codec_write_cache(codec, 0x01, 0,
5543                                           AC_VERB_SET_GPIO_DATA, 1);
5544                 snd_hda_codec_write_cache(codec, 0x0f, 0,
5545                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
5546                                           PIN_HP);
5547         } else {
5548                 snd_hda_codec_write_cache(codec, 0x01, 0,
5549                                           AC_VERB_SET_GPIO_DATA, 0);
5550                 snd_hda_codec_write_cache(codec, 0x0f, 0,
5551                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
5552                                           PIN_OUT);
5553         }
5554 }
5555
5556 static void alc260_replacer_672v_unsol_event(struct hda_codec *codec,
5557                                        unsigned int res)
5558 {
5559         if ((res >> 26) == ALC880_HP_EVENT)
5560                 alc260_replacer_672v_automute(codec);
5561 }
5562
5563 static struct hda_verb alc260_hp_dc7600_verbs[] = {
5564         {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
5565         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
5566         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5567         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5568         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5569         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5570         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5571         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5572         {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5573         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5574         {}
5575 };
5576
5577 /* Test configuration for debugging, modelled after the ALC880 test
5578  * configuration.
5579  */
5580 #ifdef CONFIG_SND_DEBUG
5581 static hda_nid_t alc260_test_dac_nids[1] = {
5582         0x02,
5583 };
5584 static hda_nid_t alc260_test_adc_nids[2] = {
5585         0x04, 0x05,
5586 };
5587 /* For testing the ALC260, each input MUX needs its own definition since
5588  * the signal assignments are different.  This assumes that the first ADC
5589  * is NID 0x04.
5590  */
5591 static struct hda_input_mux alc260_test_capture_sources[2] = {
5592         {
5593                 .num_items = 7,
5594                 .items = {
5595                         { "MIC1 pin", 0x0 },
5596                         { "MIC2 pin", 0x1 },
5597                         { "LINE1 pin", 0x2 },
5598                         { "LINE2 pin", 0x3 },
5599                         { "CD pin", 0x4 },
5600                         { "LINE-OUT pin", 0x5 },
5601                         { "HP-OUT pin", 0x6 },
5602                 },
5603         },
5604         {
5605                 .num_items = 8,
5606                 .items = {
5607                         { "MIC1 pin", 0x0 },
5608                         { "MIC2 pin", 0x1 },
5609                         { "LINE1 pin", 0x2 },
5610                         { "LINE2 pin", 0x3 },
5611                         { "CD pin", 0x4 },
5612                         { "Mixer", 0x5 },
5613                         { "LINE-OUT pin", 0x6 },
5614                         { "HP-OUT pin", 0x7 },
5615                 },
5616         },
5617 };
5618 static struct snd_kcontrol_new alc260_test_mixer[] = {
5619         /* Output driver widgets */
5620         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
5621         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
5622         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5623         HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
5624         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5625         HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),
5626
5627         /* Modes for retasking pin widgets
5628          * Note: the ALC260 doesn't seem to act on requests to enable mic
5629          * bias from NIDs 0x0f and 0x10.  The ALC260 datasheet doesn't
5630          * mention this restriction.  At this stage it's not clear whether
5631          * this behaviour is intentional or is a hardware bug in chip
5632          * revisions available at least up until early 2006.  Therefore for
5633          * now allow the "HP-OUT" and "LINE-OUT" Mode controls to span all
5634          * choices, but if it turns out that the lack of mic bias for these
5635          * NIDs is intentional we could change their modes from
5636          * ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
5637          */
5638         ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
5639         ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
5640         ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
5641         ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
5642         ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
5643         ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),
5644
5645         /* Loopback mixer controls */
5646         HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
5647         HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
5648         HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
5649         HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
5650         HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
5651         HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
5652         HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
5653         HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
5654         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5655         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5656         HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
5657         HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
5658         HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
5659         HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
5660
5661         /* Controls for GPIO pins, assuming they are configured as outputs */
5662         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
5663         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
5664         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
5665         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
5666
5667         /* Switches to allow the digital IO pins to be enabled.  The datasheet
5668          * is ambigious as to which NID is which; testing on laptops which
5669          * make this output available should provide clarification.
5670          */
5671         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
5672         ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),
5673
5674         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
5675          * this output to turn on an external amplifier.
5676          */
5677         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
5678         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
5679
5680         { } /* end */
5681 };
5682 static struct hda_verb alc260_test_init_verbs[] = {
5683         /* Enable all GPIOs as outputs with an initial value of 0 */
5684         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
5685         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5686         {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
5687
5688         /* Enable retasking pins as output, initially without power amp */
5689         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5690         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5691         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5692         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5693         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5694         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5695
5696         /* Disable digital (SPDIF) pins initially, but users can enable
5697          * them via a mixer switch.  In the case of SPDIF-out, this initverb
5698          * payload also sets the generation to 0, output to be in "consumer"
5699          * PCM format, copyright asserted, no pre-emphasis and no validity
5700          * control.
5701          */
5702         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5703         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5704
5705         /* Ensure mic1, mic2, line1 and line2 pin widgets take input from the
5706          * OUT1 sum bus when acting as an output.
5707          */
5708         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5709         {0x0c, AC_VERB_SET_CONNECT_SEL, 0},
5710         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5711         {0x0e, AC_VERB_SET_CONNECT_SEL, 0},
5712
5713         /* Start with output sum widgets muted and their output gains at min */
5714         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5715         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5716         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5717         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5718         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5719         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5720         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5721         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5722         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5723
5724         /* Unmute retasking pin widget output buffers since the default
5725          * state appears to be output.  As the pin mode is changed by the
5726          * user the pin mode control will take care of enabling the pin's
5727          * input/output buffers as needed.
5728          */
5729         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5730         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5731         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5732         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5733         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5734         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5735         /* Also unmute the mono-out pin widget */
5736         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5737
5738         /* Mute capture amp left and right */
5739         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5740         /* Set ADC connection select to match default mixer setting (mic1
5741          * pin)
5742          */
5743         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5744
5745         /* Do the same for the second ADC: mute capture input amp and
5746          * set ADC connection to mic1 pin
5747          */
5748         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5749         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5750
5751         /* Mute all inputs to mixer widget (even unconnected ones) */
5752         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5753         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5754         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5755         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5756         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5757         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5758         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5759         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5760
5761         { }
5762 };
5763 #endif
5764
5765 #define alc260_pcm_analog_playback      alc880_pcm_analog_alt_playback
5766 #define alc260_pcm_analog_capture       alc880_pcm_analog_capture
5767
5768 #define alc260_pcm_digital_playback     alc880_pcm_digital_playback
5769 #define alc260_pcm_digital_capture      alc880_pcm_digital_capture
5770
5771 /*
5772  * for BIOS auto-configuration
5773  */
5774
5775 static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
5776                                         const char *pfx, int *vol_bits)
5777 {
5778         hda_nid_t nid_vol;
5779         unsigned long vol_val, sw_val;
5780         char name[32];
5781         int err;
5782
5783         if (nid >= 0x0f && nid < 0x11) {
5784                 nid_vol = nid - 0x7;
5785                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
5786                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
5787         } else if (nid == 0x11) {
5788                 nid_vol = nid - 0x7;
5789                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT);
5790                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
5791         } else if (nid >= 0x12 && nid <= 0x15) {
5792                 nid_vol = 0x08;
5793                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
5794                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
5795         } else
5796                 return 0; /* N/A */
5797
5798         if (!(*vol_bits & (1 << nid_vol))) {
5799                 /* first control for the volume widget */
5800                 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
5801                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name, vol_val);
5802                 if (err < 0)
5803                         return err;
5804                 *vol_bits |= (1 << nid_vol);
5805         }
5806         snprintf(name, sizeof(name), "%s Playback Switch", pfx);
5807         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, sw_val);
5808         if (err < 0)
5809                 return err;
5810         return 1;
5811 }
5812
5813 /* add playback controls from the parsed DAC table */
5814 static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
5815                                              const struct auto_pin_cfg *cfg)
5816 {
5817         hda_nid_t nid;
5818         int err;
5819         int vols = 0;
5820
5821         spec->multiout.num_dacs = 1;
5822         spec->multiout.dac_nids = spec->private_dac_nids;
5823         spec->multiout.dac_nids[0] = 0x02;
5824
5825         nid = cfg->line_out_pins[0];
5826         if (nid) {
5827                 err = alc260_add_playback_controls(spec, nid, "Front", &vols);
5828                 if (err < 0)
5829                         return err;
5830         }
5831
5832         nid = cfg->speaker_pins[0];
5833         if (nid) {
5834                 err = alc260_add_playback_controls(spec, nid, "Speaker", &vols);
5835                 if (err < 0)
5836                         return err;
5837         }
5838
5839         nid = cfg->hp_pins[0];
5840         if (nid) {
5841                 err = alc260_add_playback_controls(spec, nid, "Headphone",
5842                                                    &vols);
5843                 if (err < 0)
5844                         return err;
5845         }
5846         return 0;
5847 }
5848
5849 /* create playback/capture controls for input pins */
5850 static int alc260_auto_create_analog_input_ctls(struct alc_spec *spec,
5851                                                 const struct auto_pin_cfg *cfg)
5852 {
5853         struct hda_input_mux *imux = &spec->private_imux[0];
5854         int i, err, idx;
5855
5856         for (i = 0; i < AUTO_PIN_LAST; i++) {
5857                 if (cfg->input_pins[i] >= 0x12) {
5858                         idx = cfg->input_pins[i] - 0x12;
5859                         err = new_analog_input(spec, cfg->input_pins[i],
5860                                                auto_pin_cfg_labels[i], idx,
5861                                                0x07);
5862                         if (err < 0)
5863                                 return err;
5864                         imux->items[imux->num_items].label =
5865                                 auto_pin_cfg_labels[i];
5866                         imux->items[imux->num_items].index = idx;
5867                         imux->num_items++;
5868                 }
5869                 if (cfg->input_pins[i] >= 0x0f && cfg->input_pins[i] <= 0x10){
5870                         idx = cfg->input_pins[i] - 0x09;
5871                         err = new_analog_input(spec, cfg->input_pins[i],
5872                                                auto_pin_cfg_labels[i], idx,
5873                                                0x07);
5874                         if (err < 0)
5875                                 return err;
5876                         imux->items[imux->num_items].label =
5877                                 auto_pin_cfg_labels[i];
5878                         imux->items[imux->num_items].index = idx;
5879                         imux->num_items++;
5880                 }
5881         }
5882         return 0;
5883 }
5884
5885 static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
5886                                               hda_nid_t nid, int pin_type,
5887                                               int sel_idx)
5888 {
5889         alc_set_pin_output(codec, nid, pin_type);
5890         /* need the manual connection? */
5891         if (nid >= 0x12) {
5892                 int idx = nid - 0x12;
5893                 snd_hda_codec_write(codec, idx + 0x0b, 0,
5894                                     AC_VERB_SET_CONNECT_SEL, sel_idx);
5895         }
5896 }
5897
5898 static void alc260_auto_init_multi_out(struct hda_codec *codec)
5899 {
5900         struct alc_spec *spec = codec->spec;
5901         hda_nid_t nid;
5902
5903         nid = spec->autocfg.line_out_pins[0];
5904         if (nid) {
5905                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
5906                 alc260_auto_set_output_and_unmute(codec, nid, pin_type, 0);
5907         }
5908
5909         nid = spec->autocfg.speaker_pins[0];
5910         if (nid)
5911                 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
5912
5913         nid = spec->autocfg.hp_pins[0];
5914         if (nid)
5915                 alc260_auto_set_output_and_unmute(codec, nid, PIN_HP, 0);
5916 }
5917
5918 #define ALC260_PIN_CD_NID               0x16
5919 static void alc260_auto_init_analog_input(struct hda_codec *codec)
5920 {
5921         struct alc_spec *spec = codec->spec;
5922         int i;
5923
5924         for (i = 0; i < AUTO_PIN_LAST; i++) {
5925                 hda_nid_t nid = spec->autocfg.input_pins[i];
5926                 if (nid >= 0x12) {
5927                         alc_set_input_pin(codec, nid, i);
5928                         if (nid != ALC260_PIN_CD_NID &&
5929                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
5930                                 snd_hda_codec_write(codec, nid, 0,
5931                                                     AC_VERB_SET_AMP_GAIN_MUTE,
5932                                                     AMP_OUT_MUTE);
5933                 }
5934         }
5935 }
5936
5937 /*
5938  * generic initialization of ADC, input mixers and output mixers
5939  */
5940 static struct hda_verb alc260_volume_init_verbs[] = {
5941         /*
5942          * Unmute ADC0-1 and set the default input to mic-in
5943          */
5944         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5945         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5946         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5947         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5948
5949         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5950          * mixer widget
5951          * Note: PASD motherboards uses the Line In 2 as the input for
5952          * front panel mic (mic 2)
5953          */
5954         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
5955         /* mute analog inputs */
5956         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5957         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5958         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5959         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5960         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5961
5962         /*
5963          * Set up output mixers (0x08 - 0x0a)
5964          */
5965         /* set vol=0 to output mixers */
5966         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5967         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5968         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5969         /* set up input amps for analog loopback */
5970         /* Amp Indices: DAC = 0, mixer = 1 */
5971         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5972         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5973         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5974         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5975         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5976         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5977
5978         { }
5979 };
5980
5981 static int alc260_parse_auto_config(struct hda_codec *codec)
5982 {
5983         struct alc_spec *spec = codec->spec;
5984         int err;
5985         static hda_nid_t alc260_ignore[] = { 0x17, 0 };
5986
5987         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
5988                                            alc260_ignore);
5989         if (err < 0)
5990                 return err;
5991         err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg);
5992         if (err < 0)
5993                 return err;
5994         if (!spec->kctls.list)
5995                 return 0; /* can't find valid BIOS pin config */
5996         err = alc260_auto_create_analog_input_ctls(spec, &spec->autocfg);
5997         if (err < 0)
5998                 return err;
5999
6000         spec->multiout.max_channels = 2;
6001
6002         if (spec->autocfg.dig_outs)
6003                 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
6004         if (spec->kctls.list)
6005                 add_mixer(spec, spec->kctls.list);
6006
6007         add_verb(spec, alc260_volume_init_verbs);
6008
6009         spec->num_mux_defs = 1;
6010         spec->input_mux = &spec->private_imux[0];
6011
6012         alc_ssid_check(codec, 0x10, 0x15, 0x0f);
6013
6014         return 1;
6015 }
6016
6017 /* additional initialization for auto-configuration model */
6018 static void alc260_auto_init(struct hda_codec *codec)
6019 {
6020         struct alc_spec *spec = codec->spec;
6021         alc260_auto_init_multi_out(codec);
6022         alc260_auto_init_analog_input(codec);
6023         if (spec->unsol_event)
6024                 alc_inithook(codec);
6025 }
6026
6027 #ifdef CONFIG_SND_HDA_POWER_SAVE
6028 static struct hda_amp_list alc260_loopbacks[] = {
6029         { 0x07, HDA_INPUT, 0 },
6030         { 0x07, HDA_INPUT, 1 },
6031         { 0x07, HDA_INPUT, 2 },
6032         { 0x07, HDA_INPUT, 3 },
6033         { 0x07, HDA_INPUT, 4 },
6034         { } /* end */
6035 };
6036 #endif
6037
6038 /*
6039  * ALC260 configurations
6040  */
6041 static const char *alc260_models[ALC260_MODEL_LAST] = {
6042         [ALC260_BASIC]          = "basic",
6043         [ALC260_HP]             = "hp",
6044         [ALC260_HP_3013]        = "hp-3013",
6045         [ALC260_HP_DC7600]      = "hp-dc7600",
6046         [ALC260_FUJITSU_S702X]  = "fujitsu",
6047         [ALC260_ACER]           = "acer",
6048         [ALC260_WILL]           = "will",
6049         [ALC260_REPLACER_672V]  = "replacer",
6050         [ALC260_FAVORIT100]     = "favorit100",
6051 #ifdef CONFIG_SND_DEBUG
6052         [ALC260_TEST]           = "test",
6053 #endif
6054         [ALC260_AUTO]           = "auto",
6055 };
6056
6057 static struct snd_pci_quirk alc260_cfg_tbl[] = {
6058         SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER),
6059         SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
6060         SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FAVORIT100),
6061         SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
6062         SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_HP_3013),
6063         SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
6064         SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP_3013),
6065         SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_DC7600),
6066         SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
6067         SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
6068         SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP),
6069         SND_PCI_QUIRK(0x103c, 0x3016, "HP", ALC260_HP),
6070         SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_BASIC),
6071         SND_PCI_QUIRK(0x104d, 0x81cc, "Sony VAIO", ALC260_BASIC),
6072         SND_PCI_QUIRK(0x104d, 0x81cd, "Sony VAIO", ALC260_BASIC),
6073         SND_PCI_QUIRK(0x10cf, 0x1326, "Fujitsu S702X", ALC260_FUJITSU_S702X),
6074         SND_PCI_QUIRK(0x152d, 0x0729, "CTL U553W", ALC260_BASIC),
6075         SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_REPLACER_672V),
6076         SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_WILL),
6077         {}
6078 };
6079
6080 static struct alc_config_preset alc260_presets[] = {
6081         [ALC260_BASIC] = {
6082                 .mixers = { alc260_base_output_mixer,
6083                             alc260_input_mixer },
6084                 .init_verbs = { alc260_init_verbs },
6085                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6086                 .dac_nids = alc260_dac_nids,
6087                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
6088                 .adc_nids = alc260_adc_nids,
6089                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6090                 .channel_mode = alc260_modes,
6091                 .input_mux = &alc260_capture_source,
6092         },
6093         [ALC260_HP] = {
6094                 .mixers = { alc260_hp_output_mixer,
6095                             alc260_input_mixer },
6096                 .init_verbs = { alc260_init_verbs,
6097                                 alc260_hp_unsol_verbs },
6098                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6099                 .dac_nids = alc260_dac_nids,
6100                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
6101                 .adc_nids = alc260_adc_nids_alt,
6102                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6103                 .channel_mode = alc260_modes,
6104                 .input_mux = &alc260_capture_source,
6105                 .unsol_event = alc260_hp_unsol_event,
6106                 .init_hook = alc260_hp_automute,
6107         },
6108         [ALC260_HP_DC7600] = {
6109                 .mixers = { alc260_hp_dc7600_mixer,
6110                             alc260_input_mixer },
6111                 .init_verbs = { alc260_init_verbs,
6112                                 alc260_hp_dc7600_verbs },
6113                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6114                 .dac_nids = alc260_dac_nids,
6115                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
6116                 .adc_nids = alc260_adc_nids_alt,
6117                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6118                 .channel_mode = alc260_modes,
6119                 .input_mux = &alc260_capture_source,
6120                 .unsol_event = alc260_hp_3012_unsol_event,
6121                 .init_hook = alc260_hp_3012_automute,
6122         },
6123         [ALC260_HP_3013] = {
6124                 .mixers = { alc260_hp_3013_mixer,
6125                             alc260_input_mixer },
6126                 .init_verbs = { alc260_hp_3013_init_verbs,
6127                                 alc260_hp_3013_unsol_verbs },
6128                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6129                 .dac_nids = alc260_dac_nids,
6130                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
6131                 .adc_nids = alc260_adc_nids_alt,
6132                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6133                 .channel_mode = alc260_modes,
6134                 .input_mux = &alc260_capture_source,
6135                 .unsol_event = alc260_hp_3013_unsol_event,
6136                 .init_hook = alc260_hp_3013_automute,
6137         },
6138         [ALC260_FUJITSU_S702X] = {
6139                 .mixers = { alc260_fujitsu_mixer },
6140                 .init_verbs = { alc260_fujitsu_init_verbs },
6141                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6142                 .dac_nids = alc260_dac_nids,
6143                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
6144                 .adc_nids = alc260_dual_adc_nids,
6145                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6146                 .channel_mode = alc260_modes,
6147                 .num_mux_defs = ARRAY_SIZE(alc260_fujitsu_capture_sources),
6148                 .input_mux = alc260_fujitsu_capture_sources,
6149         },
6150         [ALC260_ACER] = {
6151                 .mixers = { alc260_acer_mixer },
6152                 .init_verbs = { alc260_acer_init_verbs },
6153                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6154                 .dac_nids = alc260_dac_nids,
6155                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
6156                 .adc_nids = alc260_dual_adc_nids,
6157                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6158                 .channel_mode = alc260_modes,
6159                 .num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources),
6160                 .input_mux = alc260_acer_capture_sources,
6161         },
6162         [ALC260_FAVORIT100] = {
6163                 .mixers = { alc260_favorit100_mixer },
6164                 .init_verbs = { alc260_favorit100_init_verbs },
6165                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6166                 .dac_nids = alc260_dac_nids,
6167                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
6168                 .adc_nids = alc260_dual_adc_nids,
6169                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6170                 .channel_mode = alc260_modes,
6171                 .num_mux_defs = ARRAY_SIZE(alc260_favorit100_capture_sources),
6172                 .input_mux = alc260_favorit100_capture_sources,
6173         },
6174         [ALC260_WILL] = {
6175                 .mixers = { alc260_will_mixer },
6176                 .init_verbs = { alc260_init_verbs, alc260_will_verbs },
6177                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6178                 .dac_nids = alc260_dac_nids,
6179                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
6180                 .adc_nids = alc260_adc_nids,
6181                 .dig_out_nid = ALC260_DIGOUT_NID,
6182                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6183                 .channel_mode = alc260_modes,
6184                 .input_mux = &alc260_capture_source,
6185         },
6186         [ALC260_REPLACER_672V] = {
6187                 .mixers = { alc260_replacer_672v_mixer },
6188                 .init_verbs = { alc260_init_verbs, alc260_replacer_672v_verbs },
6189                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
6190                 .dac_nids = alc260_dac_nids,
6191                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
6192                 .adc_nids = alc260_adc_nids,
6193                 .dig_out_nid = ALC260_DIGOUT_NID,
6194                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6195                 .channel_mode = alc260_modes,
6196                 .input_mux = &alc260_capture_source,
6197                 .unsol_event = alc260_replacer_672v_unsol_event,
6198                 .init_hook = alc260_replacer_672v_automute,
6199         },
6200 #ifdef CONFIG_SND_DEBUG
6201         [ALC260_TEST] = {
6202                 .mixers = { alc260_test_mixer },
6203                 .init_verbs = { alc260_test_init_verbs },
6204                 .num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
6205                 .dac_nids = alc260_test_dac_nids,
6206                 .num_adc_nids = ARRAY_SIZE(alc260_test_adc_nids),
6207                 .adc_nids = alc260_test_adc_nids,
6208                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
6209                 .channel_mode = alc260_modes,
6210                 .num_mux_defs = ARRAY_SIZE(alc260_test_capture_sources),
6211                 .input_mux = alc260_test_capture_sources,
6212         },
6213 #endif
6214 };
6215
6216 static int patch_alc260(struct hda_codec *codec)
6217 {
6218         struct alc_spec *spec;
6219         int err, board_config;
6220
6221         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6222         if (spec == NULL)
6223                 return -ENOMEM;
6224
6225         codec->spec = spec;
6226
6227         board_config = snd_hda_check_board_config(codec, ALC260_MODEL_LAST,
6228                                                   alc260_models,
6229                                                   alc260_cfg_tbl);
6230         if (board_config < 0) {
6231                 snd_printd(KERN_INFO "hda_codec: Unknown model for %s, "
6232                            "trying auto-probe from BIOS...\n",
6233                            codec->chip_name);
6234                 board_config = ALC260_AUTO;
6235         }
6236
6237         if (board_config == ALC260_AUTO) {
6238                 /* automatic parse from the BIOS config */
6239                 err = alc260_parse_auto_config(codec);
6240                 if (err < 0) {
6241                         alc_free(codec);
6242                         return err;
6243                 } else if (!err) {
6244                         printk(KERN_INFO
6245                                "hda_codec: Cannot set up configuration "
6246                                "from BIOS.  Using base mode...\n");
6247                         board_config = ALC260_BASIC;
6248                 }
6249         }
6250
6251         err = snd_hda_attach_beep_device(codec, 0x1);
6252         if (err < 0) {
6253                 alc_free(codec);
6254                 return err;
6255         }
6256
6257         if (board_config != ALC260_AUTO)
6258                 setup_preset(spec, &alc260_presets[board_config]);
6259
6260         spec->stream_analog_playback = &alc260_pcm_analog_playback;
6261         spec->stream_analog_capture = &alc260_pcm_analog_capture;
6262
6263         spec->stream_digital_playback = &alc260_pcm_digital_playback;
6264         spec->stream_digital_capture = &alc260_pcm_digital_capture;
6265
6266         if (!spec->adc_nids && spec->input_mux) {
6267                 /* check whether NID 0x04 is valid */
6268                 unsigned int wcap = get_wcaps(codec, 0x04);
6269                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
6270                 /* get type */
6271                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
6272                         spec->adc_nids = alc260_adc_nids_alt;
6273                         spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
6274                 } else {
6275                         spec->adc_nids = alc260_adc_nids;
6276                         spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
6277                 }
6278         }
6279         set_capture_mixer(spec);
6280         set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
6281
6282         spec->vmaster_nid = 0x08;
6283
6284         codec->patch_ops = alc_patch_ops;
6285         if (board_config == ALC260_AUTO)
6286                 spec->init_hook = alc260_auto_init;
6287 #ifdef CONFIG_SND_HDA_POWER_SAVE
6288         if (!spec->loopback.amplist)
6289                 spec->loopback.amplist = alc260_loopbacks;
6290 #endif
6291         codec->proc_widget_hook = print_realtek_coef;
6292
6293         return 0;
6294 }
6295
6296
6297 /*
6298  * ALC882 support
6299  *
6300  * ALC882 is almost identical with ALC880 but has cleaner and more flexible
6301  * configuration.  Each pin widget can choose any input DACs and a mixer.
6302  * Each ADC is connected from a mixer of all inputs.  This makes possible
6303  * 6-channel independent captures.
6304  *
6305  * In addition, an independent DAC for the multi-playback (not used in this
6306  * driver yet).
6307  */
6308 #define ALC882_DIGOUT_NID       0x06
6309 #define ALC882_DIGIN_NID        0x0a
6310
6311 static struct hda_channel_mode alc882_ch_modes[1] = {
6312         { 8, NULL }
6313 };
6314
6315 static hda_nid_t alc882_dac_nids[4] = {
6316         /* front, rear, clfe, rear_surr */
6317         0x02, 0x03, 0x04, 0x05
6318 };
6319
6320 /* identical with ALC880 */
6321 #define alc882_adc_nids         alc880_adc_nids
6322 #define alc882_adc_nids_alt     alc880_adc_nids_alt
6323
6324 static hda_nid_t alc882_capsrc_nids[3] = { 0x24, 0x23, 0x22 };
6325 static hda_nid_t alc882_capsrc_nids_alt[2] = { 0x23, 0x22 };
6326
6327 /* input MUX */
6328 /* FIXME: should be a matrix-type input source selection */
6329
6330 static struct hda_input_mux alc882_capture_source = {
6331         .num_items = 4,
6332         .items = {
6333                 { "Mic", 0x0 },
6334                 { "Front Mic", 0x1 },
6335                 { "Line", 0x2 },
6336                 { "CD", 0x4 },
6337         },
6338 };
6339
6340 static struct hda_input_mux mb5_capture_source = {
6341         .num_items = 3,
6342         .items = {
6343                 { "Mic", 0x1 },
6344                 { "Line", 0x2 },
6345                 { "CD", 0x4 },
6346         },
6347 };
6348
6349 /*
6350  * 2ch mode
6351  */
6352 static struct hda_verb alc882_3ST_ch2_init[] = {
6353         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6354         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6355         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6356         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6357         { } /* end */
6358 };
6359
6360 /*
6361  * 6ch mode
6362  */
6363 static struct hda_verb alc882_3ST_ch6_init[] = {
6364         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6365         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6366         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6367         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6368         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6369         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6370         { } /* end */
6371 };
6372
6373 static struct hda_channel_mode alc882_3ST_6ch_modes[2] = {
6374         { 2, alc882_3ST_ch2_init },
6375         { 6, alc882_3ST_ch6_init },
6376 };
6377
6378 /*
6379  * 6ch mode
6380  */
6381 static struct hda_verb alc882_sixstack_ch6_init[] = {
6382         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
6383         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6384         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6385         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6386         { } /* end */
6387 };
6388
6389 /*
6390  * 8ch mode
6391  */
6392 static struct hda_verb alc882_sixstack_ch8_init[] = {
6393         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6394         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6395         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6396         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6397         { } /* end */
6398 };
6399
6400 static struct hda_channel_mode alc882_sixstack_modes[2] = {
6401         { 6, alc882_sixstack_ch6_init },
6402         { 8, alc882_sixstack_ch8_init },
6403 };
6404
6405 /*
6406  * macbook pro ALC885 can switch LineIn to LineOut without losing Mic
6407  */
6408
6409 /*
6410  * 2ch mode
6411  */
6412 static struct hda_verb alc885_mbp_ch2_init[] = {
6413         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6414         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6415         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6416         { } /* end */
6417 };
6418
6419 /*
6420  * 6ch mode
6421  */
6422 static struct hda_verb alc885_mbp_ch6_init[] = {
6423         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6424         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6425         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6426         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6427         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6428         { } /* end */
6429 };
6430
6431 static struct hda_channel_mode alc885_mbp_6ch_modes[2] = {
6432         { 2, alc885_mbp_ch2_init },
6433         { 6, alc885_mbp_ch6_init },
6434 };
6435
6436 /*
6437  * 2ch
6438  * Speakers/Woofer/HP = Front
6439  * LineIn = Input
6440  */
6441 static struct hda_verb alc885_mb5_ch2_init[] = {
6442         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6443         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6444         { } /* end */
6445 };
6446
6447 /*
6448  * 6ch mode
6449  * Speakers/HP = Front
6450  * Woofer = LFE
6451  * LineIn = Surround
6452  */
6453 static struct hda_verb alc885_mb5_ch6_init[] = {
6454         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6455         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6456         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
6457         { } /* end */
6458 };
6459
6460 static struct hda_channel_mode alc885_mb5_6ch_modes[2] = {
6461         { 2, alc885_mb5_ch2_init },
6462         { 6, alc885_mb5_ch6_init },
6463 };
6464
6465 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
6466  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
6467  */
6468 static struct snd_kcontrol_new alc882_base_mixer[] = {
6469         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6470         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6471         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6472         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6473         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6474         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6475         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6476         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6477         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
6478         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
6479         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6480         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6481         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6482         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6483         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6484         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6485         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6486         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6487         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6488         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6489         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6490         { } /* end */
6491 };
6492
6493 static struct snd_kcontrol_new alc885_mbp3_mixer[] = {
6494         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
6495         HDA_BIND_MUTE   ("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
6496         HDA_CODEC_MUTE  ("Speaker Playback Switch", 0x14, 0x00, HDA_OUTPUT),
6497         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
6498         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6499         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6500         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
6501         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
6502         HDA_CODEC_VOLUME("Line Boost", 0x1a, 0x00, HDA_INPUT),
6503         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
6504         { } /* end */
6505 };
6506
6507 static struct snd_kcontrol_new alc885_mb5_mixer[] = {
6508         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
6509         HDA_BIND_MUTE   ("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
6510         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
6511         HDA_BIND_MUTE   ("Surround Playback Switch", 0x0d, 0x02, HDA_INPUT),
6512         HDA_CODEC_VOLUME("LFE Playback Volume", 0x0e, 0x00, HDA_OUTPUT),
6513         HDA_BIND_MUTE   ("LFE Playback Switch", 0x0e, 0x02, HDA_INPUT),
6514         HDA_CODEC_VOLUME("HP Playback Volume", 0x0f, 0x00, HDA_OUTPUT),
6515         HDA_BIND_MUTE   ("HP Playback Switch", 0x0f, 0x02, HDA_INPUT),
6516         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6517         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6518         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
6519         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
6520         HDA_CODEC_VOLUME("Line Boost", 0x15, 0x00, HDA_INPUT),
6521         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0x00, HDA_INPUT),
6522         { } /* end */
6523 };
6524
6525 static struct snd_kcontrol_new alc882_w2jc_mixer[] = {
6526         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6527         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6528         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6529         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6530         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6531         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6532         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6533         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6534         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6535         { } /* end */
6536 };
6537
6538 static struct snd_kcontrol_new alc882_targa_mixer[] = {
6539         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6540         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6541         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6542         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6543         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6544         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6545         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6546         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6547         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6548         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6549         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6550         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6551         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6552         { } /* end */
6553 };
6554
6555 /* Pin assignment: Front=0x14, HP = 0x15, Front = 0x16, ???
6556  *                 Front Mic=0x18, Line In = 0x1a, Line In = 0x1b, CD = 0x1c
6557  */
6558 static struct snd_kcontrol_new alc882_asus_a7j_mixer[] = {
6559         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6560         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6561         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6562         HDA_CODEC_MUTE("Mobile Front Playback Switch", 0x16, 0x0, HDA_OUTPUT),
6563         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6564         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6565         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6566         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6567         HDA_CODEC_VOLUME("Mobile Line Playback Volume", 0x0b, 0x03, HDA_INPUT),
6568         HDA_CODEC_MUTE("Mobile Line Playback Switch", 0x0b, 0x03, HDA_INPUT),
6569         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6570         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6571         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6572         { } /* end */
6573 };
6574
6575 static struct snd_kcontrol_new alc882_asus_a7m_mixer[] = {
6576         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6577         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6578         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6579         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6580         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6581         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6582         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6583         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6584         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6585         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6586         { } /* end */
6587 };
6588
6589 static struct snd_kcontrol_new alc882_chmode_mixer[] = {
6590         {
6591                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6592                 .name = "Channel Mode",
6593                 .info = alc_ch_mode_info,
6594                 .get = alc_ch_mode_get,
6595                 .put = alc_ch_mode_put,
6596         },
6597         { } /* end */
6598 };
6599
6600 static struct hda_verb alc882_init_verbs[] = {
6601         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6602         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6603         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6604         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6605         /* Rear mixer */
6606         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6607         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6608         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6609         /* CLFE mixer */
6610         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6611         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6612         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6613         /* Side mixer */
6614         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6615         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6616         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6617
6618         /* Front Pin: output 0 (0x0c) */
6619         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6620         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6621         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6622         /* Rear Pin: output 1 (0x0d) */
6623         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6624         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6625         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
6626         /* CLFE Pin: output 2 (0x0e) */
6627         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6628         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6629         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
6630         /* Side Pin: output 3 (0x0f) */
6631         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6632         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6633         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
6634         /* Mic (rear) pin: input vref at 80% */
6635         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6636         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6637         /* Front Mic pin: input vref at 80% */
6638         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6639         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6640         /* Line In pin: input */
6641         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6642         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6643         /* Line-2 In: Headphone output (output 0 - 0x0c) */
6644         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6645         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6646         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
6647         /* CD pin widget for input */
6648         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6649
6650         /* FIXME: use matrix-type input source selection */
6651         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6652         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6653         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6654         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6655         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6656         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6657         /* Input mixer2 */
6658         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6659         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6660         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6661         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6662         /* Input mixer3 */
6663         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6664         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6665         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6666         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6667         /* ADC1: mute amp left and right */
6668         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6669         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6670         /* ADC2: mute amp left and right */
6671         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6672         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6673         /* ADC3: mute amp left and right */
6674         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6675         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6676
6677         { }
6678 };
6679
6680 static struct hda_verb alc882_eapd_verbs[] = {
6681         /* change to EAPD mode */
6682         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
6683         {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
6684         { }
6685 };
6686
6687 /* Mac Pro test */
6688 static struct snd_kcontrol_new alc882_macpro_mixer[] = {
6689         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6690         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6691         HDA_CODEC_MUTE("Headphone Playback Switch", 0x18, 0x0, HDA_OUTPUT),
6692         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
6693         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
6694         /* FIXME: this looks suspicious...
6695         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x02, HDA_INPUT),
6696         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x02, HDA_INPUT),
6697         */
6698         { } /* end */
6699 };
6700
6701 static struct hda_verb alc882_macpro_init_verbs[] = {
6702         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6703         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6704         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6705         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6706         /* Front Pin: output 0 (0x0c) */
6707         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6708         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6709         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6710         /* Front Mic pin: input vref at 80% */
6711         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6712         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6713         /* Speaker:  output */
6714         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6715         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6716         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x04},
6717         /* Headphone output (output 0 - 0x0c) */
6718         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6719         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6720         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
6721
6722         /* FIXME: use matrix-type input source selection */
6723         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6724         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6725         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6726         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6727         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6728         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6729         /* Input mixer2 */
6730         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6731         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6732         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6733         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6734         /* Input mixer3 */
6735         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6736         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6737         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6738         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6739         /* ADC1: mute amp left and right */
6740         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6741         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6742         /* ADC2: mute amp left and right */
6743         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6744         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6745         /* ADC3: mute amp left and right */
6746         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6747         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6748
6749         { }
6750 };
6751
6752 /* Macbook 5,1 */
6753 static struct hda_verb alc885_mb5_init_verbs[] = {
6754         /* DACs */
6755         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6756         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6757         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6758         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6759         /* Front mixer */
6760         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6761         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6762         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6763         /* Surround mixer */
6764         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6765         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6766         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6767         /* LFE mixer */
6768         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6769         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6770         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6771         /* HP mixer */
6772         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6773         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6774         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6775         /* Front Pin (0x0c) */
6776         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x01},
6777         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6778         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
6779         /* LFE Pin (0x0e) */
6780         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x01},
6781         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6782         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x02},
6783         /* HP Pin (0x0f) */
6784         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6785         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6786         {0x14, AC_VERB_SET_CONNECT_SEL, 0x03},
6787         /* Front Mic pin: input vref at 80% */
6788         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6789         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6790         /* Line In pin */
6791         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6792         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6793
6794         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6795         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6796         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6797         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6798         { }
6799 };
6800
6801 /* Macbook Pro rev3 */
6802 static struct hda_verb alc885_mbp3_init_verbs[] = {
6803         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6804         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6805         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6806         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6807         /* Rear mixer */
6808         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6809         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6810         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6811         /* Front Pin: output 0 (0x0c) */
6812         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6813         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6814         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6815         /* HP Pin: output 0 (0x0d) */
6816         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},
6817         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6818         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6819         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6820         /* Mic (rear) pin: input vref at 80% */
6821         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6822         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6823         /* Front Mic pin: input vref at 80% */
6824         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6825         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6826         /* Line In pin: use output 1 when in LineOut mode */
6827         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6828         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6829         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
6830
6831         /* FIXME: use matrix-type input source selection */
6832         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6833         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6834         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6835         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6836         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6837         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6838         /* Input mixer2 */
6839         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6840         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6841         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6842         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6843         /* Input mixer3 */
6844         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6845         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6846         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6847         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6848         /* ADC1: mute amp left and right */
6849         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6850         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6851         /* ADC2: mute amp left and right */
6852         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6853         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6854         /* ADC3: mute amp left and right */
6855         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6856         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6857
6858         { }
6859 };
6860
6861 /* iMac 24 mixer. */
6862 static struct snd_kcontrol_new alc885_imac24_mixer[] = {
6863         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
6864         HDA_CODEC_MUTE("Master Playback Switch", 0x0c, 0x00, HDA_INPUT),
6865         { } /* end */
6866 };
6867
6868 /* iMac 24 init verbs. */
6869 static struct hda_verb alc885_imac24_init_verbs[] = {
6870         /* Internal speakers: output 0 (0x0c) */
6871         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6872         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6873         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
6874         /* Internal speakers: output 0 (0x0c) */
6875         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6876         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6877         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
6878         /* Headphone: output 0 (0x0c) */
6879         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6880         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6881         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6882         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6883         /* Front Mic: input vref at 80% */
6884         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6885         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6886         { }
6887 };
6888
6889 /* Toggle speaker-output according to the hp-jack state */
6890 static void alc885_imac24_automute_init_hook(struct hda_codec *codec)
6891 {
6892         struct alc_spec *spec = codec->spec;
6893
6894         spec->autocfg.hp_pins[0] = 0x14;
6895         spec->autocfg.speaker_pins[0] = 0x18;
6896         spec->autocfg.speaker_pins[1] = 0x1a;
6897         alc_automute_amp(codec);
6898 }
6899
6900 static void alc885_mbp3_init_hook(struct hda_codec *codec)
6901 {
6902         struct alc_spec *spec = codec->spec;
6903
6904         spec->autocfg.hp_pins[0] = 0x15;
6905         spec->autocfg.speaker_pins[0] = 0x14;
6906         alc_automute_amp(codec);
6907 }
6908
6909
6910 static struct hda_verb alc882_targa_verbs[] = {
6911         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6912         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6913
6914         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6915         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6916
6917         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6918         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6919         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6920
6921         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6922         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6923         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
6924         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
6925         { } /* end */
6926 };
6927
6928 /* toggle speaker-output according to the hp-jack state */
6929 static void alc882_targa_automute(struct hda_codec *codec)
6930 {
6931         struct alc_spec *spec = codec->spec;
6932         alc_automute_amp(codec);
6933         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
6934                                   spec->jack_present ? 1 : 3);
6935 }
6936
6937 static void alc882_targa_init_hook(struct hda_codec *codec)
6938 {
6939         struct alc_spec *spec = codec->spec;
6940
6941         spec->autocfg.hp_pins[0] = 0x14;
6942         spec->autocfg.speaker_pins[0] = 0x1b;
6943         alc882_targa_automute(codec);
6944 }
6945
6946 static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res)
6947 {
6948         if ((res >> 26) == ALC880_HP_EVENT)
6949                 alc882_targa_automute(codec);
6950 }
6951
6952 static struct hda_verb alc882_asus_a7j_verbs[] = {
6953         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6954         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6955
6956         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6957         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6958         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6959
6960         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6961         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6962         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6963
6964         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6965         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6966         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6967         { } /* end */
6968 };
6969
6970 static struct hda_verb alc882_asus_a7m_verbs[] = {
6971         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6972         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6973
6974         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6975         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6976         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6977
6978         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6979         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6980         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6981
6982         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6983         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6984         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6985         { } /* end */
6986 };
6987
6988 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
6989 {
6990         unsigned int gpiostate, gpiomask, gpiodir;
6991
6992         gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
6993                                        AC_VERB_GET_GPIO_DATA, 0);
6994
6995         if (!muted)
6996                 gpiostate |= (1 << pin);
6997         else
6998                 gpiostate &= ~(1 << pin);
6999
7000         gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
7001                                       AC_VERB_GET_GPIO_MASK, 0);
7002         gpiomask |= (1 << pin);
7003
7004         gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
7005                                      AC_VERB_GET_GPIO_DIRECTION, 0);
7006         gpiodir |= (1 << pin);
7007
7008
7009         snd_hda_codec_write(codec, codec->afg, 0,
7010                             AC_VERB_SET_GPIO_MASK, gpiomask);
7011         snd_hda_codec_write(codec, codec->afg, 0,
7012                             AC_VERB_SET_GPIO_DIRECTION, gpiodir);
7013
7014         msleep(1);
7015
7016         snd_hda_codec_write(codec, codec->afg, 0,
7017                             AC_VERB_SET_GPIO_DATA, gpiostate);
7018 }
7019
7020 /* set up GPIO at initialization */
7021 static void alc885_macpro_init_hook(struct hda_codec *codec)
7022 {
7023         alc882_gpio_mute(codec, 0, 0);
7024         alc882_gpio_mute(codec, 1, 0);
7025 }
7026
7027 /* set up GPIO and update auto-muting at initialization */
7028 static void alc885_imac24_init_hook(struct hda_codec *codec)
7029 {
7030         alc885_macpro_init_hook(codec);
7031         alc885_imac24_automute_init_hook(codec);
7032 }
7033
7034 /*
7035  * generic initialization of ADC, input mixers and output mixers
7036  */
7037 static struct hda_verb alc882_auto_init_verbs[] = {
7038         /*
7039          * Unmute ADC0-2 and set the default input to mic-in
7040          */
7041         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
7042         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7043         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7044         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7045         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7046         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7047
7048         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
7049          * mixer widget
7050          * Note: PASD motherboards uses the Line In 2 as the input for
7051          * front panel mic (mic 2)
7052          */
7053         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
7054         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7055         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7056         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7057         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7058         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7059
7060         /*
7061          * Set up output mixers (0x0c - 0x0f)
7062          */
7063         /* set vol=0 to output mixers */
7064         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7065         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7066         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7067         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7068         /* set up input amps for analog loopback */
7069         /* Amp Indices: DAC = 0, mixer = 1 */
7070         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7071         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7072         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7073         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7074         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7075         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7076         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7077         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7078         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7079         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
7080
7081         /* FIXME: use matrix-type input source selection */
7082         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7083         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
7084         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7085         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7086         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
7087         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
7088         /* Input mixer2 */
7089         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7090         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7091         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
7092         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
7093         /* Input mixer3 */
7094         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
7095         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
7096         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
7097         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
7098
7099         { }
7100 };
7101
7102 #ifdef CONFIG_SND_HDA_POWER_SAVE
7103 #define alc882_loopbacks        alc880_loopbacks
7104 #endif
7105
7106 /* pcm configuration: identical with ALC880 */
7107 #define alc882_pcm_analog_playback      alc880_pcm_analog_playback
7108 #define alc882_pcm_analog_capture       alc880_pcm_analog_capture
7109 #define alc882_pcm_digital_playback     alc880_pcm_digital_playback
7110 #define alc882_pcm_digital_capture      alc880_pcm_digital_capture
7111
7112 /*
7113  * configuration and preset
7114  */
7115 static const char *alc882_models[ALC882_MODEL_LAST] = {
7116         [ALC882_3ST_DIG]        = "3stack-dig",
7117         [ALC882_6ST_DIG]        = "6stack-dig",
7118         [ALC882_ARIMA]          = "arima",
7119         [ALC882_W2JC]           = "w2jc",
7120         [ALC882_TARGA]          = "targa",
7121         [ALC882_ASUS_A7J]       = "asus-a7j",
7122         [ALC882_ASUS_A7M]       = "asus-a7m",
7123         [ALC885_MACPRO]         = "macpro",
7124         [ALC885_MB5]            = "mb5",
7125         [ALC885_MBP3]           = "mbp3",
7126         [ALC885_IMAC24]         = "imac24",
7127         [ALC882_AUTO]           = "auto",
7128 };
7129
7130 static struct snd_pci_quirk alc882_cfg_tbl[] = {
7131         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),
7132         SND_PCI_QUIRK(0x1043, 0x060d, "Asus A7J", ALC882_ASUS_A7J),
7133         SND_PCI_QUIRK(0x1043, 0x1243, "Asus A7J", ALC882_ASUS_A7J),
7134         SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_ASUS_A7M),
7135         SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_W2JC),
7136         SND_PCI_QUIRK(0x1043, 0x817f, "Asus P5LD2", ALC882_6ST_DIG),
7137         SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
7138         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
7139         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte P35 DS3R", ALC882_6ST_DIG),
7140         SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8  */
7141         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
7142         SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA),
7143         {}
7144 };
7145
7146 static struct alc_config_preset alc882_presets[] = {
7147         [ALC882_3ST_DIG] = {
7148                 .mixers = { alc882_base_mixer },
7149                 .init_verbs = { alc882_init_verbs },
7150                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7151                 .dac_nids = alc882_dac_nids,
7152                 .dig_out_nid = ALC882_DIGOUT_NID,
7153                 .dig_in_nid = ALC882_DIGIN_NID,
7154                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
7155                 .channel_mode = alc882_ch_modes,
7156                 .need_dac_fix = 1,
7157                 .input_mux = &alc882_capture_source,
7158         },
7159         [ALC882_6ST_DIG] = {
7160                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
7161                 .init_verbs = { alc882_init_verbs },
7162                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7163                 .dac_nids = alc882_dac_nids,
7164                 .dig_out_nid = ALC882_DIGOUT_NID,
7165                 .dig_in_nid = ALC882_DIGIN_NID,
7166                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
7167                 .channel_mode = alc882_sixstack_modes,
7168                 .input_mux = &alc882_capture_source,
7169         },
7170         [ALC882_ARIMA] = {
7171                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
7172                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs },
7173                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7174                 .dac_nids = alc882_dac_nids,
7175                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
7176                 .channel_mode = alc882_sixstack_modes,
7177                 .input_mux = &alc882_capture_source,
7178         },
7179         [ALC882_W2JC] = {
7180                 .mixers = { alc882_w2jc_mixer, alc882_chmode_mixer },
7181                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
7182                                 alc880_gpio1_init_verbs },
7183                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7184                 .dac_nids = alc882_dac_nids,
7185                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
7186                 .channel_mode = alc880_threestack_modes,
7187                 .need_dac_fix = 1,
7188                 .input_mux = &alc882_capture_source,
7189                 .dig_out_nid = ALC882_DIGOUT_NID,
7190         },
7191         [ALC885_MBP3] = {
7192                 .mixers = { alc885_mbp3_mixer, alc882_chmode_mixer },
7193                 .init_verbs = { alc885_mbp3_init_verbs,
7194                                 alc880_gpio1_init_verbs },
7195                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7196                 .dac_nids = alc882_dac_nids,
7197                 .channel_mode = alc885_mbp_6ch_modes,
7198                 .num_channel_mode = ARRAY_SIZE(alc885_mbp_6ch_modes),
7199                 .input_mux = &alc882_capture_source,
7200                 .dig_out_nid = ALC882_DIGOUT_NID,
7201                 .dig_in_nid = ALC882_DIGIN_NID,
7202                 .unsol_event = alc_automute_amp_unsol_event,
7203                 .init_hook = alc885_mbp3_init_hook,
7204         },
7205         [ALC885_MB5] = {
7206                 .mixers = { alc885_mb5_mixer, alc882_chmode_mixer },
7207                 .init_verbs = { alc885_mb5_init_verbs,
7208                                 alc880_gpio1_init_verbs },
7209                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7210                 .dac_nids = alc882_dac_nids,
7211                 .channel_mode = alc885_mb5_6ch_modes,
7212                 .num_channel_mode = ARRAY_SIZE(alc885_mb5_6ch_modes),
7213                 .input_mux = &mb5_capture_source,
7214                 .dig_out_nid = ALC882_DIGOUT_NID,
7215                 .dig_in_nid = ALC882_DIGIN_NID,
7216         },
7217         [ALC885_MACPRO] = {
7218                 .mixers = { alc882_macpro_mixer },
7219                 .init_verbs = { alc882_macpro_init_verbs },
7220                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7221                 .dac_nids = alc882_dac_nids,
7222                 .dig_out_nid = ALC882_DIGOUT_NID,
7223                 .dig_in_nid = ALC882_DIGIN_NID,
7224                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
7225                 .channel_mode = alc882_ch_modes,
7226                 .input_mux = &alc882_capture_source,
7227                 .init_hook = alc885_macpro_init_hook,
7228         },
7229         [ALC885_IMAC24] = {
7230                 .mixers = { alc885_imac24_mixer },
7231                 .init_verbs = { alc885_imac24_init_verbs },
7232                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7233                 .dac_nids = alc882_dac_nids,
7234                 .dig_out_nid = ALC882_DIGOUT_NID,
7235                 .dig_in_nid = ALC882_DIGIN_NID,
7236                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
7237                 .channel_mode = alc882_ch_modes,
7238                 .input_mux = &alc882_capture_source,
7239                 .unsol_event = alc_automute_amp_unsol_event,
7240                 .init_hook = alc885_imac24_init_hook,
7241         },
7242         [ALC882_TARGA] = {
7243                 .mixers = { alc882_targa_mixer, alc882_chmode_mixer },
7244                 .init_verbs = { alc882_init_verbs, alc882_targa_verbs},
7245                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7246                 .dac_nids = alc882_dac_nids,
7247                 .dig_out_nid = ALC882_DIGOUT_NID,
7248                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
7249                 .adc_nids = alc882_adc_nids,
7250                 .capsrc_nids = alc882_capsrc_nids,
7251                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
7252                 .channel_mode = alc882_3ST_6ch_modes,
7253                 .need_dac_fix = 1,
7254                 .input_mux = &alc882_capture_source,
7255                 .unsol_event = alc882_targa_unsol_event,
7256                 .init_hook = alc882_targa_init_hook,
7257         },
7258         [ALC882_ASUS_A7J] = {
7259                 .mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer },
7260                 .init_verbs = { alc882_init_verbs, alc882_asus_a7j_verbs},
7261                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7262                 .dac_nids = alc882_dac_nids,
7263                 .dig_out_nid = ALC882_DIGOUT_NID,
7264                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
7265                 .adc_nids = alc882_adc_nids,
7266                 .capsrc_nids = alc882_capsrc_nids,
7267                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
7268                 .channel_mode = alc882_3ST_6ch_modes,
7269                 .need_dac_fix = 1,
7270                 .input_mux = &alc882_capture_source,
7271         },
7272         [ALC882_ASUS_A7M] = {
7273                 .mixers = { alc882_asus_a7m_mixer, alc882_chmode_mixer },
7274                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
7275                                 alc880_gpio1_init_verbs,
7276                                 alc882_asus_a7m_verbs },
7277                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
7278                 .dac_nids = alc882_dac_nids,
7279                 .dig_out_nid = ALC882_DIGOUT_NID,
7280                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
7281                 .channel_mode = alc880_threestack_modes,
7282                 .need_dac_fix = 1,
7283                 .input_mux = &alc882_capture_source,
7284         },
7285 };
7286
7287
7288 /*
7289  * Pin config fixes
7290  */
7291 enum {
7292         PINFIX_ABIT_AW9D_MAX
7293 };
7294
7295 static struct alc_pincfg alc882_abit_aw9d_pinfix[] = {
7296         { 0x15, 0x01080104 }, /* side */
7297         { 0x16, 0x01011012 }, /* rear */
7298         { 0x17, 0x01016011 }, /* clfe */
7299         { }
7300 };
7301
7302 static const struct alc_pincfg *alc882_pin_fixes[] = {
7303         [PINFIX_ABIT_AW9D_MAX] = alc882_abit_aw9d_pinfix,
7304 };
7305
7306 static struct snd_pci_quirk alc882_pinfix_tbl[] = {
7307         SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
7308         {}
7309 };
7310
7311 /*
7312  * BIOS auto configuration
7313  */
7314 static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
7315                                               hda_nid_t nid, int pin_type,
7316                                               int dac_idx)
7317 {
7318         /* set as output */
7319         struct alc_spec *spec = codec->spec;
7320         int idx;
7321
7322         alc_set_pin_output(codec, nid, pin_type);
7323         if (spec->multiout.dac_nids[dac_idx] == 0x25)
7324                 idx = 4;
7325         else
7326                 idx = spec->multiout.dac_nids[dac_idx] - 2;
7327         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
7328
7329 }
7330
7331 static void alc882_auto_init_multi_out(struct hda_codec *codec)
7332 {
7333         struct alc_spec *spec = codec->spec;
7334         int i;
7335
7336         for (i = 0; i <= HDA_SIDE; i++) {
7337                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
7338                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
7339                 if (nid)
7340                         alc882_auto_set_output_and_unmute(codec, nid, pin_type,
7341                                                           i);
7342         }
7343 }
7344
7345 static void alc882_auto_init_hp_out(struct hda_codec *codec)
7346 {
7347         struct alc_spec *spec = codec->spec;
7348         hda_nid_t pin;
7349
7350         pin = spec->autocfg.hp_pins[0];
7351         if (pin) /* connect to front */
7352                 /* use dac 0 */
7353                 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
7354         pin = spec->autocfg.speaker_pins[0];
7355         if (pin)
7356                 alc882_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
7357 }
7358
7359 #define alc882_is_input_pin(nid)        alc880_is_input_pin(nid)
7360 #define ALC882_PIN_CD_NID               ALC880_PIN_CD_NID
7361
7362 static void alc882_auto_init_analog_input(struct hda_codec *codec)
7363 {
7364         struct alc_spec *spec = codec->spec;
7365         int i;
7366
7367         for (i = 0; i < AUTO_PIN_LAST; i++) {
7368                 hda_nid_t nid = spec->autocfg.input_pins[i];
7369                 if (!nid)
7370                         continue;
7371                 alc_set_input_pin(codec, nid, AUTO_PIN_FRONT_MIC /*i*/);
7372                 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
7373                         snd_hda_codec_write(codec, nid, 0,
7374                                             AC_VERB_SET_AMP_GAIN_MUTE,
7375                                             AMP_OUT_MUTE);
7376         }
7377 }
7378
7379 static void alc882_auto_init_input_src(struct hda_codec *codec)
7380 {
7381         struct alc_spec *spec = codec->spec;
7382         int c;
7383
7384         for (c = 0; c < spec->num_adc_nids; c++) {
7385                 hda_nid_t conn_list[HDA_MAX_NUM_INPUTS];
7386                 hda_nid_t nid = spec->capsrc_nids[c];
7387                 unsigned int mux_idx;
7388                 const struct hda_input_mux *imux;
7389                 int conns, mute, idx, item;
7390
7391                 conns = snd_hda_get_connections(codec, nid, conn_list,
7392                                                 ARRAY_SIZE(conn_list));
7393                 if (conns < 0)
7394                         continue;
7395                 mux_idx = c >= spec->num_mux_defs ? 0 : c;
7396                 imux = &spec->input_mux[mux_idx];
7397                 for (idx = 0; idx < conns; idx++) {
7398                         /* if the current connection is the selected one,
7399                          * unmute it as default - otherwise mute it
7400                          */
7401                         mute = AMP_IN_MUTE(idx);
7402                         for (item = 0; item < imux->num_items; item++) {
7403                                 if (imux->items[item].index == idx) {
7404                                         if (spec->cur_mux[c] == item)
7405                                                 mute = AMP_IN_UNMUTE(idx);
7406                                         break;
7407                                 }
7408                         }
7409                         /* check if we have a selector or mixer
7410                          * we could check for the widget type instead, but
7411                          * just check for Amp-In presence (in case of mixer
7412                          * without amp-in there is something wrong, this
7413                          * function shouldn't be used or capsrc nid is wrong)
7414                          */
7415                         if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)
7416                                 snd_hda_codec_write(codec, nid, 0,
7417                                                     AC_VERB_SET_AMP_GAIN_MUTE,
7418                                                     mute);
7419                         else if (mute != AMP_IN_MUTE(idx))
7420                                 snd_hda_codec_write(codec, nid, 0,
7421                                                     AC_VERB_SET_CONNECT_SEL,
7422                                                     idx);
7423                 }
7424         }
7425 }
7426
7427 /* add mic boosts if needed */
7428 static int alc_auto_add_mic_boost(struct hda_codec *codec)
7429 {
7430         struct alc_spec *spec = codec->spec;
7431         int err;
7432         hda_nid_t nid;
7433
7434         nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
7435         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
7436                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
7437                                   "Mic Boost",
7438                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
7439                 if (err < 0)
7440                         return err;
7441         }
7442         nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
7443         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
7444                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
7445                                   "Front Mic Boost",
7446                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
7447                 if (err < 0)
7448                         return err;
7449         }
7450         return 0;
7451 }
7452
7453 /* almost identical with ALC880 parser... */
7454 static int alc882_parse_auto_config(struct hda_codec *codec)
7455 {
7456         struct alc_spec *spec = codec->spec;
7457         int err = alc880_parse_auto_config(codec);
7458
7459         if (err < 0)
7460                 return err;
7461         else if (!err)
7462                 return 0; /* no config found */
7463
7464         err = alc_auto_add_mic_boost(codec);
7465         if (err < 0)
7466                 return err;
7467
7468         /* hack - override the init verbs */
7469         spec->init_verbs[0] = alc882_auto_init_verbs;
7470
7471         return 1; /* config found */
7472 }
7473
7474 /* additional initialization for auto-configuration model */
7475 static void alc882_auto_init(struct hda_codec *codec)
7476 {
7477         struct alc_spec *spec = codec->spec;
7478         alc882_auto_init_multi_out(codec);
7479         alc882_auto_init_hp_out(codec);
7480         alc882_auto_init_analog_input(codec);
7481         alc882_auto_init_input_src(codec);
7482         if (spec->unsol_event)
7483                 alc_inithook(codec);
7484 }
7485
7486 static int patch_alc883(struct hda_codec *codec); /* called in patch_alc882() */
7487
7488 static int patch_alc882(struct hda_codec *codec)
7489 {
7490         struct alc_spec *spec;
7491         int err, board_config;
7492
7493         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
7494         if (spec == NULL)
7495                 return -ENOMEM;
7496
7497         codec->spec = spec;
7498
7499         board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
7500                                                   alc882_models,
7501                                                   alc882_cfg_tbl);
7502
7503         if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
7504                 /* Pick up systems that don't supply PCI SSID */
7505                 switch (codec->subsystem_id) {
7506                 case 0x106b0c00: /* Mac Pro */
7507                         board_config = ALC885_MACPRO;
7508                         break;
7509                 case 0x106b1000: /* iMac 24 */
7510                 case 0x106b2800: /* AppleTV */
7511                 case 0x106b3e00: /* iMac 24 Aluminium */
7512                         board_config = ALC885_IMAC24;
7513                         break;
7514                 case 0x106b00a0: /* MacBookPro3,1 - Another revision */
7515                 case 0x106b00a1: /* Macbook (might be wrong - PCI SSID?) */
7516                 case 0x106b00a4: /* MacbookPro4,1 */
7517                 case 0x106b2c00: /* Macbook Pro rev3 */
7518                 /* Macbook 3.1 (0x106b3600) is handled by patch_alc883() */
7519                 case 0x106b3800: /* MacbookPro4,1 - latter revision */
7520                         board_config = ALC885_MBP3;
7521                         break;
7522                 case 0x106b3f00: /* Macbook 5,1 */
7523                 case 0x106b4000: /* Macbook Pro 5,1 - FIXME: HP jack sense
7524                                   *   seems not working, so apparently
7525                                   *   no perfect solution yet
7526                                   */
7527                         board_config = ALC885_MB5;
7528                         break;
7529                 default:
7530                         /* ALC889A is handled better as ALC888-compatible */
7531                         if (codec->revision_id == 0x100101 ||
7532                             codec->revision_id == 0x100103) {
7533                                 alc_free(codec);
7534                                 return patch_alc883(codec);
7535                         }
7536                         printk(KERN_INFO "hda_codec: Unknown model for %s, "
7537                                "trying auto-probe from BIOS...\n",
7538                                codec->chip_name);
7539                         board_config = ALC882_AUTO;
7540                 }
7541         }
7542
7543         alc_fix_pincfg(codec, alc882_pinfix_tbl, alc882_pin_fixes);
7544
7545         if (board_config == ALC882_AUTO) {
7546                 /* automatic parse from the BIOS config */
7547                 err = alc882_parse_auto_config(codec);
7548                 if (err < 0) {
7549                         alc_free(codec);
7550                         return err;
7551                 } else if (!err) {
7552                         printk(KERN_INFO
7553                                "hda_codec: Cannot set up configuration "
7554                                "from BIOS.  Using base mode...\n");
7555                         board_config = ALC882_3ST_DIG;
7556                 }
7557         }
7558
7559         err = snd_hda_attach_beep_device(codec, 0x1);
7560         if (err < 0) {
7561                 alc_free(codec);
7562                 return err;
7563         }
7564
7565         if (board_config != ALC882_AUTO)
7566                 setup_preset(spec, &alc882_presets[board_config]);
7567
7568         spec->stream_analog_playback = &alc882_pcm_analog_playback;
7569         spec->stream_analog_capture = &alc882_pcm_analog_capture;
7570         /* FIXME: setup DAC5 */
7571         /*spec->stream_analog_alt_playback = &alc880_pcm_analog_alt_playback;*/
7572         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
7573
7574         spec->stream_digital_playback = &alc882_pcm_digital_playback;
7575         spec->stream_digital_capture = &alc882_pcm_digital_capture;
7576
7577         if (!spec->adc_nids && spec->input_mux) {
7578                 /* check whether NID 0x07 is valid */
7579                 unsigned int wcap = get_wcaps(codec, 0x07);
7580                 /* get type */
7581                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
7582                 if (wcap != AC_WID_AUD_IN) {
7583                         spec->adc_nids = alc882_adc_nids_alt;
7584                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt);
7585                         spec->capsrc_nids = alc882_capsrc_nids_alt;
7586                 } else {
7587                         spec->adc_nids = alc882_adc_nids;
7588                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
7589                         spec->capsrc_nids = alc882_capsrc_nids;
7590                 }
7591         }
7592         set_capture_mixer(spec);
7593         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
7594
7595         spec->vmaster_nid = 0x0c;
7596
7597         codec->patch_ops = alc_patch_ops;
7598         if (board_config == ALC882_AUTO)
7599                 spec->init_hook = alc882_auto_init;
7600 #ifdef CONFIG_SND_HDA_POWER_SAVE
7601         if (!spec->loopback.amplist)
7602                 spec->loopback.amplist = alc882_loopbacks;
7603 #endif
7604         codec->proc_widget_hook = print_realtek_coef;
7605
7606         return 0;
7607 }
7608
7609 /*
7610  * ALC883 support
7611  *
7612  * ALC883 is almost identical with ALC880 but has cleaner and more flexible
7613  * configuration.  Each pin widget can choose any input DACs and a mixer.
7614  * Each ADC is connected from a mixer of all inputs.  This makes possible
7615  * 6-channel independent captures.
7616  *
7617  * In addition, an independent DAC for the multi-playback (not used in this
7618  * driver yet).
7619  */
7620 #define ALC883_DIGOUT_NID       0x06
7621 #define ALC883_DIGIN_NID        0x0a
7622
7623 #define ALC1200_DIGOUT_NID      0x10
7624
7625 static hda_nid_t alc883_dac_nids[4] = {
7626         /* front, rear, clfe, rear_surr */
7627         0x02, 0x03, 0x04, 0x05
7628 };
7629
7630 static hda_nid_t alc883_adc_nids[2] = {
7631         /* ADC1-2 */
7632         0x08, 0x09,
7633 };
7634
7635 static hda_nid_t alc883_adc_nids_alt[1] = {
7636         /* ADC1 */
7637         0x08,
7638 };
7639
7640 static hda_nid_t alc883_adc_nids_rev[2] = {
7641         /* ADC2-1 */
7642         0x09, 0x08
7643 };
7644
7645 #define alc889_adc_nids         alc880_adc_nids
7646
7647 static hda_nid_t alc883_capsrc_nids[2] = { 0x23, 0x22 };
7648
7649 static hda_nid_t alc883_capsrc_nids_rev[2] = { 0x22, 0x23 };
7650
7651 #define alc889_capsrc_nids      alc882_capsrc_nids
7652
7653 /* input MUX */
7654 /* FIXME: should be a matrix-type input source selection */
7655
7656 static struct hda_input_mux alc883_capture_source = {
7657         .num_items = 4,
7658         .items = {
7659                 { "Mic", 0x0 },
7660                 { "Front Mic", 0x1 },
7661                 { "Line", 0x2 },
7662                 { "CD", 0x4 },
7663         },
7664 };
7665
7666 static struct hda_input_mux alc883_3stack_6ch_intel = {
7667         .num_items = 4,
7668         .items = {
7669                 { "Mic", 0x1 },
7670                 { "Front Mic", 0x0 },
7671                 { "Line", 0x2 },
7672                 { "CD", 0x4 },
7673         },
7674 };
7675
7676 static struct hda_input_mux alc883_lenovo_101e_capture_source = {
7677         .num_items = 2,
7678         .items = {
7679                 { "Mic", 0x1 },
7680                 { "Line", 0x2 },
7681         },
7682 };
7683
7684 static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
7685         .num_items = 4,
7686         .items = {
7687                 { "Mic", 0x0 },
7688                 { "iMic", 0x1 },
7689                 { "Line", 0x2 },
7690                 { "CD", 0x4 },
7691         },
7692 };
7693
7694 static struct hda_input_mux alc883_fujitsu_pi2515_capture_source = {
7695         .num_items = 2,
7696         .items = {
7697                 { "Mic", 0x0 },
7698                 { "Int Mic", 0x1 },
7699         },
7700 };
7701
7702 static struct hda_input_mux alc883_lenovo_sky_capture_source = {
7703         .num_items = 3,
7704         .items = {
7705                 { "Mic", 0x0 },
7706                 { "Front Mic", 0x1 },
7707                 { "Line", 0x4 },
7708         },
7709 };
7710
7711 static struct hda_input_mux alc883_asus_eee1601_capture_source = {
7712         .num_items = 2,
7713         .items = {
7714                 { "Mic", 0x0 },
7715                 { "Line", 0x2 },
7716         },
7717 };
7718
7719 static struct hda_input_mux alc889A_mb31_capture_source = {
7720         .num_items = 2,
7721         .items = {
7722                 { "Mic", 0x0 },
7723                 /* Front Mic (0x01) unused */
7724                 { "Line", 0x2 },
7725                 /* Line 2 (0x03) unused */
7726                 /* CD (0x04) unsused? */
7727         },
7728 };
7729
7730 /*
7731  * 2ch mode
7732  */
7733 static struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
7734         { 2, NULL }
7735 };
7736
7737 /*
7738  * 2ch mode
7739  */
7740 static struct hda_verb alc883_3ST_ch2_init[] = {
7741         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7742         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7743         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7744         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7745         { } /* end */
7746 };
7747
7748 /*
7749  * 4ch mode
7750  */
7751 static struct hda_verb alc883_3ST_ch4_init[] = {
7752         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7753         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7754         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7755         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7756         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7757         { } /* end */
7758 };
7759
7760 /*
7761  * 6ch mode
7762  */
7763 static struct hda_verb alc883_3ST_ch6_init[] = {
7764         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7765         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7766         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
7767         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7768         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7769         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7770         { } /* end */
7771 };
7772
7773 static struct hda_channel_mode alc883_3ST_6ch_modes[3] = {
7774         { 2, alc883_3ST_ch2_init },
7775         { 4, alc883_3ST_ch4_init },
7776         { 6, alc883_3ST_ch6_init },
7777 };
7778
7779
7780 /*
7781  * 2ch mode
7782  */
7783 static struct hda_verb alc883_4ST_ch2_init[] = {
7784         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7785         { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7786         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7787         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7788         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7789         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7790         { } /* end */
7791 };
7792
7793 /*
7794  * 4ch mode
7795  */
7796 static struct hda_verb alc883_4ST_ch4_init[] = {
7797         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7798         { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7799         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7800         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7801         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7802         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7803         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7804         { } /* end */
7805 };
7806
7807 /*
7808  * 6ch mode
7809  */
7810 static struct hda_verb alc883_4ST_ch6_init[] = {
7811         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7812         { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7813         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7814         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7815         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
7816         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7817         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7818         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7819         { } /* end */
7820 };
7821
7822 /*
7823  * 8ch mode
7824  */
7825 static struct hda_verb alc883_4ST_ch8_init[] = {
7826         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7827         { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7828         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03 },
7829         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7830         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7831         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
7832         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7833         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7834         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7835         { } /* end */
7836 };
7837
7838 static struct hda_channel_mode alc883_4ST_8ch_modes[4] = {
7839         { 2, alc883_4ST_ch2_init },
7840         { 4, alc883_4ST_ch4_init },
7841         { 6, alc883_4ST_ch6_init },
7842         { 8, alc883_4ST_ch8_init },
7843 };
7844
7845
7846 /*
7847  * 2ch mode
7848  */
7849 static struct hda_verb alc883_3ST_ch2_intel_init[] = {
7850         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7851         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7852         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7853         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7854         { } /* end */
7855 };
7856
7857 /*
7858  * 4ch mode
7859  */
7860 static struct hda_verb alc883_3ST_ch4_intel_init[] = {
7861         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7862         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7863         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7864         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7865         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7866         { } /* end */
7867 };
7868
7869 /*
7870  * 6ch mode
7871  */
7872 static struct hda_verb alc883_3ST_ch6_intel_init[] = {
7873         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7874         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7875         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x02 },
7876         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7877         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7878         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7879         { } /* end */
7880 };
7881
7882 static struct hda_channel_mode alc883_3ST_6ch_intel_modes[3] = {
7883         { 2, alc883_3ST_ch2_intel_init },
7884         { 4, alc883_3ST_ch4_intel_init },
7885         { 6, alc883_3ST_ch6_intel_init },
7886 };
7887
7888 /*
7889  * 6ch mode
7890  */
7891 static struct hda_verb alc883_sixstack_ch6_init[] = {
7892         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
7893         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7894         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7895         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7896         { } /* end */
7897 };
7898
7899 /*
7900  * 8ch mode
7901  */
7902 static struct hda_verb alc883_sixstack_ch8_init[] = {
7903         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7904         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7905         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7906         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7907         { } /* end */
7908 };
7909
7910 static struct hda_channel_mode alc883_sixstack_modes[2] = {
7911         { 6, alc883_sixstack_ch6_init },
7912         { 8, alc883_sixstack_ch8_init },
7913 };
7914
7915 /* 2ch mode (Speaker:front, Subwoofer:CLFE, Line:input, Headphones:front) */
7916 static struct hda_verb alc889A_mb31_ch2_init[] = {
7917         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},             /* HP as front */
7918         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Subwoofer on */
7919         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},    /* Line as input */
7920         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},   /* Line off */
7921         { } /* end */
7922 };
7923
7924 /* 4ch mode (Speaker:front, Subwoofer:CLFE, Line:CLFE, Headphones:front) */
7925 static struct hda_verb alc889A_mb31_ch4_init[] = {
7926         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},             /* HP as front */
7927         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Subwoofer on */
7928         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},   /* Line as output */
7929         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Line on */
7930         { } /* end */
7931 };
7932
7933 /* 5ch mode (Speaker:front, Subwoofer:CLFE, Line:input, Headphones:rear) */
7934 static struct hda_verb alc889A_mb31_ch5_init[] = {
7935         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},             /* HP as rear */
7936         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Subwoofer on */
7937         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},    /* Line as input */
7938         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},   /* Line off */
7939         { } /* end */
7940 };
7941
7942 /* 6ch mode (Speaker:front, Subwoofer:off, Line:CLFE, Headphones:Rear) */
7943 static struct hda_verb alc889A_mb31_ch6_init[] = {
7944         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},             /* HP as front */
7945         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},   /* Subwoofer off */
7946         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},   /* Line as output */
7947         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Line on */
7948         { } /* end */
7949 };
7950
7951 static struct hda_channel_mode alc889A_mb31_6ch_modes[4] = {
7952         { 2, alc889A_mb31_ch2_init },
7953         { 4, alc889A_mb31_ch4_init },
7954         { 5, alc889A_mb31_ch5_init },
7955         { 6, alc889A_mb31_ch6_init },
7956 };
7957
7958 static struct hda_verb alc883_medion_eapd_verbs[] = {
7959         /* eanable EAPD on medion laptop */
7960         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7961         {0x20, AC_VERB_SET_PROC_COEF, 0x3070},
7962         { }
7963 };
7964
7965 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
7966  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
7967  */
7968
7969 static struct snd_kcontrol_new alc883_base_mixer[] = {
7970         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7971         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7972         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7973         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7974         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7975         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7976         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7977         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7978         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7979         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7980         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7981         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7982         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7983         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7984         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7985         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7986         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7987         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7988         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7989         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7990         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7991         { } /* end */
7992 };
7993
7994 static struct snd_kcontrol_new alc883_mitac_mixer[] = {
7995         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7996         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7997         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7998         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7999         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
8000         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
8001         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8002         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8003         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8004         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8005         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8006         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8007         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8008         { } /* end */
8009 };
8010
8011 static struct snd_kcontrol_new alc883_clevo_m720_mixer[] = {
8012         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8013         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
8014         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8015         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
8016         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8017         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8018         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8019         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8020         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
8021         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8022         { } /* end */
8023 };
8024
8025 static struct snd_kcontrol_new alc883_2ch_fujitsu_pi2515_mixer[] = {
8026         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8027         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
8028         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8029         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
8030         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8031         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8032         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8033         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8034         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
8035         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8036         { } /* end */
8037 };
8038
8039 static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
8040         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8041         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8042         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8043         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8044         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8045         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8046         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8047         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8048         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8049         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8050         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8051         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8052         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8053         { } /* end */
8054 };
8055
8056 static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
8057         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8058         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8059         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8060         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
8061         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
8062         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
8063         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
8064         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
8065         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8066         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8067         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8068         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8069         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8070         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8071         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8072         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8073         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8074         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8075         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8076         { } /* end */
8077 };
8078
8079 static struct snd_kcontrol_new alc883_3ST_6ch_intel_mixer[] = {
8080         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8081         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8082         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8083         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
8084         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
8085                               HDA_OUTPUT),
8086         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
8087         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
8088         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
8089         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8090         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8091         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8092         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8093         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8094         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8095         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
8096         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8097         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8098         HDA_CODEC_VOLUME("Front Mic Boost", 0x18, 0, HDA_INPUT),
8099         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8100         { } /* end */
8101 };
8102
8103 static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
8104         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8105         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8106         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8107         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
8108         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
8109         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
8110         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
8111         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
8112         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8113         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8114         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8115         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8116         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8117         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8118         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8119         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8120         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8121         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8122         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8123         { } /* end */
8124 };
8125
8126 static struct snd_kcontrol_new alc883_targa_mixer[] = {
8127         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8128         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8129         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8130         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8131         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
8132         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
8133         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
8134         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
8135         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
8136         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8137         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8138         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8139         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8140         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8141         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8142         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8143         { } /* end */
8144 };
8145
8146 static struct snd_kcontrol_new alc883_targa_2ch_mixer[] = {
8147         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8148         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8149         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8150         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8151         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8152         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8153         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8154         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8155         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8156         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
8157         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8158         { } /* end */
8159 };
8160
8161 static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
8162         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8163         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8164         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
8165         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
8166         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
8167         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8168         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8169         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8170         { } /* end */
8171 };
8172
8173 static struct snd_kcontrol_new alc883_lenovo_nb0763_mixer[] = {
8174         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8175         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
8176         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8177         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8178         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8179         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8180         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8181         HDA_CODEC_VOLUME("iMic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8182         HDA_CODEC_MUTE("iMic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8183         { } /* end */
8184 };
8185
8186 static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
8187         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8188         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8189         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8190         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8191         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8192         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8193         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8194         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8195         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8196         { } /* end */
8197 };
8198
8199 static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
8200         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8201         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8202         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8203         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8204         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8205         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8206         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8207         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8208         { } /* end */
8209 };
8210
8211 static struct snd_kcontrol_new alc888_acer_aspire_6530_mixer[] = {
8212         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8213         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8214         HDA_CODEC_VOLUME("LFE Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
8215         HDA_BIND_MUTE("LFE Playback Switch", 0x0f, 2, HDA_INPUT),
8216         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8217         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8218         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8219         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8220         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8221         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8222         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8223         { } /* end */
8224 };
8225
8226 static struct snd_kcontrol_new alc888_lenovo_sky_mixer[] = {
8227         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8228         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8229         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
8230         HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
8231         HDA_CODEC_VOLUME_MONO("Center Playback Volume",
8232                                                 0x0d, 1, 0x0, HDA_OUTPUT),
8233         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
8234         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
8235         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
8236         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
8237         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
8238         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8239         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8240         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8241         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8242         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8243         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8244         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8245         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8246         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
8247         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8248         { } /* end */
8249 };
8250
8251 static struct snd_kcontrol_new alc889A_mb31_mixer[] = {
8252         /* Output mixers */
8253         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
8254         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
8255         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
8256         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 0x02, HDA_INPUT),
8257         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x00,
8258                 HDA_OUTPUT),
8259         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x02, HDA_INPUT),
8260         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x00, HDA_OUTPUT),
8261         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x02, HDA_INPUT),
8262         /* Output switches */
8263         HDA_CODEC_MUTE("Enable Speaker", 0x14, 0x00, HDA_OUTPUT),
8264         HDA_CODEC_MUTE("Enable Headphones", 0x15, 0x00, HDA_OUTPUT),
8265         HDA_CODEC_MUTE_MONO("Enable LFE", 0x16, 2, 0x00, HDA_OUTPUT),
8266         /* Boost mixers */
8267         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
8268         HDA_CODEC_VOLUME("Line Boost", 0x1a, 0x00, HDA_INPUT),
8269         /* Input mixers */
8270         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
8271         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
8272         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8273         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8274         { } /* end */
8275 };
8276
8277 static struct snd_kcontrol_new alc883_vaiott_mixer[] = {
8278         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8279         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8280         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8281         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8282         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
8283         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8284         { } /* end */
8285 };
8286
8287 static struct hda_bind_ctls alc883_bind_cap_vol = {
8288         .ops = &snd_hda_bind_vol,
8289         .values = {
8290                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
8291                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
8292                 0
8293         },
8294 };
8295
8296 static struct hda_bind_ctls alc883_bind_cap_switch = {
8297         .ops = &snd_hda_bind_sw,
8298         .values = {
8299                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
8300                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
8301                 0
8302         },
8303 };
8304
8305 static struct snd_kcontrol_new alc883_asus_eee1601_mixer[] = {
8306         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8307         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
8308         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
8309         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
8310         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
8311         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8312         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8313         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8314         { } /* end */
8315 };
8316
8317 static struct snd_kcontrol_new alc883_asus_eee1601_cap_mixer[] = {
8318         HDA_BIND_VOL("Capture Volume", &alc883_bind_cap_vol),
8319         HDA_BIND_SW("Capture Switch", &alc883_bind_cap_switch),
8320         {
8321                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8322                 /* .name = "Capture Source", */
8323                 .name = "Input Source",
8324                 .count = 1,
8325                 .info = alc_mux_enum_info,
8326                 .get = alc_mux_enum_get,
8327                 .put = alc_mux_enum_put,
8328         },
8329         { } /* end */
8330 };
8331
8332 static struct snd_kcontrol_new alc883_chmode_mixer[] = {
8333         {
8334                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8335                 .name = "Channel Mode",
8336                 .info = alc_ch_mode_info,
8337                 .get = alc_ch_mode_get,
8338                 .put = alc_ch_mode_put,
8339         },
8340         { } /* end */
8341 };
8342
8343 static struct hda_verb alc883_init_verbs[] = {
8344         /* ADC1: mute amp left and right */
8345         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8346         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8347         /* ADC2: mute amp left and right */
8348         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8349         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8350         /* Front mixer: unmute input/output amp left and right (volume = 0) */
8351         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8352         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8353         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8354         /* Rear mixer */
8355         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8356         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8357         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8358         /* CLFE mixer */
8359         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8360         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8361         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8362         /* Side mixer */
8363         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8364         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8365         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8366
8367         /* mute analog input loopbacks */
8368         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8369         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8370         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8371         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8372         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8373
8374         /* Front Pin: output 0 (0x0c) */
8375         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8376         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8377         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8378         /* Rear Pin: output 1 (0x0d) */
8379         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8380         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8381         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
8382         /* CLFE Pin: output 2 (0x0e) */
8383         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8384         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8385         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
8386         /* Side Pin: output 3 (0x0f) */
8387         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8388         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8389         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
8390         /* Mic (rear) pin: input vref at 80% */
8391         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
8392         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8393         /* Front Mic pin: input vref at 80% */
8394         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
8395         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8396         /* Line In pin: input */
8397         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
8398         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8399         /* Line-2 In: Headphone output (output 0 - 0x0c) */
8400         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8401         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8402         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8403         /* CD pin widget for input */
8404         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
8405
8406         /* FIXME: use matrix-type input source selection */
8407         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8408         /* Input mixer2 */
8409         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8410         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8411         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8412         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8413         /* Input mixer3 */
8414         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8415         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8416         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8417         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8418         { }
8419 };
8420
8421 /* toggle speaker-output according to the hp-jack state */
8422 static void alc883_mitac_init_hook(struct hda_codec *codec)
8423 {
8424         struct alc_spec *spec = codec->spec;
8425
8426         spec->autocfg.hp_pins[0] = 0x15;
8427         spec->autocfg.speaker_pins[0] = 0x14;
8428         spec->autocfg.speaker_pins[1] = 0x17;
8429         alc_automute_amp(codec);
8430 }
8431
8432 /* auto-toggle front mic */
8433 /*
8434 static void alc883_mitac_mic_automute(struct hda_codec *codec)
8435 {
8436         unsigned int present;
8437         unsigned char bits;
8438
8439         present = snd_hda_codec_read(codec, 0x18, 0,
8440                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8441         bits = present ? HDA_AMP_MUTE : 0;
8442         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
8443 }
8444 */
8445
8446 static struct hda_verb alc883_mitac_verbs[] = {
8447         /* HP */
8448         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8449         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8450         /* Subwoofer */
8451         {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
8452         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8453
8454         /* enable unsolicited event */
8455         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8456         /* {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN}, */
8457
8458         { } /* end */
8459 };
8460
8461 static struct hda_verb alc883_clevo_m720_verbs[] = {
8462         /* HP */
8463         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8464         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8465         /* Int speaker */
8466         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
8467         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8468
8469         /* enable unsolicited event */
8470         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8471         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
8472
8473         { } /* end */
8474 };
8475
8476 static struct hda_verb alc883_2ch_fujitsu_pi2515_verbs[] = {
8477         /* HP */
8478         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8479         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8480         /* Subwoofer */
8481         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
8482         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8483
8484         /* enable unsolicited event */
8485         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8486
8487         { } /* end */
8488 };
8489
8490 static struct hda_verb alc883_targa_verbs[] = {
8491         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8492         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8493
8494         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8495         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8496
8497 /* Connect Line-Out side jack (SPDIF) to Side */
8498         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8499         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8500         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
8501 /* Connect Mic jack to CLFE */
8502         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8503         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8504         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},
8505 /* Connect Line-in jack to Surround */
8506         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8507         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8508         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
8509 /* Connect HP out jack to Front */
8510         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8511         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8512         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8513
8514         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8515
8516         { } /* end */
8517 };
8518
8519 static struct hda_verb alc883_lenovo_101e_verbs[] = {
8520         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8521         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT|AC_USRSP_EN},
8522         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT|AC_USRSP_EN},
8523         { } /* end */
8524 };
8525
8526 static struct hda_verb alc883_lenovo_nb0763_verbs[] = {
8527         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8528         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8529         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8530         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8531         { } /* end */
8532 };
8533
8534 static struct hda_verb alc888_lenovo_ms7195_verbs[] = {
8535         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8536         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8537         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8538         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT | AC_USRSP_EN},
8539         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT    | AC_USRSP_EN},
8540         { } /* end */
8541 };
8542
8543 static struct hda_verb alc883_haier_w66_verbs[] = {
8544         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8545         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8546
8547         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8548
8549         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8550         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8551         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8552         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8553         { } /* end */
8554 };
8555
8556 static struct hda_verb alc888_lenovo_sky_verbs[] = {
8557         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8558         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8559         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8560         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8561         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8562         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8563         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
8564         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8565         { } /* end */
8566 };
8567
8568 static struct hda_verb alc888_6st_dell_verbs[] = {
8569         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8570         { }
8571 };
8572
8573 static struct hda_verb alc883_vaiott_verbs[] = {
8574         /* HP */
8575         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8576         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8577
8578         /* enable unsolicited event */
8579         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8580
8581         { } /* end */
8582 };
8583
8584 static void alc888_3st_hp_init_hook(struct hda_codec *codec)
8585 {
8586         struct alc_spec *spec = codec->spec;
8587
8588         spec->autocfg.hp_pins[0] = 0x1b;
8589         spec->autocfg.speaker_pins[0] = 0x14;
8590         spec->autocfg.speaker_pins[1] = 0x16;
8591         spec->autocfg.speaker_pins[2] = 0x18;
8592         alc_automute_amp(codec);
8593 }
8594
8595 static struct hda_verb alc888_3st_hp_verbs[] = {
8596         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
8597         {0x16, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Rear : output 1 (0x0d) */
8598         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},  /* CLFE : output 2 (0x0e) */
8599         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8600         { } /* end */
8601 };
8602
8603 /*
8604  * 2ch mode
8605  */
8606 static struct hda_verb alc888_3st_hp_2ch_init[] = {
8607         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
8608         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8609         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
8610         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8611         { } /* end */
8612 };
8613
8614 /*
8615  * 4ch mode
8616  */
8617 static struct hda_verb alc888_3st_hp_4ch_init[] = {
8618         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
8619         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8620         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8621         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8622         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x01 },
8623         { } /* end */
8624 };
8625
8626 /*
8627  * 6ch mode
8628  */
8629 static struct hda_verb alc888_3st_hp_6ch_init[] = {
8630         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8631         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8632         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
8633         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8634         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8635         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x01 },
8636         { } /* end */
8637 };
8638
8639 static struct hda_channel_mode alc888_3st_hp_modes[3] = {
8640         { 2, alc888_3st_hp_2ch_init },
8641         { 4, alc888_3st_hp_4ch_init },
8642         { 6, alc888_3st_hp_6ch_init },
8643 };
8644
8645 /* toggle front-jack and RCA according to the hp-jack state */
8646 static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
8647 {
8648         unsigned int present;
8649
8650         present = snd_hda_codec_read(codec, 0x1b, 0,
8651                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8652         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8653                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8654         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8655                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8656 }
8657
8658 /* toggle RCA according to the front-jack state */
8659 static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
8660 {
8661         unsigned int present;
8662
8663         present = snd_hda_codec_read(codec, 0x14, 0,
8664                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8665         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8666                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8667 }
8668
8669 static void alc883_lenovo_ms7195_unsol_event(struct hda_codec *codec,
8670                                              unsigned int res)
8671 {
8672         if ((res >> 26) == ALC880_HP_EVENT)
8673                 alc888_lenovo_ms7195_front_automute(codec);
8674         if ((res >> 26) == ALC880_FRONT_EVENT)
8675                 alc888_lenovo_ms7195_rca_automute(codec);
8676 }
8677
8678 static struct hda_verb alc883_medion_md2_verbs[] = {
8679         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8680         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8681
8682         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8683
8684         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8685         { } /* end */
8686 };
8687
8688 /* toggle speaker-output according to the hp-jack state */
8689 static void alc883_medion_md2_init_hook(struct hda_codec *codec)
8690 {
8691         struct alc_spec *spec = codec->spec;
8692
8693         spec->autocfg.hp_pins[0] = 0x14;
8694         spec->autocfg.speaker_pins[0] = 0x15;
8695         alc_automute_amp(codec);
8696 }
8697
8698 /* toggle speaker-output according to the hp-jack state */
8699 #define alc883_targa_init_hook          alc882_targa_init_hook
8700 #define alc883_targa_unsol_event        alc882_targa_unsol_event
8701
8702 static void alc883_clevo_m720_mic_automute(struct hda_codec *codec)
8703 {
8704         unsigned int present;
8705
8706         present = snd_hda_codec_read(codec, 0x18, 0,
8707                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8708         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
8709                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8710 }
8711
8712 static void alc883_clevo_m720_init_hook(struct hda_codec *codec)
8713 {
8714         struct alc_spec *spec = codec->spec;
8715
8716         spec->autocfg.hp_pins[0] = 0x15;
8717         spec->autocfg.speaker_pins[0] = 0x14;
8718         alc_automute_amp(codec);
8719         alc883_clevo_m720_mic_automute(codec);
8720 }
8721
8722 static void alc883_clevo_m720_unsol_event(struct hda_codec *codec,
8723                                            unsigned int res)
8724 {
8725         switch (res >> 26) {
8726         case ALC880_MIC_EVENT:
8727                 alc883_clevo_m720_mic_automute(codec);
8728                 break;
8729         default:
8730                 alc_automute_amp_unsol_event(codec, res);
8731                 break;
8732         }
8733 }
8734
8735 /* toggle speaker-output according to the hp-jack state */
8736 static void alc883_2ch_fujitsu_pi2515_init_hook(struct hda_codec *codec)
8737 {
8738         struct alc_spec *spec = codec->spec;
8739
8740         spec->autocfg.hp_pins[0] = 0x14;
8741         spec->autocfg.speaker_pins[0] = 0x15;
8742         alc_automute_amp(codec);
8743 }
8744
8745 static void alc883_haier_w66_init_hook(struct hda_codec *codec)
8746 {
8747         struct alc_spec *spec = codec->spec;
8748
8749         spec->autocfg.hp_pins[0] = 0x1b;
8750         spec->autocfg.speaker_pins[0] = 0x14;
8751         alc_automute_amp(codec);
8752 }
8753
8754 static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
8755 {
8756         unsigned int present;
8757         unsigned char bits;
8758
8759         present = snd_hda_codec_read(codec, 0x14, 0, AC_VERB_GET_PIN_SENSE, 0)
8760                 & AC_PINSENSE_PRESENCE;
8761         bits = present ? HDA_AMP_MUTE : 0;
8762         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8763                                  HDA_AMP_MUTE, bits);
8764 }
8765
8766 static void alc883_lenovo_101e_all_automute(struct hda_codec *codec)
8767 {
8768         unsigned int present;
8769         unsigned char bits;
8770
8771         present = snd_hda_codec_read(codec, 0x1b, 0,
8772                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8773         bits = present ? HDA_AMP_MUTE : 0;
8774         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8775                                  HDA_AMP_MUTE, bits);
8776         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8777                                  HDA_AMP_MUTE, bits);
8778 }
8779
8780 static void alc883_lenovo_101e_unsol_event(struct hda_codec *codec,
8781                                            unsigned int res)
8782 {
8783         if ((res >> 26) == ALC880_HP_EVENT)
8784                 alc883_lenovo_101e_all_automute(codec);
8785         if ((res >> 26) == ALC880_FRONT_EVENT)
8786                 alc883_lenovo_101e_ispeaker_automute(codec);
8787 }
8788
8789 /* toggle speaker-output according to the hp-jack state */
8790 static void alc883_acer_aspire_init_hook(struct hda_codec *codec)
8791 {
8792         struct alc_spec *spec = codec->spec;
8793
8794         spec->autocfg.hp_pins[0] = 0x14;
8795         spec->autocfg.speaker_pins[0] = 0x15;
8796         spec->autocfg.speaker_pins[1] = 0x16;
8797         alc_automute_amp(codec);
8798 }
8799
8800 static struct hda_verb alc883_acer_eapd_verbs[] = {
8801         /* HP Pin: output 0 (0x0c) */
8802         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8803         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8804         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8805         /* Front Pin: output 0 (0x0c) */
8806         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8807         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8808         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8809         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
8810         /* eanable EAPD on medion laptop */
8811         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
8812         {0x20, AC_VERB_SET_PROC_COEF, 0x3050},
8813         /* enable unsolicited event */
8814         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8815         { }
8816 };
8817
8818 static void alc888_6st_dell_init_hook(struct hda_codec *codec)
8819 {
8820         struct alc_spec *spec = codec->spec;
8821
8822         spec->autocfg.hp_pins[0] = 0x1b;
8823         spec->autocfg.speaker_pins[0] = 0x14;
8824         spec->autocfg.speaker_pins[1] = 0x15;
8825         spec->autocfg.speaker_pins[2] = 0x16;
8826         spec->autocfg.speaker_pins[3] = 0x17;
8827         alc_automute_amp(codec);
8828 }
8829
8830 static void alc888_lenovo_sky_init_hook(struct hda_codec *codec)
8831 {
8832         struct alc_spec *spec = codec->spec;
8833
8834         spec->autocfg.hp_pins[0] = 0x1b;
8835         spec->autocfg.speaker_pins[0] = 0x14;
8836         spec->autocfg.speaker_pins[1] = 0x15;
8837         spec->autocfg.speaker_pins[2] = 0x16;
8838         spec->autocfg.speaker_pins[3] = 0x17;
8839         spec->autocfg.speaker_pins[4] = 0x1a;
8840         alc_automute_amp(codec);
8841 }
8842
8843 static void alc883_vaiott_init_hook(struct hda_codec *codec)
8844 {
8845         struct alc_spec *spec = codec->spec;
8846
8847         spec->autocfg.hp_pins[0] = 0x15;
8848         spec->autocfg.speaker_pins[0] = 0x14;
8849         spec->autocfg.speaker_pins[1] = 0x17;
8850         alc_automute_amp(codec);
8851 }
8852
8853 /*
8854  * generic initialization of ADC, input mixers and output mixers
8855  */
8856 static struct hda_verb alc883_auto_init_verbs[] = {
8857         /*
8858          * Unmute ADC0-2 and set the default input to mic-in
8859          */
8860         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8861         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8862         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8863         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8864
8865         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
8866          * mixer widget
8867          * Note: PASD motherboards uses the Line In 2 as the input for
8868          * front panel mic (mic 2)
8869          */
8870         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
8871         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8872         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8873         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8874         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8875         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8876
8877         /*
8878          * Set up output mixers (0x0c - 0x0f)
8879          */
8880         /* set vol=0 to output mixers */
8881         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8882         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8883         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8884         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8885         /* set up input amps for analog loopback */
8886         /* Amp Indices: DAC = 0, mixer = 1 */
8887         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8888         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8889         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8890         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8891         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8892         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8893         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8894         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8895         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8896         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8897
8898         /* FIXME: use matrix-type input source selection */
8899         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8900         /* Input mixer1 */
8901         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8902         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8903         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8904         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
8905         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
8906         /* Input mixer2 */
8907         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8908         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8909         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8910         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
8911         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
8912
8913         { }
8914 };
8915
8916 static struct hda_verb alc888_asus_m90v_verbs[] = {
8917         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8918         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8919         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8920         /* enable unsolicited event */
8921         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8922         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
8923         { } /* end */
8924 };
8925
8926 static void alc883_nb_mic_automute(struct hda_codec *codec)
8927 {
8928         unsigned int present;
8929
8930         present = snd_hda_codec_read(codec, 0x18, 0,
8931                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8932         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
8933                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
8934         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
8935                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
8936 }
8937
8938 static void alc883_M90V_init_hook(struct hda_codec *codec)
8939 {
8940         struct alc_spec *spec = codec->spec;
8941
8942         spec->autocfg.hp_pins[0] = 0x1b;
8943         spec->autocfg.speaker_pins[0] = 0x14;
8944         spec->autocfg.speaker_pins[1] = 0x15;
8945         spec->autocfg.speaker_pins[2] = 0x16;
8946         alc_automute_pin(codec);
8947 }
8948
8949 static void alc883_mode2_unsol_event(struct hda_codec *codec,
8950                                            unsigned int res)
8951 {
8952         switch (res >> 26) {
8953         case ALC880_MIC_EVENT:
8954                 alc883_nb_mic_automute(codec);
8955                 break;
8956         default:
8957                 alc_sku_unsol_event(codec, res);
8958                 break;
8959         }
8960 }
8961
8962 static void alc883_mode2_inithook(struct hda_codec *codec)
8963 {
8964         alc883_M90V_init_hook(codec);
8965         alc883_nb_mic_automute(codec);
8966 }
8967
8968 static struct hda_verb alc888_asus_eee1601_verbs[] = {
8969         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8970         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8971         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8972         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8973         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8974         {0x20, AC_VERB_SET_COEF_INDEX, 0x0b},
8975         {0x20, AC_VERB_SET_PROC_COEF,  0x0838},
8976         /* enable unsolicited event */
8977         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8978         { } /* end */
8979 };
8980
8981 static void alc883_eee1601_inithook(struct hda_codec *codec)
8982 {
8983         struct alc_spec *spec = codec->spec;
8984
8985         spec->autocfg.hp_pins[0] = 0x14;
8986         spec->autocfg.speaker_pins[0] = 0x1b;
8987         alc_automute_pin(codec);
8988 }
8989
8990 static struct hda_verb alc889A_mb31_verbs[] = {
8991         /* Init rear pin (used as headphone output) */
8992         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},    /* Apple Headphones */
8993         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},           /* Connect to front */
8994         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8995         /* Init line pin (used as output in 4ch and 6ch mode) */
8996         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x02},           /* Connect to CLFE */
8997         /* Init line 2 pin (used as headphone out by default) */
8998         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},  /* Use as input */
8999         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Mute output */
9000         { } /* end */
9001 };
9002
9003 /* Mute speakers according to the headphone jack state */
9004 static void alc889A_mb31_automute(struct hda_codec *codec)
9005 {
9006         unsigned int present;
9007
9008         /* Mute only in 2ch or 4ch mode */
9009         if (snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_CONNECT_SEL, 0)
9010             == 0x00) {
9011                 present = snd_hda_codec_read(codec, 0x15, 0,
9012                         AC_VERB_GET_PIN_SENSE, 0) & AC_PINSENSE_PRESENCE;
9013                 snd_hda_codec_amp_stereo(codec, 0x14,  HDA_OUTPUT, 0,
9014                         HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
9015                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
9016                         HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
9017         }
9018 }
9019
9020 static void alc889A_mb31_unsol_event(struct hda_codec *codec, unsigned int res)
9021 {
9022         if ((res >> 26) == ALC880_HP_EVENT)
9023                 alc889A_mb31_automute(codec);
9024 }
9025
9026 #ifdef CONFIG_SND_HDA_POWER_SAVE
9027 #define alc883_loopbacks        alc880_loopbacks
9028 #endif
9029
9030 /* pcm configuration: identical with ALC880 */
9031 #define alc883_pcm_analog_playback      alc880_pcm_analog_playback
9032 #define alc883_pcm_analog_capture       alc880_pcm_analog_capture
9033 #define alc883_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
9034 #define alc883_pcm_digital_playback     alc880_pcm_digital_playback
9035 #define alc883_pcm_digital_capture      alc880_pcm_digital_capture
9036
9037 /*
9038  * configuration and preset
9039  */
9040 static const char *alc883_models[ALC883_MODEL_LAST] = {
9041         [ALC883_3ST_2ch_DIG]    = "3stack-dig",
9042         [ALC883_3ST_6ch_DIG]    = "3stack-6ch-dig",
9043         [ALC883_3ST_6ch]        = "3stack-6ch",
9044         [ALC883_6ST_DIG]        = "6stack-dig",
9045         [ALC883_TARGA_DIG]      = "targa-dig",
9046         [ALC883_TARGA_2ch_DIG]  = "targa-2ch-dig",
9047         [ALC883_TARGA_8ch_DIG]  = "targa-8ch-dig",
9048         [ALC883_ACER]           = "acer",
9049         [ALC883_ACER_ASPIRE]    = "acer-aspire",
9050         [ALC888_ACER_ASPIRE_4930G]      = "acer-aspire-4930g",
9051         [ALC888_ACER_ASPIRE_6530G]      = "acer-aspire-6530g",
9052         [ALC888_ACER_ASPIRE_8930G]      = "acer-aspire-8930g",
9053         [ALC883_MEDION]         = "medion",
9054         [ALC883_MEDION_MD2]     = "medion-md2",
9055         [ALC883_LAPTOP_EAPD]    = "laptop-eapd",
9056         [ALC883_LENOVO_101E_2ch] = "lenovo-101e",
9057         [ALC883_LENOVO_NB0763]  = "lenovo-nb0763",
9058         [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
9059         [ALC888_LENOVO_SKY] = "lenovo-sky",
9060         [ALC883_HAIER_W66]      = "haier-w66",
9061         [ALC888_3ST_HP]         = "3stack-hp",
9062         [ALC888_6ST_DELL]       = "6stack-dell",
9063         [ALC883_MITAC]          = "mitac",
9064         [ALC883_CLEVO_M720]     = "clevo-m720",
9065         [ALC883_FUJITSU_PI2515] = "fujitsu-pi2515",
9066         [ALC888_FUJITSU_XA3530] = "fujitsu-xa3530",
9067         [ALC883_3ST_6ch_INTEL]  = "3stack-6ch-intel",
9068         [ALC1200_ASUS_P5Q]      = "asus-p5q",
9069         [ALC889A_MB31]          = "mb31",
9070         [ALC883_SONY_VAIO_TT]   = "sony-vaio-tt",
9071         [ALC883_AUTO]           = "auto",
9072 };
9073
9074 static struct snd_pci_quirk alc883_cfg_tbl[] = {
9075         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC883_3ST_6ch_DIG),
9076         SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE),
9077         SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_ACER_ASPIRE),
9078         SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_ACER_ASPIRE),
9079         SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE),
9080         SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE),
9081         SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_ACER_ASPIRE),
9082         SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
9083                 ALC888_ACER_ASPIRE_4930G),
9084         SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
9085                 ALC888_ACER_ASPIRE_4930G),
9086         SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
9087                 ALC888_ACER_ASPIRE_8930G),
9088         SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
9089                 ALC888_ACER_ASPIRE_8930G),
9090         SND_PCI_QUIRK(0x1025, 0x0157, "Acer X3200", ALC883_AUTO),
9091         SND_PCI_QUIRK(0x1025, 0x0158, "Acer AX1700-U3700A", ALC883_AUTO),
9092         SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
9093                 ALC888_ACER_ASPIRE_6530G),
9094         SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
9095                 ALC888_ACER_ASPIRE_6530G),
9096         /* default Acer -- disabled as it causes more problems.
9097          *    model=auto should work fine now
9098          */
9099         /* SND_PCI_QUIRK_VENDOR(0x1025, "Acer laptop", ALC883_ACER), */
9100         SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL),
9101         SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
9102         SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
9103         SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
9104         SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG),
9105         SND_PCI_QUIRK(0x103c, 0x2a66, "HP Acacia", ALC888_3ST_HP),
9106         SND_PCI_QUIRK(0x103c, 0x2a72, "HP Educ.ar", ALC888_3ST_HP),
9107         SND_PCI_QUIRK(0x1043, 0x1873, "Asus M90V", ALC888_ASUS_M90V),
9108         SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG),
9109         SND_PCI_QUIRK(0x1043, 0x8284, "Asus Z37E", ALC883_6ST_DIG),
9110         SND_PCI_QUIRK(0x1043, 0x82fe, "Asus P5Q-EM HDMI", ALC1200_ASUS_P5Q),
9111         SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_ASUS_EEE1601),
9112         SND_PCI_QUIRK(0x105b, 0x0ce8, "Foxconn P35AX-S", ALC883_6ST_DIG),
9113         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG),
9114         SND_PCI_QUIRK(0x1071, 0x8227, "Mitac 82801H", ALC883_MITAC),
9115         SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC),
9116         SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
9117         SND_PCI_QUIRK(0x10f1, 0x2350, "TYAN-S2350", ALC888_6ST_DELL),
9118         SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
9119         SND_PCI_QUIRK(0x1458, 0xa002, "MSI", ALC883_6ST_DIG),
9120         SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
9121         SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG),
9122         SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
9123         SND_PCI_QUIRK(0x1462, 0x2fb3, "MSI", ALC883_TARGA_2ch_DIG),
9124         SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
9125         SND_PCI_QUIRK(0x1462, 0x3783, "NEC S970", ALC883_TARGA_DIG),
9126         SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
9127         SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
9128         SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
9129         SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG),
9130         SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG),
9131         SND_PCI_QUIRK(0x1462, 0x3fdf, "MSI", ALC883_TARGA_DIG),
9132         SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
9133         SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
9134         SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
9135         SND_PCI_QUIRK(0x1462, 0x6510, "MSI GX620", ALC883_TARGA_8ch_DIG),
9136         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
9137         SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
9138         SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
9139         SND_PCI_QUIRK(0x1462, 0x7260, "MSI 7260", ALC883_TARGA_DIG),
9140         SND_PCI_QUIRK(0x1462, 0x7267, "MSI", ALC883_3ST_6ch_DIG),
9141         SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
9142         SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
9143         SND_PCI_QUIRK(0x1462, 0x7350, "MSI", ALC883_6ST_DIG),
9144         SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
9145         SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG),
9146         SND_PCI_QUIRK(0x1558, 0x0721, "Clevo laptop M720R", ALC883_CLEVO_M720),
9147         SND_PCI_QUIRK(0x1558, 0x0722, "Clevo laptop M720SR", ALC883_CLEVO_M720),
9148         SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC883_LAPTOP_EAPD),
9149         SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
9150         SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
9151         SND_PCI_QUIRK_MASK(0x1734, 0xfff0, 0x1100, "FSC AMILO Xi/Pi25xx",
9152                       ALC883_FUJITSU_PI2515),
9153         SND_PCI_QUIRK_MASK(0x1734, 0xfff0, 0x1130, "Fujitsu AMILO Xa35xx",
9154                 ALC888_FUJITSU_XA3530),
9155         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
9156         SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
9157         SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
9158         SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763),
9159         SND_PCI_QUIRK(0x17aa, 0x101d, "Lenovo Sky", ALC888_LENOVO_SKY),
9160         SND_PCI_QUIRK(0x17c0, 0x4071, "MEDION MD2", ALC883_MEDION_MD2),
9161         SND_PCI_QUIRK(0x17c0, 0x4085, "MEDION MD96630", ALC888_LENOVO_MS7195_DIG),
9162         SND_PCI_QUIRK(0x17f2, 0x5000, "Albatron KI690-AM2", ALC883_6ST_DIG),
9163         SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66),
9164         SND_PCI_QUIRK(0x8086, 0x0001, "DG33BUC", ALC883_3ST_6ch_INTEL),
9165         SND_PCI_QUIRK(0x8086, 0x0002, "DG33FBC", ALC883_3ST_6ch_INTEL),
9166         SND_PCI_QUIRK(0x8086, 0x2503, "82801H", ALC883_MITAC),
9167         SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC883_3ST_6ch_INTEL),
9168         SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch),
9169         SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC883_SONY_VAIO_TT),
9170         {}
9171 };
9172
9173 static hda_nid_t alc883_slave_dig_outs[] = {
9174         ALC1200_DIGOUT_NID, 0,
9175 };
9176
9177 static hda_nid_t alc1200_slave_dig_outs[] = {
9178         ALC883_DIGOUT_NID, 0,
9179 };
9180
9181 static struct alc_config_preset alc883_presets[] = {
9182         [ALC883_3ST_2ch_DIG] = {
9183                 .mixers = { alc883_3ST_2ch_mixer },
9184                 .init_verbs = { alc883_init_verbs },
9185                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9186                 .dac_nids = alc883_dac_nids,
9187                 .dig_out_nid = ALC883_DIGOUT_NID,
9188                 .dig_in_nid = ALC883_DIGIN_NID,
9189                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9190                 .channel_mode = alc883_3ST_2ch_modes,
9191                 .input_mux = &alc883_capture_source,
9192         },
9193         [ALC883_3ST_6ch_DIG] = {
9194                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9195                 .init_verbs = { alc883_init_verbs },
9196                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9197                 .dac_nids = alc883_dac_nids,
9198                 .dig_out_nid = ALC883_DIGOUT_NID,
9199                 .dig_in_nid = ALC883_DIGIN_NID,
9200                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9201                 .channel_mode = alc883_3ST_6ch_modes,
9202                 .need_dac_fix = 1,
9203                 .input_mux = &alc883_capture_source,
9204         },
9205         [ALC883_3ST_6ch] = {
9206                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9207                 .init_verbs = { alc883_init_verbs },
9208                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9209                 .dac_nids = alc883_dac_nids,
9210                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9211                 .channel_mode = alc883_3ST_6ch_modes,
9212                 .need_dac_fix = 1,
9213                 .input_mux = &alc883_capture_source,
9214         },
9215         [ALC883_3ST_6ch_INTEL] = {
9216                 .mixers = { alc883_3ST_6ch_intel_mixer, alc883_chmode_mixer },
9217                 .init_verbs = { alc883_init_verbs },
9218                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9219                 .dac_nids = alc883_dac_nids,
9220                 .dig_out_nid = ALC883_DIGOUT_NID,
9221                 .dig_in_nid = ALC883_DIGIN_NID,
9222                 .slave_dig_outs = alc883_slave_dig_outs,
9223                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_intel_modes),
9224                 .channel_mode = alc883_3ST_6ch_intel_modes,
9225                 .need_dac_fix = 1,
9226                 .input_mux = &alc883_3stack_6ch_intel,
9227         },
9228         [ALC883_6ST_DIG] = {
9229                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
9230                 .init_verbs = { alc883_init_verbs },
9231                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9232                 .dac_nids = alc883_dac_nids,
9233                 .dig_out_nid = ALC883_DIGOUT_NID,
9234                 .dig_in_nid = ALC883_DIGIN_NID,
9235                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9236                 .channel_mode = alc883_sixstack_modes,
9237                 .input_mux = &alc883_capture_source,
9238         },
9239         [ALC883_TARGA_DIG] = {
9240                 .mixers = { alc883_targa_mixer, alc883_chmode_mixer },
9241                 .init_verbs = { alc883_init_verbs, alc883_targa_verbs},
9242                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9243                 .dac_nids = alc883_dac_nids,
9244                 .dig_out_nid = ALC883_DIGOUT_NID,
9245                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9246                 .channel_mode = alc883_3ST_6ch_modes,
9247                 .need_dac_fix = 1,
9248                 .input_mux = &alc883_capture_source,
9249                 .unsol_event = alc883_targa_unsol_event,
9250                 .init_hook = alc883_targa_init_hook,
9251         },
9252         [ALC883_TARGA_2ch_DIG] = {
9253                 .mixers = { alc883_targa_2ch_mixer},
9254                 .init_verbs = { alc883_init_verbs, alc883_targa_verbs},
9255                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9256                 .dac_nids = alc883_dac_nids,
9257                 .adc_nids = alc883_adc_nids_alt,
9258                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
9259                 .dig_out_nid = ALC883_DIGOUT_NID,
9260                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9261                 .channel_mode = alc883_3ST_2ch_modes,
9262                 .input_mux = &alc883_capture_source,
9263                 .unsol_event = alc883_targa_unsol_event,
9264                 .init_hook = alc883_targa_init_hook,
9265         },
9266         [ALC883_TARGA_8ch_DIG] = {
9267                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
9268                 .init_verbs = { alc883_init_verbs, alc880_gpio3_init_verbs,
9269                                 alc883_targa_verbs },
9270                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9271                 .dac_nids = alc883_dac_nids,
9272                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
9273                 .adc_nids = alc883_adc_nids_rev,
9274                 .capsrc_nids = alc883_capsrc_nids_rev,
9275                 .dig_out_nid = ALC883_DIGOUT_NID,
9276                 .dig_in_nid = ALC883_DIGIN_NID,
9277                 .num_channel_mode = ARRAY_SIZE(alc883_4ST_8ch_modes),
9278                 .channel_mode = alc883_4ST_8ch_modes,
9279                 .need_dac_fix = 1,
9280                 .input_mux = &alc883_capture_source,
9281                 .unsol_event = alc883_targa_unsol_event,
9282                 .init_hook = alc883_targa_init_hook,
9283         },
9284         [ALC883_ACER] = {
9285                 .mixers = { alc883_base_mixer },
9286                 /* On TravelMate laptops, GPIO 0 enables the internal speaker
9287                  * and the headphone jack.  Turn this on and rely on the
9288                  * standard mute methods whenever the user wants to turn
9289                  * these outputs off.
9290                  */
9291                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
9292                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9293                 .dac_nids = alc883_dac_nids,
9294                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9295                 .channel_mode = alc883_3ST_2ch_modes,
9296                 .input_mux = &alc883_capture_source,
9297         },
9298         [ALC883_ACER_ASPIRE] = {
9299                 .mixers = { alc883_acer_aspire_mixer },
9300                 .init_verbs = { alc883_init_verbs, alc883_acer_eapd_verbs },
9301                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9302                 .dac_nids = alc883_dac_nids,
9303                 .dig_out_nid = ALC883_DIGOUT_NID,
9304                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9305                 .channel_mode = alc883_3ST_2ch_modes,
9306                 .input_mux = &alc883_capture_source,
9307                 .unsol_event = alc_automute_amp_unsol_event,
9308                 .init_hook = alc883_acer_aspire_init_hook,
9309         },
9310         [ALC888_ACER_ASPIRE_4930G] = {
9311                 .mixers = { alc888_base_mixer,
9312                                 alc883_chmode_mixer },
9313                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
9314                                 alc888_acer_aspire_4930g_verbs },
9315                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9316                 .dac_nids = alc883_dac_nids,
9317                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
9318                 .adc_nids = alc883_adc_nids_rev,
9319                 .capsrc_nids = alc883_capsrc_nids_rev,
9320                 .dig_out_nid = ALC883_DIGOUT_NID,
9321                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9322                 .channel_mode = alc883_3ST_6ch_modes,
9323                 .need_dac_fix = 1,
9324                 .num_mux_defs =
9325                         ARRAY_SIZE(alc888_2_capture_sources),
9326                 .input_mux = alc888_2_capture_sources,
9327                 .unsol_event = alc_automute_amp_unsol_event,
9328                 .init_hook = alc888_acer_aspire_4930g_init_hook,
9329         },
9330         [ALC888_ACER_ASPIRE_6530G] = {
9331                 .mixers = { alc888_acer_aspire_6530_mixer },
9332                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
9333                                 alc888_acer_aspire_6530g_verbs },
9334                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9335                 .dac_nids = alc883_dac_nids,
9336                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
9337                 .adc_nids = alc883_adc_nids_rev,
9338                 .capsrc_nids = alc883_capsrc_nids_rev,
9339                 .dig_out_nid = ALC883_DIGOUT_NID,
9340                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9341                 .channel_mode = alc883_3ST_2ch_modes,
9342                 .num_mux_defs =
9343                         ARRAY_SIZE(alc888_2_capture_sources),
9344                 .input_mux = alc888_acer_aspire_6530_sources,
9345                 .unsol_event = alc_automute_amp_unsol_event,
9346                 .init_hook = alc888_acer_aspire_6530g_init_hook,
9347         },
9348         [ALC888_ACER_ASPIRE_8930G] = {
9349                 .mixers = { alc888_base_mixer,
9350                                 alc883_chmode_mixer },
9351                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
9352                                 alc889_acer_aspire_8930g_verbs },
9353                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9354                 .dac_nids = alc883_dac_nids,
9355                 .num_adc_nids = ARRAY_SIZE(alc889_adc_nids),
9356                 .adc_nids = alc889_adc_nids,
9357                 .capsrc_nids = alc889_capsrc_nids,
9358                 .dig_out_nid = ALC883_DIGOUT_NID,
9359                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9360                 .channel_mode = alc883_3ST_6ch_modes,
9361                 .need_dac_fix = 1,
9362                 .const_channel_count = 6,
9363                 .num_mux_defs =
9364                         ARRAY_SIZE(alc889_capture_sources),
9365                 .input_mux = alc889_capture_sources,
9366                 .unsol_event = alc_automute_amp_unsol_event,
9367                 .init_hook = alc889_acer_aspire_8930g_init_hook,
9368         },
9369         [ALC883_MEDION] = {
9370                 .mixers = { alc883_fivestack_mixer,
9371                             alc883_chmode_mixer },
9372                 .init_verbs = { alc883_init_verbs,
9373                                 alc883_medion_eapd_verbs },
9374                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9375                 .dac_nids = alc883_dac_nids,
9376                 .adc_nids = alc883_adc_nids_alt,
9377                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
9378                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9379                 .channel_mode = alc883_sixstack_modes,
9380                 .input_mux = &alc883_capture_source,
9381         },
9382         [ALC883_MEDION_MD2] = {
9383                 .mixers = { alc883_medion_md2_mixer},
9384                 .init_verbs = { alc883_init_verbs, alc883_medion_md2_verbs},
9385                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9386                 .dac_nids = alc883_dac_nids,
9387                 .dig_out_nid = ALC883_DIGOUT_NID,
9388                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9389                 .channel_mode = alc883_3ST_2ch_modes,
9390                 .input_mux = &alc883_capture_source,
9391                 .unsol_event = alc_automute_amp_unsol_event,
9392                 .init_hook = alc883_medion_md2_init_hook,
9393         },
9394         [ALC883_LAPTOP_EAPD] = {
9395                 .mixers = { alc883_base_mixer },
9396                 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
9397                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9398                 .dac_nids = alc883_dac_nids,
9399                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9400                 .channel_mode = alc883_3ST_2ch_modes,
9401                 .input_mux = &alc883_capture_source,
9402         },
9403         [ALC883_CLEVO_M720] = {
9404                 .mixers = { alc883_clevo_m720_mixer },
9405                 .init_verbs = { alc883_init_verbs, alc883_clevo_m720_verbs },
9406                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9407                 .dac_nids = alc883_dac_nids,
9408                 .dig_out_nid = ALC883_DIGOUT_NID,
9409                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9410                 .channel_mode = alc883_3ST_2ch_modes,
9411                 .input_mux = &alc883_capture_source,
9412                 .unsol_event = alc883_clevo_m720_unsol_event,
9413                 .init_hook = alc883_clevo_m720_init_hook,
9414         },
9415         [ALC883_LENOVO_101E_2ch] = {
9416                 .mixers = { alc883_lenovo_101e_2ch_mixer},
9417                 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
9418                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9419                 .dac_nids = alc883_dac_nids,
9420                 .adc_nids = alc883_adc_nids_alt,
9421                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
9422                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9423                 .channel_mode = alc883_3ST_2ch_modes,
9424                 .input_mux = &alc883_lenovo_101e_capture_source,
9425                 .unsol_event = alc883_lenovo_101e_unsol_event,
9426                 .init_hook = alc883_lenovo_101e_all_automute,
9427         },
9428         [ALC883_LENOVO_NB0763] = {
9429                 .mixers = { alc883_lenovo_nb0763_mixer },
9430                 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs},
9431                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9432                 .dac_nids = alc883_dac_nids,
9433                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9434                 .channel_mode = alc883_3ST_2ch_modes,
9435                 .need_dac_fix = 1,
9436                 .input_mux = &alc883_lenovo_nb0763_capture_source,
9437                 .unsol_event = alc_automute_amp_unsol_event,
9438                 .init_hook = alc883_medion_md2_init_hook,
9439         },
9440         [ALC888_LENOVO_MS7195_DIG] = {
9441                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9442                 .init_verbs = { alc883_init_verbs, alc888_lenovo_ms7195_verbs},
9443                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9444                 .dac_nids = alc883_dac_nids,
9445                 .dig_out_nid = ALC883_DIGOUT_NID,
9446                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9447                 .channel_mode = alc883_3ST_6ch_modes,
9448                 .need_dac_fix = 1,
9449                 .input_mux = &alc883_capture_source,
9450                 .unsol_event = alc883_lenovo_ms7195_unsol_event,
9451                 .init_hook = alc888_lenovo_ms7195_front_automute,
9452         },
9453         [ALC883_HAIER_W66] = {
9454                 .mixers = { alc883_targa_2ch_mixer},
9455                 .init_verbs = { alc883_init_verbs, alc883_haier_w66_verbs},
9456                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9457                 .dac_nids = alc883_dac_nids,
9458                 .dig_out_nid = ALC883_DIGOUT_NID,
9459                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9460                 .channel_mode = alc883_3ST_2ch_modes,
9461                 .input_mux = &alc883_capture_source,
9462                 .unsol_event = alc_automute_amp_unsol_event,
9463                 .init_hook = alc883_haier_w66_init_hook,
9464         },
9465         [ALC888_3ST_HP] = {
9466                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9467                 .init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs },
9468                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9469                 .dac_nids = alc883_dac_nids,
9470                 .num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes),
9471                 .channel_mode = alc888_3st_hp_modes,
9472                 .need_dac_fix = 1,
9473                 .input_mux = &alc883_capture_source,
9474                 .unsol_event = alc_automute_amp_unsol_event,
9475                 .init_hook = alc888_3st_hp_init_hook,
9476         },
9477         [ALC888_6ST_DELL] = {
9478                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
9479                 .init_verbs = { alc883_init_verbs, alc888_6st_dell_verbs },
9480                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9481                 .dac_nids = alc883_dac_nids,
9482                 .dig_out_nid = ALC883_DIGOUT_NID,
9483                 .dig_in_nid = ALC883_DIGIN_NID,
9484                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9485                 .channel_mode = alc883_sixstack_modes,
9486                 .input_mux = &alc883_capture_source,
9487                 .unsol_event = alc_automute_amp_unsol_event,
9488                 .init_hook = alc888_6st_dell_init_hook,
9489         },
9490         [ALC883_MITAC] = {
9491                 .mixers = { alc883_mitac_mixer },
9492                 .init_verbs = { alc883_init_verbs, alc883_mitac_verbs },
9493                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9494                 .dac_nids = alc883_dac_nids,
9495                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9496                 .channel_mode = alc883_3ST_2ch_modes,
9497                 .input_mux = &alc883_capture_source,
9498                 .unsol_event = alc_automute_amp_unsol_event,
9499                 .init_hook = alc883_mitac_init_hook,
9500         },
9501         [ALC883_FUJITSU_PI2515] = {
9502                 .mixers = { alc883_2ch_fujitsu_pi2515_mixer },
9503                 .init_verbs = { alc883_init_verbs,
9504                                 alc883_2ch_fujitsu_pi2515_verbs},
9505                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9506                 .dac_nids = alc883_dac_nids,
9507                 .dig_out_nid = ALC883_DIGOUT_NID,
9508                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9509                 .channel_mode = alc883_3ST_2ch_modes,
9510                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
9511                 .unsol_event = alc_automute_amp_unsol_event,
9512                 .init_hook = alc883_2ch_fujitsu_pi2515_init_hook,
9513         },
9514         [ALC888_FUJITSU_XA3530] = {
9515                 .mixers = { alc888_base_mixer, alc883_chmode_mixer },
9516                 .init_verbs = { alc883_init_verbs,
9517                         alc888_fujitsu_xa3530_verbs },
9518                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9519                 .dac_nids = alc883_dac_nids,
9520                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
9521                 .adc_nids = alc883_adc_nids_rev,
9522                 .capsrc_nids = alc883_capsrc_nids_rev,
9523                 .dig_out_nid = ALC883_DIGOUT_NID,
9524                 .num_channel_mode = ARRAY_SIZE(alc888_4ST_8ch_intel_modes),
9525                 .channel_mode = alc888_4ST_8ch_intel_modes,
9526                 .num_mux_defs =
9527                         ARRAY_SIZE(alc888_2_capture_sources),
9528                 .input_mux = alc888_2_capture_sources,
9529                 .unsol_event = alc_automute_amp_unsol_event,
9530                 .init_hook = alc888_fujitsu_xa3530_init_hook,
9531         },
9532         [ALC888_LENOVO_SKY] = {
9533                 .mixers = { alc888_lenovo_sky_mixer, alc883_chmode_mixer },
9534                 .init_verbs = { alc883_init_verbs, alc888_lenovo_sky_verbs},
9535                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9536                 .dac_nids = alc883_dac_nids,
9537                 .dig_out_nid = ALC883_DIGOUT_NID,
9538                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9539                 .channel_mode = alc883_sixstack_modes,
9540                 .need_dac_fix = 1,
9541                 .input_mux = &alc883_lenovo_sky_capture_source,
9542                 .unsol_event = alc_automute_amp_unsol_event,
9543                 .init_hook = alc888_lenovo_sky_init_hook,
9544         },
9545         [ALC888_ASUS_M90V] = {
9546                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9547                 .init_verbs = { alc883_init_verbs, alc888_asus_m90v_verbs },
9548                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9549                 .dac_nids = alc883_dac_nids,
9550                 .dig_out_nid = ALC883_DIGOUT_NID,
9551                 .dig_in_nid = ALC883_DIGIN_NID,
9552                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9553                 .channel_mode = alc883_3ST_6ch_modes,
9554                 .need_dac_fix = 1,
9555                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
9556                 .unsol_event = alc883_mode2_unsol_event,
9557                 .init_hook = alc883_mode2_inithook,
9558         },
9559         [ALC888_ASUS_EEE1601] = {
9560                 .mixers = { alc883_asus_eee1601_mixer },
9561                 .cap_mixer = alc883_asus_eee1601_cap_mixer,
9562                 .init_verbs = { alc883_init_verbs, alc888_asus_eee1601_verbs },
9563                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9564                 .dac_nids = alc883_dac_nids,
9565                 .dig_out_nid = ALC883_DIGOUT_NID,
9566                 .dig_in_nid = ALC883_DIGIN_NID,
9567                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9568                 .channel_mode = alc883_3ST_2ch_modes,
9569                 .need_dac_fix = 1,
9570                 .input_mux = &alc883_asus_eee1601_capture_source,
9571                 .unsol_event = alc_sku_unsol_event,
9572                 .init_hook = alc883_eee1601_inithook,
9573         },
9574         [ALC1200_ASUS_P5Q] = {
9575                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
9576                 .init_verbs = { alc883_init_verbs },
9577                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9578                 .dac_nids = alc883_dac_nids,
9579                 .dig_out_nid = ALC1200_DIGOUT_NID,
9580                 .dig_in_nid = ALC883_DIGIN_NID,
9581                 .slave_dig_outs = alc1200_slave_dig_outs,
9582                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9583                 .channel_mode = alc883_sixstack_modes,
9584                 .input_mux = &alc883_capture_source,
9585         },
9586         [ALC889A_MB31] = {
9587                 .mixers = { alc889A_mb31_mixer, alc883_chmode_mixer},
9588                 .init_verbs = { alc883_init_verbs, alc889A_mb31_verbs,
9589                         alc880_gpio1_init_verbs },
9590                 .adc_nids = alc883_adc_nids,
9591                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
9592                 .dac_nids = alc883_dac_nids,
9593                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9594                 .channel_mode = alc889A_mb31_6ch_modes,
9595                 .num_channel_mode = ARRAY_SIZE(alc889A_mb31_6ch_modes),
9596                 .input_mux = &alc889A_mb31_capture_source,
9597                 .dig_out_nid = ALC883_DIGOUT_NID,
9598                 .unsol_event = alc889A_mb31_unsol_event,
9599                 .init_hook = alc889A_mb31_automute,
9600         },
9601         [ALC883_SONY_VAIO_TT] = {
9602                 .mixers = { alc883_vaiott_mixer },
9603                 .init_verbs = { alc883_init_verbs, alc883_vaiott_verbs },
9604                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9605                 .dac_nids = alc883_dac_nids,
9606                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9607                 .channel_mode = alc883_3ST_2ch_modes,
9608                 .input_mux = &alc883_capture_source,
9609                 .unsol_event = alc_automute_amp_unsol_event,
9610                 .init_hook = alc883_vaiott_init_hook,
9611         },
9612 };
9613
9614
9615 /*
9616  * BIOS auto configuration
9617  */
9618 static void alc883_auto_set_output_and_unmute(struct hda_codec *codec,
9619                                               hda_nid_t nid, int pin_type,
9620                                               int dac_idx)
9621 {
9622         /* set as output */
9623         struct alc_spec *spec = codec->spec;
9624         int idx;
9625
9626         alc_set_pin_output(codec, nid, pin_type);
9627         if (spec->multiout.dac_nids[dac_idx] == 0x25)
9628                 idx = 4;
9629         else
9630                 idx = spec->multiout.dac_nids[dac_idx] - 2;
9631         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
9632
9633 }
9634
9635 static void alc883_auto_init_multi_out(struct hda_codec *codec)
9636 {
9637         struct alc_spec *spec = codec->spec;
9638         int i;
9639
9640         for (i = 0; i <= HDA_SIDE; i++) {
9641                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
9642                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
9643                 if (nid)
9644                         alc883_auto_set_output_and_unmute(codec, nid, pin_type,
9645                                                           i);
9646         }
9647 }
9648
9649 static void alc883_auto_init_hp_out(struct hda_codec *codec)
9650 {
9651         struct alc_spec *spec = codec->spec;
9652         hda_nid_t pin;
9653
9654         pin = spec->autocfg.hp_pins[0];
9655         if (pin) /* connect to front */
9656                 /* use dac 0 */
9657                 alc883_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
9658         pin = spec->autocfg.speaker_pins[0];
9659         if (pin)
9660                 alc883_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
9661 }
9662
9663 #define alc883_is_input_pin(nid)        alc880_is_input_pin(nid)
9664 #define ALC883_PIN_CD_NID               ALC880_PIN_CD_NID
9665
9666 static void alc883_auto_init_analog_input(struct hda_codec *codec)
9667 {
9668         struct alc_spec *spec = codec->spec;
9669         int i;
9670
9671         for (i = 0; i < AUTO_PIN_LAST; i++) {
9672                 hda_nid_t nid = spec->autocfg.input_pins[i];
9673                 if (alc883_is_input_pin(nid)) {
9674                         alc_set_input_pin(codec, nid, i);
9675                         if (nid != ALC883_PIN_CD_NID &&
9676                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
9677                                 snd_hda_codec_write(codec, nid, 0,
9678                                                     AC_VERB_SET_AMP_GAIN_MUTE,
9679                                                     AMP_OUT_MUTE);
9680                 }
9681         }
9682 }
9683
9684 #define alc883_auto_init_input_src      alc882_auto_init_input_src
9685
9686 /* almost identical with ALC880 parser... */
9687 static int alc883_parse_auto_config(struct hda_codec *codec)
9688 {
9689         struct alc_spec *spec = codec->spec;
9690         int err = alc880_parse_auto_config(codec);
9691         struct auto_pin_cfg *cfg = &spec->autocfg;
9692         int i;
9693
9694         if (err < 0)
9695                 return err;
9696         else if (!err)
9697                 return 0; /* no config found */
9698
9699         err = alc_auto_add_mic_boost(codec);
9700         if (err < 0)
9701                 return err;
9702
9703         /* hack - override the init verbs */
9704         spec->init_verbs[0] = alc883_auto_init_verbs;
9705
9706         /* setup input_mux for ALC889 */
9707         if (codec->vendor_id == 0x10ec0889) {
9708                 /* digital-mic input pin is excluded in alc880_auto_create..()
9709                  * because it's under 0x18
9710                  */
9711                 if (cfg->input_pins[AUTO_PIN_MIC] == 0x12 ||
9712                     cfg->input_pins[AUTO_PIN_FRONT_MIC] == 0x12) {
9713                         struct hda_input_mux *imux = &spec->private_imux[0];
9714                         for (i = 1; i < 3; i++)
9715                                 memcpy(&spec->private_imux[i],
9716                                        &spec->private_imux[0],
9717                                        sizeof(spec->private_imux[0]));
9718                         imux->items[imux->num_items].label = "Int DMic";
9719                         imux->items[imux->num_items].index = 0x0b;
9720                         imux->num_items++;
9721                         spec->num_mux_defs = 3;
9722                         spec->input_mux = spec->private_imux;
9723                 }
9724         }
9725
9726         return 1; /* config found */
9727 }
9728
9729 /* additional initialization for auto-configuration model */
9730 static void alc883_auto_init(struct hda_codec *codec)
9731 {
9732         struct alc_spec *spec = codec->spec;
9733         alc883_auto_init_multi_out(codec);
9734         alc883_auto_init_hp_out(codec);
9735         alc883_auto_init_analog_input(codec);
9736         alc883_auto_init_input_src(codec);
9737         if (spec->unsol_event)
9738                 alc_inithook(codec);
9739 }
9740
9741 static int patch_alc883(struct hda_codec *codec)
9742 {
9743         struct alc_spec *spec;
9744         int err, board_config;
9745
9746         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
9747         if (spec == NULL)
9748                 return -ENOMEM;
9749
9750         codec->spec = spec;
9751
9752         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
9753
9754         board_config = snd_hda_check_board_config(codec, ALC883_MODEL_LAST,
9755                                                   alc883_models,
9756                                                   alc883_cfg_tbl);
9757         if (board_config < 0 || board_config >= ALC883_MODEL_LAST) {
9758                 /* Pick up systems that don't supply PCI SSID */
9759                 switch (codec->subsystem_id) {
9760                 case 0x106b3600: /* Macbook 3.1 */
9761                         board_config = ALC889A_MB31;
9762                         break;
9763                 default:
9764                         printk(KERN_INFO
9765                                 "hda_codec: Unknown model for %s, trying "
9766                                 "auto-probe from BIOS...\n", codec->chip_name);
9767                         board_config = ALC883_AUTO;
9768                 }
9769         }
9770
9771         if (board_config == ALC883_AUTO) {
9772                 /* automatic parse from the BIOS config */
9773                 err = alc883_parse_auto_config(codec);
9774                 if (err < 0) {
9775                         alc_free(codec);
9776                         return err;
9777                 } else if (!err) {
9778                         printk(KERN_INFO
9779                                "hda_codec: Cannot set up configuration "
9780                                "from BIOS.  Using base mode...\n");
9781                         board_config = ALC883_3ST_2ch_DIG;
9782                 }
9783         }
9784
9785         err = snd_hda_attach_beep_device(codec, 0x1);
9786         if (err < 0) {
9787                 alc_free(codec);
9788                 return err;
9789         }
9790
9791         if (board_config != ALC883_AUTO)
9792                 setup_preset(spec, &alc883_presets[board_config]);
9793
9794         switch (codec->vendor_id) {
9795         case 0x10ec0888:
9796                 if (!spec->num_adc_nids) {
9797                         spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
9798                         spec->adc_nids = alc883_adc_nids;
9799                 }
9800                 if (!spec->capsrc_nids)
9801                         spec->capsrc_nids = alc883_capsrc_nids;
9802                 spec->init_amp = ALC_INIT_DEFAULT; /* always initialize */
9803                 break;
9804         case 0x10ec0889:
9805                 if (!spec->num_adc_nids) {
9806                         spec->num_adc_nids = ARRAY_SIZE(alc889_adc_nids);
9807                         spec->adc_nids = alc889_adc_nids;
9808                 }
9809                 if (!spec->capsrc_nids)
9810                         spec->capsrc_nids = alc889_capsrc_nids;
9811                 break;
9812         default:
9813                 if (!spec->num_adc_nids) {
9814                         spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
9815                         spec->adc_nids = alc883_adc_nids;
9816                 }
9817                 if (!spec->capsrc_nids)
9818                         spec->capsrc_nids = alc883_capsrc_nids;
9819                 break;
9820         }
9821
9822         spec->stream_analog_playback = &alc883_pcm_analog_playback;
9823         spec->stream_analog_capture = &alc883_pcm_analog_capture;
9824         spec->stream_analog_alt_capture = &alc883_pcm_analog_alt_capture;
9825
9826         spec->stream_digital_playback = &alc883_pcm_digital_playback;
9827         spec->stream_digital_capture = &alc883_pcm_digital_capture;
9828
9829         if (!spec->cap_mixer)
9830                 set_capture_mixer(spec);
9831         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
9832
9833         spec->vmaster_nid = 0x0c;
9834
9835         codec->patch_ops = alc_patch_ops;
9836         if (board_config == ALC883_AUTO)
9837                 spec->init_hook = alc883_auto_init;
9838
9839 #ifdef CONFIG_SND_HDA_POWER_SAVE
9840         if (!spec->loopback.amplist)
9841                 spec->loopback.amplist = alc883_loopbacks;
9842 #endif
9843         codec->proc_widget_hook = print_realtek_coef;
9844
9845         return 0;
9846 }
9847
9848 /*
9849  * ALC262 support
9850  */
9851
9852 #define ALC262_DIGOUT_NID       ALC880_DIGOUT_NID
9853 #define ALC262_DIGIN_NID        ALC880_DIGIN_NID
9854
9855 #define alc262_dac_nids         alc260_dac_nids
9856 #define alc262_adc_nids         alc882_adc_nids
9857 #define alc262_adc_nids_alt     alc882_adc_nids_alt
9858 #define alc262_capsrc_nids      alc882_capsrc_nids
9859 #define alc262_capsrc_nids_alt  alc882_capsrc_nids_alt
9860
9861 #define alc262_modes            alc260_modes
9862 #define alc262_capture_source   alc882_capture_source
9863
9864 static hda_nid_t alc262_dmic_adc_nids[1] = {
9865         /* ADC0 */
9866         0x09
9867 };
9868
9869 static hda_nid_t alc262_dmic_capsrc_nids[1] = { 0x22 };
9870
9871 static struct snd_kcontrol_new alc262_base_mixer[] = {
9872         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9873         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9874         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9875         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9876         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9877         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9878         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9879         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9880         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9881         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9882         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9883         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9884         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
9885         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9886         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
9887         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
9888         { } /* end */
9889 };
9890
9891 /* update HP, line and mono-out pins according to the master switch */
9892 static void alc262_hp_master_update(struct hda_codec *codec)
9893 {
9894         struct alc_spec *spec = codec->spec;
9895         int val = spec->master_sw;
9896
9897         /* HP & line-out */
9898         snd_hda_codec_write_cache(codec, 0x1b, 0,
9899                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9900                                   val ? PIN_HP : 0);
9901         snd_hda_codec_write_cache(codec, 0x15, 0,
9902                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9903                                   val ? PIN_HP : 0);
9904         /* mono (speaker) depending on the HP jack sense */
9905         val = val && !spec->jack_present;
9906         snd_hda_codec_write_cache(codec, 0x16, 0,
9907                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9908                                   val ? PIN_OUT : 0);
9909 }
9910
9911 static void alc262_hp_bpc_automute(struct hda_codec *codec)
9912 {
9913         struct alc_spec *spec = codec->spec;
9914         unsigned int presence;
9915         presence = snd_hda_codec_read(codec, 0x1b, 0,
9916                                       AC_VERB_GET_PIN_SENSE, 0);
9917         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
9918         alc262_hp_master_update(codec);
9919 }
9920
9921 static void alc262_hp_bpc_unsol_event(struct hda_codec *codec, unsigned int res)
9922 {
9923         if ((res >> 26) != ALC880_HP_EVENT)
9924                 return;
9925         alc262_hp_bpc_automute(codec);
9926 }
9927
9928 static void alc262_hp_wildwest_automute(struct hda_codec *codec)
9929 {
9930         struct alc_spec *spec = codec->spec;
9931         unsigned int presence;
9932         presence = snd_hda_codec_read(codec, 0x15, 0,
9933                                       AC_VERB_GET_PIN_SENSE, 0);
9934         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
9935         alc262_hp_master_update(codec);
9936 }
9937
9938 static void alc262_hp_wildwest_unsol_event(struct hda_codec *codec,
9939                                            unsigned int res)
9940 {
9941         if ((res >> 26) != ALC880_HP_EVENT)
9942                 return;
9943         alc262_hp_wildwest_automute(codec);
9944 }
9945
9946 #define alc262_hp_master_sw_get         alc260_hp_master_sw_get
9947
9948 static int alc262_hp_master_sw_put(struct snd_kcontrol *kcontrol,
9949                                    struct snd_ctl_elem_value *ucontrol)
9950 {
9951         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9952         struct alc_spec *spec = codec->spec;
9953         int val = !!*ucontrol->value.integer.value;
9954
9955         if (val == spec->master_sw)
9956                 return 0;
9957         spec->master_sw = val;
9958         alc262_hp_master_update(codec);
9959         return 1;
9960 }
9961
9962 #define ALC262_HP_MASTER_SWITCH                                 \
9963         {                                                       \
9964                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,            \
9965                 .name = "Master Playback Switch",               \
9966                 .info = snd_ctl_boolean_mono_info,              \
9967                 .get = alc262_hp_master_sw_get,                 \
9968                 .put = alc262_hp_master_sw_put,                 \
9969         }
9970
9971 static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
9972         ALC262_HP_MASTER_SWITCH,
9973         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9974         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9975         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9976         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
9977                               HDA_OUTPUT),
9978         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
9979                             HDA_OUTPUT),
9980         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9981         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9982         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9983         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9984         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9985         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9986         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9987         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9988         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9989         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9990         HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
9991         HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
9992         { } /* end */
9993 };
9994
9995 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
9996         ALC262_HP_MASTER_SWITCH,
9997         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9998         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9999         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
10000         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10001         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
10002                               HDA_OUTPUT),
10003         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
10004                             HDA_OUTPUT),
10005         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
10006         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
10007         HDA_CODEC_VOLUME("Front Mic Boost", 0x1a, 0, HDA_INPUT),
10008         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
10009         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
10010         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10011         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10012         { } /* end */
10013 };
10014
10015 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
10016         HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10017         HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10018         HDA_CODEC_VOLUME("Rear Mic Boost", 0x18, 0, HDA_INPUT),
10019         { } /* end */
10020 };
10021
10022 /* mute/unmute internal speaker according to the hp jack and mute state */
10023 static void alc262_hp_t5735_init_hook(struct hda_codec *codec)
10024 {
10025         struct alc_spec *spec = codec->spec;
10026
10027         spec->autocfg.hp_pins[0] = 0x15;
10028         spec->autocfg.speaker_pins[0] = 0x0c; /* HACK: not actually a pin */
10029         alc_automute_amp(codec);
10030 }
10031
10032 static struct snd_kcontrol_new alc262_hp_t5735_mixer[] = {
10033         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10034         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10035         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
10036         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10037         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10038         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10039         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10040         { } /* end */
10041 };
10042
10043 static struct hda_verb alc262_hp_t5735_verbs[] = {
10044         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10045         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10046
10047         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10048         { }
10049 };
10050
10051 static struct snd_kcontrol_new alc262_hp_rp5700_mixer[] = {
10052         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10053         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
10054         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
10055         HDA_CODEC_MUTE("Speaker Playback Switch", 0x16, 0x0, HDA_OUTPUT),
10056         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
10057         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
10058         { } /* end */
10059 };
10060
10061 static struct hda_verb alc262_hp_rp5700_verbs[] = {
10062         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10063         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10064         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10065         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10066         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10067         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10068         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10069         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10070         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
10071         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
10072         {}
10073 };
10074
10075 static struct hda_input_mux alc262_hp_rp5700_capture_source = {
10076         .num_items = 1,
10077         .items = {
10078                 { "Line", 0x1 },
10079         },
10080 };
10081
10082 /* bind hp and internal speaker mute (with plug check) as master switch */
10083 static void alc262_hippo_master_update(struct hda_codec *codec)
10084 {
10085         struct alc_spec *spec = codec->spec;
10086         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
10087         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
10088         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
10089         unsigned int mute;
10090
10091         /* HP */
10092         mute = spec->master_sw ? 0 : HDA_AMP_MUTE;
10093         snd_hda_codec_amp_stereo(codec, hp_nid, HDA_OUTPUT, 0,
10094                                  HDA_AMP_MUTE, mute);
10095         /* mute internal speaker per jack sense */
10096         if (spec->jack_present)
10097                 mute = HDA_AMP_MUTE;
10098         if (line_nid)
10099                 snd_hda_codec_amp_stereo(codec, line_nid, HDA_OUTPUT, 0,
10100                                          HDA_AMP_MUTE, mute);
10101         if (speaker_nid && speaker_nid != line_nid)
10102                 snd_hda_codec_amp_stereo(codec, speaker_nid, HDA_OUTPUT, 0,
10103                                          HDA_AMP_MUTE, mute);
10104 }
10105
10106 #define alc262_hippo_master_sw_get      alc262_hp_master_sw_get
10107
10108 static int alc262_hippo_master_sw_put(struct snd_kcontrol *kcontrol,
10109                                       struct snd_ctl_elem_value *ucontrol)
10110 {
10111         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10112         struct alc_spec *spec = codec->spec;
10113         int val = !!*ucontrol->value.integer.value;
10114
10115         if (val == spec->master_sw)
10116                 return 0;
10117         spec->master_sw = val;
10118         alc262_hippo_master_update(codec);
10119         return 1;
10120 }
10121
10122 #define ALC262_HIPPO_MASTER_SWITCH                              \
10123         {                                                       \
10124                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,            \
10125                 .name = "Master Playback Switch",               \
10126                 .info = snd_ctl_boolean_mono_info,              \
10127                 .get = alc262_hippo_master_sw_get,              \
10128                 .put = alc262_hippo_master_sw_put,              \
10129         }
10130
10131 static struct snd_kcontrol_new alc262_hippo_mixer[] = {
10132         ALC262_HIPPO_MASTER_SWITCH,
10133         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10134         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10135         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10136         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10137         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10138         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10139         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10140         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10141         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10142         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10143         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10144         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
10145         { } /* end */
10146 };
10147
10148 static struct snd_kcontrol_new alc262_hippo1_mixer[] = {
10149         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10150         ALC262_HIPPO_MASTER_SWITCH,
10151         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10152         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10153         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10154         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10155         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10156         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10157         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10158         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10159         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10160         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10161         { } /* end */
10162 };
10163
10164 /* mute/unmute internal speaker according to the hp jack and mute state */
10165 static void alc262_hippo_automute(struct hda_codec *codec)
10166 {
10167         struct alc_spec *spec = codec->spec;
10168         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
10169         unsigned int present;
10170
10171         /* need to execute and sync at first */
10172         snd_hda_codec_read(codec, hp_nid, 0, AC_VERB_SET_PIN_SENSE, 0);
10173         present = snd_hda_codec_read(codec, hp_nid, 0,
10174                                      AC_VERB_GET_PIN_SENSE, 0);
10175         spec->jack_present = (present & 0x80000000) != 0;
10176         alc262_hippo_master_update(codec);
10177 }
10178
10179 static void alc262_hippo_unsol_event(struct hda_codec *codec, unsigned int res)
10180 {
10181         if ((res >> 26) != ALC880_HP_EVENT)
10182                 return;
10183         alc262_hippo_automute(codec);
10184 }
10185
10186 static void alc262_hippo_init_hook(struct hda_codec *codec)
10187 {
10188         struct alc_spec *spec = codec->spec;
10189
10190         spec->autocfg.hp_pins[0] = 0x15;
10191         spec->autocfg.speaker_pins[0] = 0x14;
10192         alc262_hippo_automute(codec);
10193 }
10194
10195 static void alc262_hippo1_init_hook(struct hda_codec *codec)
10196 {
10197         struct alc_spec *spec = codec->spec;
10198
10199         spec->autocfg.hp_pins[0] = 0x1b;
10200         spec->autocfg.speaker_pins[0] = 0x14;
10201         alc262_hippo_automute(codec);
10202 }
10203
10204
10205 static struct snd_kcontrol_new alc262_sony_mixer[] = {
10206         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10207         ALC262_HIPPO_MASTER_SWITCH,
10208         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10209         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10210         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10211         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10212         { } /* end */
10213 };
10214
10215 static struct snd_kcontrol_new alc262_benq_t31_mixer[] = {
10216         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10217         ALC262_HIPPO_MASTER_SWITCH,
10218         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10219         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10220         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10221         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10222         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10223         { } /* end */
10224 };
10225
10226 static struct snd_kcontrol_new alc262_tyan_mixer[] = {
10227         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10228         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
10229         HDA_CODEC_VOLUME("Aux Playback Volume", 0x0b, 0x06, HDA_INPUT),
10230         HDA_CODEC_MUTE("Aux Playback Switch", 0x0b, 0x06, HDA_INPUT),
10231         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
10232         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
10233         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10234         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10235         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10236         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10237         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10238         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10239         { } /* end */
10240 };
10241
10242 static struct hda_verb alc262_tyan_verbs[] = {
10243         /* Headphone automute */
10244         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10245         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10246         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10247
10248         /* P11 AUX_IN, white 4-pin connector */
10249         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10250         {0x14, AC_VERB_SET_CONFIG_DEFAULT_BYTES_1, 0xe1},
10251         {0x14, AC_VERB_SET_CONFIG_DEFAULT_BYTES_2, 0x93},
10252         {0x14, AC_VERB_SET_CONFIG_DEFAULT_BYTES_3, 0x19},
10253
10254         {}
10255 };
10256
10257 /* unsolicited event for HP jack sensing */
10258 static void alc262_tyan_init_hook(struct hda_codec *codec)
10259 {
10260         struct alc_spec *spec = codec->spec;
10261
10262         spec->autocfg.hp_pins[0] = 0x1b;
10263         spec->autocfg.speaker_pins[0] = 0x15;
10264         alc_automute_amp(codec);
10265 }
10266
10267
10268 #define alc262_capture_mixer            alc882_capture_mixer
10269 #define alc262_capture_alt_mixer        alc882_capture_alt_mixer
10270
10271 /*
10272  * generic initialization of ADC, input mixers and output mixers
10273  */
10274 static struct hda_verb alc262_init_verbs[] = {
10275         /*
10276          * Unmute ADC0-2 and set the default input to mic-in
10277          */
10278         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10279         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10280         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10281         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10282         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10283         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10284
10285         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10286          * mixer widget
10287          * Note: PASD motherboards uses the Line In 2 as the input for
10288          * front panel mic (mic 2)
10289          */
10290         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10291         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10292         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10293         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10294         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10295         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10296
10297         /*
10298          * Set up output mixers (0x0c - 0x0e)
10299          */
10300         /* set vol=0 to output mixers */
10301         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10302         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10303         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10304         /* set up input amps for analog loopback */
10305         /* Amp Indices: DAC = 0, mixer = 1 */
10306         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10307         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10308         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10309         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10310         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10311         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10312
10313         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
10314         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
10315         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
10316         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10317         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10318         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10319
10320         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10321         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10322         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10323         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10324         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10325
10326         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
10327         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
10328
10329         /* FIXME: use matrix-type input source selection */
10330         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10331         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10332         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10333         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10334         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10335         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10336         /* Input mixer2 */
10337         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10338         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10339         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10340         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10341         /* Input mixer3 */
10342         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10343         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10344         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10345         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10346
10347         { }
10348 };
10349
10350 static struct hda_verb alc262_eapd_verbs[] = {
10351         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
10352         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
10353         { }
10354 };
10355
10356 static struct hda_verb alc262_hippo_unsol_verbs[] = {
10357         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10358         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10359         {}
10360 };
10361
10362 static struct hda_verb alc262_hippo1_unsol_verbs[] = {
10363         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
10364         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10365         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
10366
10367         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10368         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10369         {}
10370 };
10371
10372 static struct hda_verb alc262_sony_unsol_verbs[] = {
10373         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
10374         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10375         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},   // Front Mic
10376
10377         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10378         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10379         {}
10380 };
10381
10382 static struct hda_input_mux alc262_dmic_capture_source = {
10383         .num_items = 2,
10384         .items = {
10385                 { "Int DMic", 0x9 },
10386                 { "Mic", 0x0 },
10387         },
10388 };
10389
10390 static struct snd_kcontrol_new alc262_toshiba_s06_mixer[] = {
10391         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10392         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
10393         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10394         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10395         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10396         { } /* end */
10397 };
10398
10399 static struct hda_verb alc262_toshiba_s06_verbs[] = {
10400         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
10401         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10402         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10403         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10404         {0x22, AC_VERB_SET_CONNECT_SEL, 0x09},
10405         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10406         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
10407         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10408         {}
10409 };
10410
10411 static void alc262_dmic_automute(struct hda_codec *codec)
10412 {
10413         unsigned int present;
10414
10415         present = snd_hda_codec_read(codec, 0x18, 0,
10416                                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
10417         snd_hda_codec_write(codec, 0x22, 0,
10418                                 AC_VERB_SET_CONNECT_SEL, present ? 0x0 : 0x09);
10419 }
10420
10421
10422 /* unsolicited event for HP jack sensing */
10423 static void alc262_toshiba_s06_unsol_event(struct hda_codec *codec,
10424                                        unsigned int res)
10425 {
10426         if ((res >> 26) == ALC880_MIC_EVENT)
10427                 alc262_dmic_automute(codec);
10428         else
10429                 alc_sku_unsol_event(codec, res);
10430 }
10431
10432 static void alc262_toshiba_s06_init_hook(struct hda_codec *codec)
10433 {
10434         struct alc_spec *spec = codec->spec;
10435
10436         spec->autocfg.hp_pins[0] = 0x15;
10437         spec->autocfg.speaker_pins[0] = 0x14;
10438         alc_automute_pin(codec);
10439         alc262_dmic_automute(codec);
10440 }
10441
10442 /*
10443  * nec model
10444  *  0x15 = headphone
10445  *  0x16 = internal speaker
10446  *  0x18 = external mic
10447  */
10448
10449 static struct snd_kcontrol_new alc262_nec_mixer[] = {
10450         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
10451         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 0, 0x0, HDA_OUTPUT),
10452
10453         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10454         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10455         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10456
10457         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
10458         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10459         { } /* end */
10460 };
10461
10462 static struct hda_verb alc262_nec_verbs[] = {
10463         /* Unmute Speaker */
10464         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10465
10466         /* Headphone */
10467         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10468         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10469
10470         /* External mic to headphone */
10471         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10472         /* External mic to speaker */
10473         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10474         {}
10475 };
10476
10477 /*
10478  * fujitsu model
10479  *  0x14 = headphone/spdif-out, 0x15 = internal speaker,
10480  *  0x1b = port replicator headphone out
10481  */
10482
10483 #define ALC_HP_EVENT    0x37
10484
10485 static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
10486         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
10487         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10488         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
10489         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10490         {}
10491 };
10492
10493 static struct hda_verb alc262_lenovo_3000_unsol_verbs[] = {
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_input_mux alc262_fujitsu_capture_source = {
10500         .num_items = 3,
10501         .items = {
10502                 { "Mic", 0x0 },
10503                 { "Int Mic", 0x1 },
10504                 { "CD", 0x4 },
10505         },
10506 };
10507
10508 static struct hda_input_mux alc262_HP_capture_source = {
10509         .num_items = 5,
10510         .items = {
10511                 { "Mic", 0x0 },
10512                 { "Front Mic", 0x1 },
10513                 { "Line", 0x2 },
10514                 { "CD", 0x4 },
10515                 { "AUX IN", 0x6 },
10516         },
10517 };
10518
10519 static struct hda_input_mux alc262_HP_D7000_capture_source = {
10520         .num_items = 4,
10521         .items = {
10522                 { "Mic", 0x0 },
10523                 { "Front Mic", 0x2 },
10524                 { "Line", 0x1 },
10525                 { "CD", 0x4 },
10526         },
10527 };
10528
10529 /* mute/unmute internal speaker according to the hp jacks and mute state */
10530 static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
10531 {
10532         struct alc_spec *spec = codec->spec;
10533         unsigned int mute;
10534
10535         if (force || !spec->sense_updated) {
10536                 unsigned int present;
10537                 /* need to execute and sync at first */
10538                 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
10539                 /* check laptop HP jack */
10540                 present = snd_hda_codec_read(codec, 0x14, 0,
10541                                              AC_VERB_GET_PIN_SENSE, 0);
10542                 /* need to execute and sync at first */
10543                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
10544                 /* check docking HP jack */
10545                 present |= snd_hda_codec_read(codec, 0x1b, 0,
10546                                               AC_VERB_GET_PIN_SENSE, 0);
10547                 if (present & AC_PINSENSE_PRESENCE)
10548                         spec->jack_present = 1;
10549                 else
10550                         spec->jack_present = 0;
10551                 spec->sense_updated = 1;
10552         }
10553         /* unmute internal speaker only if both HPs are unplugged and
10554          * master switch is on
10555          */
10556         if (spec->jack_present)
10557                 mute = HDA_AMP_MUTE;
10558         else
10559                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
10560         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
10561                                  HDA_AMP_MUTE, mute);
10562 }
10563
10564 /* unsolicited event for HP jack sensing */
10565 static void alc262_fujitsu_unsol_event(struct hda_codec *codec,
10566                                        unsigned int res)
10567 {
10568         if ((res >> 26) != ALC_HP_EVENT)
10569                 return;
10570         alc262_fujitsu_automute(codec, 1);
10571 }
10572
10573 static void alc262_fujitsu_init_hook(struct hda_codec *codec)
10574 {
10575         alc262_fujitsu_automute(codec, 1);
10576 }
10577
10578 /* bind volumes of both NID 0x0c and 0x0d */
10579 static struct hda_bind_ctls alc262_fujitsu_bind_master_vol = {
10580         .ops = &snd_hda_bind_vol,
10581         .values = {
10582                 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
10583                 HDA_COMPOSE_AMP_VAL(0x0d, 3, 0, HDA_OUTPUT),
10584                 0
10585         },
10586 };
10587
10588 /* mute/unmute internal speaker according to the hp jack and mute state */
10589 static void alc262_lenovo_3000_automute(struct hda_codec *codec, int force)
10590 {
10591         struct alc_spec *spec = codec->spec;
10592         unsigned int mute;
10593
10594         if (force || !spec->sense_updated) {
10595                 unsigned int present_int_hp;
10596                 /* need to execute and sync at first */
10597                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
10598                 present_int_hp = snd_hda_codec_read(codec, 0x1b, 0,
10599                                         AC_VERB_GET_PIN_SENSE, 0);
10600                 spec->jack_present = (present_int_hp & 0x80000000) != 0;
10601                 spec->sense_updated = 1;
10602         }
10603         if (spec->jack_present) {
10604                 /* mute internal speaker */
10605                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10606                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
10607                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
10608                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
10609         } else {
10610                 /* unmute internal speaker if necessary */
10611                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
10612                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10613                                          HDA_AMP_MUTE, mute);
10614                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
10615                                          HDA_AMP_MUTE, mute);
10616         }
10617 }
10618
10619 /* unsolicited event for HP jack sensing */
10620 static void alc262_lenovo_3000_unsol_event(struct hda_codec *codec,
10621                                        unsigned int res)
10622 {
10623         if ((res >> 26) != ALC_HP_EVENT)
10624                 return;
10625         alc262_lenovo_3000_automute(codec, 1);
10626 }
10627
10628 /* bind hp and internal speaker mute (with plug check) */
10629 static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
10630                                          struct snd_ctl_elem_value *ucontrol)
10631 {
10632         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10633         long *valp = ucontrol->value.integer.value;
10634         int change;
10635
10636         change = snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10637                                                  HDA_AMP_MUTE,
10638                                                  valp ? 0 : HDA_AMP_MUTE);
10639         change |= snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
10640                                                  HDA_AMP_MUTE,
10641                                                  valp ? 0 : HDA_AMP_MUTE);
10642
10643         if (change)
10644                 alc262_fujitsu_automute(codec, 0);
10645         return change;
10646 }
10647
10648 static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
10649         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
10650         {
10651                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10652                 .name = "Master Playback Switch",
10653                 .info = snd_hda_mixer_amp_switch_info,
10654                 .get = snd_hda_mixer_amp_switch_get,
10655                 .put = alc262_fujitsu_master_sw_put,
10656                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
10657         },
10658         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10659         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10660         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10661         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10662         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10663         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
10664         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
10665         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
10666         { } /* end */
10667 };
10668
10669 /* bind hp and internal speaker mute (with plug check) */
10670 static int alc262_lenovo_3000_master_sw_put(struct snd_kcontrol *kcontrol,
10671                                          struct snd_ctl_elem_value *ucontrol)
10672 {
10673         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10674         long *valp = ucontrol->value.integer.value;
10675         int change;
10676
10677         change = snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
10678                                                  HDA_AMP_MUTE,
10679                                                  valp ? 0 : HDA_AMP_MUTE);
10680
10681         if (change)
10682                 alc262_lenovo_3000_automute(codec, 0);
10683         return change;
10684 }
10685
10686 static struct snd_kcontrol_new alc262_lenovo_3000_mixer[] = {
10687         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
10688         {
10689                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10690                 .name = "Master Playback Switch",
10691                 .info = snd_hda_mixer_amp_switch_info,
10692                 .get = snd_hda_mixer_amp_switch_get,
10693                 .put = alc262_lenovo_3000_master_sw_put,
10694                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
10695         },
10696         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10697         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10698         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10699         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10700         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10701         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
10702         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
10703         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
10704         { } /* end */
10705 };
10706
10707 static struct snd_kcontrol_new alc262_toshiba_rx1_mixer[] = {
10708         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
10709         ALC262_HIPPO_MASTER_SWITCH,
10710         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10711         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10712         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10713         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10714         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10715         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10716         { } /* end */
10717 };
10718
10719 /* additional init verbs for Benq laptops */
10720 static struct hda_verb alc262_EAPD_verbs[] = {
10721         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
10722         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
10723         {}
10724 };
10725
10726 static struct hda_verb alc262_benq_t31_EAPD_verbs[] = {
10727         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10728         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10729
10730         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
10731         {0x20, AC_VERB_SET_PROC_COEF,  0x3050},
10732         {}
10733 };
10734
10735 /* Samsung Q1 Ultra Vista model setup */
10736 static struct snd_kcontrol_new alc262_ultra_mixer[] = {
10737         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10738         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
10739         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10740         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10741         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
10742         HDA_CODEC_VOLUME("Headphone Mic Boost", 0x15, 0, HDA_INPUT),
10743         { } /* end */
10744 };
10745
10746 static struct hda_verb alc262_ultra_verbs[] = {
10747         /* output mixer */
10748         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10749         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10750         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10751         /* speaker */
10752         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10753         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10754         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10755         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
10756         /* HP */
10757         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10758         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10759         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10760         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10761         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10762         /* internal mic */
10763         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10764         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10765         /* ADC, choose mic */
10766         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10767         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10768         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10769         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10770         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10771         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10772         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10773         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10774         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
10775         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(8)},
10776         {}
10777 };
10778
10779 /* mute/unmute internal speaker according to the hp jack and mute state */
10780 static void alc262_ultra_automute(struct hda_codec *codec)
10781 {
10782         struct alc_spec *spec = codec->spec;
10783         unsigned int mute;
10784
10785         mute = 0;
10786         /* auto-mute only when HP is used as HP */
10787         if (!spec->cur_mux[0]) {
10788                 unsigned int present;
10789                 /* need to execute and sync at first */
10790                 snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
10791                 present = snd_hda_codec_read(codec, 0x15, 0,
10792                                              AC_VERB_GET_PIN_SENSE, 0);
10793                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
10794                 if (spec->jack_present)
10795                         mute = HDA_AMP_MUTE;
10796         }
10797         /* mute/unmute internal speaker */
10798         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10799                                  HDA_AMP_MUTE, mute);
10800         /* mute/unmute HP */
10801         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
10802                                  HDA_AMP_MUTE, mute ? 0 : HDA_AMP_MUTE);
10803 }
10804
10805 /* unsolicited event for HP jack sensing */
10806 static void alc262_ultra_unsol_event(struct hda_codec *codec,
10807                                        unsigned int res)
10808 {
10809         if ((res >> 26) != ALC880_HP_EVENT)
10810                 return;
10811         alc262_ultra_automute(codec);
10812 }
10813
10814 static struct hda_input_mux alc262_ultra_capture_source = {
10815         .num_items = 2,
10816         .items = {
10817                 { "Mic", 0x1 },
10818                 { "Headphone", 0x7 },
10819         },
10820 };
10821
10822 static int alc262_ultra_mux_enum_put(struct snd_kcontrol *kcontrol,
10823                                      struct snd_ctl_elem_value *ucontrol)
10824 {
10825         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10826         struct alc_spec *spec = codec->spec;
10827         int ret;
10828
10829         ret = alc_mux_enum_put(kcontrol, ucontrol);
10830         if (!ret)
10831                 return 0;
10832         /* reprogram the HP pin as mic or HP according to the input source */
10833         snd_hda_codec_write_cache(codec, 0x15, 0,
10834                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
10835                                   spec->cur_mux[0] ? PIN_VREF80 : PIN_HP);
10836         alc262_ultra_automute(codec); /* mute/unmute HP */
10837         return ret;
10838 }
10839
10840 static struct snd_kcontrol_new alc262_ultra_capture_mixer[] = {
10841         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
10842         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
10843         {
10844                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10845                 .name = "Capture Source",
10846                 .info = alc_mux_enum_info,
10847                 .get = alc_mux_enum_get,
10848                 .put = alc262_ultra_mux_enum_put,
10849         },
10850         { } /* end */
10851 };
10852
10853 /* add playback controls from the parsed DAC table */
10854 static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
10855                                              const struct auto_pin_cfg *cfg)
10856 {
10857         hda_nid_t nid;
10858         int err;
10859
10860         spec->multiout.num_dacs = 1;    /* only use one dac */
10861         spec->multiout.dac_nids = spec->private_dac_nids;
10862         spec->multiout.dac_nids[0] = 2;
10863
10864         nid = cfg->line_out_pins[0];
10865         if (nid) {
10866                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
10867                                   "Front Playback Volume",
10868                                   HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT));
10869                 if (err < 0)
10870                         return err;
10871                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10872                                   "Front Playback Switch",
10873                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
10874                 if (err < 0)
10875                         return err;
10876         }
10877
10878         nid = cfg->speaker_pins[0];
10879         if (nid) {
10880                 if (nid == 0x16) {
10881                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
10882                                           "Speaker Playback Volume",
10883                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
10884                                                               HDA_OUTPUT));
10885                         if (err < 0)
10886                                 return err;
10887                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10888                                           "Speaker Playback Switch",
10889                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
10890                                                               HDA_OUTPUT));
10891                         if (err < 0)
10892                                 return err;
10893                 } else {
10894                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10895                                           "Speaker Playback Switch",
10896                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
10897                                                               HDA_OUTPUT));
10898                         if (err < 0)
10899                                 return err;
10900                 }
10901         }
10902         nid = cfg->hp_pins[0];
10903         if (nid) {
10904                 /* spec->multiout.hp_nid = 2; */
10905                 if (nid == 0x16) {
10906                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
10907                                           "Headphone Playback Volume",
10908                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
10909                                                               HDA_OUTPUT));
10910                         if (err < 0)
10911                                 return err;
10912                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10913                                           "Headphone Playback Switch",
10914                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
10915                                                               HDA_OUTPUT));
10916                         if (err < 0)
10917                                 return err;
10918                 } else {
10919                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10920                                           "Headphone Playback Switch",
10921                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
10922                                                               HDA_OUTPUT));
10923                         if (err < 0)
10924                                 return err;
10925                 }
10926         }
10927         return 0;
10928 }
10929
10930 static int alc262_auto_create_analog_input_ctls(struct alc_spec *spec,
10931                                                 const struct auto_pin_cfg *cfg)
10932 {
10933         int err;
10934
10935         err = alc880_auto_create_analog_input_ctls(spec, cfg);
10936         if (err < 0)
10937                 return err;
10938         /* digital-mic input pin is excluded in alc880_auto_create..()
10939          * because it's under 0x18
10940          */
10941         if (cfg->input_pins[AUTO_PIN_MIC] == 0x12 ||
10942             cfg->input_pins[AUTO_PIN_FRONT_MIC] == 0x12) {
10943                 struct hda_input_mux *imux = &spec->private_imux[0];
10944                 imux->items[imux->num_items].label = "Int Mic";
10945                 imux->items[imux->num_items].index = 0x09;
10946                 imux->num_items++;
10947         }
10948         return 0;
10949 }
10950
10951
10952 /*
10953  * generic initialization of ADC, input mixers and output mixers
10954  */
10955 static struct hda_verb alc262_volume_init_verbs[] = {
10956         /*
10957          * Unmute ADC0-2 and set the default input to mic-in
10958          */
10959         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10960         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10961         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10962         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10963         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10964         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10965
10966         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10967          * mixer widget
10968          * Note: PASD motherboards uses the Line In 2 as the input for
10969          * front panel mic (mic 2)
10970          */
10971         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10972         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10973         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10974         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10975         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10976         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10977
10978         /*
10979          * Set up output mixers (0x0c - 0x0f)
10980          */
10981         /* set vol=0 to output mixers */
10982         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10983         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10984         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10985
10986         /* set up input amps for analog loopback */
10987         /* Amp Indices: DAC = 0, mixer = 1 */
10988         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10989         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10990         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10991         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10992         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10993         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10994
10995         /* FIXME: use matrix-type input source selection */
10996         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10997         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10998         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10999         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11000         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11001         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11002         /* Input mixer2 */
11003         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11004         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11005         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11006         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11007         /* Input mixer3 */
11008         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11009         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11010         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11011         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11012
11013         { }
11014 };
11015
11016 static struct hda_verb alc262_HP_BPC_init_verbs[] = {
11017         /*
11018          * Unmute ADC0-2 and set the default input to mic-in
11019          */
11020         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
11021         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11022         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11023         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11024         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
11025         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11026
11027         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
11028          * mixer widget
11029          * Note: PASD motherboards uses the Line In 2 as the input for
11030          * front panel mic (mic 2)
11031          */
11032         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
11033         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11034         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11035         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11036         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11037         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
11038         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
11039         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
11040
11041         /*
11042          * Set up output mixers (0x0c - 0x0e)
11043          */
11044         /* set vol=0 to output mixers */
11045         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11046         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11047         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11048
11049         /* set up input amps for analog loopback */
11050         /* Amp Indices: DAC = 0, mixer = 1 */
11051         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11052         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11053         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11054         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11055         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11056         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11057
11058         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11059         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11060         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
11061
11062         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11063         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11064
11065         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
11066         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
11067
11068         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11069         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11070         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11071         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11072         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11073
11074         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11075         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11076         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11077         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11078         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11079         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11080
11081
11082         /* FIXME: use matrix-type input source selection */
11083         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 0b, 12 */
11084         /* Input mixer1: only unmute Mic */
11085         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11086         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8))},
11087         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11088         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11089         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11090         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x05 << 8))},
11091         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x06 << 8))},
11092         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x07 << 8))},
11093         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x08 << 8))},
11094         /* Input mixer2 */
11095         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11096         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8))},
11097         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11098         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11099         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11100         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x05 << 8))},
11101         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x06 << 8))},
11102         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x07 << 8))},
11103         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x08 << 8))},
11104         /* Input mixer3 */
11105         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11106         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8))},
11107         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
11108         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
11109         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
11110         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x05 << 8))},
11111         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x06 << 8))},
11112         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x07 << 8))},
11113         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x08 << 8))},
11114
11115         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11116
11117         { }
11118 };
11119
11120 static struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
11121         /*
11122          * Unmute ADC0-2 and set the default input to mic-in
11123          */
11124         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
11125         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11126         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
11127         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11128         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
11129         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11130
11131         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
11132          * mixer widget
11133          * Note: PASD motherboards uses the Line In 2 as the input for front
11134          * panel mic (mic 2)
11135          */
11136         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
11137         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
11138         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11139         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
11140         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
11141         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
11142         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
11143         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
11144         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
11145         /*
11146          * Set up output mixers (0x0c - 0x0e)
11147          */
11148         /* set vol=0 to output mixers */
11149         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11150         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11151         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11152
11153         /* set up input amps for analog loopback */
11154         /* Amp Indices: DAC = 0, mixer = 1 */
11155         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11156         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11157         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11158         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11159         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11160         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11161
11162
11163         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP */
11164         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Mono */
11165         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* rear MIC */
11166         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* Line in */
11167         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
11168         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Line out */
11169         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* CD in */
11170
11171         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11172         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11173
11174         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
11175         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
11176
11177         /* {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 }, */
11178         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11179         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11180         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
11181         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11182         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
11183
11184         /* FIXME: use matrix-type input source selection */
11185         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
11186         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
11187         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, /*rear MIC*/
11188         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, /*Line in*/
11189         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))}, /*F MIC*/
11190         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))}, /*Front*/
11191         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))}, /*CD*/
11192         /* {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))},  */
11193         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))}, /*HP*/
11194         /* Input mixer2 */
11195         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11196         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
11197         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
11198         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
11199         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
11200         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
11201         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
11202         /* Input mixer3 */
11203         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
11204         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
11205         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
11206         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
11207         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
11208         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
11209         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
11210
11211         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11212
11213         { }
11214 };
11215
11216 static struct hda_verb alc262_toshiba_rx1_unsol_verbs[] = {
11217
11218         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Front Speaker */
11219         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
11220         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
11221
11222         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* MIC jack */
11223         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
11224         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
11225         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
11226
11227         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP  jack */
11228         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
11229         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
11230         {}
11231 };
11232
11233
11234 #ifdef CONFIG_SND_HDA_POWER_SAVE
11235 #define alc262_loopbacks        alc880_loopbacks
11236 #endif
11237
11238 /* pcm configuration: identical with ALC880 */
11239 #define alc262_pcm_analog_playback      alc880_pcm_analog_playback
11240 #define alc262_pcm_analog_capture       alc880_pcm_analog_capture
11241 #define alc262_pcm_digital_playback     alc880_pcm_digital_playback
11242 #define alc262_pcm_digital_capture      alc880_pcm_digital_capture
11243
11244 /*
11245  * BIOS auto configuration
11246  */
11247 static int alc262_parse_auto_config(struct hda_codec *codec)
11248 {
11249         struct alc_spec *spec = codec->spec;
11250         int err;
11251         static hda_nid_t alc262_ignore[] = { 0x1d, 0 };
11252
11253         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
11254                                            alc262_ignore);
11255         if (err < 0)
11256                 return err;
11257         if (!spec->autocfg.line_outs) {
11258                 if (spec->autocfg.dig_outs || spec->autocfg.dig_in_pin) {
11259                         spec->multiout.max_channels = 2;
11260                         spec->no_analog = 1;
11261                         goto dig_only;
11262                 }
11263                 return 0; /* can't find valid BIOS pin config */
11264         }
11265         err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
11266         if (err < 0)
11267                 return err;
11268         err = alc262_auto_create_analog_input_ctls(spec, &spec->autocfg);
11269         if (err < 0)
11270                 return err;
11271
11272         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
11273
11274  dig_only:
11275         if (spec->autocfg.dig_outs) {
11276                 spec->multiout.dig_out_nid = ALC262_DIGOUT_NID;
11277                 spec->dig_out_type = spec->autocfg.dig_out_type[0];
11278         }
11279         if (spec->autocfg.dig_in_pin)
11280                 spec->dig_in_nid = ALC262_DIGIN_NID;
11281
11282         if (spec->kctls.list)
11283                 add_mixer(spec, spec->kctls.list);
11284
11285         add_verb(spec, alc262_volume_init_verbs);
11286         spec->num_mux_defs = 1;
11287         spec->input_mux = &spec->private_imux[0];
11288
11289         err = alc_auto_add_mic_boost(codec);
11290         if (err < 0)
11291                 return err;
11292
11293         alc_ssid_check(codec, 0x15, 0x14, 0x1b);
11294
11295         return 1;
11296 }
11297
11298 #define alc262_auto_init_multi_out      alc882_auto_init_multi_out
11299 #define alc262_auto_init_hp_out         alc882_auto_init_hp_out
11300 #define alc262_auto_init_analog_input   alc882_auto_init_analog_input
11301 #define alc262_auto_init_input_src      alc882_auto_init_input_src
11302
11303
11304 /* init callback for auto-configuration model -- overriding the default init */
11305 static void alc262_auto_init(struct hda_codec *codec)
11306 {
11307         struct alc_spec *spec = codec->spec;
11308         alc262_auto_init_multi_out(codec);
11309         alc262_auto_init_hp_out(codec);
11310         alc262_auto_init_analog_input(codec);
11311         alc262_auto_init_input_src(codec);
11312         if (spec->unsol_event)
11313                 alc_inithook(codec);
11314 }
11315
11316 /*
11317  * configuration and preset
11318  */
11319 static const char *alc262_models[ALC262_MODEL_LAST] = {
11320         [ALC262_BASIC]          = "basic",
11321         [ALC262_HIPPO]          = "hippo",
11322         [ALC262_HIPPO_1]        = "hippo_1",
11323         [ALC262_FUJITSU]        = "fujitsu",
11324         [ALC262_HP_BPC]         = "hp-bpc",
11325         [ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000",
11326         [ALC262_HP_TC_T5735]    = "hp-tc-t5735",
11327         [ALC262_HP_RP5700]      = "hp-rp5700",
11328         [ALC262_BENQ_ED8]       = "benq",
11329         [ALC262_BENQ_T31]       = "benq-t31",
11330         [ALC262_SONY_ASSAMD]    = "sony-assamd",
11331         [ALC262_TOSHIBA_S06]    = "toshiba-s06",
11332         [ALC262_TOSHIBA_RX1]    = "toshiba-rx1",
11333         [ALC262_ULTRA]          = "ultra",
11334         [ALC262_LENOVO_3000]    = "lenovo-3000",
11335         [ALC262_NEC]            = "nec",
11336         [ALC262_TYAN]           = "tyan",
11337         [ALC262_AUTO]           = "auto",
11338 };
11339
11340 static struct snd_pci_quirk alc262_cfg_tbl[] = {
11341         SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
11342         SND_PCI_QUIRK(0x1033, 0x8895, "NEC Versa S9100", ALC262_NEC),
11343         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1200, "HP xw series",
11344                            ALC262_HP_BPC),
11345         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1300, "HP xw series",
11346                            ALC262_HP_BPC),
11347         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1700, "HP xw series",
11348                            ALC262_HP_BPC),
11349         SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
11350         SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
11351         SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
11352         SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF),
11353         SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL),
11354         SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF),
11355         SND_PCI_QUIRK(0x103c, 0x2806, "HP D7000", ALC262_HP_BPC_D7000_WL),
11356         SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF),
11357         SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC),
11358         SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC),
11359         SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC),
11360         SND_PCI_QUIRK(0x103c, 0x302f, "HP Thin Client T5735",
11361                       ALC262_HP_TC_T5735),
11362         SND_PCI_QUIRK(0x103c, 0x2817, "HP RP5700", ALC262_HP_RP5700),
11363         SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD),
11364         SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
11365         SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
11366         SND_PCI_QUIRK(0x104d, 0x9016, "Sony VAIO", ALC262_AUTO), /* dig-only */
11367         SND_PCI_QUIRK(0x104d, 0x9025, "Sony VAIO Z21MN", ALC262_TOSHIBA_S06),
11368         SND_PCI_QUIRK_MASK(0x104d, 0xff00, 0x9000, "Sony VAIO",
11369                            ALC262_SONY_ASSAMD),
11370         SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
11371                       ALC262_TOSHIBA_RX1),
11372         SND_PCI_QUIRK(0x1179, 0xff7b, "Toshiba S06", ALC262_TOSHIBA_S06),
11373         SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
11374         SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU),
11375         SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_TYAN),
11376         SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc032, "Samsung Q1",
11377                            ALC262_ULTRA),
11378         SND_PCI_QUIRK(0x144d, 0xc510, "Samsung Q45", ALC262_HIPPO),
11379         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 y410", ALC262_LENOVO_3000),
11380         SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
11381         SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
11382         SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
11383         {}
11384 };
11385
11386 static struct alc_config_preset alc262_presets[] = {
11387         [ALC262_BASIC] = {
11388                 .mixers = { alc262_base_mixer },
11389                 .init_verbs = { alc262_init_verbs },
11390                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11391                 .dac_nids = alc262_dac_nids,
11392                 .hp_nid = 0x03,
11393                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11394                 .channel_mode = alc262_modes,
11395                 .input_mux = &alc262_capture_source,
11396         },
11397         [ALC262_HIPPO] = {
11398                 .mixers = { alc262_hippo_mixer },
11399                 .init_verbs = { alc262_init_verbs, alc262_hippo_unsol_verbs},
11400                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11401                 .dac_nids = alc262_dac_nids,
11402                 .hp_nid = 0x03,
11403                 .dig_out_nid = ALC262_DIGOUT_NID,
11404                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11405                 .channel_mode = alc262_modes,
11406                 .input_mux = &alc262_capture_source,
11407                 .unsol_event = alc262_hippo_unsol_event,
11408                 .init_hook = alc262_hippo_init_hook,
11409         },
11410         [ALC262_HIPPO_1] = {
11411                 .mixers = { alc262_hippo1_mixer },
11412                 .init_verbs = { alc262_init_verbs, alc262_hippo1_unsol_verbs},
11413                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11414                 .dac_nids = alc262_dac_nids,
11415                 .hp_nid = 0x02,
11416                 .dig_out_nid = ALC262_DIGOUT_NID,
11417                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11418                 .channel_mode = alc262_modes,
11419                 .input_mux = &alc262_capture_source,
11420                 .unsol_event = alc262_hippo_unsol_event,
11421                 .init_hook = alc262_hippo1_init_hook,
11422         },
11423         [ALC262_FUJITSU] = {
11424                 .mixers = { alc262_fujitsu_mixer },
11425                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
11426                                 alc262_fujitsu_unsol_verbs },
11427                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11428                 .dac_nids = alc262_dac_nids,
11429                 .hp_nid = 0x03,
11430                 .dig_out_nid = ALC262_DIGOUT_NID,
11431                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11432                 .channel_mode = alc262_modes,
11433                 .input_mux = &alc262_fujitsu_capture_source,
11434                 .unsol_event = alc262_fujitsu_unsol_event,
11435                 .init_hook = alc262_fujitsu_init_hook,
11436         },
11437         [ALC262_HP_BPC] = {
11438                 .mixers = { alc262_HP_BPC_mixer },
11439                 .init_verbs = { alc262_HP_BPC_init_verbs },
11440                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11441                 .dac_nids = alc262_dac_nids,
11442                 .hp_nid = 0x03,
11443                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11444                 .channel_mode = alc262_modes,
11445                 .input_mux = &alc262_HP_capture_source,
11446                 .unsol_event = alc262_hp_bpc_unsol_event,
11447                 .init_hook = alc262_hp_bpc_automute,
11448         },
11449         [ALC262_HP_BPC_D7000_WF] = {
11450                 .mixers = { alc262_HP_BPC_WildWest_mixer },
11451                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
11452                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11453                 .dac_nids = alc262_dac_nids,
11454                 .hp_nid = 0x03,
11455                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11456                 .channel_mode = alc262_modes,
11457                 .input_mux = &alc262_HP_D7000_capture_source,
11458                 .unsol_event = alc262_hp_wildwest_unsol_event,
11459                 .init_hook = alc262_hp_wildwest_automute,
11460         },
11461         [ALC262_HP_BPC_D7000_WL] = {
11462                 .mixers = { alc262_HP_BPC_WildWest_mixer,
11463                             alc262_HP_BPC_WildWest_option_mixer },
11464                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
11465                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11466                 .dac_nids = alc262_dac_nids,
11467                 .hp_nid = 0x03,
11468                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11469                 .channel_mode = alc262_modes,
11470                 .input_mux = &alc262_HP_D7000_capture_source,
11471                 .unsol_event = alc262_hp_wildwest_unsol_event,
11472                 .init_hook = alc262_hp_wildwest_automute,
11473         },
11474         [ALC262_HP_TC_T5735] = {
11475                 .mixers = { alc262_hp_t5735_mixer },
11476                 .init_verbs = { alc262_init_verbs, alc262_hp_t5735_verbs },
11477                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11478                 .dac_nids = alc262_dac_nids,
11479                 .hp_nid = 0x03,
11480                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11481                 .channel_mode = alc262_modes,
11482                 .input_mux = &alc262_capture_source,
11483                 .unsol_event = alc_automute_amp_unsol_event,
11484                 .init_hook = alc262_hp_t5735_init_hook,
11485         },
11486         [ALC262_HP_RP5700] = {
11487                 .mixers = { alc262_hp_rp5700_mixer },
11488                 .init_verbs = { alc262_init_verbs, alc262_hp_rp5700_verbs },
11489                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11490                 .dac_nids = alc262_dac_nids,
11491                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11492                 .channel_mode = alc262_modes,
11493                 .input_mux = &alc262_hp_rp5700_capture_source,
11494         },
11495         [ALC262_BENQ_ED8] = {
11496                 .mixers = { alc262_base_mixer },
11497                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs },
11498                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11499                 .dac_nids = alc262_dac_nids,
11500                 .hp_nid = 0x03,
11501                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11502                 .channel_mode = alc262_modes,
11503                 .input_mux = &alc262_capture_source,
11504         },
11505         [ALC262_SONY_ASSAMD] = {
11506                 .mixers = { alc262_sony_mixer },
11507                 .init_verbs = { alc262_init_verbs, alc262_sony_unsol_verbs},
11508                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11509                 .dac_nids = alc262_dac_nids,
11510                 .hp_nid = 0x02,
11511                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11512                 .channel_mode = alc262_modes,
11513                 .input_mux = &alc262_capture_source,
11514                 .unsol_event = alc262_hippo_unsol_event,
11515                 .init_hook = alc262_hippo_init_hook,
11516         },
11517         [ALC262_BENQ_T31] = {
11518                 .mixers = { alc262_benq_t31_mixer },
11519                 .init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs, alc262_hippo_unsol_verbs },
11520                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11521                 .dac_nids = alc262_dac_nids,
11522                 .hp_nid = 0x03,
11523                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11524                 .channel_mode = alc262_modes,
11525                 .input_mux = &alc262_capture_source,
11526                 .unsol_event = alc262_hippo_unsol_event,
11527                 .init_hook = alc262_hippo_init_hook,
11528         },
11529         [ALC262_ULTRA] = {
11530                 .mixers = { alc262_ultra_mixer },
11531                 .cap_mixer = alc262_ultra_capture_mixer,
11532                 .init_verbs = { alc262_ultra_verbs },
11533                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11534                 .dac_nids = alc262_dac_nids,
11535                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11536                 .channel_mode = alc262_modes,
11537                 .input_mux = &alc262_ultra_capture_source,
11538                 .adc_nids = alc262_adc_nids, /* ADC0 */
11539                 .capsrc_nids = alc262_capsrc_nids,
11540                 .num_adc_nids = 1, /* single ADC */
11541                 .unsol_event = alc262_ultra_unsol_event,
11542                 .init_hook = alc262_ultra_automute,
11543         },
11544         [ALC262_LENOVO_3000] = {
11545                 .mixers = { alc262_lenovo_3000_mixer },
11546                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
11547                                 alc262_lenovo_3000_unsol_verbs },
11548                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11549                 .dac_nids = alc262_dac_nids,
11550                 .hp_nid = 0x03,
11551                 .dig_out_nid = ALC262_DIGOUT_NID,
11552                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11553                 .channel_mode = alc262_modes,
11554                 .input_mux = &alc262_fujitsu_capture_source,
11555                 .unsol_event = alc262_lenovo_3000_unsol_event,
11556         },
11557         [ALC262_NEC] = {
11558                 .mixers = { alc262_nec_mixer },
11559                 .init_verbs = { alc262_nec_verbs },
11560                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11561                 .dac_nids = alc262_dac_nids,
11562                 .hp_nid = 0x03,
11563                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11564                 .channel_mode = alc262_modes,
11565                 .input_mux = &alc262_capture_source,
11566         },
11567         [ALC262_TOSHIBA_S06] = {
11568                 .mixers = { alc262_toshiba_s06_mixer },
11569                 .init_verbs = { alc262_init_verbs, alc262_toshiba_s06_verbs,
11570                                                         alc262_eapd_verbs },
11571                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11572                 .capsrc_nids = alc262_dmic_capsrc_nids,
11573                 .dac_nids = alc262_dac_nids,
11574                 .adc_nids = alc262_dmic_adc_nids, /* ADC0 */
11575                 .num_adc_nids = 1, /* single ADC */
11576                 .dig_out_nid = ALC262_DIGOUT_NID,
11577                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11578                 .channel_mode = alc262_modes,
11579                 .input_mux = &alc262_dmic_capture_source,
11580                 .unsol_event = alc262_toshiba_s06_unsol_event,
11581                 .init_hook = alc262_toshiba_s06_init_hook,
11582         },
11583         [ALC262_TOSHIBA_RX1] = {
11584                 .mixers = { alc262_toshiba_rx1_mixer },
11585                 .init_verbs = { alc262_init_verbs, alc262_toshiba_rx1_unsol_verbs },
11586                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11587                 .dac_nids = alc262_dac_nids,
11588                 .hp_nid = 0x03,
11589                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11590                 .channel_mode = alc262_modes,
11591                 .input_mux = &alc262_capture_source,
11592                 .unsol_event = alc262_hippo_unsol_event,
11593                 .init_hook = alc262_hippo_init_hook,
11594         },
11595         [ALC262_TYAN] = {
11596                 .mixers = { alc262_tyan_mixer },
11597                 .init_verbs = { alc262_init_verbs, alc262_tyan_verbs},
11598                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11599                 .dac_nids = alc262_dac_nids,
11600                 .hp_nid = 0x02,
11601                 .dig_out_nid = ALC262_DIGOUT_NID,
11602                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11603                 .channel_mode = alc262_modes,
11604                 .input_mux = &alc262_capture_source,
11605                 .unsol_event = alc_automute_amp_unsol_event,
11606                 .init_hook = alc262_tyan_init_hook,
11607         },
11608 };
11609
11610 static int patch_alc262(struct hda_codec *codec)
11611 {
11612         struct alc_spec *spec;
11613         int board_config;
11614         int err;
11615
11616         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
11617         if (spec == NULL)
11618                 return -ENOMEM;
11619
11620         codec->spec = spec;
11621 #if 0
11622         /* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is
11623          * under-run
11624          */
11625         {
11626         int tmp;
11627         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
11628         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
11629         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
11630         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
11631         }
11632 #endif
11633
11634         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
11635
11636         board_config = snd_hda_check_board_config(codec, ALC262_MODEL_LAST,
11637                                                   alc262_models,
11638                                                   alc262_cfg_tbl);
11639
11640         if (board_config < 0) {
11641                 printk(KERN_INFO "hda_codec: Unknown model for %s, "
11642                        "trying auto-probe from BIOS...\n", codec->chip_name);
11643                 board_config = ALC262_AUTO;
11644         }
11645
11646         if (board_config == ALC262_AUTO) {
11647                 /* automatic parse from the BIOS config */
11648                 err = alc262_parse_auto_config(codec);
11649                 if (err < 0) {
11650                         alc_free(codec);
11651                         return err;
11652                 } else if (!err) {
11653                         printk(KERN_INFO
11654                                "hda_codec: Cannot set up configuration "
11655                                "from BIOS.  Using base mode...\n");
11656                         board_config = ALC262_BASIC;
11657                 }
11658         }
11659
11660         if (!spec->no_analog) {
11661                 err = snd_hda_attach_beep_device(codec, 0x1);
11662                 if (err < 0) {
11663                         alc_free(codec);
11664                         return err;
11665                 }
11666         }
11667
11668         if (board_config != ALC262_AUTO)
11669                 setup_preset(spec, &alc262_presets[board_config]);
11670
11671         spec->stream_analog_playback = &alc262_pcm_analog_playback;
11672         spec->stream_analog_capture = &alc262_pcm_analog_capture;
11673
11674         spec->stream_digital_playback = &alc262_pcm_digital_playback;
11675         spec->stream_digital_capture = &alc262_pcm_digital_capture;
11676
11677         if (!spec->adc_nids && spec->input_mux) {
11678                 int i;
11679                 /* check whether the digital-mic has to be supported */
11680                 for (i = 0; i < spec->input_mux->num_items; i++) {
11681                         if (spec->input_mux->items[i].index >= 9)
11682                                 break;
11683                 }
11684                 if (i < spec->input_mux->num_items) {
11685                         /* use only ADC0 */
11686                         spec->adc_nids = alc262_dmic_adc_nids;
11687                         spec->num_adc_nids = 1;
11688                         spec->capsrc_nids = alc262_dmic_capsrc_nids;
11689                 } else {
11690                         /* all analog inputs */
11691                         /* check whether NID 0x07 is valid */
11692                         unsigned int wcap = get_wcaps(codec, 0x07);
11693
11694                         /* get type */
11695                         wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
11696                         if (wcap != AC_WID_AUD_IN) {
11697                                 spec->adc_nids = alc262_adc_nids_alt;
11698                                 spec->num_adc_nids =
11699                                         ARRAY_SIZE(alc262_adc_nids_alt);
11700                                 spec->capsrc_nids = alc262_capsrc_nids_alt;
11701                         } else {
11702                                 spec->adc_nids = alc262_adc_nids;
11703                                 spec->num_adc_nids =
11704                                         ARRAY_SIZE(alc262_adc_nids);
11705                                 spec->capsrc_nids = alc262_capsrc_nids;
11706                         }
11707                 }
11708         }
11709         if (!spec->cap_mixer && !spec->no_analog)
11710                 set_capture_mixer(spec);
11711         if (!spec->no_analog)
11712                 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
11713
11714         spec->vmaster_nid = 0x0c;
11715
11716         codec->patch_ops = alc_patch_ops;
11717         if (board_config == ALC262_AUTO)
11718                 spec->init_hook = alc262_auto_init;
11719 #ifdef CONFIG_SND_HDA_POWER_SAVE
11720         if (!spec->loopback.amplist)
11721                 spec->loopback.amplist = alc262_loopbacks;
11722 #endif
11723         codec->proc_widget_hook = print_realtek_coef;
11724
11725         return 0;
11726 }
11727
11728 /*
11729  *  ALC268 channel source setting (2 channel)
11730  */
11731 #define ALC268_DIGOUT_NID       ALC880_DIGOUT_NID
11732 #define alc268_modes            alc260_modes
11733
11734 static hda_nid_t alc268_dac_nids[2] = {
11735         /* front, hp */
11736         0x02, 0x03
11737 };
11738
11739 static hda_nid_t alc268_adc_nids[2] = {
11740         /* ADC0-1 */
11741         0x08, 0x07
11742 };
11743
11744 static hda_nid_t alc268_adc_nids_alt[1] = {
11745         /* ADC0 */
11746         0x08
11747 };
11748
11749 static hda_nid_t alc268_capsrc_nids[2] = { 0x23, 0x24 };
11750
11751 static struct snd_kcontrol_new alc268_base_mixer[] = {
11752         /* output mixer control */
11753         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
11754         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11755         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
11756         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11757         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11758         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
11759         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11760         { }
11761 };
11762
11763 static struct snd_kcontrol_new alc268_toshiba_mixer[] = {
11764         /* output mixer control */
11765         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
11766         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
11767         ALC262_HIPPO_MASTER_SWITCH,
11768         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11769         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
11770         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11771         { }
11772 };
11773
11774 /* bind Beep switches of both NID 0x0f and 0x10 */
11775 static struct hda_bind_ctls alc268_bind_beep_sw = {
11776         .ops = &snd_hda_bind_sw,
11777         .values = {
11778                 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
11779                 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
11780                 0
11781         },
11782 };
11783
11784 static struct snd_kcontrol_new alc268_beep_mixer[] = {
11785         HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
11786         HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
11787         { }
11788 };
11789
11790 static struct hda_verb alc268_eapd_verbs[] = {
11791         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
11792         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
11793         { }
11794 };
11795
11796 /* Toshiba specific */
11797 static struct hda_verb alc268_toshiba_verbs[] = {
11798         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11799         { } /* end */
11800 };
11801
11802 static struct hda_input_mux alc268_acer_lc_capture_source = {
11803         .num_items = 2,
11804         .items = {
11805                 { "i-Mic", 0x6 },
11806                 { "E-Mic", 0x0 },
11807         },
11808 };
11809
11810 /* Acer specific */
11811 /* bind volumes of both NID 0x02 and 0x03 */
11812 static struct hda_bind_ctls alc268_acer_bind_master_vol = {
11813         .ops = &snd_hda_bind_vol,
11814         .values = {
11815                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
11816                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
11817                 0
11818         },
11819 };
11820
11821 /* mute/unmute internal speaker according to the hp jack and mute state */
11822 static void alc268_acer_automute(struct hda_codec *codec, int force)
11823 {
11824         struct alc_spec *spec = codec->spec;
11825         unsigned int mute;
11826
11827         if (force || !spec->sense_updated) {
11828                 unsigned int present;
11829                 present = snd_hda_codec_read(codec, 0x14, 0,
11830                                          AC_VERB_GET_PIN_SENSE, 0);
11831                 spec->jack_present = (present & 0x80000000) != 0;
11832                 spec->sense_updated = 1;
11833         }
11834         if (spec->jack_present)
11835                 mute = HDA_AMP_MUTE; /* mute internal speaker */
11836         else /* unmute internal speaker if necessary */
11837                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
11838         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
11839                                  HDA_AMP_MUTE, mute);
11840 }
11841
11842
11843 /* bind hp and internal speaker mute (with plug check) */
11844 static int alc268_acer_master_sw_put(struct snd_kcontrol *kcontrol,
11845                                      struct snd_ctl_elem_value *ucontrol)
11846 {
11847         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
11848         long *valp = ucontrol->value.integer.value;
11849         int change;
11850
11851         change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
11852                                           HDA_AMP_MUTE,
11853                                           valp[0] ? 0 : HDA_AMP_MUTE);
11854         change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
11855                                            HDA_AMP_MUTE,
11856                                            valp[1] ? 0 : HDA_AMP_MUTE);
11857         if (change)
11858                 alc268_acer_automute(codec, 0);
11859         return change;
11860 }
11861
11862 static struct snd_kcontrol_new alc268_acer_aspire_one_mixer[] = {
11863         /* output mixer control */
11864         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11865         {
11866                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11867                 .name = "Master Playback Switch",
11868                 .info = snd_hda_mixer_amp_switch_info,
11869                 .get = snd_hda_mixer_amp_switch_get,
11870                 .put = alc268_acer_master_sw_put,
11871                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11872         },
11873         HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x18, 0, HDA_INPUT),
11874         { }
11875 };
11876
11877 static struct snd_kcontrol_new alc268_acer_mixer[] = {
11878         /* output mixer control */
11879         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11880         {
11881                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11882                 .name = "Master Playback Switch",
11883                 .info = snd_hda_mixer_amp_switch_info,
11884                 .get = snd_hda_mixer_amp_switch_get,
11885                 .put = alc268_acer_master_sw_put,
11886                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11887         },
11888         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11889         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
11890         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11891         { }
11892 };
11893
11894 static struct snd_kcontrol_new alc268_acer_dmic_mixer[] = {
11895         /* output mixer control */
11896         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11897         {
11898                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11899                 .name = "Master Playback Switch",
11900                 .info = snd_hda_mixer_amp_switch_info,
11901                 .get = snd_hda_mixer_amp_switch_get,
11902                 .put = alc268_acer_master_sw_put,
11903                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11904         },
11905         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11906         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11907         { }
11908 };
11909
11910 static struct hda_verb alc268_acer_aspire_one_verbs[] = {
11911         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11912         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11913         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11914         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
11915         {0x23, AC_VERB_SET_CONNECT_SEL, 0x06},
11916         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, 0xa017},
11917         { }
11918 };
11919
11920 static struct hda_verb alc268_acer_verbs[] = {
11921         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* internal dmic? */
11922         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11923         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11924         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11925         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11926         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11927         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11928         { }
11929 };
11930
11931 /* unsolicited event for HP jack sensing */
11932 #define alc268_toshiba_unsol_event      alc262_hippo_unsol_event
11933 #define alc268_toshiba_init_hook        alc262_hippo_init_hook
11934
11935 static void alc268_acer_unsol_event(struct hda_codec *codec,
11936                                        unsigned int res)
11937 {
11938         if ((res >> 26) != ALC880_HP_EVENT)
11939                 return;
11940         alc268_acer_automute(codec, 1);
11941 }
11942
11943 static void alc268_acer_init_hook(struct hda_codec *codec)
11944 {
11945         alc268_acer_automute(codec, 1);
11946 }
11947
11948 /* toggle speaker-output according to the hp-jack state */
11949 static void alc268_aspire_one_speaker_automute(struct hda_codec *codec)
11950 {
11951         unsigned int present;
11952         unsigned char bits;
11953
11954         present = snd_hda_codec_read(codec, 0x15, 0,
11955                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11956         bits = present ? AMP_IN_MUTE(0) : 0;
11957         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 0,
11958                                 AMP_IN_MUTE(0), bits);
11959         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 1,
11960                                 AMP_IN_MUTE(0), bits);
11961 }
11962
11963
11964 static void alc268_acer_mic_automute(struct hda_codec *codec)
11965 {
11966         unsigned int present;
11967
11968         present = snd_hda_codec_read(codec, 0x18, 0,
11969                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11970         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_CONNECT_SEL,
11971                             present ? 0x0 : 0x6);
11972 }
11973
11974 static void alc268_acer_lc_unsol_event(struct hda_codec *codec,
11975                                     unsigned int res)
11976 {
11977         if ((res >> 26) == ALC880_HP_EVENT)
11978                 alc268_aspire_one_speaker_automute(codec);
11979         if ((res >> 26) == ALC880_MIC_EVENT)
11980                 alc268_acer_mic_automute(codec);
11981 }
11982
11983 static void alc268_acer_lc_init_hook(struct hda_codec *codec)
11984 {
11985         alc268_aspire_one_speaker_automute(codec);
11986         alc268_acer_mic_automute(codec);
11987 }
11988
11989 static struct snd_kcontrol_new alc268_dell_mixer[] = {
11990         /* output mixer control */
11991         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11992         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11993         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
11994         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11995         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11996         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
11997         { }
11998 };
11999
12000 static struct hda_verb alc268_dell_verbs[] = {
12001         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12002         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12003         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12004         { }
12005 };
12006
12007 /* mute/unmute internal speaker according to the hp jack and mute state */
12008 static void alc268_dell_init_hook(struct hda_codec *codec)
12009 {
12010         struct alc_spec *spec = codec->spec;
12011
12012         spec->autocfg.hp_pins[0] = 0x15;
12013         spec->autocfg.speaker_pins[0] = 0x14;
12014         alc_automute_pin(codec);
12015 }
12016
12017 static struct snd_kcontrol_new alc267_quanta_il1_mixer[] = {
12018         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x2, 0x0, HDA_OUTPUT),
12019         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12020         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
12021         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12022         HDA_CODEC_VOLUME("Mic Capture Volume", 0x23, 0x0, HDA_OUTPUT),
12023         HDA_BIND_MUTE("Mic Capture Switch", 0x23, 2, HDA_OUTPUT),
12024         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
12025         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
12026         { }
12027 };
12028
12029 static struct hda_verb alc267_quanta_il1_verbs[] = {
12030         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12031         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
12032         { }
12033 };
12034
12035 static void alc267_quanta_il1_mic_automute(struct hda_codec *codec)
12036 {
12037         unsigned int present;
12038
12039         present = snd_hda_codec_read(codec, 0x18, 0,
12040                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12041         snd_hda_codec_write(codec, 0x23, 0,
12042                             AC_VERB_SET_CONNECT_SEL,
12043                             present ? 0x00 : 0x01);
12044 }
12045
12046 static void alc267_quanta_il1_init_hook(struct hda_codec *codec)
12047 {
12048         struct alc_spec *spec = codec->spec;
12049
12050         spec->autocfg.hp_pins[0] = 0x15;
12051         spec->autocfg.speaker_pins[0] = 0x14;
12052         alc_automute_pin(codec);
12053         alc267_quanta_il1_mic_automute(codec);
12054 }
12055
12056 static void alc267_quanta_il1_unsol_event(struct hda_codec *codec,
12057                                            unsigned int res)
12058 {
12059         switch (res >> 26) {
12060         case ALC880_MIC_EVENT:
12061                 alc267_quanta_il1_mic_automute(codec);
12062                 break;
12063         default:
12064                 alc_sku_unsol_event(codec, res);
12065                 break;
12066         }
12067 }
12068
12069 /*
12070  * generic initialization of ADC, input mixers and output mixers
12071  */
12072 static struct hda_verb alc268_base_init_verbs[] = {
12073         /* Unmute DAC0-1 and set vol = 0 */
12074         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12075         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12076
12077         /*
12078          * Set up output mixers (0x0c - 0x0e)
12079          */
12080         /* set vol=0 to output mixers */
12081         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12082         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
12083
12084         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12085         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12086
12087         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
12088         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
12089         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
12090         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
12091         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
12092         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12093         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12094         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12095
12096         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12097         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12098         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12099         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12100         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12101
12102         /* set PCBEEP vol = 0, mute connections */
12103         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12104         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12105         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12106
12107         /* Unmute Selector 23h,24h and set the default input to mic-in */
12108
12109         {0x23, AC_VERB_SET_CONNECT_SEL, 0x00},
12110         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12111         {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
12112         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12113
12114         { }
12115 };
12116
12117 /*
12118  * generic initialization of ADC, input mixers and output mixers
12119  */
12120 static struct hda_verb alc268_volume_init_verbs[] = {
12121         /* set output DAC */
12122         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12123         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12124
12125         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
12126         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
12127         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12128         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12129         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
12130
12131         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12132         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12133         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12134
12135         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12136         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12137
12138         /* set PCBEEP vol = 0, mute connections */
12139         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12140         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12141         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12142
12143         { }
12144 };
12145
12146 static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
12147         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
12148         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
12149         {
12150                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12151                 /* The multiple "Capture Source" controls confuse alsamixer
12152                  * So call somewhat different..
12153                  */
12154                 /* .name = "Capture Source", */
12155                 .name = "Input Source",
12156                 .count = 1,
12157                 .info = alc_mux_enum_info,
12158                 .get = alc_mux_enum_get,
12159                 .put = alc_mux_enum_put,
12160         },
12161         { } /* end */
12162 };
12163
12164 static struct snd_kcontrol_new alc268_capture_mixer[] = {
12165         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
12166         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
12167         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
12168         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
12169         {
12170                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12171                 /* The multiple "Capture Source" controls confuse alsamixer
12172                  * So call somewhat different..
12173                  */
12174                 /* .name = "Capture Source", */
12175                 .name = "Input Source",
12176                 .count = 2,
12177                 .info = alc_mux_enum_info,
12178                 .get = alc_mux_enum_get,
12179                 .put = alc_mux_enum_put,
12180         },
12181         { } /* end */
12182 };
12183
12184 static struct hda_input_mux alc268_capture_source = {
12185         .num_items = 4,
12186         .items = {
12187                 { "Mic", 0x0 },
12188                 { "Front Mic", 0x1 },
12189                 { "Line", 0x2 },
12190                 { "CD", 0x3 },
12191         },
12192 };
12193
12194 static struct hda_input_mux alc268_acer_capture_source = {
12195         .num_items = 3,
12196         .items = {
12197                 { "Mic", 0x0 },
12198                 { "Internal Mic", 0x1 },
12199                 { "Line", 0x2 },
12200         },
12201 };
12202
12203 static struct hda_input_mux alc268_acer_dmic_capture_source = {
12204         .num_items = 3,
12205         .items = {
12206                 { "Mic", 0x0 },
12207                 { "Internal Mic", 0x6 },
12208                 { "Line", 0x2 },
12209         },
12210 };
12211
12212 #ifdef CONFIG_SND_DEBUG
12213 static struct snd_kcontrol_new alc268_test_mixer[] = {
12214         /* Volume widgets */
12215         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12216         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12217         HDA_BIND_MUTE_MONO("Mono sum Playback Switch", 0x0e, 1, 2, HDA_INPUT),
12218         HDA_BIND_MUTE("LINE-OUT sum Playback Switch", 0x0f, 2, HDA_INPUT),
12219         HDA_BIND_MUTE("HP-OUT sum Playback Switch", 0x10, 2, HDA_INPUT),
12220         HDA_BIND_MUTE("LINE-OUT Playback Switch", 0x14, 2, HDA_OUTPUT),
12221         HDA_BIND_MUTE("HP-OUT Playback Switch", 0x15, 2, HDA_OUTPUT),
12222         HDA_BIND_MUTE("Mono Playback Switch", 0x16, 2, HDA_OUTPUT),
12223         HDA_CODEC_VOLUME("MIC1 Capture Volume", 0x18, 0x0, HDA_INPUT),
12224         HDA_BIND_MUTE("MIC1 Capture Switch", 0x18, 2, HDA_OUTPUT),
12225         HDA_CODEC_VOLUME("MIC2 Capture Volume", 0x19, 0x0, HDA_INPUT),
12226         HDA_CODEC_VOLUME("LINE1 Capture Volume", 0x1a, 0x0, HDA_INPUT),
12227         HDA_BIND_MUTE("LINE1 Capture Switch", 0x1a, 2, HDA_OUTPUT),
12228         /* The below appears problematic on some hardwares */
12229         /*HDA_CODEC_VOLUME("PCBEEP Playback Volume", 0x1d, 0x0, HDA_INPUT),*/
12230         HDA_CODEC_VOLUME("PCM-IN1 Capture Volume", 0x23, 0x0, HDA_OUTPUT),
12231         HDA_BIND_MUTE("PCM-IN1 Capture Switch", 0x23, 2, HDA_OUTPUT),
12232         HDA_CODEC_VOLUME("PCM-IN2 Capture Volume", 0x24, 0x0, HDA_OUTPUT),
12233         HDA_BIND_MUTE("PCM-IN2 Capture Switch", 0x24, 2, HDA_OUTPUT),
12234
12235         /* Modes for retasking pin widgets */
12236         ALC_PIN_MODE("LINE-OUT pin mode", 0x14, ALC_PIN_DIR_INOUT),
12237         ALC_PIN_MODE("HP-OUT pin mode", 0x15, ALC_PIN_DIR_INOUT),
12238         ALC_PIN_MODE("MIC1 pin mode", 0x18, ALC_PIN_DIR_INOUT),
12239         ALC_PIN_MODE("LINE1 pin mode", 0x1a, ALC_PIN_DIR_INOUT),
12240
12241         /* Controls for GPIO pins, assuming they are configured as outputs */
12242         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
12243         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
12244         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
12245         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
12246
12247         /* Switches to allow the digital SPDIF output pin to be enabled.
12248          * The ALC268 does not have an SPDIF input.
12249          */
12250         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x06, 0x01),
12251
12252         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
12253          * this output to turn on an external amplifier.
12254          */
12255         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
12256         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
12257
12258         { } /* end */
12259 };
12260 #endif
12261
12262 /* create input playback/capture controls for the given pin */
12263 static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
12264                                     const char *ctlname, int idx)
12265 {
12266         char name[32];
12267         int err;
12268
12269         sprintf(name, "%s Playback Volume", ctlname);
12270         if (nid == 0x14) {
12271                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
12272                                   HDA_COMPOSE_AMP_VAL(0x02, 3, idx,
12273                                                       HDA_OUTPUT));
12274                 if (err < 0)
12275                         return err;
12276         } else if (nid == 0x15) {
12277                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
12278                                   HDA_COMPOSE_AMP_VAL(0x03, 3, idx,
12279                                                       HDA_OUTPUT));
12280                 if (err < 0)
12281                         return err;
12282         } else
12283                 return -1;
12284         sprintf(name, "%s Playback Switch", ctlname);
12285         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
12286                           HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
12287         if (err < 0)
12288                 return err;
12289         return 0;
12290 }
12291
12292 /* add playback controls from the parsed DAC table */
12293 static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
12294                                              const struct auto_pin_cfg *cfg)
12295 {
12296         hda_nid_t nid;
12297         int err;
12298
12299         spec->multiout.num_dacs = 2;    /* only use one dac */
12300         spec->multiout.dac_nids = spec->private_dac_nids;
12301         spec->multiout.dac_nids[0] = 2;
12302         spec->multiout.dac_nids[1] = 3;
12303
12304         nid = cfg->line_out_pins[0];
12305         if (nid)
12306                 alc268_new_analog_output(spec, nid, "Front", 0);
12307
12308         nid = cfg->speaker_pins[0];
12309         if (nid == 0x1d) {
12310                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
12311                                   "Speaker Playback Volume",
12312                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
12313                 if (err < 0)
12314                         return err;
12315         }
12316         nid = cfg->hp_pins[0];
12317         if (nid)
12318                 alc268_new_analog_output(spec, nid, "Headphone", 0);
12319
12320         nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
12321         if (nid == 0x16) {
12322                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12323                                   "Mono Playback Switch",
12324                                   HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_INPUT));
12325                 if (err < 0)
12326                         return err;
12327         }
12328         return 0;
12329 }
12330
12331 /* create playback/capture controls for input pins */
12332 static int alc268_auto_create_analog_input_ctls(struct alc_spec *spec,
12333                                                 const struct auto_pin_cfg *cfg)
12334 {
12335         struct hda_input_mux *imux = &spec->private_imux[0];
12336         int i, idx1;
12337
12338         for (i = 0; i < AUTO_PIN_LAST; i++) {
12339                 switch(cfg->input_pins[i]) {
12340                 case 0x18:
12341                         idx1 = 0;       /* Mic 1 */
12342                         break;
12343                 case 0x19:
12344                         idx1 = 1;       /* Mic 2 */
12345                         break;
12346                 case 0x1a:
12347                         idx1 = 2;       /* Line In */
12348                         break;
12349                 case 0x1c:
12350                         idx1 = 3;       /* CD */
12351                         break;
12352                 case 0x12:
12353                 case 0x13:
12354                         idx1 = 6;       /* digital mics */
12355                         break;
12356                 default:
12357                         continue;
12358                 }
12359                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
12360                 imux->items[imux->num_items].index = idx1;
12361                 imux->num_items++;
12362         }
12363         return 0;
12364 }
12365
12366 static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
12367 {
12368         struct alc_spec *spec = codec->spec;
12369         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
12370         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
12371         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
12372         unsigned int    dac_vol1, dac_vol2;
12373
12374         if (speaker_nid) {
12375                 snd_hda_codec_write(codec, speaker_nid, 0,
12376                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
12377                 snd_hda_codec_write(codec, 0x0f, 0,
12378                                     AC_VERB_SET_AMP_GAIN_MUTE,
12379                                     AMP_IN_UNMUTE(1));
12380                 snd_hda_codec_write(codec, 0x10, 0,
12381                                     AC_VERB_SET_AMP_GAIN_MUTE,
12382                                     AMP_IN_UNMUTE(1));
12383         } else {
12384                 snd_hda_codec_write(codec, 0x0f, 0,
12385                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
12386                 snd_hda_codec_write(codec, 0x10, 0,
12387                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
12388         }
12389
12390         dac_vol1 = dac_vol2 = 0xb000 | 0x40;    /* set max volume  */
12391         if (line_nid == 0x14)
12392                 dac_vol2 = AMP_OUT_ZERO;
12393         else if (line_nid == 0x15)
12394                 dac_vol1 = AMP_OUT_ZERO;
12395         if (hp_nid == 0x14)
12396                 dac_vol2 = AMP_OUT_ZERO;
12397         else if (hp_nid == 0x15)
12398                 dac_vol1 = AMP_OUT_ZERO;
12399         if (line_nid != 0x16 || hp_nid != 0x16 ||
12400             spec->autocfg.line_out_pins[1] != 0x16 ||
12401             spec->autocfg.line_out_pins[2] != 0x16)
12402                 dac_vol1 = dac_vol2 = AMP_OUT_ZERO;
12403
12404         snd_hda_codec_write(codec, 0x02, 0,
12405                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol1);
12406         snd_hda_codec_write(codec, 0x03, 0,
12407                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol2);
12408 }
12409
12410 /* pcm configuration: identical with ALC880 */
12411 #define alc268_pcm_analog_playback      alc880_pcm_analog_playback
12412 #define alc268_pcm_analog_capture       alc880_pcm_analog_capture
12413 #define alc268_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
12414 #define alc268_pcm_digital_playback     alc880_pcm_digital_playback
12415
12416 /*
12417  * BIOS auto configuration
12418  */
12419 static int alc268_parse_auto_config(struct hda_codec *codec)
12420 {
12421         struct alc_spec *spec = codec->spec;
12422         int err;
12423         static hda_nid_t alc268_ignore[] = { 0 };
12424
12425         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
12426                                            alc268_ignore);
12427         if (err < 0)
12428                 return err;
12429         if (!spec->autocfg.line_outs) {
12430                 if (spec->autocfg.dig_outs || spec->autocfg.dig_in_pin) {
12431                         spec->multiout.max_channels = 2;
12432                         spec->no_analog = 1;
12433                         goto dig_only;
12434                 }
12435                 return 0; /* can't find valid BIOS pin config */
12436         }
12437         err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
12438         if (err < 0)
12439                 return err;
12440         err = alc268_auto_create_analog_input_ctls(spec, &spec->autocfg);
12441         if (err < 0)
12442                 return err;
12443
12444         spec->multiout.max_channels = 2;
12445
12446  dig_only:
12447         /* digital only support output */
12448         if (spec->autocfg.dig_outs) {
12449                 spec->multiout.dig_out_nid = ALC268_DIGOUT_NID;
12450                 spec->dig_out_type = spec->autocfg.dig_out_type[0];
12451         }
12452         if (spec->kctls.list)
12453                 add_mixer(spec, spec->kctls.list);
12454
12455         if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d)
12456                 add_mixer(spec, alc268_beep_mixer);
12457
12458         add_verb(spec, alc268_volume_init_verbs);
12459         spec->num_mux_defs = 1;
12460         spec->input_mux = &spec->private_imux[0];
12461
12462         err = alc_auto_add_mic_boost(codec);
12463         if (err < 0)
12464                 return err;
12465
12466         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
12467
12468         return 1;
12469 }
12470
12471 #define alc268_auto_init_multi_out      alc882_auto_init_multi_out
12472 #define alc268_auto_init_hp_out         alc882_auto_init_hp_out
12473 #define alc268_auto_init_analog_input   alc882_auto_init_analog_input
12474
12475 /* init callback for auto-configuration model -- overriding the default init */
12476 static void alc268_auto_init(struct hda_codec *codec)
12477 {
12478         struct alc_spec *spec = codec->spec;
12479         alc268_auto_init_multi_out(codec);
12480         alc268_auto_init_hp_out(codec);
12481         alc268_auto_init_mono_speaker_out(codec);
12482         alc268_auto_init_analog_input(codec);
12483         if (spec->unsol_event)
12484                 alc_inithook(codec);
12485 }
12486
12487 /*
12488  * configuration and preset
12489  */
12490 static const char *alc268_models[ALC268_MODEL_LAST] = {
12491         [ALC267_QUANTA_IL1]     = "quanta-il1",
12492         [ALC268_3ST]            = "3stack",
12493         [ALC268_TOSHIBA]        = "toshiba",
12494         [ALC268_ACER]           = "acer",
12495         [ALC268_ACER_DMIC]      = "acer-dmic",
12496         [ALC268_ACER_ASPIRE_ONE]        = "acer-aspire",
12497         [ALC268_DELL]           = "dell",
12498         [ALC268_ZEPTO]          = "zepto",
12499 #ifdef CONFIG_SND_DEBUG
12500         [ALC268_TEST]           = "test",
12501 #endif
12502         [ALC268_AUTO]           = "auto",
12503 };
12504
12505 static struct snd_pci_quirk alc268_cfg_tbl[] = {
12506         SND_PCI_QUIRK(0x1025, 0x011e, "Acer Aspire 5720z", ALC268_ACER),
12507         SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
12508         SND_PCI_QUIRK(0x1025, 0x012e, "Acer Aspire 5310", ALC268_ACER),
12509         SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
12510         SND_PCI_QUIRK(0x1025, 0x0136, "Acer Aspire 5315", ALC268_ACER),
12511         SND_PCI_QUIRK(0x1025, 0x015b, "Acer Aspire One",
12512                                                 ALC268_ACER_ASPIRE_ONE),
12513         SND_PCI_QUIRK(0x1028, 0x0253, "Dell OEM", ALC268_DELL),
12514         SND_PCI_QUIRK(0x1028, 0x02b0, "Dell Inspiron Mini9", ALC268_DELL),
12515         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP TX25xx series",
12516                            ALC268_TOSHIBA),
12517         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
12518         SND_PCI_QUIRK(0x1170, 0x0040, "ZEPTO", ALC268_ZEPTO),
12519         SND_PCI_QUIRK_MASK(0x1179, 0xff00, 0xff00, "TOSHIBA A/Lx05",
12520                            ALC268_TOSHIBA),
12521         SND_PCI_QUIRK(0x14c0, 0x0025, "COMPAL IFL90/JFL-92", ALC268_TOSHIBA),
12522         SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER),
12523         SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1),
12524         SND_PCI_QUIRK(0x1854, 0x1775, "LG R510", ALC268_DELL),
12525         {}
12526 };
12527
12528 static struct alc_config_preset alc268_presets[] = {
12529         [ALC267_QUANTA_IL1] = {
12530                 .mixers = { alc267_quanta_il1_mixer, alc268_beep_mixer },
12531                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12532                                 alc267_quanta_il1_verbs },
12533                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12534                 .dac_nids = alc268_dac_nids,
12535                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12536                 .adc_nids = alc268_adc_nids_alt,
12537                 .hp_nid = 0x03,
12538                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12539                 .channel_mode = alc268_modes,
12540                 .input_mux = &alc268_capture_source,
12541                 .unsol_event = alc267_quanta_il1_unsol_event,
12542                 .init_hook = alc267_quanta_il1_init_hook,
12543         },
12544         [ALC268_3ST] = {
12545                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
12546                             alc268_beep_mixer },
12547                 .init_verbs = { alc268_base_init_verbs },
12548                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12549                 .dac_nids = alc268_dac_nids,
12550                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12551                 .adc_nids = alc268_adc_nids_alt,
12552                 .capsrc_nids = alc268_capsrc_nids,
12553                 .hp_nid = 0x03,
12554                 .dig_out_nid = ALC268_DIGOUT_NID,
12555                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12556                 .channel_mode = alc268_modes,
12557                 .input_mux = &alc268_capture_source,
12558         },
12559         [ALC268_TOSHIBA] = {
12560                 .mixers = { alc268_toshiba_mixer, alc268_capture_alt_mixer,
12561                             alc268_beep_mixer },
12562                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12563                                 alc268_toshiba_verbs },
12564                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12565                 .dac_nids = alc268_dac_nids,
12566                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12567                 .adc_nids = alc268_adc_nids_alt,
12568                 .capsrc_nids = alc268_capsrc_nids,
12569                 .hp_nid = 0x03,
12570                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12571                 .channel_mode = alc268_modes,
12572                 .input_mux = &alc268_capture_source,
12573                 .unsol_event = alc268_toshiba_unsol_event,
12574                 .init_hook = alc268_toshiba_init_hook,
12575         },
12576         [ALC268_ACER] = {
12577                 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer,
12578                             alc268_beep_mixer },
12579                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12580                                 alc268_acer_verbs },
12581                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12582                 .dac_nids = alc268_dac_nids,
12583                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12584                 .adc_nids = alc268_adc_nids_alt,
12585                 .capsrc_nids = alc268_capsrc_nids,
12586                 .hp_nid = 0x02,
12587                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12588                 .channel_mode = alc268_modes,
12589                 .input_mux = &alc268_acer_capture_source,
12590                 .unsol_event = alc268_acer_unsol_event,
12591                 .init_hook = alc268_acer_init_hook,
12592         },
12593         [ALC268_ACER_DMIC] = {
12594                 .mixers = { alc268_acer_dmic_mixer, alc268_capture_alt_mixer,
12595                             alc268_beep_mixer },
12596                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12597                                 alc268_acer_verbs },
12598                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12599                 .dac_nids = alc268_dac_nids,
12600                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12601                 .adc_nids = alc268_adc_nids_alt,
12602                 .capsrc_nids = alc268_capsrc_nids,
12603                 .hp_nid = 0x02,
12604                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12605                 .channel_mode = alc268_modes,
12606                 .input_mux = &alc268_acer_dmic_capture_source,
12607                 .unsol_event = alc268_acer_unsol_event,
12608                 .init_hook = alc268_acer_init_hook,
12609         },
12610         [ALC268_ACER_ASPIRE_ONE] = {
12611                 .mixers = { alc268_acer_aspire_one_mixer,
12612                             alc268_beep_mixer,
12613                             alc268_capture_alt_mixer },
12614                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12615                                 alc268_acer_aspire_one_verbs },
12616                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12617                 .dac_nids = alc268_dac_nids,
12618                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12619                 .adc_nids = alc268_adc_nids_alt,
12620                 .capsrc_nids = alc268_capsrc_nids,
12621                 .hp_nid = 0x03,
12622                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12623                 .channel_mode = alc268_modes,
12624                 .input_mux = &alc268_acer_lc_capture_source,
12625                 .unsol_event = alc268_acer_lc_unsol_event,
12626                 .init_hook = alc268_acer_lc_init_hook,
12627         },
12628         [ALC268_DELL] = {
12629                 .mixers = { alc268_dell_mixer, alc268_beep_mixer },
12630                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12631                                 alc268_dell_verbs },
12632                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12633                 .dac_nids = alc268_dac_nids,
12634                 .hp_nid = 0x02,
12635                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12636                 .channel_mode = alc268_modes,
12637                 .unsol_event = alc_sku_unsol_event,
12638                 .init_hook = alc268_dell_init_hook,
12639                 .input_mux = &alc268_capture_source,
12640         },
12641         [ALC268_ZEPTO] = {
12642                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
12643                             alc268_beep_mixer },
12644                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12645                                 alc268_toshiba_verbs },
12646                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12647                 .dac_nids = alc268_dac_nids,
12648                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12649                 .adc_nids = alc268_adc_nids_alt,
12650                 .capsrc_nids = alc268_capsrc_nids,
12651                 .hp_nid = 0x03,
12652                 .dig_out_nid = ALC268_DIGOUT_NID,
12653                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12654                 .channel_mode = alc268_modes,
12655                 .input_mux = &alc268_capture_source,
12656                 .unsol_event = alc268_toshiba_unsol_event,
12657                 .init_hook = alc268_toshiba_init_hook
12658         },
12659 #ifdef CONFIG_SND_DEBUG
12660         [ALC268_TEST] = {
12661                 .mixers = { alc268_test_mixer, alc268_capture_mixer },
12662                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12663                                 alc268_volume_init_verbs },
12664                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12665                 .dac_nids = alc268_dac_nids,
12666                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12667                 .adc_nids = alc268_adc_nids_alt,
12668                 .capsrc_nids = alc268_capsrc_nids,
12669                 .hp_nid = 0x03,
12670                 .dig_out_nid = ALC268_DIGOUT_NID,
12671                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12672                 .channel_mode = alc268_modes,
12673                 .input_mux = &alc268_capture_source,
12674         },
12675 #endif
12676 };
12677
12678 static int patch_alc268(struct hda_codec *codec)
12679 {
12680         struct alc_spec *spec;
12681         int board_config;
12682         int i, has_beep, err;
12683
12684         spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
12685         if (spec == NULL)
12686                 return -ENOMEM;
12687
12688         codec->spec = spec;
12689
12690         board_config = snd_hda_check_board_config(codec, ALC268_MODEL_LAST,
12691                                                   alc268_models,
12692                                                   alc268_cfg_tbl);
12693
12694         if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
12695                 printk(KERN_INFO "hda_codec: Unknown model for %s, "
12696                        "trying auto-probe from BIOS...\n", codec->chip_name);
12697                 board_config = ALC268_AUTO;
12698         }
12699
12700         if (board_config == ALC268_AUTO) {
12701                 /* automatic parse from the BIOS config */
12702                 err = alc268_parse_auto_config(codec);
12703                 if (err < 0) {
12704                         alc_free(codec);
12705                         return err;
12706                 } else if (!err) {
12707                         printk(KERN_INFO
12708                                "hda_codec: Cannot set up configuration "
12709                                "from BIOS.  Using base mode...\n");
12710                         board_config = ALC268_3ST;
12711                 }
12712         }
12713
12714         if (board_config != ALC268_AUTO)
12715                 setup_preset(spec, &alc268_presets[board_config]);
12716
12717         spec->stream_analog_playback = &alc268_pcm_analog_playback;
12718         spec->stream_analog_capture = &alc268_pcm_analog_capture;
12719         spec->stream_analog_alt_capture = &alc268_pcm_analog_alt_capture;
12720
12721         spec->stream_digital_playback = &alc268_pcm_digital_playback;
12722
12723         has_beep = 0;
12724         for (i = 0; i < spec->num_mixers; i++) {
12725                 if (spec->mixers[i] == alc268_beep_mixer) {
12726                         has_beep = 1;
12727                         break;
12728                 }
12729         }
12730
12731         if (has_beep) {
12732                 err = snd_hda_attach_beep_device(codec, 0x1);
12733                 if (err < 0) {
12734                         alc_free(codec);
12735                         return err;
12736                 }
12737                 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
12738                         /* override the amp caps for beep generator */
12739                         snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
12740                                           (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
12741                                           (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
12742                                           (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
12743                                           (0 << AC_AMPCAP_MUTE_SHIFT));
12744         }
12745
12746         if (!spec->no_analog && !spec->adc_nids && spec->input_mux) {
12747                 /* check whether NID 0x07 is valid */
12748                 unsigned int wcap = get_wcaps(codec, 0x07);
12749                 int i;
12750
12751                 /* get type */
12752                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
12753                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
12754                         spec->adc_nids = alc268_adc_nids_alt;
12755                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt);
12756                         add_mixer(spec, alc268_capture_alt_mixer);
12757                 } else {
12758                         spec->adc_nids = alc268_adc_nids;
12759                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids);
12760                         add_mixer(spec, alc268_capture_mixer);
12761                 }
12762                 spec->capsrc_nids = alc268_capsrc_nids;
12763                 /* set default input source */
12764                 for (i = 0; i < spec->num_adc_nids; i++)
12765                         snd_hda_codec_write_cache(codec, alc268_capsrc_nids[i],
12766                                 0, AC_VERB_SET_CONNECT_SEL,
12767                                 spec->input_mux->items[0].index);
12768         }
12769
12770         spec->vmaster_nid = 0x02;
12771
12772         codec->patch_ops = alc_patch_ops;
12773         if (board_config == ALC268_AUTO)
12774                 spec->init_hook = alc268_auto_init;
12775
12776         codec->proc_widget_hook = print_realtek_coef;
12777
12778         return 0;
12779 }
12780
12781 /*
12782  *  ALC269 channel source setting (2 channel)
12783  */
12784 #define ALC269_DIGOUT_NID       ALC880_DIGOUT_NID
12785
12786 #define alc269_dac_nids         alc260_dac_nids
12787
12788 static hda_nid_t alc269_adc_nids[1] = {
12789         /* ADC1 */
12790         0x08,
12791 };
12792
12793 static hda_nid_t alc269_capsrc_nids[1] = {
12794         0x23,
12795 };
12796
12797 /* NOTE: ADC2 (0x07) is connected from a recording *MIXER* (0x24),
12798  *       not a mux!
12799  */
12800
12801 static struct hda_input_mux alc269_eeepc_dmic_capture_source = {
12802         .num_items = 2,
12803         .items = {
12804                 { "i-Mic", 0x5 },
12805                 { "e-Mic", 0x0 },
12806         },
12807 };
12808
12809 static struct hda_input_mux alc269_eeepc_amic_capture_source = {
12810         .num_items = 2,
12811         .items = {
12812                 { "i-Mic", 0x1 },
12813                 { "e-Mic", 0x0 },
12814         },
12815 };
12816
12817 #define alc269_modes            alc260_modes
12818 #define alc269_capture_source   alc880_lg_lw_capture_source
12819
12820 static struct snd_kcontrol_new alc269_base_mixer[] = {
12821         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12822         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12823         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
12824         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
12825         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12826         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12827         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12828         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12829         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12830         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
12831         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12832         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
12833         { } /* end */
12834 };
12835
12836 static struct snd_kcontrol_new alc269_quanta_fl1_mixer[] = {
12837         /* output mixer control */
12838         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
12839         {
12840                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12841                 .name = "Master Playback Switch",
12842                 .info = snd_hda_mixer_amp_switch_info,
12843                 .get = snd_hda_mixer_amp_switch_get,
12844                 .put = alc268_acer_master_sw_put,
12845                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
12846         },
12847         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12848         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12849         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12850         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12851         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12852         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
12853         { }
12854 };
12855
12856 static struct snd_kcontrol_new alc269_lifebook_mixer[] = {
12857         /* output mixer control */
12858         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
12859         {
12860                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12861                 .name = "Master Playback Switch",
12862                 .info = snd_hda_mixer_amp_switch_info,
12863                 .get = snd_hda_mixer_amp_switch_get,
12864                 .put = alc268_acer_master_sw_put,
12865                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
12866         },
12867         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12868         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12869         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12870         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12871         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12872         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
12873         HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x0b, 0x03, HDA_INPUT),
12874         HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x0b, 0x03, HDA_INPUT),
12875         HDA_CODEC_VOLUME("Dock Mic Boost", 0x1b, 0, HDA_INPUT),
12876         { }
12877 };
12878
12879 /* bind volumes of both NID 0x0c and 0x0d */
12880 static struct hda_bind_ctls alc269_epc_bind_vol = {
12881         .ops = &snd_hda_bind_vol,
12882         .values = {
12883                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
12884                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
12885                 0
12886         },
12887 };
12888
12889 static struct snd_kcontrol_new alc269_eeepc_mixer[] = {
12890         HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12891         HDA_BIND_VOL("LineOut Playback Volume", &alc269_epc_bind_vol),
12892         HDA_CODEC_MUTE("LineOut Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12893         { } /* end */
12894 };
12895
12896 /* capture mixer elements */
12897 static struct snd_kcontrol_new alc269_epc_capture_mixer[] = {
12898         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
12899         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
12900         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12901         { } /* end */
12902 };
12903
12904 /* FSC amilo */
12905 static struct snd_kcontrol_new alc269_fujitsu_mixer[] = {
12906         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12907         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12908         HDA_BIND_VOL("PCM Playback Volume", &alc269_epc_bind_vol),
12909         { } /* end */
12910 };
12911
12912 static struct hda_verb alc269_quanta_fl1_verbs[] = {
12913         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12914         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12915         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12916         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12917         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12918         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12919         { }
12920 };
12921
12922 static struct hda_verb alc269_lifebook_verbs[] = {
12923         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12924         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
12925         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12926         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12927         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12928         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12929         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12930         {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12931         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12932         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12933         { }
12934 };
12935
12936 /* toggle speaker-output according to the hp-jack state */
12937 static void alc269_quanta_fl1_speaker_automute(struct hda_codec *codec)
12938 {
12939         unsigned int present;
12940         unsigned char bits;
12941
12942         present = snd_hda_codec_read(codec, 0x15, 0,
12943                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12944         bits = present ? AMP_IN_MUTE(0) : 0;
12945         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
12946                         AMP_IN_MUTE(0), bits);
12947         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
12948                         AMP_IN_MUTE(0), bits);
12949
12950         snd_hda_codec_write(codec, 0x20, 0,
12951                         AC_VERB_SET_COEF_INDEX, 0x0c);
12952         snd_hda_codec_write(codec, 0x20, 0,
12953                         AC_VERB_SET_PROC_COEF, 0x680);
12954
12955         snd_hda_codec_write(codec, 0x20, 0,
12956                         AC_VERB_SET_COEF_INDEX, 0x0c);
12957         snd_hda_codec_write(codec, 0x20, 0,
12958                         AC_VERB_SET_PROC_COEF, 0x480);
12959 }
12960
12961 /* toggle speaker-output according to the hp-jacks state */
12962 static void alc269_lifebook_speaker_automute(struct hda_codec *codec)
12963 {
12964         unsigned int present;
12965         unsigned char bits;
12966
12967         /* Check laptop headphone socket */
12968         present = snd_hda_codec_read(codec, 0x15, 0,
12969                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12970
12971         /* Check port replicator headphone socket */
12972         present |= snd_hda_codec_read(codec, 0x1a, 0,
12973                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12974
12975         bits = present ? AMP_IN_MUTE(0) : 0;
12976         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
12977                         AMP_IN_MUTE(0), bits);
12978         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
12979                         AMP_IN_MUTE(0), bits);
12980
12981         snd_hda_codec_write(codec, 0x20, 0,
12982                         AC_VERB_SET_COEF_INDEX, 0x0c);
12983         snd_hda_codec_write(codec, 0x20, 0,
12984                         AC_VERB_SET_PROC_COEF, 0x680);
12985
12986         snd_hda_codec_write(codec, 0x20, 0,
12987                         AC_VERB_SET_COEF_INDEX, 0x0c);
12988         snd_hda_codec_write(codec, 0x20, 0,
12989                         AC_VERB_SET_PROC_COEF, 0x480);
12990 }
12991
12992 static void alc269_quanta_fl1_mic_automute(struct hda_codec *codec)
12993 {
12994         unsigned int present;
12995
12996         present = snd_hda_codec_read(codec, 0x18, 0,
12997                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12998         snd_hda_codec_write(codec, 0x23, 0,
12999                             AC_VERB_SET_CONNECT_SEL, present ? 0x0 : 0x1);
13000 }
13001
13002 static void alc269_lifebook_mic_autoswitch(struct hda_codec *codec)
13003 {
13004         unsigned int present_laptop;
13005         unsigned int present_dock;
13006
13007         present_laptop = snd_hda_codec_read(codec, 0x18, 0,
13008                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13009
13010         present_dock = snd_hda_codec_read(codec, 0x1b, 0,
13011                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13012
13013         /* Laptop mic port overrides dock mic port, design decision */
13014         if (present_dock)
13015                 snd_hda_codec_write(codec, 0x23, 0,
13016                                 AC_VERB_SET_CONNECT_SEL, 0x3);
13017         if (present_laptop)
13018                 snd_hda_codec_write(codec, 0x23, 0,
13019                                 AC_VERB_SET_CONNECT_SEL, 0x0);
13020         if (!present_dock && !present_laptop)
13021                 snd_hda_codec_write(codec, 0x23, 0,
13022                                 AC_VERB_SET_CONNECT_SEL, 0x1);
13023 }
13024
13025 static void alc269_quanta_fl1_unsol_event(struct hda_codec *codec,
13026                                     unsigned int res)
13027 {
13028         if ((res >> 26) == ALC880_HP_EVENT)
13029                 alc269_quanta_fl1_speaker_automute(codec);
13030         if ((res >> 26) == ALC880_MIC_EVENT)
13031                 alc269_quanta_fl1_mic_automute(codec);
13032 }
13033
13034 static void alc269_lifebook_unsol_event(struct hda_codec *codec,
13035                                         unsigned int res)
13036 {
13037         if ((res >> 26) == ALC880_HP_EVENT)
13038                 alc269_lifebook_speaker_automute(codec);
13039         if ((res >> 26) == ALC880_MIC_EVENT)
13040                 alc269_lifebook_mic_autoswitch(codec);
13041 }
13042
13043 static void alc269_quanta_fl1_init_hook(struct hda_codec *codec)
13044 {
13045         alc269_quanta_fl1_speaker_automute(codec);
13046         alc269_quanta_fl1_mic_automute(codec);
13047 }
13048
13049 static void alc269_lifebook_init_hook(struct hda_codec *codec)
13050 {
13051         alc269_lifebook_speaker_automute(codec);
13052         alc269_lifebook_mic_autoswitch(codec);
13053 }
13054
13055 static struct hda_verb alc269_eeepc_dmic_init_verbs[] = {
13056         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
13057         {0x23, AC_VERB_SET_CONNECT_SEL, 0x05},
13058         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
13059         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))},
13060         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13061         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
13062         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13063         {}
13064 };
13065
13066 static struct hda_verb alc269_eeepc_amic_init_verbs[] = {
13067         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
13068         {0x23, AC_VERB_SET_CONNECT_SEL, 0x01},
13069         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
13070         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x701b | (0x00 << 8))},
13071         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
13072         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13073         {}
13074 };
13075
13076 /* toggle speaker-output according to the hp-jack state */
13077 static void alc269_speaker_automute(struct hda_codec *codec)
13078 {
13079         unsigned int present;
13080         unsigned char bits;
13081
13082         present = snd_hda_codec_read(codec, 0x15, 0,
13083                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13084         bits = present ? AMP_IN_MUTE(0) : 0;
13085         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
13086                                 AMP_IN_MUTE(0), bits);
13087         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
13088                                 AMP_IN_MUTE(0), bits);
13089 }
13090
13091 static void alc269_eeepc_dmic_automute(struct hda_codec *codec)
13092 {
13093         unsigned int present;
13094
13095         present = snd_hda_codec_read(codec, 0x18, 0,
13096                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13097         snd_hda_codec_write(codec, 0x23, 0,
13098                                 AC_VERB_SET_CONNECT_SEL,  (present ? 0 : 5));
13099 }
13100
13101 static void alc269_eeepc_amic_automute(struct hda_codec *codec)
13102 {
13103         unsigned int present;
13104
13105         present = snd_hda_codec_read(codec, 0x18, 0,
13106                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13107         snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
13108                                 0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
13109         snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
13110                                 0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
13111 }
13112
13113 /* unsolicited event for HP jack sensing */
13114 static void alc269_eeepc_dmic_unsol_event(struct hda_codec *codec,
13115                                      unsigned int res)
13116 {
13117         if ((res >> 26) == ALC880_HP_EVENT)
13118                 alc269_speaker_automute(codec);
13119
13120         if ((res >> 26) == ALC880_MIC_EVENT)
13121                 alc269_eeepc_dmic_automute(codec);
13122 }
13123
13124 static void alc269_eeepc_dmic_inithook(struct hda_codec *codec)
13125 {
13126         alc269_speaker_automute(codec);
13127         alc269_eeepc_dmic_automute(codec);
13128 }
13129
13130 /* unsolicited event for HP jack sensing */
13131 static void alc269_eeepc_amic_unsol_event(struct hda_codec *codec,
13132                                      unsigned int res)
13133 {
13134         if ((res >> 26) == ALC880_HP_EVENT)
13135                 alc269_speaker_automute(codec);
13136
13137         if ((res >> 26) == ALC880_MIC_EVENT)
13138                 alc269_eeepc_amic_automute(codec);
13139 }
13140
13141 static void alc269_eeepc_amic_inithook(struct hda_codec *codec)
13142 {
13143         alc269_speaker_automute(codec);
13144         alc269_eeepc_amic_automute(codec);
13145 }
13146
13147 /*
13148  * generic initialization of ADC, input mixers and output mixers
13149  */
13150 static struct hda_verb alc269_init_verbs[] = {
13151         /*
13152          * Unmute ADC0 and set the default input to mic-in
13153          */
13154         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13155
13156         /* Mute input amps (PCBeep, Line In, Mic 1 & Mic 2) of the
13157          * analog-loopback mixer widget
13158          * Note: PASD motherboards uses the Line In 2 as the input for
13159          * front panel mic (mic 2)
13160          */
13161         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
13162         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13163         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13164         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
13165         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
13166         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
13167
13168         /*
13169          * Set up output mixers (0x0c - 0x0e)
13170          */
13171         /* set vol=0 to output mixers */
13172         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13173         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
13174
13175         /* set up input amps for analog loopback */
13176         /* Amp Indices: DAC = 0, mixer = 1 */
13177         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13178         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13179         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13180         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13181         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13182         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13183
13184         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13185         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
13186         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
13187         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13188         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
13189         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13190         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
13191
13192         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13193         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13194         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13195         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13196         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13197         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13198         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13199
13200         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
13201         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
13202
13203         /* FIXME: use matrix-type input source selection */
13204         /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
13205         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
13206         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13207         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13208         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
13209         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
13210
13211         /* set EAPD */
13212         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
13213         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
13214         { }
13215 };
13216
13217 /* add playback controls from the parsed DAC table */
13218 static int alc269_auto_create_multi_out_ctls(struct alc_spec *spec,
13219                                              const struct auto_pin_cfg *cfg)
13220 {
13221         hda_nid_t nid;
13222         int err;
13223
13224         spec->multiout.num_dacs = 1;    /* only use one dac */
13225         spec->multiout.dac_nids = spec->private_dac_nids;
13226         spec->multiout.dac_nids[0] = 2;
13227
13228         nid = cfg->line_out_pins[0];
13229         if (nid) {
13230                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
13231                                   "Front Playback Volume",
13232                                   HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT));
13233                 if (err < 0)
13234                         return err;
13235                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
13236                                   "Front Playback Switch",
13237                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
13238                 if (err < 0)
13239                         return err;
13240         }
13241
13242         nid = cfg->speaker_pins[0];
13243         if (nid) {
13244                 if (!cfg->line_out_pins[0]) {
13245                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
13246                                           "Speaker Playback Volume",
13247                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
13248                                                               HDA_OUTPUT));
13249                         if (err < 0)
13250                                 return err;
13251                 }
13252                 if (nid == 0x16) {
13253                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
13254                                           "Speaker Playback Switch",
13255                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
13256                                                               HDA_OUTPUT));
13257                         if (err < 0)
13258                                 return err;
13259                 } else {
13260                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
13261                                           "Speaker Playback Switch",
13262                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
13263                                                               HDA_OUTPUT));
13264                         if (err < 0)
13265                                 return err;
13266                 }
13267         }
13268         nid = cfg->hp_pins[0];
13269         if (nid) {
13270                 /* spec->multiout.hp_nid = 2; */
13271                 if (!cfg->line_out_pins[0] && !cfg->speaker_pins[0]) {
13272                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
13273                                           "Headphone Playback Volume",
13274                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
13275                                                               HDA_OUTPUT));
13276                         if (err < 0)
13277                                 return err;
13278                 }
13279                 if (nid == 0x16) {
13280                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
13281                                           "Headphone Playback Switch",
13282                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
13283                                                               HDA_OUTPUT));
13284                         if (err < 0)
13285                                 return err;
13286                 } else {
13287                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
13288                                           "Headphone Playback Switch",
13289                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
13290                                                               HDA_OUTPUT));
13291                         if (err < 0)
13292                                 return err;
13293                 }
13294         }
13295         return 0;
13296 }
13297
13298 #define alc269_auto_create_analog_input_ctls \
13299         alc262_auto_create_analog_input_ctls
13300
13301 #ifdef CONFIG_SND_HDA_POWER_SAVE
13302 #define alc269_loopbacks        alc880_loopbacks
13303 #endif
13304
13305 /* pcm configuration: identical with ALC880 */
13306 #define alc269_pcm_analog_playback      alc880_pcm_analog_playback
13307 #define alc269_pcm_analog_capture       alc880_pcm_analog_capture
13308 #define alc269_pcm_digital_playback     alc880_pcm_digital_playback
13309 #define alc269_pcm_digital_capture      alc880_pcm_digital_capture
13310
13311 static struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
13312         .substreams = 1,
13313         .channels_min = 2,
13314         .channels_max = 8,
13315         .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
13316         /* NID is set in alc_build_pcms */
13317         .ops = {
13318                 .open = alc880_playback_pcm_open,
13319                 .prepare = alc880_playback_pcm_prepare,
13320                 .cleanup = alc880_playback_pcm_cleanup
13321         },
13322 };
13323
13324 static struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
13325         .substreams = 1,
13326         .channels_min = 2,
13327         .channels_max = 2,
13328         .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
13329         /* NID is set in alc_build_pcms */
13330 };
13331
13332 /*
13333  * BIOS auto configuration
13334  */
13335 static int alc269_parse_auto_config(struct hda_codec *codec)
13336 {
13337         struct alc_spec *spec = codec->spec;
13338         int err;
13339         static hda_nid_t alc269_ignore[] = { 0x1d, 0 };
13340
13341         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
13342                                            alc269_ignore);
13343         if (err < 0)
13344                 return err;
13345
13346         err = alc269_auto_create_multi_out_ctls(spec, &spec->autocfg);
13347         if (err < 0)
13348                 return err;
13349         err = alc269_auto_create_analog_input_ctls(spec, &spec->autocfg);
13350         if (err < 0)
13351                 return err;
13352
13353         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
13354
13355         if (spec->autocfg.dig_outs)
13356                 spec->multiout.dig_out_nid = ALC269_DIGOUT_NID;
13357
13358         if (spec->kctls.list)
13359                 add_mixer(spec, spec->kctls.list);
13360
13361         add_verb(spec, alc269_init_verbs);
13362         spec->num_mux_defs = 1;
13363         spec->input_mux = &spec->private_imux[0];
13364         /* set default input source */
13365         snd_hda_codec_write_cache(codec, alc269_capsrc_nids[0],
13366                                   0, AC_VERB_SET_CONNECT_SEL,
13367                                   spec->input_mux->items[0].index);
13368
13369         err = alc_auto_add_mic_boost(codec);
13370         if (err < 0)
13371                 return err;
13372
13373         if (!spec->cap_mixer && !spec->no_analog)
13374                 set_capture_mixer(spec);
13375
13376         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
13377
13378         return 1;
13379 }
13380
13381 #define alc269_auto_init_multi_out      alc882_auto_init_multi_out
13382 #define alc269_auto_init_hp_out         alc882_auto_init_hp_out
13383 #define alc269_auto_init_analog_input   alc882_auto_init_analog_input
13384
13385
13386 /* init callback for auto-configuration model -- overriding the default init */
13387 static void alc269_auto_init(struct hda_codec *codec)
13388 {
13389         struct alc_spec *spec = codec->spec;
13390         alc269_auto_init_multi_out(codec);
13391         alc269_auto_init_hp_out(codec);
13392         alc269_auto_init_analog_input(codec);
13393         if (spec->unsol_event)
13394                 alc_inithook(codec);
13395 }
13396
13397 /*
13398  * configuration and preset
13399  */
13400 static const char *alc269_models[ALC269_MODEL_LAST] = {
13401         [ALC269_BASIC]                  = "basic",
13402         [ALC269_QUANTA_FL1]             = "quanta",
13403         [ALC269_ASUS_EEEPC_P703]        = "eeepc-p703",
13404         [ALC269_ASUS_EEEPC_P901]        = "eeepc-p901",
13405         [ALC269_FUJITSU]                = "fujitsu",
13406         [ALC269_LIFEBOOK]               = "lifebook"
13407 };
13408
13409 static struct snd_pci_quirk alc269_cfg_tbl[] = {
13410         SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_QUANTA_FL1),
13411         SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
13412                       ALC269_ASUS_EEEPC_P703),
13413         SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_ASUS_EEEPC_P703),
13414         SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_ASUS_EEEPC_P703),
13415         SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_ASUS_EEEPC_P703),
13416         SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_ASUS_EEEPC_P703),
13417         SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_ASUS_EEEPC_P703),
13418         SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_ASUS_EEEPC_P703),
13419         SND_PCI_QUIRK(0x1043, 0x831a, "ASUS Eeepc P901",
13420                       ALC269_ASUS_EEEPC_P901),
13421         SND_PCI_QUIRK(0x1043, 0x834a, "ASUS Eeepc S101",
13422                       ALC269_ASUS_EEEPC_P901),
13423         SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_ASUS_EEEPC_P901),
13424         SND_PCI_QUIRK(0x1734, 0x115d, "FSC Amilo", ALC269_FUJITSU),
13425         SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook ICH9M-based", ALC269_LIFEBOOK),
13426         {}
13427 };
13428
13429 static struct alc_config_preset alc269_presets[] = {
13430         [ALC269_BASIC] = {
13431                 .mixers = { alc269_base_mixer },
13432                 .init_verbs = { alc269_init_verbs },
13433                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13434                 .dac_nids = alc269_dac_nids,
13435                 .hp_nid = 0x03,
13436                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13437                 .channel_mode = alc269_modes,
13438                 .input_mux = &alc269_capture_source,
13439         },
13440         [ALC269_QUANTA_FL1] = {
13441                 .mixers = { alc269_quanta_fl1_mixer },
13442                 .init_verbs = { alc269_init_verbs, alc269_quanta_fl1_verbs },
13443                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13444                 .dac_nids = alc269_dac_nids,
13445                 .hp_nid = 0x03,
13446                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13447                 .channel_mode = alc269_modes,
13448                 .input_mux = &alc269_capture_source,
13449                 .unsol_event = alc269_quanta_fl1_unsol_event,
13450                 .init_hook = alc269_quanta_fl1_init_hook,
13451         },
13452         [ALC269_ASUS_EEEPC_P703] = {
13453                 .mixers = { alc269_eeepc_mixer },
13454                 .cap_mixer = alc269_epc_capture_mixer,
13455                 .init_verbs = { alc269_init_verbs,
13456                                 alc269_eeepc_amic_init_verbs },
13457                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13458                 .dac_nids = alc269_dac_nids,
13459                 .hp_nid = 0x03,
13460                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13461                 .channel_mode = alc269_modes,
13462                 .input_mux = &alc269_eeepc_amic_capture_source,
13463                 .unsol_event = alc269_eeepc_amic_unsol_event,
13464                 .init_hook = alc269_eeepc_amic_inithook,
13465         },
13466         [ALC269_ASUS_EEEPC_P901] = {
13467                 .mixers = { alc269_eeepc_mixer },
13468                 .cap_mixer = alc269_epc_capture_mixer,
13469                 .init_verbs = { alc269_init_verbs,
13470                                 alc269_eeepc_dmic_init_verbs },
13471                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13472                 .dac_nids = alc269_dac_nids,
13473                 .hp_nid = 0x03,
13474                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13475                 .channel_mode = alc269_modes,
13476                 .input_mux = &alc269_eeepc_dmic_capture_source,
13477                 .unsol_event = alc269_eeepc_dmic_unsol_event,
13478                 .init_hook = alc269_eeepc_dmic_inithook,
13479         },
13480         [ALC269_FUJITSU] = {
13481                 .mixers = { alc269_fujitsu_mixer },
13482                 .cap_mixer = alc269_epc_capture_mixer,
13483                 .init_verbs = { alc269_init_verbs,
13484                                 alc269_eeepc_dmic_init_verbs },
13485                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13486                 .dac_nids = alc269_dac_nids,
13487                 .hp_nid = 0x03,
13488                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13489                 .channel_mode = alc269_modes,
13490                 .input_mux = &alc269_eeepc_dmic_capture_source,
13491                 .unsol_event = alc269_eeepc_dmic_unsol_event,
13492                 .init_hook = alc269_eeepc_dmic_inithook,
13493         },
13494         [ALC269_LIFEBOOK] = {
13495                 .mixers = { alc269_lifebook_mixer },
13496                 .init_verbs = { alc269_init_verbs, alc269_lifebook_verbs },
13497                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13498                 .dac_nids = alc269_dac_nids,
13499                 .hp_nid = 0x03,
13500                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13501                 .channel_mode = alc269_modes,
13502                 .input_mux = &alc269_capture_source,
13503                 .unsol_event = alc269_lifebook_unsol_event,
13504                 .init_hook = alc269_lifebook_init_hook,
13505         },
13506 };
13507
13508 static int patch_alc269(struct hda_codec *codec)
13509 {
13510         struct alc_spec *spec;
13511         int board_config;
13512         int err;
13513
13514         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
13515         if (spec == NULL)
13516                 return -ENOMEM;
13517
13518         codec->spec = spec;
13519
13520         alc_fix_pll_init(codec, 0x20, 0x04, 15);
13521
13522         board_config = snd_hda_check_board_config(codec, ALC269_MODEL_LAST,
13523                                                   alc269_models,
13524                                                   alc269_cfg_tbl);
13525
13526         if (board_config < 0) {
13527                 printk(KERN_INFO "hda_codec: Unknown model for %s, "
13528                        "trying auto-probe from BIOS...\n", codec->chip_name);
13529                 board_config = ALC269_AUTO;
13530         }
13531
13532         if (board_config == ALC269_AUTO) {
13533                 /* automatic parse from the BIOS config */
13534                 err = alc269_parse_auto_config(codec);
13535                 if (err < 0) {
13536                         alc_free(codec);
13537                         return err;
13538                 } else if (!err) {
13539                         printk(KERN_INFO
13540                                "hda_codec: Cannot set up configuration "
13541                                "from BIOS.  Using base mode...\n");
13542                         board_config = ALC269_BASIC;
13543                 }
13544         }
13545
13546         err = snd_hda_attach_beep_device(codec, 0x1);
13547         if (err < 0) {
13548                 alc_free(codec);
13549                 return err;
13550         }
13551
13552         if (board_config != ALC269_AUTO)
13553                 setup_preset(spec, &alc269_presets[board_config]);
13554
13555         if (codec->subsystem_id == 0x17aa3bf8) {
13556                 /* Due to a hardware problem on Lenovo Ideadpad, we need to
13557                  * fix the sample rate of analog I/O to 44.1kHz
13558                  */
13559                 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
13560                 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
13561         } else {
13562                 spec->stream_analog_playback = &alc269_pcm_analog_playback;
13563                 spec->stream_analog_capture = &alc269_pcm_analog_capture;
13564         }
13565         spec->stream_digital_playback = &alc269_pcm_digital_playback;
13566         spec->stream_digital_capture = &alc269_pcm_digital_capture;
13567
13568         spec->adc_nids = alc269_adc_nids;
13569         spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids);
13570         spec->capsrc_nids = alc269_capsrc_nids;
13571         if (!spec->cap_mixer)
13572                 set_capture_mixer(spec);
13573         set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
13574
13575         codec->patch_ops = alc_patch_ops;
13576         if (board_config == ALC269_AUTO)
13577                 spec->init_hook = alc269_auto_init;
13578 #ifdef CONFIG_SND_HDA_POWER_SAVE
13579         if (!spec->loopback.amplist)
13580                 spec->loopback.amplist = alc269_loopbacks;
13581 #endif
13582         codec->proc_widget_hook = print_realtek_coef;
13583
13584         return 0;
13585 }
13586
13587 /*
13588  *  ALC861 channel source setting (2/6 channel selection for 3-stack)
13589  */
13590
13591 /*
13592  * set the path ways for 2 channel output
13593  * need to set the codec line out and mic 1 pin widgets to inputs
13594  */
13595 static struct hda_verb alc861_threestack_ch2_init[] = {
13596         /* set pin widget 1Ah (line in) for input */
13597         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13598         /* set pin widget 18h (mic1/2) for input, for mic also enable
13599          * the vref
13600          */
13601         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13602
13603         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
13604 #if 0
13605         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
13606         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
13607 #endif
13608         { } /* end */
13609 };
13610 /*
13611  * 6ch mode
13612  * need to set the codec line out and mic 1 pin widgets to outputs
13613  */
13614 static struct hda_verb alc861_threestack_ch6_init[] = {
13615         /* set pin widget 1Ah (line in) for output (Back Surround)*/
13616         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13617         /* set pin widget 18h (mic1) for output (CLFE)*/
13618         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13619
13620         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
13621         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
13622
13623         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
13624 #if 0
13625         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
13626         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
13627 #endif
13628         { } /* end */
13629 };
13630
13631 static struct hda_channel_mode alc861_threestack_modes[2] = {
13632         { 2, alc861_threestack_ch2_init },
13633         { 6, alc861_threestack_ch6_init },
13634 };
13635 /* Set mic1 as input and unmute the mixer */
13636 static struct hda_verb alc861_uniwill_m31_ch2_init[] = {
13637         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13638         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
13639         { } /* end */
13640 };
13641 /* Set mic1 as output and mute mixer */
13642 static struct hda_verb alc861_uniwill_m31_ch4_init[] = {
13643         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13644         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
13645         { } /* end */
13646 };
13647
13648 static struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
13649         { 2, alc861_uniwill_m31_ch2_init },
13650         { 4, alc861_uniwill_m31_ch4_init },
13651 };
13652
13653 /* Set mic1 and line-in as input and unmute the mixer */
13654 static struct hda_verb alc861_asus_ch2_init[] = {
13655         /* set pin widget 1Ah (line in) for input */
13656         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13657         /* set pin widget 18h (mic1/2) for input, for mic also enable
13658          * the vref
13659          */
13660         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13661
13662         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
13663 #if 0
13664         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
13665         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
13666 #endif
13667         { } /* end */
13668 };
13669 /* Set mic1 nad line-in as output and mute mixer */
13670 static struct hda_verb alc861_asus_ch6_init[] = {
13671         /* set pin widget 1Ah (line in) for output (Back Surround)*/
13672         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13673         /* { 0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
13674         /* set pin widget 18h (mic1) for output (CLFE)*/
13675         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13676         /* { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
13677         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
13678         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
13679
13680         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
13681 #if 0
13682         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
13683         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
13684 #endif
13685         { } /* end */
13686 };
13687
13688 static struct hda_channel_mode alc861_asus_modes[2] = {
13689         { 2, alc861_asus_ch2_init },
13690         { 6, alc861_asus_ch6_init },
13691 };
13692
13693 /* patch-ALC861 */
13694
13695 static struct snd_kcontrol_new alc861_base_mixer[] = {
13696         /* output mixer control */
13697         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13698         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
13699         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
13700         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13701         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
13702
13703         /*Input mixer control */
13704         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13705            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
13706         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13707         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13708         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13709         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13710         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13711         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13712         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13713         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
13714
13715         { } /* end */
13716 };
13717
13718 static struct snd_kcontrol_new alc861_3ST_mixer[] = {
13719         /* output mixer control */
13720         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13721         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
13722         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
13723         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13724         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
13725
13726         /* Input mixer control */
13727         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13728            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
13729         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13730         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13731         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13732         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13733         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13734         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13735         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13736         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
13737
13738         {
13739                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13740                 .name = "Channel Mode",
13741                 .info = alc_ch_mode_info,
13742                 .get = alc_ch_mode_get,
13743                 .put = alc_ch_mode_put,
13744                 .private_value = ARRAY_SIZE(alc861_threestack_modes),
13745         },
13746         { } /* end */
13747 };
13748
13749 static struct snd_kcontrol_new alc861_toshiba_mixer[] = {
13750         /* output mixer control */
13751         HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13752         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13753         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13754
13755         { } /* end */
13756 };
13757
13758 static struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
13759         /* output mixer control */
13760         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13761         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
13762         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
13763         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13764         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
13765
13766         /* Input mixer control */
13767         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13768            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
13769         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13770         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13771         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13772         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13773         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13774         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13775         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13776         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
13777
13778         {
13779                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13780                 .name = "Channel Mode",
13781                 .info = alc_ch_mode_info,
13782                 .get = alc_ch_mode_get,
13783                 .put = alc_ch_mode_put,
13784                 .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
13785         },
13786         { } /* end */
13787 };
13788
13789 static struct snd_kcontrol_new alc861_asus_mixer[] = {
13790         /* output mixer control */
13791         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13792         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
13793         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
13794         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13795         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
13796
13797         /* Input mixer control */
13798         HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13799         HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT),
13800         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13801         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13802         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13803         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13804         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13805         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13806         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13807         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT),
13808
13809         {
13810                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13811                 .name = "Channel Mode",
13812                 .info = alc_ch_mode_info,
13813                 .get = alc_ch_mode_get,
13814                 .put = alc_ch_mode_put,
13815                 .private_value = ARRAY_SIZE(alc861_asus_modes),
13816         },
13817         { }
13818 };
13819
13820 /* additional mixer */
13821 static struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
13822         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13823         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13824         { }
13825 };
13826
13827 /*
13828  * generic initialization of ADC, input mixers and output mixers
13829  */
13830 static struct hda_verb alc861_base_init_verbs[] = {
13831         /*
13832          * Unmute ADC0 and set the default input to mic-in
13833          */
13834         /* port-A for surround (rear panel) */
13835         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13836         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
13837         /* port-B for mic-in (rear panel) with vref */
13838         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13839         /* port-C for line-in (rear panel) */
13840         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13841         /* port-D for Front */
13842         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13843         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13844         /* port-E for HP out (front panel) */
13845         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
13846         /* route front PCM to HP */
13847         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13848         /* port-F for mic-in (front panel) with vref */
13849         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13850         /* port-G for CLFE (rear panel) */
13851         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13852         { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13853         /* port-H for side (rear panel) */
13854         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13855         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
13856         /* CD-in */
13857         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13858         /* route front mic to ADC1*/
13859         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13860         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13861
13862         /* Unmute DAC0~3 & spdif out*/
13863         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13864         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13865         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13866         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13867         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13868
13869         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13870         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13871         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13872         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13873         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13874
13875         /* Unmute Stereo Mixer 15 */
13876         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13877         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13878         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13879         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13880
13881         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13882         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13883         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13884         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13885         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13886         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13887         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13888         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13889         /* hp used DAC 3 (Front) */
13890         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13891         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13892
13893         { }
13894 };
13895
13896 static struct hda_verb alc861_threestack_init_verbs[] = {
13897         /*
13898          * Unmute ADC0 and set the default input to mic-in
13899          */
13900         /* port-A for surround (rear panel) */
13901         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13902         /* port-B for mic-in (rear panel) with vref */
13903         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13904         /* port-C for line-in (rear panel) */
13905         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13906         /* port-D for Front */
13907         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13908         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13909         /* port-E for HP out (front panel) */
13910         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
13911         /* route front PCM to HP */
13912         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13913         /* port-F for mic-in (front panel) with vref */
13914         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13915         /* port-G for CLFE (rear panel) */
13916         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13917         /* port-H for side (rear panel) */
13918         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13919         /* CD-in */
13920         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13921         /* route front mic to ADC1*/
13922         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13923         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13924         /* Unmute DAC0~3 & spdif out*/
13925         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13926         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13927         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13928         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13929         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13930
13931         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13932         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13933         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13934         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13935         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13936
13937         /* Unmute Stereo Mixer 15 */
13938         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13939         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13940         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13941         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13942
13943         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13944         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13945         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13946         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13947         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13948         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13949         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13950         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13951         /* hp used DAC 3 (Front) */
13952         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13953         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13954         { }
13955 };
13956
13957 static struct hda_verb alc861_uniwill_m31_init_verbs[] = {
13958         /*
13959          * Unmute ADC0 and set the default input to mic-in
13960          */
13961         /* port-A for surround (rear panel) */
13962         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13963         /* port-B for mic-in (rear panel) with vref */
13964         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13965         /* port-C for line-in (rear panel) */
13966         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13967         /* port-D for Front */
13968         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13969         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13970         /* port-E for HP out (front panel) */
13971         /* this has to be set to VREF80 */
13972         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13973         /* route front PCM to HP */
13974         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13975         /* port-F for mic-in (front panel) with vref */
13976         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13977         /* port-G for CLFE (rear panel) */
13978         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13979         /* port-H for side (rear panel) */
13980         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13981         /* CD-in */
13982         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13983         /* route front mic to ADC1*/
13984         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13985         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13986         /* Unmute DAC0~3 & spdif out*/
13987         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13988         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13989         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13990         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13991         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13992
13993         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13994         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13995         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13996         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13997         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13998
13999         /* Unmute Stereo Mixer 15 */
14000         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14001         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14002         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14003         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
14004
14005         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14006         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14007         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14008         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14009         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14010         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14011         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14012         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14013         /* hp used DAC 3 (Front) */
14014         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
14015         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14016         { }
14017 };
14018
14019 static struct hda_verb alc861_asus_init_verbs[] = {
14020         /*
14021          * Unmute ADC0 and set the default input to mic-in
14022          */
14023         /* port-A for surround (rear panel)
14024          * according to codec#0 this is the HP jack
14025          */
14026         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, /* was 0x00 */
14027         /* route front PCM to HP */
14028         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x01 },
14029         /* port-B for mic-in (rear panel) with vref */
14030         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
14031         /* port-C for line-in (rear panel) */
14032         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
14033         /* port-D for Front */
14034         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
14035         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
14036         /* port-E for HP out (front panel) */
14037         /* this has to be set to VREF80 */
14038         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
14039         /* route front PCM to HP */
14040         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
14041         /* port-F for mic-in (front panel) with vref */
14042         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
14043         /* port-G for CLFE (rear panel) */
14044         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
14045         /* port-H for side (rear panel) */
14046         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
14047         /* CD-in */
14048         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
14049         /* route front mic to ADC1*/
14050         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
14051         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14052         /* Unmute DAC0~3 & spdif out*/
14053         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14054         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14055         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14056         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14057         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14058         /* Unmute Mixer 14 (mic) 1c (Line in)*/
14059         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14060         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14061         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14062         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14063
14064         /* Unmute Stereo Mixer 15 */
14065         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14066         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14067         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14068         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
14069
14070         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14071         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14072         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14073         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14074         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14075         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14076         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14077         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14078         /* hp used DAC 3 (Front) */
14079         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
14080         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14081         { }
14082 };
14083
14084 /* additional init verbs for ASUS laptops */
14085 static struct hda_verb alc861_asus_laptop_init_verbs[] = {
14086         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x45 }, /* HP-out */
14087         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2) }, /* mute line-in */
14088         { }
14089 };
14090
14091 /*
14092  * generic initialization of ADC, input mixers and output mixers
14093  */
14094 static struct hda_verb alc861_auto_init_verbs[] = {
14095         /*
14096          * Unmute ADC0 and set the default input to mic-in
14097          */
14098         /* {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, */
14099         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14100
14101         /* Unmute DAC0~3 & spdif out*/
14102         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14103         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14104         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14105         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14106         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14107
14108         /* Unmute Mixer 14 (mic) 1c (Line in)*/
14109         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14110         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14111         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14112         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14113
14114         /* Unmute Stereo Mixer 15 */
14115         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14116         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14117         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14118         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c},
14119
14120         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14121         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14122         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14123         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14124         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14125         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14126         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14127         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14128
14129         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14130         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14131         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14132         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
14133         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14134         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14135         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14136         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
14137
14138         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},  /* set Mic 1 */
14139
14140         { }
14141 };
14142
14143 static struct hda_verb alc861_toshiba_init_verbs[] = {
14144         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14145
14146         { }
14147 };
14148
14149 /* toggle speaker-output according to the hp-jack state */
14150 static void alc861_toshiba_automute(struct hda_codec *codec)
14151 {
14152         unsigned int present;
14153
14154         present = snd_hda_codec_read(codec, 0x0f, 0,
14155                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14156         snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
14157                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
14158         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
14159                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
14160 }
14161
14162 static void alc861_toshiba_unsol_event(struct hda_codec *codec,
14163                                        unsigned int res)
14164 {
14165         if ((res >> 26) == ALC880_HP_EVENT)
14166                 alc861_toshiba_automute(codec);
14167 }
14168
14169 /* pcm configuration: identical with ALC880 */
14170 #define alc861_pcm_analog_playback      alc880_pcm_analog_playback
14171 #define alc861_pcm_analog_capture       alc880_pcm_analog_capture
14172 #define alc861_pcm_digital_playback     alc880_pcm_digital_playback
14173 #define alc861_pcm_digital_capture      alc880_pcm_digital_capture
14174
14175
14176 #define ALC861_DIGOUT_NID       0x07
14177
14178 static struct hda_channel_mode alc861_8ch_modes[1] = {
14179         { 8, NULL }
14180 };
14181
14182 static hda_nid_t alc861_dac_nids[4] = {
14183         /* front, surround, clfe, side */
14184         0x03, 0x06, 0x05, 0x04
14185 };
14186
14187 static hda_nid_t alc660_dac_nids[3] = {
14188         /* front, clfe, surround */
14189         0x03, 0x05, 0x06
14190 };
14191
14192 static hda_nid_t alc861_adc_nids[1] = {
14193         /* ADC0-2 */
14194         0x08,
14195 };
14196
14197 static struct hda_input_mux alc861_capture_source = {
14198         .num_items = 5,
14199         .items = {
14200                 { "Mic", 0x0 },
14201                 { "Front Mic", 0x3 },
14202                 { "Line", 0x1 },
14203                 { "CD", 0x4 },
14204                 { "Mixer", 0x5 },
14205         },
14206 };
14207
14208 /* fill in the dac_nids table from the parsed pin configuration */
14209 static int alc861_auto_fill_dac_nids(struct alc_spec *spec,
14210                                      const struct auto_pin_cfg *cfg)
14211 {
14212         int i;
14213         hda_nid_t nid;
14214
14215         spec->multiout.dac_nids = spec->private_dac_nids;
14216         for (i = 0; i < cfg->line_outs; i++) {
14217                 nid = cfg->line_out_pins[i];
14218                 if (nid) {
14219                         if (i >= ARRAY_SIZE(alc861_dac_nids))
14220                                 continue;
14221                         spec->multiout.dac_nids[i] = alc861_dac_nids[i];
14222                 }
14223         }
14224         spec->multiout.num_dacs = cfg->line_outs;
14225         return 0;
14226 }
14227
14228 /* add playback controls from the parsed DAC table */
14229 static int alc861_auto_create_multi_out_ctls(struct alc_spec *spec,
14230                                              const struct auto_pin_cfg *cfg)
14231 {
14232         char name[32];
14233         static const char *chname[4] = {
14234                 "Front", "Surround", NULL /*CLFE*/, "Side"
14235         };
14236         hda_nid_t nid;
14237         int i, idx, err;
14238
14239         for (i = 0; i < cfg->line_outs; i++) {
14240                 nid = spec->multiout.dac_nids[i];
14241                 if (!nid)
14242                         continue;
14243                 if (nid == 0x05) {
14244                         /* Center/LFE */
14245                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14246                                           "Center Playback Switch",
14247                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
14248                                                               HDA_OUTPUT));
14249                         if (err < 0)
14250                                 return err;
14251                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14252                                           "LFE Playback Switch",
14253                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
14254                                                               HDA_OUTPUT));
14255                         if (err < 0)
14256                                 return err;
14257                 } else {
14258                         for (idx = 0; idx < ARRAY_SIZE(alc861_dac_nids) - 1;
14259                              idx++)
14260                                 if (nid == alc861_dac_nids[idx])
14261                                         break;
14262                         sprintf(name, "%s Playback Switch", chname[idx]);
14263                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
14264                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
14265                                                               HDA_OUTPUT));
14266                         if (err < 0)
14267                                 return err;
14268                 }
14269         }
14270         return 0;
14271 }
14272
14273 static int alc861_auto_create_hp_ctls(struct alc_spec *spec, hda_nid_t pin)
14274 {
14275         int err;
14276         hda_nid_t nid;
14277
14278         if (!pin)
14279                 return 0;
14280
14281         if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
14282                 nid = 0x03;
14283                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
14284                                   "Headphone Playback Switch",
14285                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
14286                 if (err < 0)
14287                         return err;
14288                 spec->multiout.hp_nid = nid;
14289         }
14290         return 0;
14291 }
14292
14293 /* create playback/capture controls for input pins */
14294 static int alc861_auto_create_analog_input_ctls(struct alc_spec *spec,
14295                                                 const struct auto_pin_cfg *cfg)
14296 {
14297         struct hda_input_mux *imux = &spec->private_imux[0];
14298         int i, err, idx, idx1;
14299
14300         for (i = 0; i < AUTO_PIN_LAST; i++) {
14301                 switch (cfg->input_pins[i]) {
14302                 case 0x0c:
14303                         idx1 = 1;
14304                         idx = 2;        /* Line In */
14305                         break;
14306                 case 0x0f:
14307                         idx1 = 2;
14308                         idx = 2;        /* Line In */
14309                         break;
14310                 case 0x0d:
14311                         idx1 = 0;
14312                         idx = 1;        /* Mic In */
14313                         break;
14314                 case 0x10:
14315                         idx1 = 3;
14316                         idx = 1;        /* Mic In */
14317                         break;
14318                 case 0x11:
14319                         idx1 = 4;
14320                         idx = 0;        /* CD */
14321                         break;
14322                 default:
14323                         continue;
14324                 }
14325
14326                 err = new_analog_input(spec, cfg->input_pins[i],
14327                                        auto_pin_cfg_labels[i], idx, 0x15);
14328                 if (err < 0)
14329                         return err;
14330
14331                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
14332                 imux->items[imux->num_items].index = idx1;
14333                 imux->num_items++;
14334         }
14335         return 0;
14336 }
14337
14338 static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
14339                                               hda_nid_t nid,
14340                                               int pin_type, int dac_idx)
14341 {
14342         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
14343                             pin_type);
14344         snd_hda_codec_write(codec, dac_idx, 0, AC_VERB_SET_AMP_GAIN_MUTE,
14345                             AMP_OUT_UNMUTE);
14346 }
14347
14348 static void alc861_auto_init_multi_out(struct hda_codec *codec)
14349 {
14350         struct alc_spec *spec = codec->spec;
14351         int i;
14352
14353         for (i = 0; i < spec->autocfg.line_outs; i++) {
14354                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
14355                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
14356                 if (nid)
14357                         alc861_auto_set_output_and_unmute(codec, nid, pin_type,
14358                                                           spec->multiout.dac_nids[i]);
14359         }
14360 }
14361
14362 static void alc861_auto_init_hp_out(struct hda_codec *codec)
14363 {
14364         struct alc_spec *spec = codec->spec;
14365         hda_nid_t pin;
14366
14367         pin = spec->autocfg.hp_pins[0];
14368         if (pin) /* connect to front */
14369                 alc861_auto_set_output_and_unmute(codec, pin, PIN_HP,
14370                                                   spec->multiout.dac_nids[0]);
14371         pin = spec->autocfg.speaker_pins[0];
14372         if (pin)
14373                 alc861_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
14374 }
14375
14376 static void alc861_auto_init_analog_input(struct hda_codec *codec)
14377 {
14378         struct alc_spec *spec = codec->spec;
14379         int i;
14380
14381         for (i = 0; i < AUTO_PIN_LAST; i++) {
14382                 hda_nid_t nid = spec->autocfg.input_pins[i];
14383                 if (nid >= 0x0c && nid <= 0x11)
14384                         alc_set_input_pin(codec, nid, i);
14385         }
14386 }
14387
14388 /* parse the BIOS configuration and set up the alc_spec */
14389 /* return 1 if successful, 0 if the proper config is not found,
14390  * or a negative error code
14391  */
14392 static int alc861_parse_auto_config(struct hda_codec *codec)
14393 {
14394         struct alc_spec *spec = codec->spec;
14395         int err;
14396         static hda_nid_t alc861_ignore[] = { 0x1d, 0 };
14397
14398         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
14399                                            alc861_ignore);
14400         if (err < 0)
14401                 return err;
14402         if (!spec->autocfg.line_outs)
14403                 return 0; /* can't find valid BIOS pin config */
14404
14405         err = alc861_auto_fill_dac_nids(spec, &spec->autocfg);
14406         if (err < 0)
14407                 return err;
14408         err = alc861_auto_create_multi_out_ctls(spec, &spec->autocfg);
14409         if (err < 0)
14410                 return err;
14411         err = alc861_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
14412         if (err < 0)
14413                 return err;
14414         err = alc861_auto_create_analog_input_ctls(spec, &spec->autocfg);
14415         if (err < 0)
14416                 return err;
14417
14418         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
14419
14420         if (spec->autocfg.dig_outs)
14421                 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;
14422
14423         if (spec->kctls.list)
14424                 add_mixer(spec, spec->kctls.list);
14425
14426         add_verb(spec, alc861_auto_init_verbs);
14427
14428         spec->num_mux_defs = 1;
14429         spec->input_mux = &spec->private_imux[0];
14430
14431         spec->adc_nids = alc861_adc_nids;
14432         spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
14433         set_capture_mixer(spec);
14434
14435         alc_ssid_check(codec, 0x0e, 0x0f, 0x0b);
14436
14437         return 1;
14438 }
14439
14440 /* additional initialization for auto-configuration model */
14441 static void alc861_auto_init(struct hda_codec *codec)
14442 {
14443         struct alc_spec *spec = codec->spec;
14444         alc861_auto_init_multi_out(codec);
14445         alc861_auto_init_hp_out(codec);
14446         alc861_auto_init_analog_input(codec);
14447         if (spec->unsol_event)
14448                 alc_inithook(codec);
14449 }
14450
14451 #ifdef CONFIG_SND_HDA_POWER_SAVE
14452 static struct hda_amp_list alc861_loopbacks[] = {
14453         { 0x15, HDA_INPUT, 0 },
14454         { 0x15, HDA_INPUT, 1 },
14455         { 0x15, HDA_INPUT, 2 },
14456         { 0x15, HDA_INPUT, 3 },
14457         { } /* end */
14458 };
14459 #endif
14460
14461
14462 /*
14463  * configuration and preset
14464  */
14465 static const char *alc861_models[ALC861_MODEL_LAST] = {
14466         [ALC861_3ST]            = "3stack",
14467         [ALC660_3ST]            = "3stack-660",
14468         [ALC861_3ST_DIG]        = "3stack-dig",
14469         [ALC861_6ST_DIG]        = "6stack-dig",
14470         [ALC861_UNIWILL_M31]    = "uniwill-m31",
14471         [ALC861_TOSHIBA]        = "toshiba",
14472         [ALC861_ASUS]           = "asus",
14473         [ALC861_ASUS_LAPTOP]    = "asus-laptop",
14474         [ALC861_AUTO]           = "auto",
14475 };
14476
14477 static struct snd_pci_quirk alc861_cfg_tbl[] = {
14478         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC861_3ST),
14479         SND_PCI_QUIRK(0x1043, 0x1335, "ASUS F2/3", ALC861_ASUS_LAPTOP),
14480         SND_PCI_QUIRK(0x1043, 0x1338, "ASUS F2/3", ALC861_ASUS_LAPTOP),
14481         SND_PCI_QUIRK(0x1043, 0x1393, "ASUS", ALC861_ASUS),
14482         SND_PCI_QUIRK(0x1043, 0x13d7, "ASUS A9rp", ALC861_ASUS_LAPTOP),
14483         SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS P1-AH2", ALC861_3ST_DIG),
14484         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba", ALC861_TOSHIBA),
14485         /* FIXME: the entry below breaks Toshiba A100 (model=auto works!)
14486          *        Any other models that need this preset?
14487          */
14488         /* SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba", ALC861_TOSHIBA), */
14489         SND_PCI_QUIRK(0x1462, 0x7254, "HP dx2200 (MSI MS-7254)", ALC861_3ST),
14490         SND_PCI_QUIRK(0x1462, 0x7297, "HP dx2250 (MSI MS-7297)", ALC861_3ST),
14491         SND_PCI_QUIRK(0x1584, 0x2b01, "Uniwill X40AIx", ALC861_UNIWILL_M31),
14492         SND_PCI_QUIRK(0x1584, 0x9072, "Uniwill m31", ALC861_UNIWILL_M31),
14493         SND_PCI_QUIRK(0x1584, 0x9075, "Airis Praxis N1212", ALC861_ASUS_LAPTOP),
14494         /* FIXME: the below seems conflict */
14495         /* SND_PCI_QUIRK(0x1584, 0x9075, "Uniwill", ALC861_UNIWILL_M31), */
14496         SND_PCI_QUIRK(0x1849, 0x0660, "Asrock 939SLI32", ALC660_3ST),
14497         SND_PCI_QUIRK(0x8086, 0xd600, "Intel", ALC861_3ST),
14498         {}
14499 };
14500
14501 static struct alc_config_preset alc861_presets[] = {
14502         [ALC861_3ST] = {
14503                 .mixers = { alc861_3ST_mixer },
14504                 .init_verbs = { alc861_threestack_init_verbs },
14505                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14506                 .dac_nids = alc861_dac_nids,
14507                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
14508                 .channel_mode = alc861_threestack_modes,
14509                 .need_dac_fix = 1,
14510                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14511                 .adc_nids = alc861_adc_nids,
14512                 .input_mux = &alc861_capture_source,
14513         },
14514         [ALC861_3ST_DIG] = {
14515                 .mixers = { alc861_base_mixer },
14516                 .init_verbs = { alc861_threestack_init_verbs },
14517                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14518                 .dac_nids = alc861_dac_nids,
14519                 .dig_out_nid = ALC861_DIGOUT_NID,
14520                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
14521                 .channel_mode = alc861_threestack_modes,
14522                 .need_dac_fix = 1,
14523                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14524                 .adc_nids = alc861_adc_nids,
14525                 .input_mux = &alc861_capture_source,
14526         },
14527         [ALC861_6ST_DIG] = {
14528                 .mixers = { alc861_base_mixer },
14529                 .init_verbs = { alc861_base_init_verbs },
14530                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14531                 .dac_nids = alc861_dac_nids,
14532                 .dig_out_nid = ALC861_DIGOUT_NID,
14533                 .num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
14534                 .channel_mode = alc861_8ch_modes,
14535                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14536                 .adc_nids = alc861_adc_nids,
14537                 .input_mux = &alc861_capture_source,
14538         },
14539         [ALC660_3ST] = {
14540                 .mixers = { alc861_3ST_mixer },
14541                 .init_verbs = { alc861_threestack_init_verbs },
14542                 .num_dacs = ARRAY_SIZE(alc660_dac_nids),
14543                 .dac_nids = alc660_dac_nids,
14544                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
14545                 .channel_mode = alc861_threestack_modes,
14546                 .need_dac_fix = 1,
14547                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14548                 .adc_nids = alc861_adc_nids,
14549                 .input_mux = &alc861_capture_source,
14550         },
14551         [ALC861_UNIWILL_M31] = {
14552                 .mixers = { alc861_uniwill_m31_mixer },
14553                 .init_verbs = { alc861_uniwill_m31_init_verbs },
14554                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14555                 .dac_nids = alc861_dac_nids,
14556                 .dig_out_nid = ALC861_DIGOUT_NID,
14557                 .num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
14558                 .channel_mode = alc861_uniwill_m31_modes,
14559                 .need_dac_fix = 1,
14560                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14561                 .adc_nids = alc861_adc_nids,
14562                 .input_mux = &alc861_capture_source,
14563         },
14564         [ALC861_TOSHIBA] = {
14565                 .mixers = { alc861_toshiba_mixer },
14566                 .init_verbs = { alc861_base_init_verbs,
14567                                 alc861_toshiba_init_verbs },
14568                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14569                 .dac_nids = alc861_dac_nids,
14570                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
14571                 .channel_mode = alc883_3ST_2ch_modes,
14572                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14573                 .adc_nids = alc861_adc_nids,
14574                 .input_mux = &alc861_capture_source,
14575                 .unsol_event = alc861_toshiba_unsol_event,
14576                 .init_hook = alc861_toshiba_automute,
14577         },
14578         [ALC861_ASUS] = {
14579                 .mixers = { alc861_asus_mixer },
14580                 .init_verbs = { alc861_asus_init_verbs },
14581                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14582                 .dac_nids = alc861_dac_nids,
14583                 .dig_out_nid = ALC861_DIGOUT_NID,
14584                 .num_channel_mode = ARRAY_SIZE(alc861_asus_modes),
14585                 .channel_mode = alc861_asus_modes,
14586                 .need_dac_fix = 1,
14587                 .hp_nid = 0x06,
14588                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14589                 .adc_nids = alc861_adc_nids,
14590                 .input_mux = &alc861_capture_source,
14591         },
14592         [ALC861_ASUS_LAPTOP] = {
14593                 .mixers = { alc861_toshiba_mixer, alc861_asus_laptop_mixer },
14594                 .init_verbs = { alc861_asus_init_verbs,
14595                                 alc861_asus_laptop_init_verbs },
14596                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14597                 .dac_nids = alc861_dac_nids,
14598                 .dig_out_nid = ALC861_DIGOUT_NID,
14599                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
14600                 .channel_mode = alc883_3ST_2ch_modes,
14601                 .need_dac_fix = 1,
14602                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14603                 .adc_nids = alc861_adc_nids,
14604                 .input_mux = &alc861_capture_source,
14605         },
14606 };
14607
14608
14609 static int patch_alc861(struct hda_codec *codec)
14610 {
14611         struct alc_spec *spec;
14612         int board_config;
14613         int err;
14614
14615         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
14616         if (spec == NULL)
14617                 return -ENOMEM;
14618
14619         codec->spec = spec;
14620
14621         board_config = snd_hda_check_board_config(codec, ALC861_MODEL_LAST,
14622                                                   alc861_models,
14623                                                   alc861_cfg_tbl);
14624
14625         if (board_config < 0) {
14626                 printk(KERN_INFO "hda_codec: Unknown model for %s, "
14627                        "trying auto-probe from BIOS...\n", codec->chip_name);
14628                 board_config = ALC861_AUTO;
14629         }
14630
14631         if (board_config == ALC861_AUTO) {
14632                 /* automatic parse from the BIOS config */
14633                 err = alc861_parse_auto_config(codec);
14634                 if (err < 0) {
14635                         alc_free(codec);
14636                         return err;
14637                 } else if (!err) {
14638                         printk(KERN_INFO
14639                                "hda_codec: Cannot set up configuration "
14640                                "from BIOS.  Using base mode...\n");
14641                    board_config = ALC861_3ST_DIG;
14642                 }
14643         }
14644
14645         err = snd_hda_attach_beep_device(codec, 0x23);
14646         if (err < 0) {
14647                 alc_free(codec);
14648                 return err;
14649         }
14650
14651         if (board_config != ALC861_AUTO)
14652                 setup_preset(spec, &alc861_presets[board_config]);
14653
14654         spec->stream_analog_playback = &alc861_pcm_analog_playback;
14655         spec->stream_analog_capture = &alc861_pcm_analog_capture;
14656
14657         spec->stream_digital_playback = &alc861_pcm_digital_playback;
14658         spec->stream_digital_capture = &alc861_pcm_digital_capture;
14659
14660         set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
14661
14662         spec->vmaster_nid = 0x03;
14663
14664         codec->patch_ops = alc_patch_ops;
14665         if (board_config == ALC861_AUTO)
14666                 spec->init_hook = alc861_auto_init;
14667 #ifdef CONFIG_SND_HDA_POWER_SAVE
14668         if (!spec->loopback.amplist)
14669                 spec->loopback.amplist = alc861_loopbacks;
14670 #endif
14671         codec->proc_widget_hook = print_realtek_coef;
14672
14673         return 0;
14674 }
14675
14676 /*
14677  * ALC861-VD support
14678  *
14679  * Based on ALC882
14680  *
14681  * In addition, an independent DAC
14682  */
14683 #define ALC861VD_DIGOUT_NID     0x06
14684
14685 static hda_nid_t alc861vd_dac_nids[4] = {
14686         /* front, surr, clfe, side surr */
14687         0x02, 0x03, 0x04, 0x05
14688 };
14689
14690 /* dac_nids for ALC660vd are in a different order - according to
14691  * Realtek's driver.
14692  * This should probably result in a different mixer for 6stack models
14693  * of ALC660vd codecs, but for now there is only 3stack mixer
14694  * - and it is the same as in 861vd.
14695  * adc_nids in ALC660vd are (is) the same as in 861vd
14696  */
14697 static hda_nid_t alc660vd_dac_nids[3] = {
14698         /* front, rear, clfe, rear_surr */
14699         0x02, 0x04, 0x03
14700 };
14701
14702 static hda_nid_t alc861vd_adc_nids[1] = {
14703         /* ADC0 */
14704         0x09,
14705 };
14706
14707 static hda_nid_t alc861vd_capsrc_nids[1] = { 0x22 };
14708
14709 /* input MUX */
14710 /* FIXME: should be a matrix-type input source selection */
14711 static struct hda_input_mux alc861vd_capture_source = {
14712         .num_items = 4,
14713         .items = {
14714                 { "Mic", 0x0 },
14715                 { "Front Mic", 0x1 },
14716                 { "Line", 0x2 },
14717                 { "CD", 0x4 },
14718         },
14719 };
14720
14721 static struct hda_input_mux alc861vd_dallas_capture_source = {
14722         .num_items = 2,
14723         .items = {
14724                 { "Ext Mic", 0x0 },
14725                 { "Int Mic", 0x1 },
14726         },
14727 };
14728
14729 static struct hda_input_mux alc861vd_hp_capture_source = {
14730         .num_items = 2,
14731         .items = {
14732                 { "Front Mic", 0x0 },
14733                 { "ATAPI Mic", 0x1 },
14734         },
14735 };
14736
14737 /*
14738  * 2ch mode
14739  */
14740 static struct hda_channel_mode alc861vd_3stack_2ch_modes[1] = {
14741         { 2, NULL }
14742 };
14743
14744 /*
14745  * 6ch mode
14746  */
14747 static struct hda_verb alc861vd_6stack_ch6_init[] = {
14748         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
14749         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14750         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14751         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14752         { } /* end */
14753 };
14754
14755 /*
14756  * 8ch mode
14757  */
14758 static struct hda_verb alc861vd_6stack_ch8_init[] = {
14759         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14760         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14761         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14762         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14763         { } /* end */
14764 };
14765
14766 static struct hda_channel_mode alc861vd_6stack_modes[2] = {
14767         { 6, alc861vd_6stack_ch6_init },
14768         { 8, alc861vd_6stack_ch8_init },
14769 };
14770
14771 static struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
14772         {
14773                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
14774                 .name = "Channel Mode",
14775                 .info = alc_ch_mode_info,
14776                 .get = alc_ch_mode_get,
14777                 .put = alc_ch_mode_put,
14778         },
14779         { } /* end */
14780 };
14781
14782 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
14783  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
14784  */
14785 static struct snd_kcontrol_new alc861vd_6st_mixer[] = {
14786         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14787         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14788
14789         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14790         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
14791
14792         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0,
14793                                 HDA_OUTPUT),
14794         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0,
14795                                 HDA_OUTPUT),
14796         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
14797         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
14798
14799         HDA_CODEC_VOLUME("Side Playback Volume", 0x05, 0x0, HDA_OUTPUT),
14800         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
14801
14802         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14803
14804         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
14805         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14806         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14807
14808         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
14809         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14810         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14811
14812         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14813         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14814
14815         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14816         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14817
14818         { } /* end */
14819 };
14820
14821 static struct snd_kcontrol_new alc861vd_3st_mixer[] = {
14822         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14823         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14824
14825         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14826
14827         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
14828         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14829         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14830
14831         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
14832         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14833         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14834
14835         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14836         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14837
14838         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14839         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14840
14841         { } /* end */
14842 };
14843
14844 static struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
14845         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14846         /*HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),*/
14847         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14848
14849         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14850
14851         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
14852         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14853         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14854
14855         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
14856         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14857         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14858
14859         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14860         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14861
14862         { } /* end */
14863 };
14864
14865 /* Pin assignment: Speaker=0x14, HP = 0x15,
14866  *                 Ext Mic=0x18, Int Mic = 0x19, CD = 0x1c, PC Beep = 0x1d
14867  */
14868 static struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
14869         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14870         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
14871         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14872         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
14873         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
14874         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14875         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14876         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
14877         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14878         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14879         { } /* end */
14880 };
14881
14882 /* Pin assignment: Speaker=0x14, Line-out = 0x15,
14883  *                 Front Mic=0x18, ATAPI Mic = 0x19,
14884  */
14885 static struct snd_kcontrol_new alc861vd_hp_mixer[] = {
14886         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14887         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14888         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14889         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
14890         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14891         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14892         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14893         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14894
14895         { } /* end */
14896 };
14897
14898 /*
14899  * generic initialization of ADC, input mixers and output mixers
14900  */
14901 static struct hda_verb alc861vd_volume_init_verbs[] = {
14902         /*
14903          * Unmute ADC0 and set the default input to mic-in
14904          */
14905         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
14906         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14907
14908         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of
14909          * the analog-loopback mixer widget
14910          */
14911         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
14912         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14913         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14914         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14915         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14916         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14917
14918         /* Capture mixer: unmute Mic, F-Mic, Line, CD inputs */
14919         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14920         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14921         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14922         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
14923
14924         /*
14925          * Set up output mixers (0x02 - 0x05)
14926          */
14927         /* set vol=0 to output mixers */
14928         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14929         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14930         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14931         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14932
14933         /* set up input amps for analog loopback */
14934         /* Amp Indices: DAC = 0, mixer = 1 */
14935         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14936         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14937         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14938         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14939         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14940         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14941         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14942         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14943
14944         { }
14945 };
14946
14947 /*
14948  * 3-stack pin configuration:
14949  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
14950  */
14951 static struct hda_verb alc861vd_3stack_init_verbs[] = {
14952         /*
14953          * Set pin mode and muting
14954          */
14955         /* set front pin widgets 0x14 for output */
14956         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14957         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14958         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
14959
14960         /* Mic (rear) pin: input vref at 80% */
14961         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14962         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14963         /* Front Mic pin: input vref at 80% */
14964         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14965         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14966         /* Line In pin: input */
14967         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14968         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14969         /* Line-2 In: Headphone output (output 0 - 0x0c) */
14970         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14971         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14972         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
14973         /* CD pin widget for input */
14974         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14975
14976         { }
14977 };
14978
14979 /*
14980  * 6-stack pin configuration:
14981  */
14982 static struct hda_verb alc861vd_6stack_init_verbs[] = {
14983         /*
14984          * Set pin mode and muting
14985          */
14986         /* set front pin widgets 0x14 for output */
14987         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14988         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14989         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
14990
14991         /* Rear Pin: output 1 (0x0d) */
14992         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14993         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14994         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
14995         /* CLFE Pin: output 2 (0x0e) */
14996         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14997         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14998         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
14999         /* Side Pin: output 3 (0x0f) */
15000         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15001         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15002         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
15003
15004         /* Mic (rear) pin: input vref at 80% */
15005         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
15006         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15007         /* Front Mic pin: input vref at 80% */
15008         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
15009         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15010         /* Line In pin: input */
15011         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15012         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15013         /* Line-2 In: Headphone output (output 0 - 0x0c) */
15014         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15015         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15016         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
15017         /* CD pin widget for input */
15018         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15019
15020         { }
15021 };
15022
15023 static struct hda_verb alc861vd_eapd_verbs[] = {
15024         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
15025         { }
15026 };
15027
15028 static struct hda_verb alc660vd_eapd_verbs[] = {
15029         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
15030         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
15031         { }
15032 };
15033
15034 static struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
15035         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15036         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15037         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
15038         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15039         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15040         {}
15041 };
15042
15043 static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
15044 {
15045         unsigned int present;
15046         unsigned char bits;
15047
15048         present = snd_hda_codec_read(codec, 0x18, 0,
15049                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15050         bits = present ? HDA_AMP_MUTE : 0;
15051         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
15052                                  HDA_AMP_MUTE, bits);
15053 }
15054
15055 static void alc861vd_lenovo_init_hook(struct hda_codec *codec)
15056 {
15057         struct alc_spec *spec = codec->spec;
15058
15059         spec->autocfg.hp_pins[0] = 0x1b;
15060         spec->autocfg.speaker_pins[0] = 0x14;
15061         alc_automute_amp(codec);
15062         alc861vd_lenovo_mic_automute(codec);
15063 }
15064
15065 static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
15066                                         unsigned int res)
15067 {
15068         switch (res >> 26) {
15069         case ALC880_MIC_EVENT:
15070                 alc861vd_lenovo_mic_automute(codec);
15071                 break;
15072         default:
15073                 alc_automute_amp_unsol_event(codec, res);
15074                 break;
15075         }
15076 }
15077
15078 static struct hda_verb alc861vd_dallas_verbs[] = {
15079         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15080         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15081         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15082         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15083
15084         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15085         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15086         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15087         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15088         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15089         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15090         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15091         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15092
15093         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15094         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15095         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15096         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15097         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15098         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15099         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15100         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15101
15102         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
15103         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15104         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
15105         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15106         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15107         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15108         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15109         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15110
15111         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15112         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
15113         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
15114         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
15115
15116         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15117         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
15118         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15119
15120         { } /* end */
15121 };
15122
15123 /* toggle speaker-output according to the hp-jack state */
15124 static void alc861vd_dallas_init_hook(struct hda_codec *codec)
15125 {
15126         struct alc_spec *spec = codec->spec;
15127
15128         spec->autocfg.hp_pins[0] = 0x15;
15129         spec->autocfg.speaker_pins[0] = 0x14;
15130         alc_automute_amp(codec);
15131 }
15132
15133 #ifdef CONFIG_SND_HDA_POWER_SAVE
15134 #define alc861vd_loopbacks      alc880_loopbacks
15135 #endif
15136
15137 /* pcm configuration: identical with ALC880 */
15138 #define alc861vd_pcm_analog_playback    alc880_pcm_analog_playback
15139 #define alc861vd_pcm_analog_capture     alc880_pcm_analog_capture
15140 #define alc861vd_pcm_digital_playback   alc880_pcm_digital_playback
15141 #define alc861vd_pcm_digital_capture    alc880_pcm_digital_capture
15142
15143 /*
15144  * configuration and preset
15145  */
15146 static const char *alc861vd_models[ALC861VD_MODEL_LAST] = {
15147         [ALC660VD_3ST]          = "3stack-660",
15148         [ALC660VD_3ST_DIG]      = "3stack-660-digout",
15149         [ALC660VD_ASUS_V1S]     = "asus-v1s",
15150         [ALC861VD_3ST]          = "3stack",
15151         [ALC861VD_3ST_DIG]      = "3stack-digout",
15152         [ALC861VD_6ST_DIG]      = "6stack-digout",
15153         [ALC861VD_LENOVO]       = "lenovo",
15154         [ALC861VD_DALLAS]       = "dallas",
15155         [ALC861VD_HP]           = "hp",
15156         [ALC861VD_AUTO]         = "auto",
15157 };
15158
15159 static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
15160         SND_PCI_QUIRK(0x1019, 0xa88d, "Realtek ALC660 demo", ALC660VD_3ST),
15161         SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_HP),
15162         SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST),
15163         SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),
15164         SND_PCI_QUIRK(0x1043, 0x1633, "Asus V1Sn", ALC660VD_ASUS_V1S),
15165         SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG),
15166         SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
15167         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
15168         /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
15169         SND_PCI_QUIRK(0x1179, 0xff01, "DALLAS", ALC861VD_DALLAS),
15170         SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
15171         SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_DALLAS),
15172         SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
15173         SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", ALC861VD_LENOVO),
15174         SND_PCI_QUIRK(0x1849, 0x0862, "ASRock K8NF6G-VSTA", ALC861VD_6ST_DIG),
15175         {}
15176 };
15177
15178 static struct alc_config_preset alc861vd_presets[] = {
15179         [ALC660VD_3ST] = {
15180                 .mixers = { alc861vd_3st_mixer },
15181                 .init_verbs = { alc861vd_volume_init_verbs,
15182                                  alc861vd_3stack_init_verbs },
15183                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
15184                 .dac_nids = alc660vd_dac_nids,
15185                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15186                 .channel_mode = alc861vd_3stack_2ch_modes,
15187                 .input_mux = &alc861vd_capture_source,
15188         },
15189         [ALC660VD_3ST_DIG] = {
15190                 .mixers = { alc861vd_3st_mixer },
15191                 .init_verbs = { alc861vd_volume_init_verbs,
15192                                  alc861vd_3stack_init_verbs },
15193                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
15194                 .dac_nids = alc660vd_dac_nids,
15195                 .dig_out_nid = ALC861VD_DIGOUT_NID,
15196                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15197                 .channel_mode = alc861vd_3stack_2ch_modes,
15198                 .input_mux = &alc861vd_capture_source,
15199         },
15200         [ALC861VD_3ST] = {
15201                 .mixers = { alc861vd_3st_mixer },
15202                 .init_verbs = { alc861vd_volume_init_verbs,
15203                                  alc861vd_3stack_init_verbs },
15204                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
15205                 .dac_nids = alc861vd_dac_nids,
15206                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15207                 .channel_mode = alc861vd_3stack_2ch_modes,
15208                 .input_mux = &alc861vd_capture_source,
15209         },
15210         [ALC861VD_3ST_DIG] = {
15211                 .mixers = { alc861vd_3st_mixer },
15212                 .init_verbs = { alc861vd_volume_init_verbs,
15213                                  alc861vd_3stack_init_verbs },
15214                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
15215                 .dac_nids = alc861vd_dac_nids,
15216                 .dig_out_nid = ALC861VD_DIGOUT_NID,
15217                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15218                 .channel_mode = alc861vd_3stack_2ch_modes,
15219                 .input_mux = &alc861vd_capture_source,
15220         },
15221         [ALC861VD_6ST_DIG] = {
15222                 .mixers = { alc861vd_6st_mixer, alc861vd_chmode_mixer },
15223                 .init_verbs = { alc861vd_volume_init_verbs,
15224                                 alc861vd_6stack_init_verbs },
15225                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
15226                 .dac_nids = alc861vd_dac_nids,
15227                 .dig_out_nid = ALC861VD_DIGOUT_NID,
15228                 .num_channel_mode = ARRAY_SIZE(alc861vd_6stack_modes),
15229                 .channel_mode = alc861vd_6stack_modes,
15230                 .input_mux = &alc861vd_capture_source,
15231         },
15232         [ALC861VD_LENOVO] = {
15233                 .mixers = { alc861vd_lenovo_mixer },
15234                 .init_verbs = { alc861vd_volume_init_verbs,
15235                                 alc861vd_3stack_init_verbs,
15236                                 alc861vd_eapd_verbs,
15237                                 alc861vd_lenovo_unsol_verbs },
15238                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
15239                 .dac_nids = alc660vd_dac_nids,
15240                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15241                 .channel_mode = alc861vd_3stack_2ch_modes,
15242                 .input_mux = &alc861vd_capture_source,
15243                 .unsol_event = alc861vd_lenovo_unsol_event,
15244                 .init_hook = alc861vd_lenovo_init_hook,
15245         },
15246         [ALC861VD_DALLAS] = {
15247                 .mixers = { alc861vd_dallas_mixer },
15248                 .init_verbs = { alc861vd_dallas_verbs },
15249                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
15250                 .dac_nids = alc861vd_dac_nids,
15251                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15252                 .channel_mode = alc861vd_3stack_2ch_modes,
15253                 .input_mux = &alc861vd_dallas_capture_source,
15254                 .unsol_event = alc_automute_amp_unsol_event,
15255                 .init_hook = alc861vd_dallas_init_hook,
15256         },
15257         [ALC861VD_HP] = {
15258                 .mixers = { alc861vd_hp_mixer },
15259                 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs },
15260                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
15261                 .dac_nids = alc861vd_dac_nids,
15262                 .dig_out_nid = ALC861VD_DIGOUT_NID,
15263                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15264                 .channel_mode = alc861vd_3stack_2ch_modes,
15265                 .input_mux = &alc861vd_hp_capture_source,
15266                 .unsol_event = alc_automute_amp_unsol_event,
15267                 .init_hook = alc861vd_dallas_init_hook,
15268         },
15269         [ALC660VD_ASUS_V1S] = {
15270                 .mixers = { alc861vd_lenovo_mixer },
15271                 .init_verbs = { alc861vd_volume_init_verbs,
15272                                 alc861vd_3stack_init_verbs,
15273                                 alc861vd_eapd_verbs,
15274                                 alc861vd_lenovo_unsol_verbs },
15275                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
15276                 .dac_nids = alc660vd_dac_nids,
15277                 .dig_out_nid = ALC861VD_DIGOUT_NID,
15278                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
15279                 .channel_mode = alc861vd_3stack_2ch_modes,
15280                 .input_mux = &alc861vd_capture_source,
15281                 .unsol_event = alc861vd_lenovo_unsol_event,
15282                 .init_hook = alc861vd_lenovo_init_hook,
15283         },
15284 };
15285
15286 /*
15287  * BIOS auto configuration
15288  */
15289 static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
15290                                 hda_nid_t nid, int pin_type, int dac_idx)
15291 {
15292         alc_set_pin_output(codec, nid, pin_type);
15293 }
15294
15295 static void alc861vd_auto_init_multi_out(struct hda_codec *codec)
15296 {
15297         struct alc_spec *spec = codec->spec;
15298         int i;
15299
15300         for (i = 0; i <= HDA_SIDE; i++) {
15301                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
15302                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
15303                 if (nid)
15304                         alc861vd_auto_set_output_and_unmute(codec, nid,
15305                                                             pin_type, i);
15306         }
15307 }
15308
15309
15310 static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
15311 {
15312         struct alc_spec *spec = codec->spec;
15313         hda_nid_t pin;
15314
15315         pin = spec->autocfg.hp_pins[0];
15316         if (pin) /* connect to front and use dac 0 */
15317                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
15318         pin = spec->autocfg.speaker_pins[0];
15319         if (pin)
15320                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
15321 }
15322
15323 #define alc861vd_is_input_pin(nid)      alc880_is_input_pin(nid)
15324 #define ALC861VD_PIN_CD_NID             ALC880_PIN_CD_NID
15325
15326 static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
15327 {
15328         struct alc_spec *spec = codec->spec;
15329         int i;
15330
15331         for (i = 0; i < AUTO_PIN_LAST; i++) {
15332                 hda_nid_t nid = spec->autocfg.input_pins[i];
15333                 if (alc861vd_is_input_pin(nid)) {
15334                         alc_set_input_pin(codec, nid, i);
15335                         if (nid != ALC861VD_PIN_CD_NID &&
15336                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
15337                                 snd_hda_codec_write(codec, nid, 0,
15338                                                 AC_VERB_SET_AMP_GAIN_MUTE,
15339                                                 AMP_OUT_MUTE);
15340                 }
15341         }
15342 }
15343
15344 #define alc861vd_auto_init_input_src    alc882_auto_init_input_src
15345
15346 #define alc861vd_idx_to_mixer_vol(nid)          ((nid) + 0x02)
15347 #define alc861vd_idx_to_mixer_switch(nid)       ((nid) + 0x0c)
15348
15349 /* add playback controls from the parsed DAC table */
15350 /* Based on ALC880 version. But ALC861VD has separate,
15351  * different NIDs for mute/unmute switch and volume control */
15352 static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
15353                                              const struct auto_pin_cfg *cfg)
15354 {
15355         char name[32];
15356         static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"};
15357         hda_nid_t nid_v, nid_s;
15358         int i, err;
15359
15360         for (i = 0; i < cfg->line_outs; i++) {
15361                 if (!spec->multiout.dac_nids[i])
15362                         continue;
15363                 nid_v = alc861vd_idx_to_mixer_vol(
15364                                 alc880_dac_to_idx(
15365                                         spec->multiout.dac_nids[i]));
15366                 nid_s = alc861vd_idx_to_mixer_switch(
15367                                 alc880_dac_to_idx(
15368                                         spec->multiout.dac_nids[i]));
15369
15370                 if (i == 2) {
15371                         /* Center/LFE */
15372                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
15373                                           "Center Playback Volume",
15374                                           HDA_COMPOSE_AMP_VAL(nid_v, 1, 0,
15375                                                               HDA_OUTPUT));
15376                         if (err < 0)
15377                                 return err;
15378                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
15379                                           "LFE Playback Volume",
15380                                           HDA_COMPOSE_AMP_VAL(nid_v, 2, 0,
15381                                                               HDA_OUTPUT));
15382                         if (err < 0)
15383                                 return err;
15384                         err = add_control(spec, ALC_CTL_BIND_MUTE,
15385                                           "Center Playback Switch",
15386                                           HDA_COMPOSE_AMP_VAL(nid_s, 1, 2,
15387                                                               HDA_INPUT));
15388                         if (err < 0)
15389                                 return err;
15390                         err = add_control(spec, ALC_CTL_BIND_MUTE,
15391                                           "LFE Playback Switch",
15392                                           HDA_COMPOSE_AMP_VAL(nid_s, 2, 2,
15393                                                               HDA_INPUT));
15394                         if (err < 0)
15395                                 return err;
15396                 } else {
15397                         sprintf(name, "%s Playback Volume", chname[i]);
15398                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
15399                                           HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
15400                                                               HDA_OUTPUT));
15401                         if (err < 0)
15402                                 return err;
15403                         sprintf(name, "%s Playback Switch", chname[i]);
15404                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
15405                                           HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
15406                                                               HDA_INPUT));
15407                         if (err < 0)
15408                                 return err;
15409                 }
15410         }
15411         return 0;
15412 }
15413
15414 /* add playback controls for speaker and HP outputs */
15415 /* Based on ALC880 version. But ALC861VD has separate,
15416  * different NIDs for mute/unmute switch and volume control */
15417 static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
15418                                         hda_nid_t pin, const char *pfx)
15419 {
15420         hda_nid_t nid_v, nid_s;
15421         int err;
15422         char name[32];
15423
15424         if (!pin)
15425                 return 0;
15426
15427         if (alc880_is_fixed_pin(pin)) {
15428                 nid_v = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
15429                 /* specify the DAC as the extra output */
15430                 if (!spec->multiout.hp_nid)
15431                         spec->multiout.hp_nid = nid_v;
15432                 else
15433                         spec->multiout.extra_out_nid[0] = nid_v;
15434                 /* control HP volume/switch on the output mixer amp */
15435                 nid_v = alc861vd_idx_to_mixer_vol(
15436                                 alc880_fixed_pin_idx(pin));
15437                 nid_s = alc861vd_idx_to_mixer_switch(
15438                                 alc880_fixed_pin_idx(pin));
15439
15440                 sprintf(name, "%s Playback Volume", pfx);
15441                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
15442                                   HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT));
15443                 if (err < 0)
15444                         return err;
15445                 sprintf(name, "%s Playback Switch", pfx);
15446                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
15447                                   HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT));
15448                 if (err < 0)
15449                         return err;
15450         } else if (alc880_is_multi_pin(pin)) {
15451                 /* set manual connection */
15452                 /* we have only a switch on HP-out PIN */
15453                 sprintf(name, "%s Playback Switch", pfx);
15454                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
15455                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
15456                 if (err < 0)
15457                         return err;
15458         }
15459         return 0;
15460 }
15461
15462 /* parse the BIOS configuration and set up the alc_spec
15463  * return 1 if successful, 0 if the proper config is not found,
15464  * or a negative error code
15465  * Based on ALC880 version - had to change it to override
15466  * alc880_auto_create_extra_out and alc880_auto_create_multi_out_ctls */
15467 static int alc861vd_parse_auto_config(struct hda_codec *codec)
15468 {
15469         struct alc_spec *spec = codec->spec;
15470         int err;
15471         static hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
15472
15473         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
15474                                            alc861vd_ignore);
15475         if (err < 0)
15476                 return err;
15477         if (!spec->autocfg.line_outs)
15478                 return 0; /* can't find valid BIOS pin config */
15479
15480         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
15481         if (err < 0)
15482                 return err;
15483         err = alc861vd_auto_create_multi_out_ctls(spec, &spec->autocfg);
15484         if (err < 0)
15485                 return err;
15486         err = alc861vd_auto_create_extra_out(spec,
15487                                              spec->autocfg.speaker_pins[0],
15488                                              "Speaker");
15489         if (err < 0)
15490                 return err;
15491         err = alc861vd_auto_create_extra_out(spec,
15492                                              spec->autocfg.hp_pins[0],
15493                                              "Headphone");
15494         if (err < 0)
15495                 return err;
15496         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
15497         if (err < 0)
15498                 return err;
15499
15500         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
15501
15502         if (spec->autocfg.dig_outs)
15503                 spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID;
15504
15505         if (spec->kctls.list)
15506                 add_mixer(spec, spec->kctls.list);
15507
15508         add_verb(spec, alc861vd_volume_init_verbs);
15509
15510         spec->num_mux_defs = 1;
15511         spec->input_mux = &spec->private_imux[0];
15512
15513         err = alc_auto_add_mic_boost(codec);
15514         if (err < 0)
15515                 return err;
15516
15517         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
15518
15519         return 1;
15520 }
15521
15522 /* additional initialization for auto-configuration model */
15523 static void alc861vd_auto_init(struct hda_codec *codec)
15524 {
15525         struct alc_spec *spec = codec->spec;
15526         alc861vd_auto_init_multi_out(codec);
15527         alc861vd_auto_init_hp_out(codec);
15528         alc861vd_auto_init_analog_input(codec);
15529         alc861vd_auto_init_input_src(codec);
15530         if (spec->unsol_event)
15531                 alc_inithook(codec);
15532 }
15533
15534 static int patch_alc861vd(struct hda_codec *codec)
15535 {
15536         struct alc_spec *spec;
15537         int err, board_config;
15538
15539         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
15540         if (spec == NULL)
15541                 return -ENOMEM;
15542
15543         codec->spec = spec;
15544
15545         board_config = snd_hda_check_board_config(codec, ALC861VD_MODEL_LAST,
15546                                                   alc861vd_models,
15547                                                   alc861vd_cfg_tbl);
15548
15549         if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) {
15550                 printk(KERN_INFO "hda_codec: Unknown model for %s, "
15551                        "trying auto-probe from BIOS...\n", codec->chip_name);
15552                 board_config = ALC861VD_AUTO;
15553         }
15554
15555         if (board_config == ALC861VD_AUTO) {
15556                 /* automatic parse from the BIOS config */
15557                 err = alc861vd_parse_auto_config(codec);
15558                 if (err < 0) {
15559                         alc_free(codec);
15560                         return err;
15561                 } else if (!err) {
15562                         printk(KERN_INFO
15563                                "hda_codec: Cannot set up configuration "
15564                                "from BIOS.  Using base mode...\n");
15565                         board_config = ALC861VD_3ST;
15566                 }
15567         }
15568
15569         err = snd_hda_attach_beep_device(codec, 0x23);
15570         if (err < 0) {
15571                 alc_free(codec);
15572                 return err;
15573         }
15574
15575         if (board_config != ALC861VD_AUTO)
15576                 setup_preset(spec, &alc861vd_presets[board_config]);
15577
15578         if (codec->vendor_id == 0x10ec0660) {
15579                 /* always turn on EAPD */
15580                 add_verb(spec, alc660vd_eapd_verbs);
15581         }
15582
15583         spec->stream_analog_playback = &alc861vd_pcm_analog_playback;
15584         spec->stream_analog_capture = &alc861vd_pcm_analog_capture;
15585
15586         spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
15587         spec->stream_digital_capture = &alc861vd_pcm_digital_capture;
15588
15589         spec->adc_nids = alc861vd_adc_nids;
15590         spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
15591         spec->capsrc_nids = alc861vd_capsrc_nids;
15592
15593         set_capture_mixer(spec);
15594         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
15595
15596         spec->vmaster_nid = 0x02;
15597
15598         codec->patch_ops = alc_patch_ops;
15599
15600         if (board_config == ALC861VD_AUTO)
15601                 spec->init_hook = alc861vd_auto_init;
15602 #ifdef CONFIG_SND_HDA_POWER_SAVE
15603         if (!spec->loopback.amplist)
15604                 spec->loopback.amplist = alc861vd_loopbacks;
15605 #endif
15606         codec->proc_widget_hook = print_realtek_coef;
15607
15608         return 0;
15609 }
15610
15611 /*
15612  * ALC662 support
15613  *
15614  * ALC662 is almost identical with ALC880 but has cleaner and more flexible
15615  * configuration.  Each pin widget can choose any input DACs and a mixer.
15616  * Each ADC is connected from a mixer of all inputs.  This makes possible
15617  * 6-channel independent captures.
15618  *
15619  * In addition, an independent DAC for the multi-playback (not used in this
15620  * driver yet).
15621  */
15622 #define ALC662_DIGOUT_NID       0x06
15623 #define ALC662_DIGIN_NID        0x0a
15624
15625 static hda_nid_t alc662_dac_nids[4] = {
15626         /* front, rear, clfe, rear_surr */
15627         0x02, 0x03, 0x04
15628 };
15629
15630 static hda_nid_t alc272_dac_nids[2] = {
15631         0x02, 0x03
15632 };
15633
15634 static hda_nid_t alc662_adc_nids[1] = {
15635         /* ADC1-2 */
15636         0x09,
15637 };
15638
15639 static hda_nid_t alc272_adc_nids[1] = {
15640         /* ADC1-2 */
15641         0x08,
15642 };
15643
15644 static hda_nid_t alc662_capsrc_nids[1] = { 0x22 };
15645 static hda_nid_t alc272_capsrc_nids[1] = { 0x23 };
15646
15647
15648 /* input MUX */
15649 /* FIXME: should be a matrix-type input source selection */
15650 static struct hda_input_mux alc662_capture_source = {
15651         .num_items = 4,
15652         .items = {
15653                 { "Mic", 0x0 },
15654                 { "Front Mic", 0x1 },
15655                 { "Line", 0x2 },
15656                 { "CD", 0x4 },
15657         },
15658 };
15659
15660 static struct hda_input_mux alc662_lenovo_101e_capture_source = {
15661         .num_items = 2,
15662         .items = {
15663                 { "Mic", 0x1 },
15664                 { "Line", 0x2 },
15665         },
15666 };
15667
15668 static struct hda_input_mux alc662_eeepc_capture_source = {
15669         .num_items = 2,
15670         .items = {
15671                 { "i-Mic", 0x1 },
15672                 { "e-Mic", 0x0 },
15673         },
15674 };
15675
15676 static struct hda_input_mux alc663_capture_source = {
15677         .num_items = 3,
15678         .items = {
15679                 { "Mic", 0x0 },
15680                 { "Front Mic", 0x1 },
15681                 { "Line", 0x2 },
15682         },
15683 };
15684
15685 static struct hda_input_mux alc663_m51va_capture_source = {
15686         .num_items = 2,
15687         .items = {
15688                 { "Ext-Mic", 0x0 },
15689                 { "D-Mic", 0x9 },
15690         },
15691 };
15692
15693 #if 1 /* set to 0 for testing other input sources below */
15694 static struct hda_input_mux alc272_nc10_capture_source = {
15695         .num_items = 2,
15696         .items = {
15697                 { "Autoselect Mic", 0x0 },
15698                 { "Internal Mic", 0x1 },
15699         },
15700 };
15701 #else
15702 static struct hda_input_mux alc272_nc10_capture_source = {
15703         .num_items = 16,
15704         .items = {
15705                 { "Autoselect Mic", 0x0 },
15706                 { "Internal Mic", 0x1 },
15707                 { "In-0x02", 0x2 },
15708                 { "In-0x03", 0x3 },
15709                 { "In-0x04", 0x4 },
15710                 { "In-0x05", 0x5 },
15711                 { "In-0x06", 0x6 },
15712                 { "In-0x07", 0x7 },
15713                 { "In-0x08", 0x8 },
15714                 { "In-0x09", 0x9 },
15715                 { "In-0x0a", 0x0a },
15716                 { "In-0x0b", 0x0b },
15717                 { "In-0x0c", 0x0c },
15718                 { "In-0x0d", 0x0d },
15719                 { "In-0x0e", 0x0e },
15720                 { "In-0x0f", 0x0f },
15721         },
15722 };
15723 #endif
15724
15725 /*
15726  * 2ch mode
15727  */
15728 static struct hda_channel_mode alc662_3ST_2ch_modes[1] = {
15729         { 2, NULL }
15730 };
15731
15732 /*
15733  * 2ch mode
15734  */
15735 static struct hda_verb alc662_3ST_ch2_init[] = {
15736         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
15737         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
15738         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
15739         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
15740         { } /* end */
15741 };
15742
15743 /*
15744  * 6ch mode
15745  */
15746 static struct hda_verb alc662_3ST_ch6_init[] = {
15747         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15748         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
15749         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
15750         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15751         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
15752         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
15753         { } /* end */
15754 };
15755
15756 static struct hda_channel_mode alc662_3ST_6ch_modes[2] = {
15757         { 2, alc662_3ST_ch2_init },
15758         { 6, alc662_3ST_ch6_init },
15759 };
15760
15761 /*
15762  * 2ch mode
15763  */
15764 static struct hda_verb alc662_sixstack_ch6_init[] = {
15765         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
15766         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
15767         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15768         { } /* end */
15769 };
15770
15771 /*
15772  * 6ch mode
15773  */
15774 static struct hda_verb alc662_sixstack_ch8_init[] = {
15775         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15776         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15777         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15778         { } /* end */
15779 };
15780
15781 static struct hda_channel_mode alc662_5stack_modes[2] = {
15782         { 2, alc662_sixstack_ch6_init },
15783         { 6, alc662_sixstack_ch8_init },
15784 };
15785
15786 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
15787  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
15788  */
15789
15790 static struct snd_kcontrol_new alc662_base_mixer[] = {
15791         /* output mixer control */
15792         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
15793         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
15794         HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
15795         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
15796         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15797         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15798         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
15799         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
15800         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15801
15802         /*Input mixer control */
15803         HDA_CODEC_VOLUME("CD Playback Volume", 0xb, 0x4, HDA_INPUT),
15804         HDA_CODEC_MUTE("CD Playback Switch", 0xb, 0x4, HDA_INPUT),
15805         HDA_CODEC_VOLUME("Line Playback Volume", 0xb, 0x02, HDA_INPUT),
15806         HDA_CODEC_MUTE("Line Playback Switch", 0xb, 0x02, HDA_INPUT),
15807         HDA_CODEC_VOLUME("Mic Playback Volume", 0xb, 0x0, HDA_INPUT),
15808         HDA_CODEC_MUTE("Mic Playback Switch", 0xb, 0x0, HDA_INPUT),
15809         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0xb, 0x01, HDA_INPUT),
15810         HDA_CODEC_MUTE("Front Mic Playback Switch", 0xb, 0x01, HDA_INPUT),
15811         { } /* end */
15812 };
15813
15814 static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
15815         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15816         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
15817         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15818         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
15819         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
15820         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15821         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15822         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15823         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15824         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15825         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15826         { } /* end */
15827 };
15828
15829 static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
15830         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15831         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
15832         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15833         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
15834         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15835         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15836         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
15837         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
15838         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15839         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
15840         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
15841         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15842         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15843         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15844         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15845         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15846         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15847         { } /* end */
15848 };
15849
15850 static struct snd_kcontrol_new alc662_lenovo_101e_mixer[] = {
15851         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15852         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
15853         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15854         HDA_BIND_MUTE("Speaker Playback Switch", 0x03, 2, HDA_INPUT),
15855         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15856         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15857         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15858         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15859         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15860         { } /* end */
15861 };
15862
15863 static struct snd_kcontrol_new alc662_eeepc_p701_mixer[] = {
15864         HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15865         ALC262_HIPPO_MASTER_SWITCH,
15866
15867         HDA_CODEC_VOLUME("e-Mic Boost", 0x18, 0, HDA_INPUT),
15868         HDA_CODEC_VOLUME("e-Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15869         HDA_CODEC_MUTE("e-Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15870
15871         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
15872         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15873         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15874         { } /* end */
15875 };
15876
15877 static struct snd_kcontrol_new alc662_eeepc_ep20_mixer[] = {
15878         ALC262_HIPPO_MASTER_SWITCH,
15879         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15880         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15881         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15882         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15883         HDA_BIND_MUTE("MuteCtrl Playback Switch", 0x0c, 2, HDA_INPUT),
15884         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15885         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15886         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15887         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15888         { } /* end */
15889 };
15890
15891 static struct hda_bind_ctls alc663_asus_bind_master_vol = {
15892         .ops = &snd_hda_bind_vol,
15893         .values = {
15894                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
15895                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
15896                 0
15897         },
15898 };
15899
15900 static struct hda_bind_ctls alc663_asus_one_bind_switch = {
15901         .ops = &snd_hda_bind_sw,
15902         .values = {
15903                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15904                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
15905                 0
15906         },
15907 };
15908
15909 static struct snd_kcontrol_new alc663_m51va_mixer[] = {
15910         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15911         HDA_BIND_SW("Master Playback Switch", &alc663_asus_one_bind_switch),
15912         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15913         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15914         { } /* end */
15915 };
15916
15917 static struct hda_bind_ctls alc663_asus_tree_bind_switch = {
15918         .ops = &snd_hda_bind_sw,
15919         .values = {
15920                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15921                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
15922                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
15923                 0
15924         },
15925 };
15926
15927 static struct snd_kcontrol_new alc663_two_hp_m1_mixer[] = {
15928         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15929         HDA_BIND_SW("Master Playback Switch", &alc663_asus_tree_bind_switch),
15930         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15931         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15932         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15933         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15934
15935         { } /* end */
15936 };
15937
15938 static struct hda_bind_ctls alc663_asus_four_bind_switch = {
15939         .ops = &snd_hda_bind_sw,
15940         .values = {
15941                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15942                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
15943                 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
15944                 0
15945         },
15946 };
15947
15948 static struct snd_kcontrol_new alc663_two_hp_m2_mixer[] = {
15949         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15950         HDA_BIND_SW("Master Playback Switch", &alc663_asus_four_bind_switch),
15951         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15952         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15953         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15954         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15955         { } /* end */
15956 };
15957
15958 static struct snd_kcontrol_new alc662_1bjd_mixer[] = {
15959         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15960         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15961         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15962         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15963         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15964         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15965         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15966         { } /* end */
15967 };
15968
15969 static struct hda_bind_ctls alc663_asus_two_bind_master_vol = {
15970         .ops = &snd_hda_bind_vol,
15971         .values = {
15972                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
15973                 HDA_COMPOSE_AMP_VAL(0x04, 3, 0, HDA_OUTPUT),
15974                 0
15975         },
15976 };
15977
15978 static struct hda_bind_ctls alc663_asus_two_bind_switch = {
15979         .ops = &snd_hda_bind_sw,
15980         .values = {
15981                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15982                 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT),
15983                 0
15984         },
15985 };
15986
15987 static struct snd_kcontrol_new alc663_asus_21jd_clfe_mixer[] = {
15988         HDA_BIND_VOL("Master Playback Volume",
15989                                 &alc663_asus_two_bind_master_vol),
15990         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
15991         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15992         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
15993         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15994         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15995         { } /* end */
15996 };
15997
15998 static struct snd_kcontrol_new alc663_asus_15jd_clfe_mixer[] = {
15999         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
16000         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
16001         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
16002         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
16003         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16004         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16005         { } /* end */
16006 };
16007
16008 static struct snd_kcontrol_new alc663_g71v_mixer[] = {
16009         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16010         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
16011         HDA_CODEC_VOLUME("Front Playback Volume", 0x03, 0x0, HDA_OUTPUT),
16012         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
16013         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
16014
16015         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16016         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16017         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16018         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16019         { } /* end */
16020 };
16021
16022 static struct snd_kcontrol_new alc663_g50v_mixer[] = {
16023         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16024         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
16025         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
16026
16027         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16028         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16029         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16030         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16031         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
16032         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
16033         { } /* end */
16034 };
16035
16036 static struct snd_kcontrol_new alc662_chmode_mixer[] = {
16037         {
16038                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
16039                 .name = "Channel Mode",
16040                 .info = alc_ch_mode_info,
16041                 .get = alc_ch_mode_get,
16042                 .put = alc_ch_mode_put,
16043         },
16044         { } /* end */
16045 };
16046
16047 static struct hda_verb alc662_init_verbs[] = {
16048         /* ADC: mute amp left and right */
16049         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16050         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
16051         /* Front mixer: unmute input/output amp left and right (volume = 0) */
16052
16053         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16054         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
16055         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
16056         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
16057         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
16058
16059         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16060         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16061         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16062         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16063         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16064         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16065
16066         /* Front Pin: output 0 (0x0c) */
16067         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16068         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16069
16070         /* Rear Pin: output 1 (0x0d) */
16071         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16072         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16073
16074         /* CLFE Pin: output 2 (0x0e) */
16075         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16076         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16077
16078         /* Mic (rear) pin: input vref at 80% */
16079         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
16080         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16081         /* Front Mic pin: input vref at 80% */
16082         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
16083         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16084         /* Line In pin: input */
16085         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16086         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
16087         /* Line-2 In: Headphone output (output 0 - 0x0c) */
16088         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16089         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16090         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
16091         /* CD pin widget for input */
16092         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16093
16094         /* FIXME: use matrix-type input source selection */
16095         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
16096         /* Input mixer */
16097         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16098         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16099
16100         /* always trun on EAPD */
16101         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
16102         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
16103
16104         { }
16105 };
16106
16107 static struct hda_verb alc662_sue_init_verbs[] = {
16108         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
16109         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
16110         {}
16111 };
16112
16113 static struct hda_verb alc662_eeepc_sue_init_verbs[] = {
16114         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16115         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16116         {}
16117 };
16118
16119 /* Set Unsolicited Event*/
16120 static struct hda_verb alc662_eeepc_ep20_sue_init_verbs[] = {
16121         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
16122         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16123         {}
16124 };
16125
16126 /*
16127  * generic initialization of ADC, input mixers and output mixers
16128  */
16129 static struct hda_verb alc662_auto_init_verbs[] = {
16130         /*
16131          * Unmute ADC and set the default input to mic-in
16132          */
16133         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
16134         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16135
16136         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
16137          * mixer widget
16138          * Note: PASD motherboards uses the Line In 2 as the input for front
16139          * panel mic (mic 2)
16140          */
16141         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
16142         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16143         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
16144         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
16145         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
16146         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
16147
16148         /*
16149          * Set up output mixers (0x0c - 0x0f)
16150          */
16151         /* set vol=0 to output mixers */
16152         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
16153         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
16154         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
16155
16156         /* set up input amps for analog loopback */
16157         /* Amp Indices: DAC = 0, mixer = 1 */
16158         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16159         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16160         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16161         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16162         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16163         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16164
16165
16166         /* FIXME: use matrix-type input source selection */
16167         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
16168         /* Input mixer */
16169         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16170         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16171         { }
16172 };
16173
16174 /* additional verbs for ALC663 */
16175 static struct hda_verb alc663_auto_init_verbs[] = {
16176         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
16177         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16178         { }
16179 };
16180
16181 static struct hda_verb alc663_m51va_init_verbs[] = {
16182         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16183         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16184         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16185         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16186         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16187         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16188         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
16189         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16190         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16191         {}
16192 };
16193
16194 static struct hda_verb alc663_21jd_amic_init_verbs[] = {
16195         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16196         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16197         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16198         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16199         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16200         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16201         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16202         {}
16203 };
16204
16205 static struct hda_verb alc662_1bjd_amic_init_verbs[] = {
16206         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16207         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16208         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16209         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
16210         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16211         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16212         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16213         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16214         {}
16215 };
16216
16217 static struct hda_verb alc663_15jd_amic_init_verbs[] = {
16218         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16219         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16220         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16221         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16222         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16223         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16224         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16225         {}
16226 };
16227
16228 static struct hda_verb alc663_two_hp_amic_m1_init_verbs[] = {
16229         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16230         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16231         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16232         {0x21, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
16233         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16234         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16235         {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
16236         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16237         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16238         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16239         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16240         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16241         {}
16242 };
16243
16244 static struct hda_verb alc663_two_hp_amic_m2_init_verbs[] = {
16245         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16246         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16247         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16248         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16249         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16250         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16251         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16252         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16253         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
16254         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16255         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16256         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16257         {}
16258 };
16259
16260 static struct hda_verb alc663_g71v_init_verbs[] = {
16261         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16262         /* {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
16263         /* {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, */ /* Headphone */
16264
16265         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16266         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16267         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
16268
16269         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
16270         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_MIC_EVENT},
16271         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
16272         {}
16273 };
16274
16275 static struct hda_verb alc663_g50v_init_verbs[] = {
16276         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16277         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16278         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
16279
16280         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16281         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16282         {}
16283 };
16284
16285 static struct hda_verb alc662_ecs_init_verbs[] = {
16286         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0x701f},
16287         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16288         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16289         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16290         {}
16291 };
16292
16293 static struct hda_verb alc272_dell_zm1_init_verbs[] = {
16294         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16295         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16296         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16297         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16298         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16299         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16300         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16301         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16302         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
16303         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16304         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16305         {}
16306 };
16307
16308 static struct hda_verb alc272_dell_init_verbs[] = {
16309         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16310         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16311         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16312         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
16313         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
16314         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
16315         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
16316         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
16317         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
16318         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
16319         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
16320         {}
16321 };
16322
16323 static struct snd_kcontrol_new alc662_auto_capture_mixer[] = {
16324         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
16325         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
16326         { } /* end */
16327 };
16328
16329 static struct snd_kcontrol_new alc272_auto_capture_mixer[] = {
16330         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
16331         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
16332         { } /* end */
16333 };
16334
16335 static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
16336 {
16337         unsigned int present;
16338         unsigned char bits;
16339
16340         present = snd_hda_codec_read(codec, 0x14, 0,
16341                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
16342         bits = present ? HDA_AMP_MUTE : 0;
16343         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
16344                                  HDA_AMP_MUTE, bits);
16345 }
16346
16347 static void alc662_lenovo_101e_all_automute(struct hda_codec *codec)
16348 {
16349         unsigned int present;
16350         unsigned char bits;
16351
16352         present = snd_hda_codec_read(codec, 0x1b, 0,
16353                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
16354         bits = present ? HDA_AMP_MUTE : 0;
16355         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
16356                                  HDA_AMP_MUTE, bits);
16357         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
16358                                  HDA_AMP_MUTE, bits);
16359 }
16360
16361 static void alc662_lenovo_101e_unsol_event(struct hda_codec *codec,
16362                                            unsigned int res)
16363 {
16364         if ((res >> 26) == ALC880_HP_EVENT)
16365                 alc662_lenovo_101e_all_automute(codec);
16366         if ((res >> 26) == ALC880_FRONT_EVENT)
16367                 alc662_lenovo_101e_ispeaker_automute(codec);
16368 }
16369
16370 static void alc662_eeepc_mic_automute(struct hda_codec *codec)
16371 {
16372         unsigned int present;
16373
16374         present = snd_hda_codec_read(codec, 0x18, 0,
16375                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
16376         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16377                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
16378         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16379                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
16380         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16381                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
16382         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16383                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
16384 }
16385
16386 /* unsolicited event for HP jack sensing */
16387 static void alc662_eeepc_unsol_event(struct hda_codec *codec,
16388                                      unsigned int res)
16389 {
16390         if ((res >> 26) == ALC880_MIC_EVENT)
16391                 alc662_eeepc_mic_automute(codec);
16392         else
16393                 alc262_hippo_unsol_event(codec, res);
16394 }
16395
16396 static void alc662_eeepc_inithook(struct hda_codec *codec)
16397 {
16398         alc262_hippo1_init_hook(codec);
16399         alc662_eeepc_mic_automute(codec);
16400 }
16401
16402 static void alc662_eeepc_ep20_inithook(struct hda_codec *codec)
16403 {
16404         struct alc_spec *spec = codec->spec;
16405
16406         spec->autocfg.hp_pins[0] = 0x14;
16407         spec->autocfg.speaker_pins[0] = 0x1b;
16408         alc262_hippo_master_update(codec);
16409 }
16410
16411 static void alc663_m51va_speaker_automute(struct hda_codec *codec)
16412 {
16413         unsigned int present;
16414         unsigned char bits;
16415
16416         present = snd_hda_codec_read(codec, 0x21, 0,
16417                         AC_VERB_GET_PIN_SENSE, 0)
16418                         & AC_PINSENSE_PRESENCE;
16419         bits = present ? HDA_AMP_MUTE : 0;
16420         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16421                                 AMP_IN_MUTE(0), bits);
16422         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16423                                 AMP_IN_MUTE(0), bits);
16424 }
16425
16426 static void alc663_21jd_two_speaker_automute(struct hda_codec *codec)
16427 {
16428         unsigned int present;
16429         unsigned char bits;
16430
16431         present = snd_hda_codec_read(codec, 0x21, 0,
16432                         AC_VERB_GET_PIN_SENSE, 0)
16433                         & AC_PINSENSE_PRESENCE;
16434         bits = present ? HDA_AMP_MUTE : 0;
16435         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16436                                 AMP_IN_MUTE(0), bits);
16437         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16438                                 AMP_IN_MUTE(0), bits);
16439         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
16440                                 AMP_IN_MUTE(0), bits);
16441         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
16442                                 AMP_IN_MUTE(0), bits);
16443 }
16444
16445 static void alc663_15jd_two_speaker_automute(struct hda_codec *codec)
16446 {
16447         unsigned int present;
16448         unsigned char bits;
16449
16450         present = snd_hda_codec_read(codec, 0x15, 0,
16451                         AC_VERB_GET_PIN_SENSE, 0)
16452                         & AC_PINSENSE_PRESENCE;
16453         bits = present ? HDA_AMP_MUTE : 0;
16454         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16455                                 AMP_IN_MUTE(0), bits);
16456         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16457                                 AMP_IN_MUTE(0), bits);
16458         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
16459                                 AMP_IN_MUTE(0), bits);
16460         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
16461                                 AMP_IN_MUTE(0), bits);
16462 }
16463
16464 static void alc662_f5z_speaker_automute(struct hda_codec *codec)
16465 {
16466         unsigned int present;
16467         unsigned char bits;
16468
16469         present = snd_hda_codec_read(codec, 0x1b, 0,
16470                         AC_VERB_GET_PIN_SENSE, 0)
16471                         & AC_PINSENSE_PRESENCE;
16472         bits = present ? 0 : PIN_OUT;
16473         snd_hda_codec_write(codec, 0x14, 0,
16474                          AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
16475 }
16476
16477 static void alc663_two_hp_m1_speaker_automute(struct hda_codec *codec)
16478 {
16479         unsigned int present1, present2;
16480
16481         present1 = snd_hda_codec_read(codec, 0x21, 0,
16482                         AC_VERB_GET_PIN_SENSE, 0)
16483                         & AC_PINSENSE_PRESENCE;
16484         present2 = snd_hda_codec_read(codec, 0x15, 0,
16485                         AC_VERB_GET_PIN_SENSE, 0)
16486                         & AC_PINSENSE_PRESENCE;
16487
16488         if (present1 || present2) {
16489                 snd_hda_codec_write_cache(codec, 0x14, 0,
16490                         AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
16491         } else {
16492                 snd_hda_codec_write_cache(codec, 0x14, 0,
16493                         AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
16494         }
16495 }
16496
16497 static void alc663_two_hp_m2_speaker_automute(struct hda_codec *codec)
16498 {
16499         unsigned int present1, present2;
16500
16501         present1 = snd_hda_codec_read(codec, 0x1b, 0,
16502                                 AC_VERB_GET_PIN_SENSE, 0)
16503                                 & AC_PINSENSE_PRESENCE;
16504         present2 = snd_hda_codec_read(codec, 0x15, 0,
16505                                 AC_VERB_GET_PIN_SENSE, 0)
16506                                 & AC_PINSENSE_PRESENCE;
16507
16508         if (present1 || present2) {
16509                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16510                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
16511                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16512                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
16513         } else {
16514                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16515                                 AMP_IN_MUTE(0), 0);
16516                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16517                                 AMP_IN_MUTE(0), 0);
16518         }
16519 }
16520
16521 static void alc663_m51va_mic_automute(struct hda_codec *codec)
16522 {
16523         unsigned int present;
16524
16525         present = snd_hda_codec_read(codec, 0x18, 0,
16526                         AC_VERB_GET_PIN_SENSE, 0)
16527                         & AC_PINSENSE_PRESENCE;
16528         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16529                         0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
16530         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16531                         0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
16532         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16533                         0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
16534         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16535                         0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
16536 }
16537
16538 static void alc663_m51va_unsol_event(struct hda_codec *codec,
16539                                            unsigned int res)
16540 {
16541         switch (res >> 26) {
16542         case ALC880_HP_EVENT:
16543                 alc663_m51va_speaker_automute(codec);
16544                 break;
16545         case ALC880_MIC_EVENT:
16546                 alc663_m51va_mic_automute(codec);
16547                 break;
16548         }
16549 }
16550
16551 static void alc663_m51va_inithook(struct hda_codec *codec)
16552 {
16553         alc663_m51va_speaker_automute(codec);
16554         alc663_m51va_mic_automute(codec);
16555 }
16556
16557 /* ***************** Mode1 ******************************/
16558 static void alc663_mode1_unsol_event(struct hda_codec *codec,
16559                                            unsigned int res)
16560 {
16561         switch (res >> 26) {
16562         case ALC880_HP_EVENT:
16563                 alc663_m51va_speaker_automute(codec);
16564                 break;
16565         case ALC880_MIC_EVENT:
16566                 alc662_eeepc_mic_automute(codec);
16567                 break;
16568         }
16569 }
16570
16571 static void alc663_mode1_inithook(struct hda_codec *codec)
16572 {
16573         alc663_m51va_speaker_automute(codec);
16574         alc662_eeepc_mic_automute(codec);
16575 }
16576 /* ***************** Mode2 ******************************/
16577 static void alc662_mode2_unsol_event(struct hda_codec *codec,
16578                                            unsigned int res)
16579 {
16580         switch (res >> 26) {
16581         case ALC880_HP_EVENT:
16582                 alc662_f5z_speaker_automute(codec);
16583                 break;
16584         case ALC880_MIC_EVENT:
16585                 alc662_eeepc_mic_automute(codec);
16586                 break;
16587         }
16588 }
16589
16590 static void alc662_mode2_inithook(struct hda_codec *codec)
16591 {
16592         alc662_f5z_speaker_automute(codec);
16593         alc662_eeepc_mic_automute(codec);
16594 }
16595 /* ***************** Mode3 ******************************/
16596 static void alc663_mode3_unsol_event(struct hda_codec *codec,
16597                                            unsigned int res)
16598 {
16599         switch (res >> 26) {
16600         case ALC880_HP_EVENT:
16601                 alc663_two_hp_m1_speaker_automute(codec);
16602                 break;
16603         case ALC880_MIC_EVENT:
16604                 alc662_eeepc_mic_automute(codec);
16605                 break;
16606         }
16607 }
16608
16609 static void alc663_mode3_inithook(struct hda_codec *codec)
16610 {
16611         alc663_two_hp_m1_speaker_automute(codec);
16612         alc662_eeepc_mic_automute(codec);
16613 }
16614 /* ***************** Mode4 ******************************/
16615 static void alc663_mode4_unsol_event(struct hda_codec *codec,
16616                                            unsigned int res)
16617 {
16618         switch (res >> 26) {
16619         case ALC880_HP_EVENT:
16620                 alc663_21jd_two_speaker_automute(codec);
16621                 break;
16622         case ALC880_MIC_EVENT:
16623                 alc662_eeepc_mic_automute(codec);
16624                 break;
16625         }
16626 }
16627
16628 static void alc663_mode4_inithook(struct hda_codec *codec)
16629 {
16630         alc663_21jd_two_speaker_automute(codec);
16631         alc662_eeepc_mic_automute(codec);
16632 }
16633 /* ***************** Mode5 ******************************/
16634 static void alc663_mode5_unsol_event(struct hda_codec *codec,
16635                                            unsigned int res)
16636 {
16637         switch (res >> 26) {
16638         case ALC880_HP_EVENT:
16639                 alc663_15jd_two_speaker_automute(codec);
16640                 break;
16641         case ALC880_MIC_EVENT:
16642                 alc662_eeepc_mic_automute(codec);
16643                 break;
16644         }
16645 }
16646
16647 static void alc663_mode5_inithook(struct hda_codec *codec)
16648 {
16649         alc663_15jd_two_speaker_automute(codec);
16650         alc662_eeepc_mic_automute(codec);
16651 }
16652 /* ***************** Mode6 ******************************/
16653 static void alc663_mode6_unsol_event(struct hda_codec *codec,
16654                                            unsigned int res)
16655 {
16656         switch (res >> 26) {
16657         case ALC880_HP_EVENT:
16658                 alc663_two_hp_m2_speaker_automute(codec);
16659                 break;
16660         case ALC880_MIC_EVENT:
16661                 alc662_eeepc_mic_automute(codec);
16662                 break;
16663         }
16664 }
16665
16666 static void alc663_mode6_inithook(struct hda_codec *codec)
16667 {
16668         alc663_two_hp_m2_speaker_automute(codec);
16669         alc662_eeepc_mic_automute(codec);
16670 }
16671
16672 static void alc663_g71v_hp_automute(struct hda_codec *codec)
16673 {
16674         unsigned int present;
16675         unsigned char bits;
16676
16677         present = snd_hda_codec_read(codec, 0x21, 0,
16678                                      AC_VERB_GET_PIN_SENSE, 0)
16679                 & AC_PINSENSE_PRESENCE;
16680         bits = present ? HDA_AMP_MUTE : 0;
16681         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
16682                                  HDA_AMP_MUTE, bits);
16683         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
16684                                  HDA_AMP_MUTE, bits);
16685 }
16686
16687 static void alc663_g71v_front_automute(struct hda_codec *codec)
16688 {
16689         unsigned int present;
16690         unsigned char bits;
16691
16692         present = snd_hda_codec_read(codec, 0x15, 0,
16693                                      AC_VERB_GET_PIN_SENSE, 0)
16694                 & AC_PINSENSE_PRESENCE;
16695         bits = present ? HDA_AMP_MUTE : 0;
16696         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
16697                                  HDA_AMP_MUTE, bits);
16698 }
16699
16700 static void alc663_g71v_unsol_event(struct hda_codec *codec,
16701                                            unsigned int res)
16702 {
16703         switch (res >> 26) {
16704         case ALC880_HP_EVENT:
16705                 alc663_g71v_hp_automute(codec);
16706                 break;
16707         case ALC880_FRONT_EVENT:
16708                 alc663_g71v_front_automute(codec);
16709                 break;
16710         case ALC880_MIC_EVENT:
16711                 alc662_eeepc_mic_automute(codec);
16712                 break;
16713         }
16714 }
16715
16716 static void alc663_g71v_inithook(struct hda_codec *codec)
16717 {
16718         alc663_g71v_front_automute(codec);
16719         alc663_g71v_hp_automute(codec);
16720         alc662_eeepc_mic_automute(codec);
16721 }
16722
16723 static void alc663_g50v_unsol_event(struct hda_codec *codec,
16724                                            unsigned int res)
16725 {
16726         switch (res >> 26) {
16727         case ALC880_HP_EVENT:
16728                 alc663_m51va_speaker_automute(codec);
16729                 break;
16730         case ALC880_MIC_EVENT:
16731                 alc662_eeepc_mic_automute(codec);
16732                 break;
16733         }
16734 }
16735
16736 static void alc663_g50v_inithook(struct hda_codec *codec)
16737 {
16738         alc663_m51va_speaker_automute(codec);
16739         alc662_eeepc_mic_automute(codec);
16740 }
16741
16742 static struct snd_kcontrol_new alc662_ecs_mixer[] = {
16743         HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16744         ALC262_HIPPO_MASTER_SWITCH,
16745
16746         HDA_CODEC_VOLUME("e-Mic/LineIn Boost", 0x18, 0, HDA_INPUT),
16747         HDA_CODEC_VOLUME("e-Mic/LineIn Playback Volume", 0x0b, 0x0, HDA_INPUT),
16748         HDA_CODEC_MUTE("e-Mic/LineIn Playback Switch", 0x0b, 0x0, HDA_INPUT),
16749
16750         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
16751         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16752         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16753         { } /* end */
16754 };
16755
16756 static struct snd_kcontrol_new alc272_nc10_mixer[] = {
16757         /* Master Playback automatically created from Speaker and Headphone */
16758         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16759         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
16760         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
16761         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
16762
16763         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
16764         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
16765         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
16766
16767         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16768         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16769         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
16770         { } /* end */
16771 };
16772
16773 #ifdef CONFIG_SND_HDA_POWER_SAVE
16774 #define alc662_loopbacks        alc880_loopbacks
16775 #endif
16776
16777
16778 /* pcm configuration: identical with ALC880 */
16779 #define alc662_pcm_analog_playback      alc880_pcm_analog_playback
16780 #define alc662_pcm_analog_capture       alc880_pcm_analog_capture
16781 #define alc662_pcm_digital_playback     alc880_pcm_digital_playback
16782 #define alc662_pcm_digital_capture      alc880_pcm_digital_capture
16783
16784 /*
16785  * configuration and preset
16786  */
16787 static const char *alc662_models[ALC662_MODEL_LAST] = {
16788         [ALC662_3ST_2ch_DIG]    = "3stack-dig",
16789         [ALC662_3ST_6ch_DIG]    = "3stack-6ch-dig",
16790         [ALC662_3ST_6ch]        = "3stack-6ch",
16791         [ALC662_5ST_DIG]        = "6stack-dig",
16792         [ALC662_LENOVO_101E]    = "lenovo-101e",
16793         [ALC662_ASUS_EEEPC_P701] = "eeepc-p701",
16794         [ALC662_ASUS_EEEPC_EP20] = "eeepc-ep20",
16795         [ALC662_ECS] = "ecs",
16796         [ALC663_ASUS_M51VA] = "m51va",
16797         [ALC663_ASUS_G71V] = "g71v",
16798         [ALC663_ASUS_H13] = "h13",
16799         [ALC663_ASUS_G50V] = "g50v",
16800         [ALC663_ASUS_MODE1] = "asus-mode1",
16801         [ALC662_ASUS_MODE2] = "asus-mode2",
16802         [ALC663_ASUS_MODE3] = "asus-mode3",
16803         [ALC663_ASUS_MODE4] = "asus-mode4",
16804         [ALC663_ASUS_MODE5] = "asus-mode5",
16805         [ALC663_ASUS_MODE6] = "asus-mode6",
16806         [ALC272_DELL]           = "dell",
16807         [ALC272_DELL_ZM1]       = "dell-zm1",
16808         [ALC272_SAMSUNG_NC10]   = "samsung-nc10",
16809         [ALC662_AUTO]           = "auto",
16810 };
16811
16812 static struct snd_pci_quirk alc662_cfg_tbl[] = {
16813         SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_ECS),
16814         SND_PCI_QUIRK(0x1028, 0x02d6, "DELL", ALC272_DELL),
16815         SND_PCI_QUIRK(0x1028, 0x02f4, "DELL ZM1", ALC272_DELL_ZM1),
16816         SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC663_ASUS_MODE1),
16817         SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC663_ASUS_MODE3),
16818         SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC663_ASUS_MODE3),
16819         SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC663_ASUS_MODE1),
16820         SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_ASUS_MODE2),
16821         SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC663_ASUS_MODE1),
16822         SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_ASUS_MODE2),
16823         SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_ASUS_MODE2),
16824         SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_ASUS_MODE2),
16825         SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC663_ASUS_MODE6),
16826         SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC663_ASUS_MODE6),
16827         SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_ASUS_MODE2),
16828         SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC663_ASUS_MODE3),
16829         SND_PCI_QUIRK(0x1043, 0x17c3, "ASUS UX20", ALC663_ASUS_M51VA),
16830         SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_ASUS_MODE2),
16831         SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_ASUS_MODE2),
16832         SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC663_ASUS_MODE5),
16833         SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC663_ASUS_MODE6),
16834         SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_ASUS_MODE2),
16835         SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC663_ASUS_MODE1),
16836         SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_ASUS_MODE2),
16837         SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_ASUS_MODE2),
16838         SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M51VA", ALC663_ASUS_M51VA),
16839         /*SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M50Vr", ALC663_ASUS_MODE1),*/
16840         SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC663_ASUS_MODE3),
16841         SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC663_ASUS_MODE3),
16842         SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC663_ASUS_MODE1),
16843         SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC663_ASUS_MODE1),
16844         SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC663_ASUS_MODE1),
16845         SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC663_ASUS_MODE1),
16846         SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_ASUS_MODE2),
16847         SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_ASUS_MODE2),
16848         SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC663_ASUS_MODE1),
16849         SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC663_ASUS_MODE1),
16850         SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC663_ASUS_MODE3),
16851         SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC663_ASUS_MODE1),
16852         SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC663_ASUS_MODE1),
16853         SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS G50V", ALC663_ASUS_G50V),
16854         /*SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS NB", ALC663_ASUS_MODE1),*/
16855         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC663_ASUS_MODE1),
16856         SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_ASUS_MODE2),
16857         SND_PCI_QUIRK(0x1043, 0x19d3, "ASUS NB", ALC663_ASUS_M51VA),
16858         SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC663_ASUS_MODE1),
16859         SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC663_ASUS_MODE4),
16860         SND_PCI_QUIRK(0x1043, 0x8290, "ASUS P5GC-MX", ALC662_3ST_6ch_DIG),
16861         SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
16862         SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20),
16863         SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_ECS),
16864         SND_PCI_QUIRK(0x105b, 0x0d47, "Foxconn 45CMX/45GMX/45CMX-K",
16865                       ALC662_3ST_6ch_DIG),
16866         SND_PCI_QUIRK(0x144d, 0xca00, "Samsung NC10", ALC272_SAMSUNG_NC10),
16867         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte 945GCM-S2L",
16868                       ALC662_3ST_6ch_DIG),
16869         SND_PCI_QUIRK(0x1565, 0x820f, "Biostar TA780G M2+", ALC662_3ST_6ch_DIG),
16870         SND_PCI_QUIRK(0x1631, 0xc10c, "PB RS65", ALC663_ASUS_M51VA),
16871         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
16872         SND_PCI_QUIRK(0x1849, 0x3662, "ASROCK K10N78FullHD-hSLI R3.0",
16873                                         ALC662_3ST_6ch_DIG),
16874         SND_PCI_QUIRK_MASK(0x1854, 0xf000, 0x2000, "ASUS H13-200x",
16875                            ALC663_ASUS_H13),
16876         {}
16877 };
16878
16879 static struct alc_config_preset alc662_presets[] = {
16880         [ALC662_3ST_2ch_DIG] = {
16881                 .mixers = { alc662_3ST_2ch_mixer },
16882                 .init_verbs = { alc662_init_verbs },
16883                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16884                 .dac_nids = alc662_dac_nids,
16885                 .dig_out_nid = ALC662_DIGOUT_NID,
16886                 .dig_in_nid = ALC662_DIGIN_NID,
16887                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16888                 .channel_mode = alc662_3ST_2ch_modes,
16889                 .input_mux = &alc662_capture_source,
16890         },
16891         [ALC662_3ST_6ch_DIG] = {
16892                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
16893                 .init_verbs = { alc662_init_verbs },
16894                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16895                 .dac_nids = alc662_dac_nids,
16896                 .dig_out_nid = ALC662_DIGOUT_NID,
16897                 .dig_in_nid = ALC662_DIGIN_NID,
16898                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16899                 .channel_mode = alc662_3ST_6ch_modes,
16900                 .need_dac_fix = 1,
16901                 .input_mux = &alc662_capture_source,
16902         },
16903         [ALC662_3ST_6ch] = {
16904                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
16905                 .init_verbs = { alc662_init_verbs },
16906                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16907                 .dac_nids = alc662_dac_nids,
16908                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16909                 .channel_mode = alc662_3ST_6ch_modes,
16910                 .need_dac_fix = 1,
16911                 .input_mux = &alc662_capture_source,
16912         },
16913         [ALC662_5ST_DIG] = {
16914                 .mixers = { alc662_base_mixer, alc662_chmode_mixer },
16915                 .init_verbs = { alc662_init_verbs },
16916                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16917                 .dac_nids = alc662_dac_nids,
16918                 .dig_out_nid = ALC662_DIGOUT_NID,
16919                 .dig_in_nid = ALC662_DIGIN_NID,
16920                 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
16921                 .channel_mode = alc662_5stack_modes,
16922                 .input_mux = &alc662_capture_source,
16923         },
16924         [ALC662_LENOVO_101E] = {
16925                 .mixers = { alc662_lenovo_101e_mixer },
16926                 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs },
16927                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16928                 .dac_nids = alc662_dac_nids,
16929                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16930                 .channel_mode = alc662_3ST_2ch_modes,
16931                 .input_mux = &alc662_lenovo_101e_capture_source,
16932                 .unsol_event = alc662_lenovo_101e_unsol_event,
16933                 .init_hook = alc662_lenovo_101e_all_automute,
16934         },
16935         [ALC662_ASUS_EEEPC_P701] = {
16936                 .mixers = { alc662_eeepc_p701_mixer },
16937                 .init_verbs = { alc662_init_verbs,
16938                                 alc662_eeepc_sue_init_verbs },
16939                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16940                 .dac_nids = alc662_dac_nids,
16941                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16942                 .channel_mode = alc662_3ST_2ch_modes,
16943                 .input_mux = &alc662_eeepc_capture_source,
16944                 .unsol_event = alc662_eeepc_unsol_event,
16945                 .init_hook = alc662_eeepc_inithook,
16946         },
16947         [ALC662_ASUS_EEEPC_EP20] = {
16948                 .mixers = { alc662_eeepc_ep20_mixer,
16949                             alc662_chmode_mixer },
16950                 .init_verbs = { alc662_init_verbs,
16951                                 alc662_eeepc_ep20_sue_init_verbs },
16952                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16953                 .dac_nids = alc662_dac_nids,
16954                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16955                 .channel_mode = alc662_3ST_6ch_modes,
16956                 .input_mux = &alc662_lenovo_101e_capture_source,
16957                 .unsol_event = alc662_eeepc_unsol_event,
16958                 .init_hook = alc662_eeepc_ep20_inithook,
16959         },
16960         [ALC662_ECS] = {
16961                 .mixers = { alc662_ecs_mixer },
16962                 .init_verbs = { alc662_init_verbs,
16963                                 alc662_ecs_init_verbs },
16964                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16965                 .dac_nids = alc662_dac_nids,
16966                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16967                 .channel_mode = alc662_3ST_2ch_modes,
16968                 .input_mux = &alc662_eeepc_capture_source,
16969                 .unsol_event = alc662_eeepc_unsol_event,
16970                 .init_hook = alc662_eeepc_inithook,
16971         },
16972         [ALC663_ASUS_M51VA] = {
16973                 .mixers = { alc663_m51va_mixer },
16974                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
16975                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16976                 .dac_nids = alc662_dac_nids,
16977                 .dig_out_nid = ALC662_DIGOUT_NID,
16978                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16979                 .channel_mode = alc662_3ST_2ch_modes,
16980                 .input_mux = &alc663_m51va_capture_source,
16981                 .unsol_event = alc663_m51va_unsol_event,
16982                 .init_hook = alc663_m51va_inithook,
16983         },
16984         [ALC663_ASUS_G71V] = {
16985                 .mixers = { alc663_g71v_mixer },
16986                 .init_verbs = { alc662_init_verbs, alc663_g71v_init_verbs },
16987                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16988                 .dac_nids = alc662_dac_nids,
16989                 .dig_out_nid = ALC662_DIGOUT_NID,
16990                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16991                 .channel_mode = alc662_3ST_2ch_modes,
16992                 .input_mux = &alc662_eeepc_capture_source,
16993                 .unsol_event = alc663_g71v_unsol_event,
16994                 .init_hook = alc663_g71v_inithook,
16995         },
16996         [ALC663_ASUS_H13] = {
16997                 .mixers = { alc663_m51va_mixer },
16998                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
16999                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17000                 .dac_nids = alc662_dac_nids,
17001                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17002                 .channel_mode = alc662_3ST_2ch_modes,
17003                 .input_mux = &alc663_m51va_capture_source,
17004                 .unsol_event = alc663_m51va_unsol_event,
17005                 .init_hook = alc663_m51va_inithook,
17006         },
17007         [ALC663_ASUS_G50V] = {
17008                 .mixers = { alc663_g50v_mixer },
17009                 .init_verbs = { alc662_init_verbs, alc663_g50v_init_verbs },
17010                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17011                 .dac_nids = alc662_dac_nids,
17012                 .dig_out_nid = ALC662_DIGOUT_NID,
17013                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
17014                 .channel_mode = alc662_3ST_6ch_modes,
17015                 .input_mux = &alc663_capture_source,
17016                 .unsol_event = alc663_g50v_unsol_event,
17017                 .init_hook = alc663_g50v_inithook,
17018         },
17019         [ALC663_ASUS_MODE1] = {
17020                 .mixers = { alc663_m51va_mixer },
17021                 .cap_mixer = alc662_auto_capture_mixer,
17022                 .init_verbs = { alc662_init_verbs,
17023                                 alc663_21jd_amic_init_verbs },
17024                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17025                 .hp_nid = 0x03,
17026                 .dac_nids = alc662_dac_nids,
17027                 .dig_out_nid = ALC662_DIGOUT_NID,
17028                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17029                 .channel_mode = alc662_3ST_2ch_modes,
17030                 .input_mux = &alc662_eeepc_capture_source,
17031                 .unsol_event = alc663_mode1_unsol_event,
17032                 .init_hook = alc663_mode1_inithook,
17033         },
17034         [ALC662_ASUS_MODE2] = {
17035                 .mixers = { alc662_1bjd_mixer },
17036                 .cap_mixer = alc662_auto_capture_mixer,
17037                 .init_verbs = { alc662_init_verbs,
17038                                 alc662_1bjd_amic_init_verbs },
17039                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17040                 .dac_nids = alc662_dac_nids,
17041                 .dig_out_nid = ALC662_DIGOUT_NID,
17042                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17043                 .channel_mode = alc662_3ST_2ch_modes,
17044                 .input_mux = &alc662_eeepc_capture_source,
17045                 .unsol_event = alc662_mode2_unsol_event,
17046                 .init_hook = alc662_mode2_inithook,
17047         },
17048         [ALC663_ASUS_MODE3] = {
17049                 .mixers = { alc663_two_hp_m1_mixer },
17050                 .cap_mixer = alc662_auto_capture_mixer,
17051                 .init_verbs = { alc662_init_verbs,
17052                                 alc663_two_hp_amic_m1_init_verbs },
17053                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17054                 .hp_nid = 0x03,
17055                 .dac_nids = alc662_dac_nids,
17056                 .dig_out_nid = ALC662_DIGOUT_NID,
17057                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17058                 .channel_mode = alc662_3ST_2ch_modes,
17059                 .input_mux = &alc662_eeepc_capture_source,
17060                 .unsol_event = alc663_mode3_unsol_event,
17061                 .init_hook = alc663_mode3_inithook,
17062         },
17063         [ALC663_ASUS_MODE4] = {
17064                 .mixers = { alc663_asus_21jd_clfe_mixer },
17065                 .cap_mixer = alc662_auto_capture_mixer,
17066                 .init_verbs = { alc662_init_verbs,
17067                                 alc663_21jd_amic_init_verbs},
17068                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17069                 .hp_nid = 0x03,
17070                 .dac_nids = alc662_dac_nids,
17071                 .dig_out_nid = ALC662_DIGOUT_NID,
17072                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17073                 .channel_mode = alc662_3ST_2ch_modes,
17074                 .input_mux = &alc662_eeepc_capture_source,
17075                 .unsol_event = alc663_mode4_unsol_event,
17076                 .init_hook = alc663_mode4_inithook,
17077         },
17078         [ALC663_ASUS_MODE5] = {
17079                 .mixers = { alc663_asus_15jd_clfe_mixer },
17080                 .cap_mixer = alc662_auto_capture_mixer,
17081                 .init_verbs = { alc662_init_verbs,
17082                                 alc663_15jd_amic_init_verbs },
17083                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17084                 .hp_nid = 0x03,
17085                 .dac_nids = alc662_dac_nids,
17086                 .dig_out_nid = ALC662_DIGOUT_NID,
17087                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17088                 .channel_mode = alc662_3ST_2ch_modes,
17089                 .input_mux = &alc662_eeepc_capture_source,
17090                 .unsol_event = alc663_mode5_unsol_event,
17091                 .init_hook = alc663_mode5_inithook,
17092         },
17093         [ALC663_ASUS_MODE6] = {
17094                 .mixers = { alc663_two_hp_m2_mixer },
17095                 .cap_mixer = alc662_auto_capture_mixer,
17096                 .init_verbs = { alc662_init_verbs,
17097                                 alc663_two_hp_amic_m2_init_verbs },
17098                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
17099                 .hp_nid = 0x03,
17100                 .dac_nids = alc662_dac_nids,
17101                 .dig_out_nid = ALC662_DIGOUT_NID,
17102                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17103                 .channel_mode = alc662_3ST_2ch_modes,
17104                 .input_mux = &alc662_eeepc_capture_source,
17105                 .unsol_event = alc663_mode6_unsol_event,
17106                 .init_hook = alc663_mode6_inithook,
17107         },
17108         [ALC272_DELL] = {
17109                 .mixers = { alc663_m51va_mixer },
17110                 .cap_mixer = alc272_auto_capture_mixer,
17111                 .init_verbs = { alc662_init_verbs, alc272_dell_init_verbs },
17112                 .num_dacs = ARRAY_SIZE(alc272_dac_nids),
17113                 .dac_nids = alc662_dac_nids,
17114                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17115                 .adc_nids = alc272_adc_nids,
17116                 .num_adc_nids = ARRAY_SIZE(alc272_adc_nids),
17117                 .capsrc_nids = alc272_capsrc_nids,
17118                 .channel_mode = alc662_3ST_2ch_modes,
17119                 .input_mux = &alc663_m51va_capture_source,
17120                 .unsol_event = alc663_m51va_unsol_event,
17121                 .init_hook = alc663_m51va_inithook,
17122         },
17123         [ALC272_DELL_ZM1] = {
17124                 .mixers = { alc663_m51va_mixer },
17125                 .cap_mixer = alc662_auto_capture_mixer,
17126                 .init_verbs = { alc662_init_verbs, alc272_dell_zm1_init_verbs },
17127                 .num_dacs = ARRAY_SIZE(alc272_dac_nids),
17128                 .dac_nids = alc662_dac_nids,
17129                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17130                 .adc_nids = alc662_adc_nids,
17131                 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
17132                 .capsrc_nids = alc662_capsrc_nids,
17133                 .channel_mode = alc662_3ST_2ch_modes,
17134                 .input_mux = &alc663_m51va_capture_source,
17135                 .unsol_event = alc663_m51va_unsol_event,
17136                 .init_hook = alc663_m51va_inithook,
17137         },
17138         [ALC272_SAMSUNG_NC10] = {
17139                 .mixers = { alc272_nc10_mixer },
17140                 .init_verbs = { alc662_init_verbs,
17141                                 alc663_21jd_amic_init_verbs },
17142                 .num_dacs = ARRAY_SIZE(alc272_dac_nids),
17143                 .dac_nids = alc272_dac_nids,
17144                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
17145                 .channel_mode = alc662_3ST_2ch_modes,
17146                 .input_mux = &alc272_nc10_capture_source,
17147                 .unsol_event = alc663_mode4_unsol_event,
17148                 .init_hook = alc663_mode4_inithook,
17149         },
17150 };
17151
17152
17153 /*
17154  * BIOS auto configuration
17155  */
17156
17157 /* add playback controls from the parsed DAC table */
17158 static int alc662_auto_create_multi_out_ctls(struct alc_spec *spec,
17159                                              const struct auto_pin_cfg *cfg)
17160 {
17161         char name[32];
17162         static const char *chname[4] = {
17163                 "Front", "Surround", NULL /*CLFE*/, "Side"
17164         };
17165         hda_nid_t nid;
17166         int i, err;
17167
17168         for (i = 0; i < cfg->line_outs; i++) {
17169                 if (!spec->multiout.dac_nids[i])
17170                         continue;
17171                 nid = alc880_idx_to_dac(i);
17172                 if (i == 2) {
17173                         /* Center/LFE */
17174                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
17175                                           "Center Playback Volume",
17176                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
17177                                                               HDA_OUTPUT));
17178                         if (err < 0)
17179                                 return err;
17180                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
17181                                           "LFE Playback Volume",
17182                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
17183                                                               HDA_OUTPUT));
17184                         if (err < 0)
17185                                 return err;
17186                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
17187                                           "Center Playback Switch",
17188                                           HDA_COMPOSE_AMP_VAL(0x0e, 1, 0,
17189                                                               HDA_INPUT));
17190                         if (err < 0)
17191                                 return err;
17192                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
17193                                           "LFE Playback Switch",
17194                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
17195                                                               HDA_INPUT));
17196                         if (err < 0)
17197                                 return err;
17198                 } else {
17199                         sprintf(name, "%s Playback Volume", chname[i]);
17200                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
17201                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
17202                                                               HDA_OUTPUT));
17203                         if (err < 0)
17204                                 return err;
17205                         sprintf(name, "%s Playback Switch", chname[i]);
17206                         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
17207                                 HDA_COMPOSE_AMP_VAL(alc880_idx_to_mixer(i),
17208                                                     3, 0, HDA_INPUT));
17209                         if (err < 0)
17210                                 return err;
17211                 }
17212         }
17213         return 0;
17214 }
17215
17216 /* add playback controls for speaker and HP outputs */
17217 static int alc662_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
17218                                         const char *pfx)
17219 {
17220         hda_nid_t nid;
17221         int err;
17222         char name[32];
17223
17224         if (!pin)
17225                 return 0;
17226
17227         if (pin == 0x17) {
17228                 /* ALC663 has a mono output pin on 0x17 */
17229                 sprintf(name, "%s Playback Switch", pfx);
17230                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
17231                                   HDA_COMPOSE_AMP_VAL(pin, 2, 0, HDA_OUTPUT));
17232                 return err;
17233         }
17234
17235         if (alc880_is_fixed_pin(pin)) {
17236                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
17237                 /* printk(KERN_DEBUG "DAC nid=%x\n",nid); */
17238                 /* specify the DAC as the extra output */
17239                 if (!spec->multiout.hp_nid)
17240                         spec->multiout.hp_nid = nid;
17241                 else
17242                         spec->multiout.extra_out_nid[0] = nid;
17243                 /* control HP volume/switch on the output mixer amp */
17244                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
17245                 sprintf(name, "%s Playback Volume", pfx);
17246                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
17247                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
17248                 if (err < 0)
17249                         return err;
17250                 sprintf(name, "%s Playback Switch", pfx);
17251                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
17252                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
17253                 if (err < 0)
17254                         return err;
17255         } else if (alc880_is_multi_pin(pin)) {
17256                 /* set manual connection */
17257                 /* we have only a switch on HP-out PIN */
17258                 sprintf(name, "%s Playback Switch", pfx);
17259                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
17260                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
17261                 if (err < 0)
17262                         return err;
17263         }
17264         return 0;
17265 }
17266
17267 /* return the index of the src widget from the connection list of the nid.
17268  * return -1 if not found
17269  */
17270 static int alc662_input_pin_idx(struct hda_codec *codec, hda_nid_t nid,
17271                                 hda_nid_t src)
17272 {
17273         hda_nid_t conn_list[HDA_MAX_CONNECTIONS];
17274         int i, conns;
17275
17276         conns = snd_hda_get_connections(codec, nid, conn_list,
17277                                         ARRAY_SIZE(conn_list));
17278         if (conns < 0)
17279                 return -1;
17280         for (i = 0; i < conns; i++)
17281                 if (conn_list[i] == src)
17282                         return i;
17283         return -1;
17284 }
17285
17286 static int alc662_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
17287 {
17288         unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
17289         return (pincap & AC_PINCAP_IN) != 0;
17290 }
17291
17292 /* create playback/capture controls for input pins */
17293 static int alc662_auto_create_analog_input_ctls(struct hda_codec *codec,
17294                                                 const struct auto_pin_cfg *cfg)
17295 {
17296         struct alc_spec *spec = codec->spec;
17297         struct hda_input_mux *imux = &spec->private_imux[0];
17298         int i, err, idx;
17299
17300         for (i = 0; i < AUTO_PIN_LAST; i++) {
17301                 if (alc662_is_input_pin(codec, cfg->input_pins[i])) {
17302                         idx = alc662_input_pin_idx(codec, 0x0b,
17303                                                    cfg->input_pins[i]);
17304                         if (idx >= 0) {
17305                                 err = new_analog_input(spec, cfg->input_pins[i],
17306                                                        auto_pin_cfg_labels[i],
17307                                                        idx, 0x0b);
17308                                 if (err < 0)
17309                                         return err;
17310                         }
17311                         idx = alc662_input_pin_idx(codec, 0x22,
17312                                                    cfg->input_pins[i]);
17313                         if (idx >= 0) {
17314                                 imux->items[imux->num_items].label =
17315                                         auto_pin_cfg_labels[i];
17316                                 imux->items[imux->num_items].index = idx;
17317                                 imux->num_items++;
17318                         }
17319                 }
17320         }
17321         return 0;
17322 }
17323
17324 static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
17325                                               hda_nid_t nid, int pin_type,
17326                                               int dac_idx)
17327 {
17328         alc_set_pin_output(codec, nid, pin_type);
17329         /* need the manual connection? */
17330         if (alc880_is_multi_pin(nid)) {
17331                 struct alc_spec *spec = codec->spec;
17332                 int idx = alc880_multi_pin_idx(nid);
17333                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
17334                                     AC_VERB_SET_CONNECT_SEL,
17335                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
17336         }
17337 }
17338
17339 static void alc662_auto_init_multi_out(struct hda_codec *codec)
17340 {
17341         struct alc_spec *spec = codec->spec;
17342         int i;
17343
17344         for (i = 0; i <= HDA_SIDE; i++) {
17345                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
17346                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
17347                 if (nid)
17348                         alc662_auto_set_output_and_unmute(codec, nid, pin_type,
17349                                                           i);
17350         }
17351 }
17352
17353 static void alc662_auto_init_hp_out(struct hda_codec *codec)
17354 {
17355         struct alc_spec *spec = codec->spec;
17356         hda_nid_t pin;
17357
17358         pin = spec->autocfg.hp_pins[0];
17359         if (pin) /* connect to front */
17360                 /* use dac 0 */
17361                 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
17362         pin = spec->autocfg.speaker_pins[0];
17363         if (pin)
17364                 alc662_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
17365 }
17366
17367 #define ALC662_PIN_CD_NID               ALC880_PIN_CD_NID
17368
17369 static void alc662_auto_init_analog_input(struct hda_codec *codec)
17370 {
17371         struct alc_spec *spec = codec->spec;
17372         int i;
17373
17374         for (i = 0; i < AUTO_PIN_LAST; i++) {
17375                 hda_nid_t nid = spec->autocfg.input_pins[i];
17376                 if (alc662_is_input_pin(codec, nid)) {
17377                         alc_set_input_pin(codec, nid, i);
17378                         if (nid != ALC662_PIN_CD_NID &&
17379                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
17380                                 snd_hda_codec_write(codec, nid, 0,
17381                                                     AC_VERB_SET_AMP_GAIN_MUTE,
17382                                                     AMP_OUT_MUTE);
17383                 }
17384         }
17385 }
17386
17387 #define alc662_auto_init_input_src      alc882_auto_init_input_src
17388
17389 static int alc662_parse_auto_config(struct hda_codec *codec)
17390 {
17391         struct alc_spec *spec = codec->spec;
17392         int err;
17393         static hda_nid_t alc662_ignore[] = { 0x1d, 0 };
17394
17395         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
17396                                            alc662_ignore);
17397         if (err < 0)
17398                 return err;
17399         if (!spec->autocfg.line_outs)
17400                 return 0; /* can't find valid BIOS pin config */
17401
17402         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
17403         if (err < 0)
17404                 return err;
17405         err = alc662_auto_create_multi_out_ctls(spec, &spec->autocfg);
17406         if (err < 0)
17407                 return err;
17408         err = alc662_auto_create_extra_out(spec,
17409                                            spec->autocfg.speaker_pins[0],
17410                                            "Speaker");
17411         if (err < 0)
17412                 return err;
17413         err = alc662_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
17414                                            "Headphone");
17415         if (err < 0)
17416                 return err;
17417         err = alc662_auto_create_analog_input_ctls(codec, &spec->autocfg);
17418         if (err < 0)
17419                 return err;
17420
17421         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
17422
17423         if (spec->autocfg.dig_outs)
17424                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
17425
17426         if (spec->kctls.list)
17427                 add_mixer(spec, spec->kctls.list);
17428
17429         spec->num_mux_defs = 1;
17430         spec->input_mux = &spec->private_imux[0];
17431
17432         add_verb(spec, alc662_auto_init_verbs);
17433         if (codec->vendor_id == 0x10ec0663)
17434                 add_verb(spec, alc663_auto_init_verbs);
17435
17436         err = alc_auto_add_mic_boost(codec);
17437         if (err < 0)
17438                 return err;
17439
17440         alc_ssid_check(codec, 0x15, 0x1b, 0x14);
17441
17442         return 1;
17443 }
17444
17445 /* additional initialization for auto-configuration model */
17446 static void alc662_auto_init(struct hda_codec *codec)
17447 {
17448         struct alc_spec *spec = codec->spec;
17449         alc662_auto_init_multi_out(codec);
17450         alc662_auto_init_hp_out(codec);
17451         alc662_auto_init_analog_input(codec);
17452         alc662_auto_init_input_src(codec);
17453         if (spec->unsol_event)
17454                 alc_inithook(codec);
17455 }
17456
17457 static int patch_alc662(struct hda_codec *codec)
17458 {
17459         struct alc_spec *spec;
17460         int err, board_config;
17461
17462         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
17463         if (!spec)
17464                 return -ENOMEM;
17465
17466         codec->spec = spec;
17467
17468         alc_fix_pll_init(codec, 0x20, 0x04, 15);
17469
17470         board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
17471                                                   alc662_models,
17472                                                   alc662_cfg_tbl);
17473         if (board_config < 0) {
17474                 printk(KERN_INFO "hda_codec: Unknown model for %s, "
17475                        "trying auto-probe from BIOS...\n", codec->chip_name);
17476                 board_config = ALC662_AUTO;
17477         }
17478
17479         if (board_config == ALC662_AUTO) {
17480                 /* automatic parse from the BIOS config */
17481                 err = alc662_parse_auto_config(codec);
17482                 if (err < 0) {
17483                         alc_free(codec);
17484                         return err;
17485                 } else if (!err) {
17486                         printk(KERN_INFO
17487                                "hda_codec: Cannot set up configuration "
17488                                "from BIOS.  Using base mode...\n");
17489                         board_config = ALC662_3ST_2ch_DIG;
17490                 }
17491         }
17492
17493         err = snd_hda_attach_beep_device(codec, 0x1);
17494         if (err < 0) {
17495                 alc_free(codec);
17496                 return err;
17497         }
17498
17499         if (board_config != ALC662_AUTO)
17500                 setup_preset(spec, &alc662_presets[board_config]);
17501
17502         spec->stream_analog_playback = &alc662_pcm_analog_playback;
17503         spec->stream_analog_capture = &alc662_pcm_analog_capture;
17504
17505         spec->stream_digital_playback = &alc662_pcm_digital_playback;
17506         spec->stream_digital_capture = &alc662_pcm_digital_capture;
17507
17508         spec->adc_nids = alc662_adc_nids;
17509         spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
17510         spec->capsrc_nids = alc662_capsrc_nids;
17511
17512         if (!spec->cap_mixer)
17513                 set_capture_mixer(spec);
17514         if (codec->vendor_id == 0x10ec0662)
17515                 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
17516         else
17517                 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
17518
17519         spec->vmaster_nid = 0x02;
17520
17521         codec->patch_ops = alc_patch_ops;
17522         if (board_config == ALC662_AUTO)
17523                 spec->init_hook = alc662_auto_init;
17524 #ifdef CONFIG_SND_HDA_POWER_SAVE
17525         if (!spec->loopback.amplist)
17526                 spec->loopback.amplist = alc662_loopbacks;
17527 #endif
17528         codec->proc_widget_hook = print_realtek_coef;
17529
17530         return 0;
17531 }
17532
17533 /*
17534  * patch entries
17535  */
17536 static struct hda_codec_preset snd_hda_preset_realtek[] = {
17537         { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
17538         { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
17539         { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
17540         { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
17541         { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
17542         { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
17543         { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
17544           .patch = patch_alc861 },
17545         { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
17546         { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
17547         { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
17548         { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
17549           .patch = patch_alc883 },
17550         { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
17551           .patch = patch_alc662 },
17552         { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
17553         { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
17554         { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
17555         { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 },
17556         { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
17557           .patch = patch_alc882 }, /* should be patch_alc883() in future */
17558         { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
17559           .patch = patch_alc882 }, /* should be patch_alc883() in future */
17560         { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
17561         { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc883 },
17562         { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
17563           .patch = patch_alc883 },
17564         { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc883 },
17565         { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc883 },
17566         {} /* terminator */
17567 };
17568
17569 MODULE_ALIAS("snd-hda-codec-id:10ec*");
17570
17571 MODULE_LICENSE("GPL");
17572 MODULE_DESCRIPTION("Realtek HD-audio codec");
17573
17574 static struct hda_codec_preset_list realtek_list = {
17575         .preset = snd_hda_preset_realtek,
17576         .owner = THIS_MODULE,
17577 };
17578
17579 static int __init patch_realtek_init(void)
17580 {
17581         return snd_hda_add_codec_preset(&realtek_list);
17582 }
17583
17584 static void __exit patch_realtek_exit(void)
17585 {
17586         snd_hda_delete_codec_preset(&realtek_list);
17587 }
17588
17589 module_init(patch_realtek_init)
17590 module_exit(patch_realtek_exit)