Merge branch 'for-linus' of git://git.kernel.dk/linux-2.6-block
[linux-2.6] / sound / pci / hda / patch_realtek.c
1 /*
2  * Universal Interface for Intel High Definition Audio Codec
3  *
4  * HD audio interface patch for ALC 260/880/882 codecs
5  *
6  * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7  *                    PeiSen Hou <pshou@realtek.com.tw>
8  *                    Takashi Iwai <tiwai@suse.de>
9  *                    Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
10  *
11  *  This driver is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This driver is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
24  */
25
26 #include <linux/init.h>
27 #include <linux/delay.h>
28 #include <linux/slab.h>
29 #include <linux/pci.h>
30 #include <sound/core.h>
31 #include "hda_codec.h"
32 #include "hda_local.h"
33 #include "hda_beep.h"
34
35 #define ALC880_FRONT_EVENT              0x01
36 #define ALC880_DCVOL_EVENT              0x02
37 #define ALC880_HP_EVENT                 0x04
38 #define ALC880_MIC_EVENT                0x08
39
40 /* ALC880 board config type */
41 enum {
42         ALC880_3ST,
43         ALC880_3ST_DIG,
44         ALC880_5ST,
45         ALC880_5ST_DIG,
46         ALC880_W810,
47         ALC880_Z71V,
48         ALC880_6ST,
49         ALC880_6ST_DIG,
50         ALC880_F1734,
51         ALC880_ASUS,
52         ALC880_ASUS_DIG,
53         ALC880_ASUS_W1V,
54         ALC880_ASUS_DIG2,
55         ALC880_FUJITSU,
56         ALC880_UNIWILL_DIG,
57         ALC880_UNIWILL,
58         ALC880_UNIWILL_P53,
59         ALC880_CLEVO,
60         ALC880_TCL_S700,
61         ALC880_LG,
62         ALC880_LG_LW,
63         ALC880_MEDION_RIM,
64 #ifdef CONFIG_SND_DEBUG
65         ALC880_TEST,
66 #endif
67         ALC880_AUTO,
68         ALC880_MODEL_LAST /* last tag */
69 };
70
71 /* ALC260 models */
72 enum {
73         ALC260_BASIC,
74         ALC260_HP,
75         ALC260_HP_DC7600,
76         ALC260_HP_3013,
77         ALC260_FUJITSU_S702X,
78         ALC260_ACER,
79         ALC260_WILL,
80         ALC260_REPLACER_672V,
81         ALC260_FAVORIT100,
82 #ifdef CONFIG_SND_DEBUG
83         ALC260_TEST,
84 #endif
85         ALC260_AUTO,
86         ALC260_MODEL_LAST /* last tag */
87 };
88
89 /* ALC262 models */
90 enum {
91         ALC262_BASIC,
92         ALC262_HIPPO,
93         ALC262_HIPPO_1,
94         ALC262_FUJITSU,
95         ALC262_HP_BPC,
96         ALC262_HP_BPC_D7000_WL,
97         ALC262_HP_BPC_D7000_WF,
98         ALC262_HP_TC_T5735,
99         ALC262_HP_RP5700,
100         ALC262_BENQ_ED8,
101         ALC262_SONY_ASSAMD,
102         ALC262_BENQ_T31,
103         ALC262_ULTRA,
104         ALC262_LENOVO_3000,
105         ALC262_NEC,
106         ALC262_TOSHIBA_S06,
107         ALC262_TOSHIBA_RX1,
108         ALC262_TYAN,
109         ALC262_AUTO,
110         ALC262_MODEL_LAST /* last tag */
111 };
112
113 /* ALC268 models */
114 enum {
115         ALC267_QUANTA_IL1,
116         ALC268_3ST,
117         ALC268_TOSHIBA,
118         ALC268_ACER,
119         ALC268_ACER_DMIC,
120         ALC268_ACER_ASPIRE_ONE,
121         ALC268_DELL,
122         ALC268_ZEPTO,
123 #ifdef CONFIG_SND_DEBUG
124         ALC268_TEST,
125 #endif
126         ALC268_AUTO,
127         ALC268_MODEL_LAST /* last tag */
128 };
129
130 /* ALC269 models */
131 enum {
132         ALC269_BASIC,
133         ALC269_QUANTA_FL1,
134         ALC269_ASUS_EEEPC_P703,
135         ALC269_ASUS_EEEPC_P901,
136         ALC269_FUJITSU,
137         ALC269_LIFEBOOK,
138         ALC269_AUTO,
139         ALC269_MODEL_LAST /* last tag */
140 };
141
142 /* ALC861 models */
143 enum {
144         ALC861_3ST,
145         ALC660_3ST,
146         ALC861_3ST_DIG,
147         ALC861_6ST_DIG,
148         ALC861_UNIWILL_M31,
149         ALC861_TOSHIBA,
150         ALC861_ASUS,
151         ALC861_ASUS_LAPTOP,
152         ALC861_AUTO,
153         ALC861_MODEL_LAST,
154 };
155
156 /* ALC861-VD models */
157 enum {
158         ALC660VD_3ST,
159         ALC660VD_3ST_DIG,
160         ALC660VD_ASUS_V1S,
161         ALC861VD_3ST,
162         ALC861VD_3ST_DIG,
163         ALC861VD_6ST_DIG,
164         ALC861VD_LENOVO,
165         ALC861VD_DALLAS,
166         ALC861VD_HP,
167         ALC861VD_AUTO,
168         ALC861VD_MODEL_LAST,
169 };
170
171 /* ALC662 models */
172 enum {
173         ALC662_3ST_2ch_DIG,
174         ALC662_3ST_6ch_DIG,
175         ALC662_3ST_6ch,
176         ALC662_5ST_DIG,
177         ALC662_LENOVO_101E,
178         ALC662_ASUS_EEEPC_P701,
179         ALC662_ASUS_EEEPC_EP20,
180         ALC663_ASUS_M51VA,
181         ALC663_ASUS_G71V,
182         ALC663_ASUS_H13,
183         ALC663_ASUS_G50V,
184         ALC662_ECS,
185         ALC663_ASUS_MODE1,
186         ALC662_ASUS_MODE2,
187         ALC663_ASUS_MODE3,
188         ALC663_ASUS_MODE4,
189         ALC663_ASUS_MODE5,
190         ALC663_ASUS_MODE6,
191         ALC662_AUTO,
192         ALC662_MODEL_LAST,
193 };
194
195 /* ALC882 models */
196 enum {
197         ALC882_3ST_DIG,
198         ALC882_6ST_DIG,
199         ALC882_ARIMA,
200         ALC882_W2JC,
201         ALC882_TARGA,
202         ALC882_ASUS_A7J,
203         ALC882_ASUS_A7M,
204         ALC885_MACPRO,
205         ALC885_MBP3,
206         ALC885_IMAC24,
207         ALC882_AUTO,
208         ALC882_MODEL_LAST,
209 };
210
211 /* ALC883 models */
212 enum {
213         ALC883_3ST_2ch_DIG,
214         ALC883_3ST_6ch_DIG,
215         ALC883_3ST_6ch,
216         ALC883_6ST_DIG,
217         ALC883_TARGA_DIG,
218         ALC883_TARGA_2ch_DIG,
219         ALC883_ACER,
220         ALC883_ACER_ASPIRE,
221         ALC888_ACER_ASPIRE_4930G,
222         ALC883_MEDION,
223         ALC883_MEDION_MD2,
224         ALC883_LAPTOP_EAPD,
225         ALC883_LENOVO_101E_2ch,
226         ALC883_LENOVO_NB0763,
227         ALC888_LENOVO_MS7195_DIG,
228         ALC888_LENOVO_SKY,
229         ALC883_HAIER_W66,
230         ALC888_3ST_HP,
231         ALC888_6ST_DELL,
232         ALC883_MITAC,
233         ALC883_CLEVO_M720,
234         ALC883_FUJITSU_PI2515,
235         ALC888_FUJITSU_XA3530,
236         ALC883_3ST_6ch_INTEL,
237         ALC888_ASUS_M90V,
238         ALC888_ASUS_EEE1601,
239         ALC1200_ASUS_P5Q,
240         ALC883_AUTO,
241         ALC883_MODEL_LAST,
242 };
243
244 /* styles of capture selection */
245 enum {
246         CAPT_MUX = 0,   /* only mux based */
247         CAPT_MIX,       /* only mixer based */
248         CAPT_1MUX_MIX,  /* first mux and other mixers */
249 };
250
251 /* for GPIO Poll */
252 #define GPIO_MASK       0x03
253
254 struct alc_spec {
255         /* codec parameterization */
256         struct snd_kcontrol_new *mixers[5];     /* mixer arrays */
257         unsigned int num_mixers;
258         struct snd_kcontrol_new *cap_mixer;     /* capture mixer */
259         unsigned int beep_amp;  /* beep amp value, set via set_beep_amp() */
260
261         const struct hda_verb *init_verbs[5];   /* initialization verbs
262                                                  * don't forget NULL
263                                                  * termination!
264                                                  */
265         unsigned int num_init_verbs;
266
267         char *stream_name_analog;       /* analog PCM stream */
268         struct hda_pcm_stream *stream_analog_playback;
269         struct hda_pcm_stream *stream_analog_capture;
270         struct hda_pcm_stream *stream_analog_alt_playback;
271         struct hda_pcm_stream *stream_analog_alt_capture;
272
273         char *stream_name_digital;      /* digital PCM stream */
274         struct hda_pcm_stream *stream_digital_playback;
275         struct hda_pcm_stream *stream_digital_capture;
276
277         /* playback */
278         struct hda_multi_out multiout;  /* playback set-up
279                                          * max_channels, dacs must be set
280                                          * dig_out_nid and hp_nid are optional
281                                          */
282         hda_nid_t alt_dac_nid;
283         hda_nid_t slave_dig_outs[3];    /* optional - for auto-parsing */
284         int dig_out_type;
285
286         /* capture */
287         unsigned int num_adc_nids;
288         hda_nid_t *adc_nids;
289         hda_nid_t *capsrc_nids;
290         hda_nid_t dig_in_nid;           /* digital-in NID; optional */
291         int capture_style;              /* capture style (CAPT_*) */
292
293         /* capture source */
294         unsigned int num_mux_defs;
295         const struct hda_input_mux *input_mux;
296         unsigned int cur_mux[3];
297
298         /* channel model */
299         const struct hda_channel_mode *channel_mode;
300         int num_channel_mode;
301         int need_dac_fix;
302
303         /* PCM information */
304         struct hda_pcm pcm_rec[3];      /* used in alc_build_pcms() */
305
306         /* dynamic controls, init_verbs and input_mux */
307         struct auto_pin_cfg autocfg;
308         struct snd_array kctls;
309         struct hda_input_mux private_imux[3];
310         hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
311
312         /* hooks */
313         void (*init_hook)(struct hda_codec *codec);
314         void (*unsol_event)(struct hda_codec *codec, unsigned int res);
315
316         /* for pin sensing */
317         unsigned int sense_updated: 1;
318         unsigned int jack_present: 1;
319         unsigned int master_sw: 1;
320
321         /* other flags */
322         unsigned int no_analog :1; /* digital I/O only */
323
324         /* for virtual master */
325         hda_nid_t vmaster_nid;
326 #ifdef CONFIG_SND_HDA_POWER_SAVE
327         struct hda_loopback_check loopback;
328 #endif
329
330         /* for PLL fix */
331         hda_nid_t pll_nid;
332         unsigned int pll_coef_idx, pll_coef_bit;
333 };
334
335 /*
336  * configuration template - to be copied to the spec instance
337  */
338 struct alc_config_preset {
339         struct snd_kcontrol_new *mixers[5]; /* should be identical size
340                                              * with spec
341                                              */
342         struct snd_kcontrol_new *cap_mixer; /* capture mixer */
343         const struct hda_verb *init_verbs[5];
344         unsigned int num_dacs;
345         hda_nid_t *dac_nids;
346         hda_nid_t dig_out_nid;          /* optional */
347         hda_nid_t hp_nid;               /* optional */
348         hda_nid_t *slave_dig_outs;
349         unsigned int num_adc_nids;
350         hda_nid_t *adc_nids;
351         hda_nid_t *capsrc_nids;
352         hda_nid_t dig_in_nid;
353         unsigned int num_channel_mode;
354         const struct hda_channel_mode *channel_mode;
355         int need_dac_fix;
356         unsigned int num_mux_defs;
357         const struct hda_input_mux *input_mux;
358         void (*unsol_event)(struct hda_codec *, unsigned int);
359         void (*init_hook)(struct hda_codec *);
360 #ifdef CONFIG_SND_HDA_POWER_SAVE
361         struct hda_amp_list *loopbacks;
362 #endif
363 };
364
365
366 /*
367  * input MUX handling
368  */
369 static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
370                              struct snd_ctl_elem_info *uinfo)
371 {
372         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
373         struct alc_spec *spec = codec->spec;
374         unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
375         if (mux_idx >= spec->num_mux_defs)
376                 mux_idx = 0;
377         return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
378 }
379
380 static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
381                             struct snd_ctl_elem_value *ucontrol)
382 {
383         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
384         struct alc_spec *spec = codec->spec;
385         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
386
387         ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
388         return 0;
389 }
390
391 static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
392                             struct snd_ctl_elem_value *ucontrol)
393 {
394         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
395         struct alc_spec *spec = codec->spec;
396         const struct hda_input_mux *imux;
397         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
398         unsigned int mux_idx;
399         hda_nid_t nid = spec->capsrc_nids ?
400                 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
401
402         mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
403         imux = &spec->input_mux[mux_idx];
404
405         if (spec->capture_style &&
406             !(spec->capture_style == CAPT_1MUX_MIX && !adc_idx)) {
407                 /* Matrix-mixer style (e.g. ALC882) */
408                 unsigned int *cur_val = &spec->cur_mux[adc_idx];
409                 unsigned int i, idx;
410
411                 idx = ucontrol->value.enumerated.item[0];
412                 if (idx >= imux->num_items)
413                         idx = imux->num_items - 1;
414                 if (*cur_val == idx)
415                         return 0;
416                 for (i = 0; i < imux->num_items; i++) {
417                         unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
418                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
419                                                  imux->items[i].index,
420                                                  HDA_AMP_MUTE, v);
421                 }
422                 *cur_val = idx;
423                 return 1;
424         } else {
425                 /* MUX style (e.g. ALC880) */
426                 return snd_hda_input_mux_put(codec, imux, ucontrol, nid,
427                                              &spec->cur_mux[adc_idx]);
428         }
429 }
430
431 /*
432  * channel mode setting
433  */
434 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
435                             struct snd_ctl_elem_info *uinfo)
436 {
437         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
438         struct alc_spec *spec = codec->spec;
439         return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
440                                     spec->num_channel_mode);
441 }
442
443 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
444                            struct snd_ctl_elem_value *ucontrol)
445 {
446         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
447         struct alc_spec *spec = codec->spec;
448         return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
449                                    spec->num_channel_mode,
450                                    spec->multiout.max_channels);
451 }
452
453 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
454                            struct snd_ctl_elem_value *ucontrol)
455 {
456         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
457         struct alc_spec *spec = codec->spec;
458         int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
459                                       spec->num_channel_mode,
460                                       &spec->multiout.max_channels);
461         if (err >= 0 && spec->need_dac_fix)
462                 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
463         return err;
464 }
465
466 /*
467  * Control the mode of pin widget settings via the mixer.  "pc" is used
468  * instead of "%" to avoid consequences of accidently treating the % as
469  * being part of a format specifier.  Maximum allowed length of a value is
470  * 63 characters plus NULL terminator.
471  *
472  * Note: some retasking pin complexes seem to ignore requests for input
473  * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
474  * are requested.  Therefore order this list so that this behaviour will not
475  * cause problems when mixer clients move through the enum sequentially.
476  * NIDs 0x0f and 0x10 have been observed to have this behaviour as of
477  * March 2006.
478  */
479 static char *alc_pin_mode_names[] = {
480         "Mic 50pc bias", "Mic 80pc bias",
481         "Line in", "Line out", "Headphone out",
482 };
483 static unsigned char alc_pin_mode_values[] = {
484         PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
485 };
486 /* The control can present all 5 options, or it can limit the options based
487  * in the pin being assumed to be exclusively an input or an output pin.  In
488  * addition, "input" pins may or may not process the mic bias option
489  * depending on actual widget capability (NIDs 0x0f and 0x10 don't seem to
490  * accept requests for bias as of chip versions up to March 2006) and/or
491  * wiring in the computer.
492  */
493 #define ALC_PIN_DIR_IN              0x00
494 #define ALC_PIN_DIR_OUT             0x01
495 #define ALC_PIN_DIR_INOUT           0x02
496 #define ALC_PIN_DIR_IN_NOMICBIAS    0x03
497 #define ALC_PIN_DIR_INOUT_NOMICBIAS 0x04
498
499 /* Info about the pin modes supported by the different pin direction modes.
500  * For each direction the minimum and maximum values are given.
501  */
502 static signed char alc_pin_mode_dir_info[5][2] = {
503         { 0, 2 },    /* ALC_PIN_DIR_IN */
504         { 3, 4 },    /* ALC_PIN_DIR_OUT */
505         { 0, 4 },    /* ALC_PIN_DIR_INOUT */
506         { 2, 2 },    /* ALC_PIN_DIR_IN_NOMICBIAS */
507         { 2, 4 },    /* ALC_PIN_DIR_INOUT_NOMICBIAS */
508 };
509 #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
510 #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
511 #define alc_pin_mode_n_items(_dir) \
512         (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
513
514 static int alc_pin_mode_info(struct snd_kcontrol *kcontrol,
515                              struct snd_ctl_elem_info *uinfo)
516 {
517         unsigned int item_num = uinfo->value.enumerated.item;
518         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
519
520         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
521         uinfo->count = 1;
522         uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
523
524         if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
525                 item_num = alc_pin_mode_min(dir);
526         strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
527         return 0;
528 }
529
530 static int alc_pin_mode_get(struct snd_kcontrol *kcontrol,
531                             struct snd_ctl_elem_value *ucontrol)
532 {
533         unsigned int i;
534         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
535         hda_nid_t nid = kcontrol->private_value & 0xffff;
536         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
537         long *valp = ucontrol->value.integer.value;
538         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
539                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
540                                                  0x00);
541
542         /* Find enumerated value for current pinctl setting */
543         i = alc_pin_mode_min(dir);
544         while (alc_pin_mode_values[i] != pinctl && i <= alc_pin_mode_max(dir))
545                 i++;
546         *valp = i <= alc_pin_mode_max(dir) ? i: alc_pin_mode_min(dir);
547         return 0;
548 }
549
550 static int alc_pin_mode_put(struct snd_kcontrol *kcontrol,
551                             struct snd_ctl_elem_value *ucontrol)
552 {
553         signed int change;
554         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
555         hda_nid_t nid = kcontrol->private_value & 0xffff;
556         unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
557         long val = *ucontrol->value.integer.value;
558         unsigned int pinctl = snd_hda_codec_read(codec, nid, 0,
559                                                  AC_VERB_GET_PIN_WIDGET_CONTROL,
560                                                  0x00);
561
562         if (val < alc_pin_mode_min(dir) || val > alc_pin_mode_max(dir))
563                 val = alc_pin_mode_min(dir);
564
565         change = pinctl != alc_pin_mode_values[val];
566         if (change) {
567                 /* Set pin mode to that requested */
568                 snd_hda_codec_write_cache(codec, nid, 0,
569                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
570                                           alc_pin_mode_values[val]);
571
572                 /* Also enable the retasking pin's input/output as required
573                  * for the requested pin mode.  Enum values of 2 or less are
574                  * input modes.
575                  *
576                  * Dynamically switching the input/output buffers probably
577                  * reduces noise slightly (particularly on input) so we'll
578                  * do it.  However, having both input and output buffers
579                  * enabled simultaneously doesn't seem to be problematic if
580                  * this turns out to be necessary in the future.
581                  */
582                 if (val <= 2) {
583                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
584                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
585                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
586                                                  HDA_AMP_MUTE, 0);
587                 } else {
588                         snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
589                                                  HDA_AMP_MUTE, HDA_AMP_MUTE);
590                         snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
591                                                  HDA_AMP_MUTE, 0);
592                 }
593         }
594         return change;
595 }
596
597 #define ALC_PIN_MODE(xname, nid, dir) \
598         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
599           .info = alc_pin_mode_info, \
600           .get = alc_pin_mode_get, \
601           .put = alc_pin_mode_put, \
602           .private_value = nid | (dir<<16) }
603
604 /* A switch control for ALC260 GPIO pins.  Multiple GPIOs can be ganged
605  * together using a mask with more than one bit set.  This control is
606  * currently used only by the ALC260 test model.  At this stage they are not
607  * needed for any "production" models.
608  */
609 #ifdef CONFIG_SND_DEBUG
610 #define alc_gpio_data_info      snd_ctl_boolean_mono_info
611
612 static int alc_gpio_data_get(struct snd_kcontrol *kcontrol,
613                              struct snd_ctl_elem_value *ucontrol)
614 {
615         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
616         hda_nid_t nid = kcontrol->private_value & 0xffff;
617         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
618         long *valp = ucontrol->value.integer.value;
619         unsigned int val = snd_hda_codec_read(codec, nid, 0,
620                                               AC_VERB_GET_GPIO_DATA, 0x00);
621
622         *valp = (val & mask) != 0;
623         return 0;
624 }
625 static int alc_gpio_data_put(struct snd_kcontrol *kcontrol,
626                              struct snd_ctl_elem_value *ucontrol)
627 {
628         signed int change;
629         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
630         hda_nid_t nid = kcontrol->private_value & 0xffff;
631         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
632         long val = *ucontrol->value.integer.value;
633         unsigned int gpio_data = snd_hda_codec_read(codec, nid, 0,
634                                                     AC_VERB_GET_GPIO_DATA,
635                                                     0x00);
636
637         /* Set/unset the masked GPIO bit(s) as needed */
638         change = (val == 0 ? 0 : mask) != (gpio_data & mask);
639         if (val == 0)
640                 gpio_data &= ~mask;
641         else
642                 gpio_data |= mask;
643         snd_hda_codec_write_cache(codec, nid, 0,
644                                   AC_VERB_SET_GPIO_DATA, gpio_data);
645
646         return change;
647 }
648 #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
649         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
650           .info = alc_gpio_data_info, \
651           .get = alc_gpio_data_get, \
652           .put = alc_gpio_data_put, \
653           .private_value = nid | (mask<<16) }
654 #endif   /* CONFIG_SND_DEBUG */
655
656 /* A switch control to allow the enabling of the digital IO pins on the
657  * ALC260.  This is incredibly simplistic; the intention of this control is
658  * to provide something in the test model allowing digital outputs to be
659  * identified if present.  If models are found which can utilise these
660  * outputs a more complete mixer control can be devised for those models if
661  * necessary.
662  */
663 #ifdef CONFIG_SND_DEBUG
664 #define alc_spdif_ctrl_info     snd_ctl_boolean_mono_info
665
666 static int alc_spdif_ctrl_get(struct snd_kcontrol *kcontrol,
667                               struct snd_ctl_elem_value *ucontrol)
668 {
669         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
670         hda_nid_t nid = kcontrol->private_value & 0xffff;
671         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
672         long *valp = ucontrol->value.integer.value;
673         unsigned int val = snd_hda_codec_read(codec, nid, 0,
674                                               AC_VERB_GET_DIGI_CONVERT_1, 0x00);
675
676         *valp = (val & mask) != 0;
677         return 0;
678 }
679 static int alc_spdif_ctrl_put(struct snd_kcontrol *kcontrol,
680                               struct snd_ctl_elem_value *ucontrol)
681 {
682         signed int change;
683         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
684         hda_nid_t nid = kcontrol->private_value & 0xffff;
685         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
686         long val = *ucontrol->value.integer.value;
687         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
688                                                     AC_VERB_GET_DIGI_CONVERT_1,
689                                                     0x00);
690
691         /* Set/unset the masked control bit(s) as needed */
692         change = (val == 0 ? 0 : mask) != (ctrl_data & mask);
693         if (val==0)
694                 ctrl_data &= ~mask;
695         else
696                 ctrl_data |= mask;
697         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
698                                   ctrl_data);
699
700         return change;
701 }
702 #define ALC_SPDIF_CTRL_SWITCH(xname, nid, mask) \
703         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
704           .info = alc_spdif_ctrl_info, \
705           .get = alc_spdif_ctrl_get, \
706           .put = alc_spdif_ctrl_put, \
707           .private_value = nid | (mask<<16) }
708 #endif   /* CONFIG_SND_DEBUG */
709
710 /* A switch control to allow the enabling EAPD digital outputs on the ALC26x.
711  * Again, this is only used in the ALC26x test models to help identify when
712  * the EAPD line must be asserted for features to work.
713  */
714 #ifdef CONFIG_SND_DEBUG
715 #define alc_eapd_ctrl_info      snd_ctl_boolean_mono_info
716
717 static int alc_eapd_ctrl_get(struct snd_kcontrol *kcontrol,
718                               struct snd_ctl_elem_value *ucontrol)
719 {
720         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
721         hda_nid_t nid = kcontrol->private_value & 0xffff;
722         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
723         long *valp = ucontrol->value.integer.value;
724         unsigned int val = snd_hda_codec_read(codec, nid, 0,
725                                               AC_VERB_GET_EAPD_BTLENABLE, 0x00);
726
727         *valp = (val & mask) != 0;
728         return 0;
729 }
730
731 static int alc_eapd_ctrl_put(struct snd_kcontrol *kcontrol,
732                               struct snd_ctl_elem_value *ucontrol)
733 {
734         int change;
735         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
736         hda_nid_t nid = kcontrol->private_value & 0xffff;
737         unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
738         long val = *ucontrol->value.integer.value;
739         unsigned int ctrl_data = snd_hda_codec_read(codec, nid, 0,
740                                                     AC_VERB_GET_EAPD_BTLENABLE,
741                                                     0x00);
742
743         /* Set/unset the masked control bit(s) as needed */
744         change = (!val ? 0 : mask) != (ctrl_data & mask);
745         if (!val)
746                 ctrl_data &= ~mask;
747         else
748                 ctrl_data |= mask;
749         snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
750                                   ctrl_data);
751
752         return change;
753 }
754
755 #define ALC_EAPD_CTRL_SWITCH(xname, nid, mask) \
756         { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
757           .info = alc_eapd_ctrl_info, \
758           .get = alc_eapd_ctrl_get, \
759           .put = alc_eapd_ctrl_put, \
760           .private_value = nid | (mask<<16) }
761 #endif   /* CONFIG_SND_DEBUG */
762
763 /*
764  * set up the input pin config (depending on the given auto-pin type)
765  */
766 static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
767                               int auto_pin_type)
768 {
769         unsigned int val = PIN_IN;
770
771         if (auto_pin_type <= AUTO_PIN_FRONT_MIC) {
772                 unsigned int pincap;
773                 pincap = snd_hda_query_pin_caps(codec, nid);
774                 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
775                 if (pincap & AC_PINCAP_VREF_80)
776                         val = PIN_VREF80;
777         }
778         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
779 }
780
781 /*
782  */
783 static void add_mixer(struct alc_spec *spec, struct snd_kcontrol_new *mix)
784 {
785         if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
786                 return;
787         spec->mixers[spec->num_mixers++] = mix;
788 }
789
790 static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
791 {
792         if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
793                 return;
794         spec->init_verbs[spec->num_init_verbs++] = verb;
795 }
796
797 #ifdef CONFIG_PROC_FS
798 /*
799  * hook for proc
800  */
801 static void print_realtek_coef(struct snd_info_buffer *buffer,
802                                struct hda_codec *codec, hda_nid_t nid)
803 {
804         int coeff;
805
806         if (nid != 0x20)
807                 return;
808         coeff = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PROC_COEF, 0);
809         snd_iprintf(buffer, "  Processing Coefficient: 0x%02x\n", coeff);
810         coeff = snd_hda_codec_read(codec, nid, 0,
811                                    AC_VERB_GET_COEF_INDEX, 0);
812         snd_iprintf(buffer, "  Coefficient Index: 0x%02x\n", coeff);
813 }
814 #else
815 #define print_realtek_coef      NULL
816 #endif
817
818 /*
819  * set up from the preset table
820  */
821 static void setup_preset(struct alc_spec *spec,
822                          const struct alc_config_preset *preset)
823 {
824         int i;
825
826         for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
827                 add_mixer(spec, preset->mixers[i]);
828         spec->cap_mixer = preset->cap_mixer;
829         for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
830              i++)
831                 add_verb(spec, preset->init_verbs[i]);
832
833         spec->channel_mode = preset->channel_mode;
834         spec->num_channel_mode = preset->num_channel_mode;
835         spec->need_dac_fix = preset->need_dac_fix;
836
837         spec->multiout.max_channels = spec->channel_mode[0].channels;
838
839         spec->multiout.num_dacs = preset->num_dacs;
840         spec->multiout.dac_nids = preset->dac_nids;
841         spec->multiout.dig_out_nid = preset->dig_out_nid;
842         spec->multiout.slave_dig_outs = preset->slave_dig_outs;
843         spec->multiout.hp_nid = preset->hp_nid;
844
845         spec->num_mux_defs = preset->num_mux_defs;
846         if (!spec->num_mux_defs)
847                 spec->num_mux_defs = 1;
848         spec->input_mux = preset->input_mux;
849
850         spec->num_adc_nids = preset->num_adc_nids;
851         spec->adc_nids = preset->adc_nids;
852         spec->capsrc_nids = preset->capsrc_nids;
853         spec->dig_in_nid = preset->dig_in_nid;
854
855         spec->unsol_event = preset->unsol_event;
856         spec->init_hook = preset->init_hook;
857 #ifdef CONFIG_SND_HDA_POWER_SAVE
858         spec->loopback.amplist = preset->loopbacks;
859 #endif
860 }
861
862 /* Enable GPIO mask and set output */
863 static struct hda_verb alc_gpio1_init_verbs[] = {
864         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
865         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
866         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
867         { }
868 };
869
870 static struct hda_verb alc_gpio2_init_verbs[] = {
871         {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
872         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
873         {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
874         { }
875 };
876
877 static struct hda_verb alc_gpio3_init_verbs[] = {
878         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
879         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
880         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
881         { }
882 };
883
884 /*
885  * Fix hardware PLL issue
886  * On some codecs, the analog PLL gating control must be off while
887  * the default value is 1.
888  */
889 static void alc_fix_pll(struct hda_codec *codec)
890 {
891         struct alc_spec *spec = codec->spec;
892         unsigned int val;
893
894         if (!spec->pll_nid)
895                 return;
896         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
897                             spec->pll_coef_idx);
898         val = snd_hda_codec_read(codec, spec->pll_nid, 0,
899                                  AC_VERB_GET_PROC_COEF, 0);
900         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
901                             spec->pll_coef_idx);
902         snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
903                             val & ~(1 << spec->pll_coef_bit));
904 }
905
906 static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
907                              unsigned int coef_idx, unsigned int coef_bit)
908 {
909         struct alc_spec *spec = codec->spec;
910         spec->pll_nid = nid;
911         spec->pll_coef_idx = coef_idx;
912         spec->pll_coef_bit = coef_bit;
913         alc_fix_pll(codec);
914 }
915
916 static void alc_sku_automute(struct hda_codec *codec)
917 {
918         struct alc_spec *spec = codec->spec;
919         unsigned int present;
920         unsigned int hp_nid = spec->autocfg.hp_pins[0];
921         unsigned int sp_nid = spec->autocfg.speaker_pins[0];
922
923         /* need to execute and sync at first */
924         snd_hda_codec_read(codec, hp_nid, 0, AC_VERB_SET_PIN_SENSE, 0);
925         present = snd_hda_codec_read(codec, hp_nid, 0,
926                                      AC_VERB_GET_PIN_SENSE, 0);
927         spec->jack_present = (present & 0x80000000) != 0;
928         snd_hda_codec_write(codec, sp_nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
929                             spec->jack_present ? 0 : PIN_OUT);
930 }
931
932 #if 0 /* it's broken in some acses -- temporarily disabled */
933 static void alc_mic_automute(struct hda_codec *codec)
934 {
935         struct alc_spec *spec = codec->spec;
936         unsigned int present;
937         unsigned int mic_nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
938         unsigned int fmic_nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
939         unsigned int mix_nid = spec->capsrc_nids[0];
940         unsigned int capsrc_idx_mic, capsrc_idx_fmic;
941
942         capsrc_idx_mic = mic_nid - 0x18;
943         capsrc_idx_fmic = fmic_nid - 0x18;
944         present = snd_hda_codec_read(codec, mic_nid, 0,
945                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
946         snd_hda_codec_write(codec, mix_nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
947                     0x7000 | (capsrc_idx_mic << 8) | (present ? 0 : 0x80));
948         snd_hda_codec_write(codec, mix_nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
949                     0x7000 | (capsrc_idx_fmic << 8) | (present ? 0x80 : 0));
950         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, capsrc_idx_fmic,
951                          HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
952 }
953 #else
954 #define alc_mic_automute(codec) do {} while(0) /* NOP */
955 #endif /* disabled */
956
957 /* unsolicited event for HP jack sensing */
958 static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
959 {
960         if (codec->vendor_id == 0x10ec0880)
961                 res >>= 28;
962         else
963                 res >>= 26;
964         if (res == ALC880_HP_EVENT)
965                 alc_sku_automute(codec);
966
967         if (res == ALC880_MIC_EVENT)
968                 alc_mic_automute(codec);
969 }
970
971 static void alc_inithook(struct hda_codec *codec)
972 {
973         alc_sku_automute(codec);
974         alc_mic_automute(codec);
975 }
976
977 /* additional initialization for ALC888 variants */
978 static void alc888_coef_init(struct hda_codec *codec)
979 {
980         unsigned int tmp;
981
982         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
983         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
984         snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
985         if ((tmp & 0xf0) == 0x20)
986                 /* alc888S-VC */
987                 snd_hda_codec_read(codec, 0x20, 0,
988                                    AC_VERB_SET_PROC_COEF, 0x830);
989          else
990                  /* alc888-VB */
991                  snd_hda_codec_read(codec, 0x20, 0,
992                                     AC_VERB_SET_PROC_COEF, 0x3030);
993 }
994
995 /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
996  *      31 ~ 16 :       Manufacture ID
997  *      15 ~ 8  :       SKU ID
998  *      7  ~ 0  :       Assembly ID
999  *      port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1000  */
1001 static void alc_subsystem_id(struct hda_codec *codec,
1002                              unsigned int porta, unsigned int porte,
1003                              unsigned int portd)
1004 {
1005         unsigned int ass, tmp, i;
1006         unsigned nid;
1007         struct alc_spec *spec = codec->spec;
1008
1009         ass = codec->subsystem_id & 0xffff;
1010         if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1011                 goto do_sku;
1012
1013         /*
1014          * 31~30        : port conetcivity
1015          * 29~21        : reserve
1016          * 20           : PCBEEP input
1017          * 19~16        : Check sum (15:1)
1018          * 15~1         : Custom
1019          * 0            : override
1020         */
1021         nid = 0x1d;
1022         if (codec->vendor_id == 0x10ec0260)
1023                 nid = 0x17;
1024         ass = snd_hda_codec_get_pincfg(codec, nid);
1025         if (!(ass & 1) && !(ass & 0x100000))
1026                 return;
1027         if ((ass >> 30) != 1)   /* no physical connection */
1028                 return;
1029
1030         /* check sum */
1031         tmp = 0;
1032         for (i = 1; i < 16; i++) {
1033                 if ((ass >> i) & 1)
1034                         tmp++;
1035         }
1036         if (((ass >> 16) & 0xf) != tmp)
1037                 return;
1038 do_sku:
1039         /*
1040          * 0 : override
1041          * 1 :  Swap Jack
1042          * 2 : 0 --> Desktop, 1 --> Laptop
1043          * 3~5 : External Amplifier control
1044          * 7~6 : Reserved
1045         */
1046         tmp = (ass & 0x38) >> 3;        /* external Amp control */
1047         switch (tmp) {
1048         case 1:
1049                 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
1050                 break;
1051         case 3:
1052                 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
1053                 break;
1054         case 7:
1055                 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
1056                 break;
1057         case 5: /* set EAPD output high */
1058                 switch (codec->vendor_id) {
1059                 case 0x10ec0260:
1060                         snd_hda_codec_write(codec, 0x0f, 0,
1061                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1062                         snd_hda_codec_write(codec, 0x10, 0,
1063                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1064                         break;
1065                 case 0x10ec0262:
1066                 case 0x10ec0267:
1067                 case 0x10ec0268:
1068                 case 0x10ec0269:
1069                 case 0x10ec0272:
1070                 case 0x10ec0660:
1071                 case 0x10ec0662:
1072                 case 0x10ec0663:
1073                 case 0x10ec0862:
1074                 case 0x10ec0889:
1075                         snd_hda_codec_write(codec, 0x14, 0,
1076                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1077                         snd_hda_codec_write(codec, 0x15, 0,
1078                                             AC_VERB_SET_EAPD_BTLENABLE, 2);
1079                         break;
1080                 }
1081                 switch (codec->vendor_id) {
1082                 case 0x10ec0260:
1083                         snd_hda_codec_write(codec, 0x1a, 0,
1084                                             AC_VERB_SET_COEF_INDEX, 7);
1085                         tmp = snd_hda_codec_read(codec, 0x1a, 0,
1086                                                  AC_VERB_GET_PROC_COEF, 0);
1087                         snd_hda_codec_write(codec, 0x1a, 0,
1088                                             AC_VERB_SET_COEF_INDEX, 7);
1089                         snd_hda_codec_write(codec, 0x1a, 0,
1090                                             AC_VERB_SET_PROC_COEF,
1091                                             tmp | 0x2010);
1092                         break;
1093                 case 0x10ec0262:
1094                 case 0x10ec0880:
1095                 case 0x10ec0882:
1096                 case 0x10ec0883:
1097                 case 0x10ec0885:
1098                 case 0x10ec0887:
1099                 case 0x10ec0889:
1100                         snd_hda_codec_write(codec, 0x20, 0,
1101                                             AC_VERB_SET_COEF_INDEX, 7);
1102                         tmp = snd_hda_codec_read(codec, 0x20, 0,
1103                                                  AC_VERB_GET_PROC_COEF, 0);
1104                         snd_hda_codec_write(codec, 0x20, 0,
1105                                             AC_VERB_SET_COEF_INDEX, 7);
1106                         snd_hda_codec_write(codec, 0x20, 0,
1107                                             AC_VERB_SET_PROC_COEF,
1108                                             tmp | 0x2010);
1109                         break;
1110                 case 0x10ec0888:
1111                         /*alc888_coef_init(codec);*/ /* called in alc_init() */
1112                         break;
1113                 case 0x10ec0267:
1114                 case 0x10ec0268:
1115                         snd_hda_codec_write(codec, 0x20, 0,
1116                                             AC_VERB_SET_COEF_INDEX, 7);
1117                         tmp = snd_hda_codec_read(codec, 0x20, 0,
1118                                                  AC_VERB_GET_PROC_COEF, 0);
1119                         snd_hda_codec_write(codec, 0x20, 0,
1120                                             AC_VERB_SET_COEF_INDEX, 7);
1121                         snd_hda_codec_write(codec, 0x20, 0,
1122                                             AC_VERB_SET_PROC_COEF,
1123                                             tmp | 0x3000);
1124                         break;
1125                 }
1126         default:
1127                 break;
1128         }
1129
1130         /* is laptop or Desktop and enable the function "Mute internal speaker
1131          * when the external headphone out jack is plugged"
1132          */
1133         if (!(ass & 0x8000))
1134                 return;
1135         /*
1136          * 10~8 : Jack location
1137          * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1138          * 14~13: Resvered
1139          * 15   : 1 --> enable the function "Mute internal speaker
1140          *              when the external headphone out jack is plugged"
1141          */
1142         if (!spec->autocfg.speaker_pins[0]) {
1143                 if (spec->autocfg.line_out_pins[0])
1144                         spec->autocfg.speaker_pins[0] =
1145                                 spec->autocfg.line_out_pins[0];
1146                 else
1147                         return;
1148         }
1149
1150         if (!spec->autocfg.hp_pins[0]) {
1151                 tmp = (ass >> 11) & 0x3;        /* HP to chassis */
1152                 if (tmp == 0)
1153                         spec->autocfg.hp_pins[0] = porta;
1154                 else if (tmp == 1)
1155                         spec->autocfg.hp_pins[0] = porte;
1156                 else if (tmp == 2)
1157                         spec->autocfg.hp_pins[0] = portd;
1158                 else
1159                         return;
1160         }
1161         if (spec->autocfg.hp_pins[0])
1162                 snd_hda_codec_write(codec, spec->autocfg.hp_pins[0], 0,
1163                         AC_VERB_SET_UNSOLICITED_ENABLE,
1164                         AC_USRSP_EN | ALC880_HP_EVENT);
1165
1166 #if 0 /* it's broken in some acses -- temporarily disabled */
1167         if (spec->autocfg.input_pins[AUTO_PIN_MIC] &&
1168                 spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC])
1169                 snd_hda_codec_write(codec,
1170                         spec->autocfg.input_pins[AUTO_PIN_MIC], 0,
1171                         AC_VERB_SET_UNSOLICITED_ENABLE,
1172                         AC_USRSP_EN | ALC880_MIC_EVENT);
1173 #endif /* disabled */
1174
1175         spec->unsol_event = alc_sku_unsol_event;
1176 }
1177
1178 /*
1179  * Fix-up pin default configurations
1180  */
1181
1182 struct alc_pincfg {
1183         hda_nid_t nid;
1184         u32 val;
1185 };
1186
1187 static void alc_fix_pincfg(struct hda_codec *codec,
1188                            const struct snd_pci_quirk *quirk,
1189                            const struct alc_pincfg **pinfix)
1190 {
1191         const struct alc_pincfg *cfg;
1192
1193         quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1194         if (!quirk)
1195                 return;
1196
1197         cfg = pinfix[quirk->value];
1198         for (; cfg->nid; cfg++)
1199                 snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val);
1200 }
1201
1202 /*
1203  * ALC888
1204  */
1205
1206 /*
1207  * 2ch mode
1208  */
1209 static struct hda_verb alc888_4ST_ch2_intel_init[] = {
1210 /* Mic-in jack as mic in */
1211         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1212         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1213 /* Line-in jack as Line in */
1214         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1215         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1216 /* Line-Out as Front */
1217         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1218         { } /* end */
1219 };
1220
1221 /*
1222  * 4ch mode
1223  */
1224 static struct hda_verb alc888_4ST_ch4_intel_init[] = {
1225 /* Mic-in jack as mic in */
1226         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1227         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1228 /* Line-in jack as Surround */
1229         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1230         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1231 /* Line-Out as Front */
1232         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1233         { } /* end */
1234 };
1235
1236 /*
1237  * 6ch mode
1238  */
1239 static struct hda_verb alc888_4ST_ch6_intel_init[] = {
1240 /* Mic-in jack as CLFE */
1241         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1242         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1243 /* Line-in jack as Surround */
1244         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1245         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1246 /* Line-Out as CLFE (workaround because Mic-in is not loud enough) */
1247         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1248         { } /* end */
1249 };
1250
1251 /*
1252  * 8ch mode
1253  */
1254 static struct hda_verb alc888_4ST_ch8_intel_init[] = {
1255 /* Mic-in jack as CLFE */
1256         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1257         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1258 /* Line-in jack as Surround */
1259         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1260         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1261 /* Line-Out as Side */
1262         { 0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1263         { } /* end */
1264 };
1265
1266 static struct hda_channel_mode alc888_4ST_8ch_intel_modes[4] = {
1267         { 2, alc888_4ST_ch2_intel_init },
1268         { 4, alc888_4ST_ch4_intel_init },
1269         { 6, alc888_4ST_ch6_intel_init },
1270         { 8, alc888_4ST_ch8_intel_init },
1271 };
1272
1273 /*
1274  * ALC888 Fujitsu Siemens Amillo xa3530
1275  */
1276
1277 static struct hda_verb alc888_fujitsu_xa3530_verbs[] = {
1278 /* Front Mic: set to PIN_IN (empty by default) */
1279         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1280 /* Connect Internal HP to Front */
1281         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1282         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1283         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1284 /* Connect Bass HP to Front */
1285         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1286         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1287         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1288 /* Connect Line-Out side jack (SPDIF) to Side */
1289         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1290         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1291         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
1292 /* Connect Mic jack to CLFE */
1293         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1294         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1295         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},
1296 /* Connect Line-in jack to Surround */
1297         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1298         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1299         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
1300 /* Connect HP out jack to Front */
1301         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1302         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1303         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1304 /* Enable unsolicited event for HP jack and Line-out jack */
1305         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1306         {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1307         {}
1308 };
1309
1310 static void alc888_fujitsu_xa3530_automute(struct hda_codec *codec)
1311 {
1312         unsigned int present;
1313         unsigned int bits;
1314         /* Line out presence */
1315         present = snd_hda_codec_read(codec, 0x17, 0,
1316                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1317         /* HP out presence */
1318         present = present || snd_hda_codec_read(codec, 0x1b, 0,
1319                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1320         bits = present ? HDA_AMP_MUTE : 0;
1321         /* Toggle internal speakers muting */
1322         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
1323                                  HDA_AMP_MUTE, bits);
1324         /* Toggle internal bass muting */
1325         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
1326                                  HDA_AMP_MUTE, bits);
1327 }
1328
1329 static void alc888_fujitsu_xa3530_unsol_event(struct hda_codec *codec,
1330                 unsigned int res)
1331 {
1332         if (res >> 26 == ALC880_HP_EVENT)
1333                 alc888_fujitsu_xa3530_automute(codec);
1334 }
1335
1336
1337 /*
1338  * ALC888 Acer Aspire 4930G model
1339  */
1340
1341 static struct hda_verb alc888_acer_aspire_4930g_verbs[] = {
1342 /* Front Mic: set to PIN_IN (empty by default) */
1343         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1344 /* Unselect Front Mic by default in input mixer 3 */
1345         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0xb)},
1346 /* Enable unsolicited event for HP jack */
1347         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
1348 /* Connect Internal HP to front */
1349         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1350         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1351         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
1352 /* Connect HP out to front */
1353         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1354         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1355         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
1356         { }
1357 };
1358
1359 static struct hda_input_mux alc888_2_capture_sources[2] = {
1360         /* Front mic only available on one ADC */
1361         {
1362                 .num_items = 4,
1363                 .items = {
1364                         { "Mic", 0x0 },
1365                         { "Line", 0x2 },
1366                         { "CD", 0x4 },
1367                         { "Front Mic", 0xb },
1368                 },
1369         },
1370         {
1371                 .num_items = 3,
1372                 .items = {
1373                         { "Mic", 0x0 },
1374                         { "Line", 0x2 },
1375                         { "CD", 0x4 },
1376                 },
1377         }
1378 };
1379
1380 static struct snd_kcontrol_new alc888_base_mixer[] = {
1381         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1382         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1383         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1384         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1385         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
1386                 HDA_OUTPUT),
1387         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1388         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1389         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1390         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1391         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1392         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1393         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1394         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1395         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1396         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1397         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
1398         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1399         { } /* end */
1400 };
1401
1402 static void alc888_acer_aspire_4930g_automute(struct hda_codec *codec)
1403 {
1404         unsigned int present;
1405         unsigned int bits;
1406         present = snd_hda_codec_read(codec, 0x15, 0,
1407                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1408         bits = present ? HDA_AMP_MUTE : 0;
1409         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
1410                                  HDA_AMP_MUTE, bits);
1411 }
1412
1413 static void alc888_acer_aspire_4930g_unsol_event(struct hda_codec *codec,
1414                 unsigned int res)
1415 {
1416         if (res >> 26 == ALC880_HP_EVENT)
1417                 alc888_acer_aspire_4930g_automute(codec);
1418 }
1419
1420 /*
1421  * ALC880 3-stack model
1422  *
1423  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
1424  * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18,
1425  *                 F-Mic = 0x1b, HP = 0x19
1426  */
1427
1428 static hda_nid_t alc880_dac_nids[4] = {
1429         /* front, rear, clfe, rear_surr */
1430         0x02, 0x05, 0x04, 0x03
1431 };
1432
1433 static hda_nid_t alc880_adc_nids[3] = {
1434         /* ADC0-2 */
1435         0x07, 0x08, 0x09,
1436 };
1437
1438 /* The datasheet says the node 0x07 is connected from inputs,
1439  * but it shows zero connection in the real implementation on some devices.
1440  * Note: this is a 915GAV bug, fixed on 915GLV
1441  */
1442 static hda_nid_t alc880_adc_nids_alt[2] = {
1443         /* ADC1-2 */
1444         0x08, 0x09,
1445 };
1446
1447 #define ALC880_DIGOUT_NID       0x06
1448 #define ALC880_DIGIN_NID        0x0a
1449
1450 static struct hda_input_mux alc880_capture_source = {
1451         .num_items = 4,
1452         .items = {
1453                 { "Mic", 0x0 },
1454                 { "Front Mic", 0x3 },
1455                 { "Line", 0x2 },
1456                 { "CD", 0x4 },
1457         },
1458 };
1459
1460 /* channel source setting (2/6 channel selection for 3-stack) */
1461 /* 2ch mode */
1462 static struct hda_verb alc880_threestack_ch2_init[] = {
1463         /* set line-in to input, mute it */
1464         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1465         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1466         /* set mic-in to input vref 80%, mute it */
1467         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1468         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1469         { } /* end */
1470 };
1471
1472 /* 6ch mode */
1473 static struct hda_verb alc880_threestack_ch6_init[] = {
1474         /* set line-in to output, unmute it */
1475         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1476         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1477         /* set mic-in to output, unmute it */
1478         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1479         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1480         { } /* end */
1481 };
1482
1483 static struct hda_channel_mode alc880_threestack_modes[2] = {
1484         { 2, alc880_threestack_ch2_init },
1485         { 6, alc880_threestack_ch6_init },
1486 };
1487
1488 static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
1489         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1490         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1491         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1492         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
1493         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1494         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1495         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1496         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1497         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1498         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1499         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1500         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1501         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1502         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1503         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
1504         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
1505         HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
1506         {
1507                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1508                 .name = "Channel Mode",
1509                 .info = alc_ch_mode_info,
1510                 .get = alc_ch_mode_get,
1511                 .put = alc_ch_mode_put,
1512         },
1513         { } /* end */
1514 };
1515
1516 /* capture mixer elements */
1517 static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1518                             struct snd_ctl_elem_info *uinfo)
1519 {
1520         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1521         struct alc_spec *spec = codec->spec;
1522         int err;
1523
1524         mutex_lock(&codec->control_mutex);
1525         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1526                                                       HDA_INPUT);
1527         err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
1528         mutex_unlock(&codec->control_mutex);
1529         return err;
1530 }
1531
1532 static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1533                            unsigned int size, unsigned int __user *tlv)
1534 {
1535         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1536         struct alc_spec *spec = codec->spec;
1537         int err;
1538
1539         mutex_lock(&codec->control_mutex);
1540         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0,
1541                                                       HDA_INPUT);
1542         err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
1543         mutex_unlock(&codec->control_mutex);
1544         return err;
1545 }
1546
1547 typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1548                              struct snd_ctl_elem_value *ucontrol);
1549
1550 static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1551                                  struct snd_ctl_elem_value *ucontrol,
1552                                  getput_call_t func)
1553 {
1554         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1555         struct alc_spec *spec = codec->spec;
1556         unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
1557         int err;
1558
1559         mutex_lock(&codec->control_mutex);
1560         kcontrol->private_value = HDA_COMPOSE_AMP_VAL(spec->adc_nids[adc_idx],
1561                                                       3, 0, HDA_INPUT);
1562         err = func(kcontrol, ucontrol);
1563         mutex_unlock(&codec->control_mutex);
1564         return err;
1565 }
1566
1567 static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1568                            struct snd_ctl_elem_value *ucontrol)
1569 {
1570         return alc_cap_getput_caller(kcontrol, ucontrol,
1571                                      snd_hda_mixer_amp_volume_get);
1572 }
1573
1574 static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1575                            struct snd_ctl_elem_value *ucontrol)
1576 {
1577         return alc_cap_getput_caller(kcontrol, ucontrol,
1578                                      snd_hda_mixer_amp_volume_put);
1579 }
1580
1581 /* capture mixer elements */
1582 #define alc_cap_sw_info         snd_ctl_boolean_stereo_info
1583
1584 static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1585                           struct snd_ctl_elem_value *ucontrol)
1586 {
1587         return alc_cap_getput_caller(kcontrol, ucontrol,
1588                                      snd_hda_mixer_amp_switch_get);
1589 }
1590
1591 static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1592                           struct snd_ctl_elem_value *ucontrol)
1593 {
1594         return alc_cap_getput_caller(kcontrol, ucontrol,
1595                                      snd_hda_mixer_amp_switch_put);
1596 }
1597
1598 #define _DEFINE_CAPMIX(num) \
1599         { \
1600                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1601                 .name = "Capture Switch", \
1602                 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1603                 .count = num, \
1604                 .info = alc_cap_sw_info, \
1605                 .get = alc_cap_sw_get, \
1606                 .put = alc_cap_sw_put, \
1607         }, \
1608         { \
1609                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1610                 .name = "Capture Volume", \
1611                 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1612                            SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1613                            SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1614                 .count = num, \
1615                 .info = alc_cap_vol_info, \
1616                 .get = alc_cap_vol_get, \
1617                 .put = alc_cap_vol_put, \
1618                 .tlv = { .c = alc_cap_vol_tlv }, \
1619         }
1620
1621 #define _DEFINE_CAPSRC(num) \
1622         { \
1623                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1624                 /* .name = "Capture Source", */ \
1625                 .name = "Input Source", \
1626                 .count = num, \
1627                 .info = alc_mux_enum_info, \
1628                 .get = alc_mux_enum_get, \
1629                 .put = alc_mux_enum_put, \
1630         }
1631
1632 #define DEFINE_CAPMIX(num) \
1633 static struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1634         _DEFINE_CAPMIX(num),                                  \
1635         _DEFINE_CAPSRC(num),                                  \
1636         { } /* end */                                         \
1637 }
1638
1639 #define DEFINE_CAPMIX_NOSRC(num) \
1640 static struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
1641         _DEFINE_CAPMIX(num),                                        \
1642         { } /* end */                                               \
1643 }
1644
1645 /* up to three ADCs */
1646 DEFINE_CAPMIX(1);
1647 DEFINE_CAPMIX(2);
1648 DEFINE_CAPMIX(3);
1649 DEFINE_CAPMIX_NOSRC(1);
1650 DEFINE_CAPMIX_NOSRC(2);
1651 DEFINE_CAPMIX_NOSRC(3);
1652
1653 /*
1654  * ALC880 5-stack model
1655  *
1656  * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d),
1657  *      Side = 0x02 (0xd)
1658  * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
1659  *                 Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
1660  */
1661
1662 /* additional mixers to alc880_three_stack_mixer */
1663 static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
1664         HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1665         HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
1666         { } /* end */
1667 };
1668
1669 /* channel source setting (6/8 channel selection for 5-stack) */
1670 /* 6ch mode */
1671 static struct hda_verb alc880_fivestack_ch6_init[] = {
1672         /* set line-in to input, mute it */
1673         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1674         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1675         { } /* end */
1676 };
1677
1678 /* 8ch mode */
1679 static struct hda_verb alc880_fivestack_ch8_init[] = {
1680         /* set line-in to output, unmute it */
1681         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
1682         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1683         { } /* end */
1684 };
1685
1686 static struct hda_channel_mode alc880_fivestack_modes[2] = {
1687         { 6, alc880_fivestack_ch6_init },
1688         { 8, alc880_fivestack_ch8_init },
1689 };
1690
1691
1692 /*
1693  * ALC880 6-stack model
1694  *
1695  * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e),
1696  *      Side = 0x05 (0x0f)
1697  * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
1698  *   Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
1699  */
1700
1701 static hda_nid_t alc880_6st_dac_nids[4] = {
1702         /* front, rear, clfe, rear_surr */
1703         0x02, 0x03, 0x04, 0x05
1704 };
1705
1706 static struct hda_input_mux alc880_6stack_capture_source = {
1707         .num_items = 4,
1708         .items = {
1709                 { "Mic", 0x0 },
1710                 { "Front Mic", 0x1 },
1711                 { "Line", 0x2 },
1712                 { "CD", 0x4 },
1713         },
1714 };
1715
1716 /* fixed 8-channels */
1717 static struct hda_channel_mode alc880_sixstack_modes[1] = {
1718         { 8, NULL },
1719 };
1720
1721 static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
1722         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1723         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1724         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1725         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1726         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1727         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1728         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1729         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1730         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1731         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1732         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1733         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1734         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1735         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1736         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1737         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1738         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1739         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1740         {
1741                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1742                 .name = "Channel Mode",
1743                 .info = alc_ch_mode_info,
1744                 .get = alc_ch_mode_get,
1745                 .put = alc_ch_mode_put,
1746         },
1747         { } /* end */
1748 };
1749
1750
1751 /*
1752  * ALC880 W810 model
1753  *
1754  * W810 has rear IO for:
1755  * Front (DAC 02)
1756  * Surround (DAC 03)
1757  * Center/LFE (DAC 04)
1758  * Digital out (06)
1759  *
1760  * The system also has a pair of internal speakers, and a headphone jack.
1761  * These are both connected to Line2 on the codec, hence to DAC 02.
1762  *
1763  * There is a variable resistor to control the speaker or headphone
1764  * volume. This is a hardware-only device without a software API.
1765  *
1766  * Plugging headphones in will disable the internal speakers. This is
1767  * implemented in hardware, not via the driver using jack sense. In
1768  * a similar fashion, plugging into the rear socket marked "front" will
1769  * disable both the speakers and headphones.
1770  *
1771  * For input, there's a microphone jack, and an "audio in" jack.
1772  * These may not do anything useful with this driver yet, because I
1773  * haven't setup any initialization verbs for these yet...
1774  */
1775
1776 static hda_nid_t alc880_w810_dac_nids[3] = {
1777         /* front, rear/surround, clfe */
1778         0x02, 0x03, 0x04
1779 };
1780
1781 /* fixed 6 channels */
1782 static struct hda_channel_mode alc880_w810_modes[1] = {
1783         { 6, NULL }
1784 };
1785
1786 /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
1787 static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
1788         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1789         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1790         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1791         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1792         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1793         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1794         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1795         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1796         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1797         { } /* end */
1798 };
1799
1800
1801 /*
1802  * Z710V model
1803  *
1804  * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
1805  * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?),
1806  *                 Line = 0x1a
1807  */
1808
1809 static hda_nid_t alc880_z71v_dac_nids[1] = {
1810         0x02
1811 };
1812 #define ALC880_Z71V_HP_DAC      0x03
1813
1814 /* fixed 2 channels */
1815 static struct hda_channel_mode alc880_2_jack_modes[1] = {
1816         { 2, NULL }
1817 };
1818
1819 static struct snd_kcontrol_new alc880_z71v_mixer[] = {
1820         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1821         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1822         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1823         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
1824         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1825         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1826         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1827         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1828         { } /* end */
1829 };
1830
1831
1832 /*
1833  * ALC880 F1734 model
1834  *
1835  * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
1836  * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
1837  */
1838
1839 static hda_nid_t alc880_f1734_dac_nids[1] = {
1840         0x03
1841 };
1842 #define ALC880_F1734_HP_DAC     0x02
1843
1844 static struct snd_kcontrol_new alc880_f1734_mixer[] = {
1845         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1846         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1847         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1848         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1849         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1850         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1851         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1852         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1853         { } /* end */
1854 };
1855
1856 static struct hda_input_mux alc880_f1734_capture_source = {
1857         .num_items = 2,
1858         .items = {
1859                 { "Mic", 0x1 },
1860                 { "CD", 0x4 },
1861         },
1862 };
1863
1864
1865 /*
1866  * ALC880 ASUS model
1867  *
1868  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1869  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1870  *  Mic = 0x18, Line = 0x1a
1871  */
1872
1873 #define alc880_asus_dac_nids    alc880_w810_dac_nids    /* identical with w810 */
1874 #define alc880_asus_modes       alc880_threestack_modes /* 2/6 channel mode */
1875
1876 static struct snd_kcontrol_new alc880_asus_mixer[] = {
1877         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1878         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1879         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1880         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1881         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1882         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1883         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1884         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1885         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1886         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1887         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1888         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1889         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1890         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1891         {
1892                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1893                 .name = "Channel Mode",
1894                 .info = alc_ch_mode_info,
1895                 .get = alc_ch_mode_get,
1896                 .put = alc_ch_mode_put,
1897         },
1898         { } /* end */
1899 };
1900
1901 /*
1902  * ALC880 ASUS W1V model
1903  *
1904  * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
1905  * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
1906  *  Mic = 0x18, Line = 0x1a, Line2 = 0x1b
1907  */
1908
1909 /* additional mixers to alc880_asus_mixer */
1910 static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
1911         HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
1912         HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
1913         { } /* end */
1914 };
1915
1916 /* TCL S700 */
1917 static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
1918         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1919         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1920         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
1921         HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
1922         HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
1923         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
1924         HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
1925         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
1926         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
1927         { } /* end */
1928 };
1929
1930 /* Uniwill */
1931 static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
1932         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1933         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1934         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1935         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1936         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
1937         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
1938         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
1939         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
1940         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1941         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1942         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
1943         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
1944         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1945         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1946         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1947         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1948         {
1949                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1950                 .name = "Channel Mode",
1951                 .info = alc_ch_mode_info,
1952                 .get = alc_ch_mode_get,
1953                 .put = alc_ch_mode_put,
1954         },
1955         { } /* end */
1956 };
1957
1958 static struct snd_kcontrol_new alc880_fujitsu_mixer[] = {
1959         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1960         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1961         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1962         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1963         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1964         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1965         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1966         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1967         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1968         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1969         { } /* end */
1970 };
1971
1972 static struct snd_kcontrol_new alc880_uniwill_p53_mixer[] = {
1973         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
1974         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
1975         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1976         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1977         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1978         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1979         { } /* end */
1980 };
1981
1982 /*
1983  * virtual master controls
1984  */
1985
1986 /*
1987  * slave controls for virtual master
1988  */
1989 static const char *alc_slave_vols[] = {
1990         "Front Playback Volume",
1991         "Surround Playback Volume",
1992         "Center Playback Volume",
1993         "LFE Playback Volume",
1994         "Side Playback Volume",
1995         "Headphone Playback Volume",
1996         "Speaker Playback Volume",
1997         "Mono Playback Volume",
1998         "Line-Out Playback Volume",
1999         "PCM Playback Volume",
2000         NULL,
2001 };
2002
2003 static const char *alc_slave_sws[] = {
2004         "Front Playback Switch",
2005         "Surround Playback Switch",
2006         "Center Playback Switch",
2007         "LFE Playback Switch",
2008         "Side Playback Switch",
2009         "Headphone Playback Switch",
2010         "Speaker Playback Switch",
2011         "Mono Playback Switch",
2012         "IEC958 Playback Switch",
2013         NULL,
2014 };
2015
2016 /*
2017  * build control elements
2018  */
2019
2020 static void alc_free_kctls(struct hda_codec *codec);
2021
2022 /* additional beep mixers; the actual parameters are overwritten at build */
2023 static struct snd_kcontrol_new alc_beep_mixer[] = {
2024         HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
2025         HDA_CODEC_MUTE("Beep Playback Switch", 0, 0, HDA_INPUT),
2026         { } /* end */
2027 };
2028
2029 static int alc_build_controls(struct hda_codec *codec)
2030 {
2031         struct alc_spec *spec = codec->spec;
2032         int err;
2033         int i;
2034
2035         for (i = 0; i < spec->num_mixers; i++) {
2036                 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
2037                 if (err < 0)
2038                         return err;
2039         }
2040         if (spec->cap_mixer) {
2041                 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
2042                 if (err < 0)
2043                         return err;
2044         }
2045         if (spec->multiout.dig_out_nid) {
2046                 err = snd_hda_create_spdif_out_ctls(codec,
2047                                                     spec->multiout.dig_out_nid);
2048                 if (err < 0)
2049                         return err;
2050                 if (!spec->no_analog) {
2051                         err = snd_hda_create_spdif_share_sw(codec,
2052                                                             &spec->multiout);
2053                         if (err < 0)
2054                                 return err;
2055                         spec->multiout.share_spdif = 1;
2056                 }
2057         }
2058         if (spec->dig_in_nid) {
2059                 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
2060                 if (err < 0)
2061                         return err;
2062         }
2063
2064         /* create beep controls if needed */
2065         if (spec->beep_amp) {
2066                 struct snd_kcontrol_new *knew;
2067                 for (knew = alc_beep_mixer; knew->name; knew++) {
2068                         struct snd_kcontrol *kctl;
2069                         kctl = snd_ctl_new1(knew, codec);
2070                         if (!kctl)
2071                                 return -ENOMEM;
2072                         kctl->private_value = spec->beep_amp;
2073                         err = snd_hda_ctl_add(codec, kctl);
2074                         if (err < 0)
2075                                 return err;
2076                 }
2077         }
2078
2079         /* if we have no master control, let's create it */
2080         if (!spec->no_analog &&
2081             !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
2082                 unsigned int vmaster_tlv[4];
2083                 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
2084                                         HDA_OUTPUT, vmaster_tlv);
2085                 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
2086                                           vmaster_tlv, alc_slave_vols);
2087                 if (err < 0)
2088                         return err;
2089         }
2090         if (!spec->no_analog &&
2091             !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
2092                 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
2093                                           NULL, alc_slave_sws);
2094                 if (err < 0)
2095                         return err;
2096         }
2097
2098         alc_free_kctls(codec); /* no longer needed */
2099         return 0;
2100 }
2101
2102
2103 /*
2104  * initialize the codec volumes, etc
2105  */
2106
2107 /*
2108  * generic initialization of ADC, input mixers and output mixers
2109  */
2110 static struct hda_verb alc880_volume_init_verbs[] = {
2111         /*
2112          * Unmute ADC0-2 and set the default input to mic-in
2113          */
2114         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
2115         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2116         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
2117         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2118         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
2119         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2120
2121         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
2122          * mixer widget
2123          * Note: PASD motherboards uses the Line In 2 as the input for front
2124          * panel mic (mic 2)
2125          */
2126         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
2127         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2128         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2129         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2130         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2131         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2132         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2133         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2134
2135         /*
2136          * Set up output mixers (0x0c - 0x0f)
2137          */
2138         /* set vol=0 to output mixers */
2139         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2140         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2141         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2142         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2143         /* set up input amps for analog loopback */
2144         /* Amp Indices: DAC = 0, mixer = 1 */
2145         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2146         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2147         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2148         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2149         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2150         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2151         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2152         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2153
2154         { }
2155 };
2156
2157 /*
2158  * 3-stack pin configuration:
2159  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
2160  */
2161 static struct hda_verb alc880_pin_3stack_init_verbs[] = {
2162         /*
2163          * preset connection lists of input pins
2164          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2165          */
2166         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2167         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2168         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2169
2170         /*
2171          * Set pin mode and muting
2172          */
2173         /* set front pin widgets 0x14 for output */
2174         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2175         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2176         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2177         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2178         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2179         /* Mic2 (as headphone out) for HP output */
2180         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2181         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2182         /* Line In pin widget for input */
2183         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2184         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2185         /* Line2 (as front mic) pin widget for input and vref at 80% */
2186         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2187         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2188         /* CD pin widget for input */
2189         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2190
2191         { }
2192 };
2193
2194 /*
2195  * 5-stack pin configuration:
2196  * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
2197  * line-in/side = 0x1a, f-mic = 0x1b
2198  */
2199 static struct hda_verb alc880_pin_5stack_init_verbs[] = {
2200         /*
2201          * preset connection lists of input pins
2202          * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
2203          */
2204         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2205         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
2206
2207         /*
2208          * Set pin mode and muting
2209          */
2210         /* set pin widgets 0x14-0x17 for output */
2211         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2212         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2213         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2214         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2215         /* unmute pins for output (no gain on this amp) */
2216         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2217         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2218         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2219         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2220
2221         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2222         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2223         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2224         /* Mic2 (as headphone out) for HP output */
2225         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2226         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2227         /* Line In pin widget for input */
2228         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2229         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2230         /* Line2 (as front mic) pin widget for input and vref at 80% */
2231         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2232         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2233         /* CD pin widget for input */
2234         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2235
2236         { }
2237 };
2238
2239 /*
2240  * W810 pin configuration:
2241  * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
2242  */
2243 static struct hda_verb alc880_pin_w810_init_verbs[] = {
2244         /* hphone/speaker input selector: front DAC */
2245         {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
2246
2247         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2248         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2249         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2250         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2251         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2252         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2253
2254         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2255         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2256
2257         { }
2258 };
2259
2260 /*
2261  * Z71V pin configuration:
2262  * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
2263  */
2264 static struct hda_verb alc880_pin_z71v_init_verbs[] = {
2265         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2266         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2267         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2268         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2269
2270         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2271         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2272         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2273         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2274
2275         { }
2276 };
2277
2278 /*
2279  * 6-stack pin configuration:
2280  * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18,
2281  * f-mic = 0x19, line = 0x1a, HP = 0x1b
2282  */
2283 static struct hda_verb alc880_pin_6stack_init_verbs[] = {
2284         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2285
2286         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2287         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2288         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2289         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2290         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2291         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2292         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2293         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2294
2295         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2296         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2297         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2298         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2299         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2300         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2301         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2302         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2303         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2304
2305         { }
2306 };
2307
2308 /*
2309  * Uniwill pin configuration:
2310  * HP = 0x14, InternalSpeaker = 0x15, mic = 0x18, internal mic = 0x19,
2311  * line = 0x1a
2312  */
2313 static struct hda_verb alc880_uniwill_init_verbs[] = {
2314         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2315
2316         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2317         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2318         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2319         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2320         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2321         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2322         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2323         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2324         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2325         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2326         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2327         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2328         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2329         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2330
2331         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2332         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2333         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2334         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2335         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2336         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2337         /* {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, */
2338         /* {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
2339         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2340
2341         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2342         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
2343
2344         { }
2345 };
2346
2347 /*
2348 * Uniwill P53
2349 * HP = 0x14, InternalSpeaker = 0x15, mic = 0x19,
2350  */
2351 static struct hda_verb alc880_uniwill_p53_init_verbs[] = {
2352         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2353
2354         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2355         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2356         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2357         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2358         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2359         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2360         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2361         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2362         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2363         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2364         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
2365         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
2366
2367         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2368         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2369         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2370         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2371         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2372         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2373
2374         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2375         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_DCVOL_EVENT},
2376
2377         { }
2378 };
2379
2380 static struct hda_verb alc880_beep_init_verbs[] = {
2381         { 0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) },
2382         { }
2383 };
2384
2385 /* toggle speaker-output according to the hp-jack state */
2386 static void alc880_uniwill_hp_automute(struct hda_codec *codec)
2387 {
2388         unsigned int present;
2389         unsigned char bits;
2390
2391         present = snd_hda_codec_read(codec, 0x14, 0,
2392                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2393         bits = present ? HDA_AMP_MUTE : 0;
2394         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
2395                                  HDA_AMP_MUTE, bits);
2396         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
2397                                  HDA_AMP_MUTE, bits);
2398 }
2399
2400 /* auto-toggle front mic */
2401 static void alc880_uniwill_mic_automute(struct hda_codec *codec)
2402 {
2403         unsigned int present;
2404         unsigned char bits;
2405
2406         present = snd_hda_codec_read(codec, 0x18, 0,
2407                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2408         bits = present ? HDA_AMP_MUTE : 0;
2409         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
2410 }
2411
2412 static void alc880_uniwill_automute(struct hda_codec *codec)
2413 {
2414         alc880_uniwill_hp_automute(codec);
2415         alc880_uniwill_mic_automute(codec);
2416 }
2417
2418 static void alc880_uniwill_unsol_event(struct hda_codec *codec,
2419                                        unsigned int res)
2420 {
2421         /* Looks like the unsol event is incompatible with the standard
2422          * definition.  4bit tag is placed at 28 bit!
2423          */
2424         switch (res >> 28) {
2425         case ALC880_HP_EVENT:
2426                 alc880_uniwill_hp_automute(codec);
2427                 break;
2428         case ALC880_MIC_EVENT:
2429                 alc880_uniwill_mic_automute(codec);
2430                 break;
2431         }
2432 }
2433
2434 static void alc880_uniwill_p53_hp_automute(struct hda_codec *codec)
2435 {
2436         unsigned int present;
2437         unsigned char bits;
2438
2439         present = snd_hda_codec_read(codec, 0x14, 0,
2440                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2441         bits = present ? HDA_AMP_MUTE : 0;
2442         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, HDA_AMP_MUTE, bits);
2443 }
2444
2445 static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
2446 {
2447         unsigned int present;
2448
2449         present = snd_hda_codec_read(codec, 0x21, 0,
2450                                      AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
2451         present &= HDA_AMP_VOLMASK;
2452         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0,
2453                                  HDA_AMP_VOLMASK, present);
2454         snd_hda_codec_amp_stereo(codec, 0x0d, HDA_OUTPUT, 0,
2455                                  HDA_AMP_VOLMASK, present);
2456 }
2457
2458 static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
2459                                            unsigned int res)
2460 {
2461         /* Looks like the unsol event is incompatible with the standard
2462          * definition.  4bit tag is placed at 28 bit!
2463          */
2464         if ((res >> 28) == ALC880_HP_EVENT)
2465                 alc880_uniwill_p53_hp_automute(codec);
2466         if ((res >> 28) == ALC880_DCVOL_EVENT)
2467                 alc880_uniwill_p53_dcvol_automute(codec);
2468 }
2469
2470 /*
2471  * F1734 pin configuration:
2472  * HP = 0x14, speaker-out = 0x15, mic = 0x18
2473  */
2474 static struct hda_verb alc880_pin_f1734_init_verbs[] = {
2475         {0x07, AC_VERB_SET_CONNECT_SEL, 0x01},
2476         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2477         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2478         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2479         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2480
2481         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2482         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2483         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2484         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2485
2486         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2487         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2488         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
2489         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2490         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2491         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2492         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2493         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2494         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2495
2496         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
2497         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_DCVOL_EVENT},
2498
2499         { }
2500 };
2501
2502 /*
2503  * ASUS pin configuration:
2504  * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
2505  */
2506 static struct hda_verb alc880_pin_asus_init_verbs[] = {
2507         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
2508         {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
2509         {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
2510         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
2511
2512         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2513         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2514         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2515         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2516         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2517         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2518         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2519         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2520
2521         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2522         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2523         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2524         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2525         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2526         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2527         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2528         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2529         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2530
2531         { }
2532 };
2533
2534 /* Enable GPIO mask and set output */
2535 #define alc880_gpio1_init_verbs alc_gpio1_init_verbs
2536 #define alc880_gpio2_init_verbs alc_gpio2_init_verbs
2537
2538 /* Clevo m520g init */
2539 static struct hda_verb alc880_pin_clevo_init_verbs[] = {
2540         /* headphone output */
2541         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2542         /* line-out */
2543         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2544         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2545         /* Line-in */
2546         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2547         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2548         /* CD */
2549         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2550         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2551         /* Mic1 (rear panel) */
2552         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2553         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2554         /* Mic2 (front panel) */
2555         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2556         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2557         /* headphone */
2558         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2559         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2560         /* change to EAPD mode */
2561         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2562         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2563
2564         { }
2565 };
2566
2567 static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
2568         /* change to EAPD mode */
2569         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2570         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2571
2572         /* Headphone output */
2573         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2574         /* Front output*/
2575         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2576         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
2577
2578         /* Line In pin widget for input */
2579         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2580         /* CD pin widget for input */
2581         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2582         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2583         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2584
2585         /* change to EAPD mode */
2586         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2587         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
2588
2589         { }
2590 };
2591
2592 /*
2593  * LG m1 express dual
2594  *
2595  * Pin assignment:
2596  *   Rear Line-In/Out (blue): 0x14
2597  *   Build-in Mic-In: 0x15
2598  *   Speaker-out: 0x17
2599  *   HP-Out (green): 0x1b
2600  *   Mic-In/Out (red): 0x19
2601  *   SPDIF-Out: 0x1e
2602  */
2603
2604 /* To make 5.1 output working (green=Front, blue=Surr, red=CLFE) */
2605 static hda_nid_t alc880_lg_dac_nids[3] = {
2606         0x05, 0x02, 0x03
2607 };
2608
2609 /* seems analog CD is not working */
2610 static struct hda_input_mux alc880_lg_capture_source = {
2611         .num_items = 3,
2612         .items = {
2613                 { "Mic", 0x1 },
2614                 { "Line", 0x5 },
2615                 { "Internal Mic", 0x6 },
2616         },
2617 };
2618
2619 /* 2,4,6 channel modes */
2620 static struct hda_verb alc880_lg_ch2_init[] = {
2621         /* set line-in and mic-in to input */
2622         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2623         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2624         { }
2625 };
2626
2627 static struct hda_verb alc880_lg_ch4_init[] = {
2628         /* set line-in to out and mic-in to input */
2629         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2630         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2631         { }
2632 };
2633
2634 static struct hda_verb alc880_lg_ch6_init[] = {
2635         /* set line-in and mic-in to output */
2636         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2637         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
2638         { }
2639 };
2640
2641 static struct hda_channel_mode alc880_lg_ch_modes[3] = {
2642         { 2, alc880_lg_ch2_init },
2643         { 4, alc880_lg_ch4_init },
2644         { 6, alc880_lg_ch6_init },
2645 };
2646
2647 static struct snd_kcontrol_new alc880_lg_mixer[] = {
2648         HDA_CODEC_VOLUME("Front Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2649         HDA_BIND_MUTE("Front Playback Switch", 0x0f, 2, HDA_INPUT),
2650         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2651         HDA_BIND_MUTE("Surround Playback Switch", 0x0c, 2, HDA_INPUT),
2652         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
2653         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
2654         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
2655         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
2656         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2657         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
2658         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x06, HDA_INPUT),
2659         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x06, HDA_INPUT),
2660         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x07, HDA_INPUT),
2661         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x07, HDA_INPUT),
2662         {
2663                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2664                 .name = "Channel Mode",
2665                 .info = alc_ch_mode_info,
2666                 .get = alc_ch_mode_get,
2667                 .put = alc_ch_mode_put,
2668         },
2669         { } /* end */
2670 };
2671
2672 static struct hda_verb alc880_lg_init_verbs[] = {
2673         /* set capture source to mic-in */
2674         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2675         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2676         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2677         /* mute all amp mixer inputs */
2678         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)},
2679         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2680         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2681         /* line-in to input */
2682         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2683         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2684         /* built-in mic */
2685         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2686         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2687         /* speaker-out */
2688         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2689         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2690         /* mic-in to input */
2691         {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
2692         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2693         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2694         /* HP-out */
2695         {0x13, AC_VERB_SET_CONNECT_SEL, 0x03},
2696         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2697         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2698         /* jack sense */
2699         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2700         { }
2701 };
2702
2703 /* toggle speaker-output according to the hp-jack state */
2704 static void alc880_lg_automute(struct hda_codec *codec)
2705 {
2706         unsigned int present;
2707         unsigned char bits;
2708
2709         present = snd_hda_codec_read(codec, 0x1b, 0,
2710                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2711         bits = present ? HDA_AMP_MUTE : 0;
2712         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
2713                                  HDA_AMP_MUTE, bits);
2714 }
2715
2716 static void alc880_lg_unsol_event(struct hda_codec *codec, unsigned int res)
2717 {
2718         /* Looks like the unsol event is incompatible with the standard
2719          * definition.  4bit tag is placed at 28 bit!
2720          */
2721         if ((res >> 28) == 0x01)
2722                 alc880_lg_automute(codec);
2723 }
2724
2725 /*
2726  * LG LW20
2727  *
2728  * Pin assignment:
2729  *   Speaker-out: 0x14
2730  *   Mic-In: 0x18
2731  *   Built-in Mic-In: 0x19
2732  *   Line-In: 0x1b
2733  *   HP-Out: 0x1a
2734  *   SPDIF-Out: 0x1e
2735  */
2736
2737 static struct hda_input_mux alc880_lg_lw_capture_source = {
2738         .num_items = 3,
2739         .items = {
2740                 { "Mic", 0x0 },
2741                 { "Internal Mic", 0x1 },
2742                 { "Line In", 0x2 },
2743         },
2744 };
2745
2746 #define alc880_lg_lw_modes alc880_threestack_modes
2747
2748 static struct snd_kcontrol_new alc880_lg_lw_mixer[] = {
2749         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2750         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2751         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2752         HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
2753         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2754         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2755         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2756         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2757         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
2758         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
2759         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2760         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2761         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
2762         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
2763         {
2764                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2765                 .name = "Channel Mode",
2766                 .info = alc_ch_mode_info,
2767                 .get = alc_ch_mode_get,
2768                 .put = alc_ch_mode_put,
2769         },
2770         { } /* end */
2771 };
2772
2773 static struct hda_verb alc880_lg_lw_init_verbs[] = {
2774         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2775         {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
2776         {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
2777
2778         /* set capture source to mic-in */
2779         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2780         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2781         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2782         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2783         /* speaker-out */
2784         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2785         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2786         /* HP-out */
2787         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2788         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2789         /* mic-in to input */
2790         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2791         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2792         /* built-in mic */
2793         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2794         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2795         /* jack sense */
2796         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | 0x1},
2797         { }
2798 };
2799
2800 /* toggle speaker-output according to the hp-jack state */
2801 static void alc880_lg_lw_automute(struct hda_codec *codec)
2802 {
2803         unsigned int present;
2804         unsigned char bits;
2805
2806         present = snd_hda_codec_read(codec, 0x1b, 0,
2807                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2808         bits = present ? HDA_AMP_MUTE : 0;
2809         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
2810                                  HDA_AMP_MUTE, bits);
2811 }
2812
2813 static void alc880_lg_lw_unsol_event(struct hda_codec *codec, unsigned int res)
2814 {
2815         /* Looks like the unsol event is incompatible with the standard
2816          * definition.  4bit tag is placed at 28 bit!
2817          */
2818         if ((res >> 28) == 0x01)
2819                 alc880_lg_lw_automute(codec);
2820 }
2821
2822 static struct snd_kcontrol_new alc880_medion_rim_mixer[] = {
2823         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2824         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
2825         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
2826         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
2827         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
2828         HDA_CODEC_MUTE("Internal Playback Switch", 0x0b, 0x1, HDA_INPUT),
2829         { } /* end */
2830 };
2831
2832 static struct hda_input_mux alc880_medion_rim_capture_source = {
2833         .num_items = 2,
2834         .items = {
2835                 { "Mic", 0x0 },
2836                 { "Internal Mic", 0x1 },
2837         },
2838 };
2839
2840 static struct hda_verb alc880_medion_rim_init_verbs[] = {
2841         {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
2842
2843         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2844         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2845
2846         /* Mic1 (rear panel) pin widget for input and vref at 80% */
2847         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2848         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2849         /* Mic2 (as headphone out) for HP output */
2850         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2851         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2852         /* Internal Speaker */
2853         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2854         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2855
2856         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
2857         {0x20, AC_VERB_SET_PROC_COEF,  0x3060},
2858
2859         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
2860         { }
2861 };
2862
2863 /* toggle speaker-output according to the hp-jack state */
2864 static void alc880_medion_rim_automute(struct hda_codec *codec)
2865 {
2866         unsigned int present;
2867         unsigned char bits;
2868
2869         present = snd_hda_codec_read(codec, 0x14, 0,
2870                                      AC_VERB_GET_PIN_SENSE, 0)
2871                 & AC_PINSENSE_PRESENCE;
2872         bits = present ? HDA_AMP_MUTE : 0;
2873         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
2874                                  HDA_AMP_MUTE, bits);
2875         if (present)
2876                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0);
2877         else
2878                 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 2);
2879 }
2880
2881 static void alc880_medion_rim_unsol_event(struct hda_codec *codec,
2882                                           unsigned int res)
2883 {
2884         /* Looks like the unsol event is incompatible with the standard
2885          * definition.  4bit tag is placed at 28 bit!
2886          */
2887         if ((res >> 28) == ALC880_HP_EVENT)
2888                 alc880_medion_rim_automute(codec);
2889 }
2890
2891 #ifdef CONFIG_SND_HDA_POWER_SAVE
2892 static struct hda_amp_list alc880_loopbacks[] = {
2893         { 0x0b, HDA_INPUT, 0 },
2894         { 0x0b, HDA_INPUT, 1 },
2895         { 0x0b, HDA_INPUT, 2 },
2896         { 0x0b, HDA_INPUT, 3 },
2897         { 0x0b, HDA_INPUT, 4 },
2898         { } /* end */
2899 };
2900
2901 static struct hda_amp_list alc880_lg_loopbacks[] = {
2902         { 0x0b, HDA_INPUT, 1 },
2903         { 0x0b, HDA_INPUT, 6 },
2904         { 0x0b, HDA_INPUT, 7 },
2905         { } /* end */
2906 };
2907 #endif
2908
2909 /*
2910  * Common callbacks
2911  */
2912
2913 static int alc_init(struct hda_codec *codec)
2914 {
2915         struct alc_spec *spec = codec->spec;
2916         unsigned int i;
2917
2918         alc_fix_pll(codec);
2919         if (codec->vendor_id == 0x10ec0888)
2920                 alc888_coef_init(codec);
2921
2922         for (i = 0; i < spec->num_init_verbs; i++)
2923                 snd_hda_sequence_write(codec, spec->init_verbs[i]);
2924
2925         if (spec->init_hook)
2926                 spec->init_hook(codec);
2927
2928         return 0;
2929 }
2930
2931 static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2932 {
2933         struct alc_spec *spec = codec->spec;
2934
2935         if (spec->unsol_event)
2936                 spec->unsol_event(codec, res);
2937 }
2938
2939 #ifdef CONFIG_SND_HDA_POWER_SAVE
2940 static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2941 {
2942         struct alc_spec *spec = codec->spec;
2943         return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2944 }
2945 #endif
2946
2947 /*
2948  * Analog playback callbacks
2949  */
2950 static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
2951                                     struct hda_codec *codec,
2952                                     struct snd_pcm_substream *substream)
2953 {
2954         struct alc_spec *spec = codec->spec;
2955         return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2956                                              hinfo);
2957 }
2958
2959 static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2960                                        struct hda_codec *codec,
2961                                        unsigned int stream_tag,
2962                                        unsigned int format,
2963                                        struct snd_pcm_substream *substream)
2964 {
2965         struct alc_spec *spec = codec->spec;
2966         return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2967                                                 stream_tag, format, substream);
2968 }
2969
2970 static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2971                                        struct hda_codec *codec,
2972                                        struct snd_pcm_substream *substream)
2973 {
2974         struct alc_spec *spec = codec->spec;
2975         return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2976 }
2977
2978 /*
2979  * Digital out
2980  */
2981 static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2982                                         struct hda_codec *codec,
2983                                         struct snd_pcm_substream *substream)
2984 {
2985         struct alc_spec *spec = codec->spec;
2986         return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2987 }
2988
2989 static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2990                                            struct hda_codec *codec,
2991                                            unsigned int stream_tag,
2992                                            unsigned int format,
2993                                            struct snd_pcm_substream *substream)
2994 {
2995         struct alc_spec *spec = codec->spec;
2996         return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2997                                              stream_tag, format, substream);
2998 }
2999
3000 static int alc880_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
3001                                            struct hda_codec *codec,
3002                                            struct snd_pcm_substream *substream)
3003 {
3004         struct alc_spec *spec = codec->spec;
3005         return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
3006 }
3007
3008 static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
3009                                          struct hda_codec *codec,
3010                                          struct snd_pcm_substream *substream)
3011 {
3012         struct alc_spec *spec = codec->spec;
3013         return snd_hda_multi_out_dig_close(codec, &spec->multiout);
3014 }
3015
3016 /*
3017  * Analog capture
3018  */
3019 static int alc880_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3020                                       struct hda_codec *codec,
3021                                       unsigned int stream_tag,
3022                                       unsigned int format,
3023                                       struct snd_pcm_substream *substream)
3024 {
3025         struct alc_spec *spec = codec->spec;
3026
3027         snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
3028                                    stream_tag, 0, format);
3029         return 0;
3030 }
3031
3032 static int alc880_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3033                                       struct hda_codec *codec,
3034                                       struct snd_pcm_substream *substream)
3035 {
3036         struct alc_spec *spec = codec->spec;
3037
3038         snd_hda_codec_cleanup_stream(codec,
3039                                      spec->adc_nids[substream->number + 1]);
3040         return 0;
3041 }
3042
3043
3044 /*
3045  */
3046 static struct hda_pcm_stream alc880_pcm_analog_playback = {
3047         .substreams = 1,
3048         .channels_min = 2,
3049         .channels_max = 8,
3050         /* NID is set in alc_build_pcms */
3051         .ops = {
3052                 .open = alc880_playback_pcm_open,
3053                 .prepare = alc880_playback_pcm_prepare,
3054                 .cleanup = alc880_playback_pcm_cleanup
3055         },
3056 };
3057
3058 static struct hda_pcm_stream alc880_pcm_analog_capture = {
3059         .substreams = 1,
3060         .channels_min = 2,
3061         .channels_max = 2,
3062         /* NID is set in alc_build_pcms */
3063 };
3064
3065 static struct hda_pcm_stream alc880_pcm_analog_alt_playback = {
3066         .substreams = 1,
3067         .channels_min = 2,
3068         .channels_max = 2,
3069         /* NID is set in alc_build_pcms */
3070 };
3071
3072 static struct hda_pcm_stream alc880_pcm_analog_alt_capture = {
3073         .substreams = 2, /* can be overridden */
3074         .channels_min = 2,
3075         .channels_max = 2,
3076         /* NID is set in alc_build_pcms */
3077         .ops = {
3078                 .prepare = alc880_alt_capture_pcm_prepare,
3079                 .cleanup = alc880_alt_capture_pcm_cleanup
3080         },
3081 };
3082
3083 static struct hda_pcm_stream alc880_pcm_digital_playback = {
3084         .substreams = 1,
3085         .channels_min = 2,
3086         .channels_max = 2,
3087         /* NID is set in alc_build_pcms */
3088         .ops = {
3089                 .open = alc880_dig_playback_pcm_open,
3090                 .close = alc880_dig_playback_pcm_close,
3091                 .prepare = alc880_dig_playback_pcm_prepare,
3092                 .cleanup = alc880_dig_playback_pcm_cleanup
3093         },
3094 };
3095
3096 static struct hda_pcm_stream alc880_pcm_digital_capture = {
3097         .substreams = 1,
3098         .channels_min = 2,
3099         .channels_max = 2,
3100         /* NID is set in alc_build_pcms */
3101 };
3102
3103 /* Used by alc_build_pcms to flag that a PCM has no playback stream */
3104 static struct hda_pcm_stream alc_pcm_null_stream = {
3105         .substreams = 0,
3106         .channels_min = 0,
3107         .channels_max = 0,
3108 };
3109
3110 static int alc_build_pcms(struct hda_codec *codec)
3111 {
3112         struct alc_spec *spec = codec->spec;
3113         struct hda_pcm *info = spec->pcm_rec;
3114         int i;
3115
3116         codec->num_pcms = 1;
3117         codec->pcm_info = info;
3118
3119         if (spec->no_analog)
3120                 goto skip_analog;
3121
3122         info->name = spec->stream_name_analog;
3123         if (spec->stream_analog_playback) {
3124                 if (snd_BUG_ON(!spec->multiout.dac_nids))
3125                         return -EINVAL;
3126                 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
3127                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
3128         }
3129         if (spec->stream_analog_capture) {
3130                 if (snd_BUG_ON(!spec->adc_nids))
3131                         return -EINVAL;
3132                 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
3133                 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
3134         }
3135
3136         if (spec->channel_mode) {
3137                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
3138                 for (i = 0; i < spec->num_channel_mode; i++) {
3139                         if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
3140                                 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
3141                         }
3142                 }
3143         }
3144
3145  skip_analog:
3146         /* SPDIF for stream index #1 */
3147         if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
3148                 codec->num_pcms = 2;
3149                 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
3150                 info = spec->pcm_rec + 1;
3151                 info->name = spec->stream_name_digital;
3152                 if (spec->dig_out_type)
3153                         info->pcm_type = spec->dig_out_type;
3154                 else
3155                         info->pcm_type = HDA_PCM_TYPE_SPDIF;
3156                 if (spec->multiout.dig_out_nid &&
3157                     spec->stream_digital_playback) {
3158                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
3159                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
3160                 }
3161                 if (spec->dig_in_nid &&
3162                     spec->stream_digital_capture) {
3163                         info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
3164                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
3165                 }
3166                 /* FIXME: do we need this for all Realtek codec models? */
3167                 codec->spdif_status_reset = 1;
3168         }
3169
3170         if (spec->no_analog)
3171                 return 0;
3172
3173         /* If the use of more than one ADC is requested for the current
3174          * model, configure a second analog capture-only PCM.
3175          */
3176         /* Additional Analaog capture for index #2 */
3177         if ((spec->alt_dac_nid && spec->stream_analog_alt_playback) ||
3178             (spec->num_adc_nids > 1 && spec->stream_analog_alt_capture)) {
3179                 codec->num_pcms = 3;
3180                 info = spec->pcm_rec + 2;
3181                 info->name = spec->stream_name_analog;
3182                 if (spec->alt_dac_nid) {
3183                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
3184                                 *spec->stream_analog_alt_playback;
3185                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
3186                                 spec->alt_dac_nid;
3187                 } else {
3188                         info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
3189                                 alc_pcm_null_stream;
3190                         info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
3191                 }
3192                 if (spec->num_adc_nids > 1) {
3193                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
3194                                 *spec->stream_analog_alt_capture;
3195                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
3196                                 spec->adc_nids[1];
3197                         info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
3198                                 spec->num_adc_nids - 1;
3199                 } else {
3200                         info->stream[SNDRV_PCM_STREAM_CAPTURE] =
3201                                 alc_pcm_null_stream;
3202                         info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
3203                 }
3204         }
3205
3206         return 0;
3207 }
3208
3209 static void alc_free_kctls(struct hda_codec *codec)
3210 {
3211         struct alc_spec *spec = codec->spec;
3212
3213         if (spec->kctls.list) {
3214                 struct snd_kcontrol_new *kctl = spec->kctls.list;
3215                 int i;
3216                 for (i = 0; i < spec->kctls.used; i++)
3217                         kfree(kctl[i].name);
3218         }
3219         snd_array_free(&spec->kctls);
3220 }
3221
3222 static void alc_free(struct hda_codec *codec)
3223 {
3224         struct alc_spec *spec = codec->spec;
3225
3226         if (!spec)
3227                 return;
3228
3229         alc_free_kctls(codec);
3230         kfree(spec);
3231         snd_hda_detach_beep_device(codec);
3232 }
3233
3234 #ifdef SND_HDA_NEEDS_RESUME
3235 static int alc_resume(struct hda_codec *codec)
3236 {
3237         codec->patch_ops.init(codec);
3238         snd_hda_codec_resume_amp(codec);
3239         snd_hda_codec_resume_cache(codec);
3240         return 0;
3241 }
3242 #endif
3243
3244 /*
3245  */
3246 static struct hda_codec_ops alc_patch_ops = {
3247         .build_controls = alc_build_controls,
3248         .build_pcms = alc_build_pcms,
3249         .init = alc_init,
3250         .free = alc_free,
3251         .unsol_event = alc_unsol_event,
3252 #ifdef SND_HDA_NEEDS_RESUME
3253         .resume = alc_resume,
3254 #endif
3255 #ifdef CONFIG_SND_HDA_POWER_SAVE
3256         .check_power_status = alc_check_power_status,
3257 #endif
3258 };
3259
3260
3261 /*
3262  * Test configuration for debugging
3263  *
3264  * Almost all inputs/outputs are enabled.  I/O pins can be configured via
3265  * enum controls.
3266  */
3267 #ifdef CONFIG_SND_DEBUG
3268 static hda_nid_t alc880_test_dac_nids[4] = {
3269         0x02, 0x03, 0x04, 0x05
3270 };
3271
3272 static struct hda_input_mux alc880_test_capture_source = {
3273         .num_items = 7,
3274         .items = {
3275                 { "In-1", 0x0 },
3276                 { "In-2", 0x1 },
3277                 { "In-3", 0x2 },
3278                 { "In-4", 0x3 },
3279                 { "CD", 0x4 },
3280                 { "Front", 0x5 },
3281                 { "Surround", 0x6 },
3282         },
3283 };
3284
3285 static struct hda_channel_mode alc880_test_modes[4] = {
3286         { 2, NULL },
3287         { 4, NULL },
3288         { 6, NULL },
3289         { 8, NULL },
3290 };
3291
3292 static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol,
3293                                  struct snd_ctl_elem_info *uinfo)
3294 {
3295         static char *texts[] = {
3296                 "N/A", "Line Out", "HP Out",
3297                 "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
3298         };
3299         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3300         uinfo->count = 1;
3301         uinfo->value.enumerated.items = 8;
3302         if (uinfo->value.enumerated.item >= 8)
3303                 uinfo->value.enumerated.item = 7;
3304         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3305         return 0;
3306 }
3307
3308 static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol,
3309                                 struct snd_ctl_elem_value *ucontrol)
3310 {
3311         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3312         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3313         unsigned int pin_ctl, item = 0;
3314
3315         pin_ctl = snd_hda_codec_read(codec, nid, 0,
3316                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3317         if (pin_ctl & AC_PINCTL_OUT_EN) {
3318                 if (pin_ctl & AC_PINCTL_HP_EN)
3319                         item = 2;
3320                 else
3321                         item = 1;
3322         } else if (pin_ctl & AC_PINCTL_IN_EN) {
3323                 switch (pin_ctl & AC_PINCTL_VREFEN) {
3324                 case AC_PINCTL_VREF_HIZ: item = 3; break;
3325                 case AC_PINCTL_VREF_50:  item = 4; break;
3326                 case AC_PINCTL_VREF_GRD: item = 5; break;
3327                 case AC_PINCTL_VREF_80:  item = 6; break;
3328                 case AC_PINCTL_VREF_100: item = 7; break;
3329                 }
3330         }
3331         ucontrol->value.enumerated.item[0] = item;
3332         return 0;
3333 }
3334
3335 static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol,
3336                                 struct snd_ctl_elem_value *ucontrol)
3337 {
3338         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3339         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3340         static unsigned int ctls[] = {
3341                 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
3342                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
3343                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
3344                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
3345                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
3346                 AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
3347         };
3348         unsigned int old_ctl, new_ctl;
3349
3350         old_ctl = snd_hda_codec_read(codec, nid, 0,
3351                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3352         new_ctl = ctls[ucontrol->value.enumerated.item[0]];
3353         if (old_ctl != new_ctl) {
3354                 int val;
3355                 snd_hda_codec_write_cache(codec, nid, 0,
3356                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
3357                                           new_ctl);
3358                 val = ucontrol->value.enumerated.item[0] >= 3 ?
3359                         HDA_AMP_MUTE : 0;
3360                 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3361                                          HDA_AMP_MUTE, val);
3362                 return 1;
3363         }
3364         return 0;
3365 }
3366
3367 static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol,
3368                                  struct snd_ctl_elem_info *uinfo)
3369 {
3370         static char *texts[] = {
3371                 "Front", "Surround", "CLFE", "Side"
3372         };
3373         uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3374         uinfo->count = 1;
3375         uinfo->value.enumerated.items = 4;
3376         if (uinfo->value.enumerated.item >= 4)
3377                 uinfo->value.enumerated.item = 3;
3378         strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
3379         return 0;
3380 }
3381
3382 static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol,
3383                                 struct snd_ctl_elem_value *ucontrol)
3384 {
3385         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3386         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3387         unsigned int sel;
3388
3389         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
3390         ucontrol->value.enumerated.item[0] = sel & 3;
3391         return 0;
3392 }
3393
3394 static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol,
3395                                 struct snd_ctl_elem_value *ucontrol)
3396 {
3397         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3398         hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
3399         unsigned int sel;
3400
3401         sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
3402         if (ucontrol->value.enumerated.item[0] != sel) {
3403                 sel = ucontrol->value.enumerated.item[0] & 3;
3404                 snd_hda_codec_write_cache(codec, nid, 0,
3405                                           AC_VERB_SET_CONNECT_SEL, sel);
3406                 return 1;
3407         }
3408         return 0;
3409 }
3410
3411 #define PIN_CTL_TEST(xname,nid) {                       \
3412                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3413                         .name = xname,                 \
3414                         .info = alc_test_pin_ctl_info, \
3415                         .get = alc_test_pin_ctl_get,   \
3416                         .put = alc_test_pin_ctl_put,   \
3417                         .private_value = nid           \
3418                         }
3419
3420 #define PIN_SRC_TEST(xname,nid) {                       \
3421                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,    \
3422                         .name = xname,                 \
3423                         .info = alc_test_pin_src_info, \
3424                         .get = alc_test_pin_src_get,   \
3425                         .put = alc_test_pin_src_put,   \
3426                         .private_value = nid           \
3427                         }
3428
3429 static struct snd_kcontrol_new alc880_test_mixer[] = {
3430         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
3431         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
3432         HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
3433         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
3434         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
3435         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
3436         HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
3437         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
3438         PIN_CTL_TEST("Front Pin Mode", 0x14),
3439         PIN_CTL_TEST("Surround Pin Mode", 0x15),
3440         PIN_CTL_TEST("CLFE Pin Mode", 0x16),
3441         PIN_CTL_TEST("Side Pin Mode", 0x17),
3442         PIN_CTL_TEST("In-1 Pin Mode", 0x18),
3443         PIN_CTL_TEST("In-2 Pin Mode", 0x19),
3444         PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
3445         PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
3446         PIN_SRC_TEST("In-1 Pin Source", 0x18),
3447         PIN_SRC_TEST("In-2 Pin Source", 0x19),
3448         PIN_SRC_TEST("In-3 Pin Source", 0x1a),
3449         PIN_SRC_TEST("In-4 Pin Source", 0x1b),
3450         HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
3451         HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
3452         HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
3453         HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
3454         HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
3455         HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
3456         HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
3457         HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
3458         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
3459         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
3460         {
3461                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3462                 .name = "Channel Mode",
3463                 .info = alc_ch_mode_info,
3464                 .get = alc_ch_mode_get,
3465                 .put = alc_ch_mode_put,
3466         },
3467         { } /* end */
3468 };
3469
3470 static struct hda_verb alc880_test_init_verbs[] = {
3471         /* Unmute inputs of 0x0c - 0x0f */
3472         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3473         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3474         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3475         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3476         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3477         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3478         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3479         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3480         /* Vol output for 0x0c-0x0f */
3481         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3482         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3483         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3484         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3485         /* Set output pins 0x14-0x17 */
3486         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3487         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3488         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3489         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3490         /* Unmute output pins 0x14-0x17 */
3491         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3492         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3493         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3494         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3495         /* Set input pins 0x18-0x1c */
3496         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3497         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3498         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3499         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3500         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3501         /* Mute input pins 0x18-0x1b */
3502         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3503         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3504         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3505         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3506         /* ADC set up */
3507         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3508         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
3509         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3510         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
3511         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3512         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
3513         /* Analog input/passthru */
3514         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3515         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3516         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3517         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3518         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3519         { }
3520 };
3521 #endif
3522
3523 /*
3524  */
3525
3526 static const char *alc880_models[ALC880_MODEL_LAST] = {
3527         [ALC880_3ST]            = "3stack",
3528         [ALC880_TCL_S700]       = "tcl",
3529         [ALC880_3ST_DIG]        = "3stack-digout",
3530         [ALC880_CLEVO]          = "clevo",
3531         [ALC880_5ST]            = "5stack",
3532         [ALC880_5ST_DIG]        = "5stack-digout",
3533         [ALC880_W810]           = "w810",
3534         [ALC880_Z71V]           = "z71v",
3535         [ALC880_6ST]            = "6stack",
3536         [ALC880_6ST_DIG]        = "6stack-digout",
3537         [ALC880_ASUS]           = "asus",
3538         [ALC880_ASUS_W1V]       = "asus-w1v",
3539         [ALC880_ASUS_DIG]       = "asus-dig",
3540         [ALC880_ASUS_DIG2]      = "asus-dig2",
3541         [ALC880_UNIWILL_DIG]    = "uniwill",
3542         [ALC880_UNIWILL_P53]    = "uniwill-p53",
3543         [ALC880_FUJITSU]        = "fujitsu",
3544         [ALC880_F1734]          = "F1734",
3545         [ALC880_LG]             = "lg",
3546         [ALC880_LG_LW]          = "lg-lw",
3547         [ALC880_MEDION_RIM]     = "medion",
3548 #ifdef CONFIG_SND_DEBUG
3549         [ALC880_TEST]           = "test",
3550 #endif
3551         [ALC880_AUTO]           = "auto",
3552 };
3553
3554 static struct snd_pci_quirk alc880_cfg_tbl[] = {
3555         SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_W810),
3556         SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_5ST_DIG),
3557         SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_6ST),
3558         SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_3ST_DIG),
3559         SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_6ST_DIG),
3560         SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_6ST_DIG),
3561         SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_6ST_DIG),
3562         SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_3ST_DIG),
3563         SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_3ST),
3564         SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_6ST_DIG),
3565         SND_PCI_QUIRK(0x103c, 0x2a09, "HP", ALC880_5ST),
3566         SND_PCI_QUIRK(0x1043, 0x10b3, "ASUS W1V", ALC880_ASUS_W1V),
3567         SND_PCI_QUIRK(0x1043, 0x10c2, "ASUS W6A", ALC880_ASUS_DIG),
3568         SND_PCI_QUIRK(0x1043, 0x10c3, "ASUS Wxx", ALC880_ASUS_DIG),
3569         SND_PCI_QUIRK(0x1043, 0x1113, "ASUS", ALC880_ASUS_DIG),
3570         SND_PCI_QUIRK(0x1043, 0x1123, "ASUS", ALC880_ASUS_DIG),
3571         SND_PCI_QUIRK(0x1043, 0x1173, "ASUS", ALC880_ASUS_DIG),
3572         SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_Z71V),
3573         /* SND_PCI_QUIRK(0x1043, 0x1964, "ASUS", ALC880_ASUS_DIG), */
3574         SND_PCI_QUIRK(0x1043, 0x1973, "ASUS", ALC880_ASUS_DIG),
3575         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS", ALC880_ASUS_DIG),
3576         SND_PCI_QUIRK(0x1043, 0x814e, "ASUS P5GD1 w/SPDIF", ALC880_6ST_DIG),
3577         SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
3578         SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
3579         SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
3580         SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_ASUS), /* default ASUS */
3581         SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
3582         SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
3583         SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
3584         SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_5ST),
3585         SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_5ST),
3586         SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_6ST_DIG),
3587         SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_6ST_DIG),
3588         SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_6ST_DIG),
3589         SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_6ST_DIG),
3590         SND_PCI_QUIRK(0x1558, 0x0520, "Clevo m520G", ALC880_CLEVO),
3591         SND_PCI_QUIRK(0x1558, 0x0660, "Clevo m655n", ALC880_CLEVO),
3592         SND_PCI_QUIRK(0x1558, 0x5401, "ASUS", ALC880_ASUS_DIG2),
3593         SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_5ST_DIG),
3594         SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_UNIWILL_DIG),
3595         SND_PCI_QUIRK(0x1584, 0x9054, "Uniwlll", ALC880_F1734),
3596         SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_UNIWILL),
3597         SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_UNIWILL_P53),
3598         SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_W810),
3599         SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_MEDION_RIM),
3600         SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_5ST_DIG),
3601         SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_5ST_DIG),
3602         SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_F1734),
3603         SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FUJITSU),
3604         SND_PCI_QUIRK(0x1734, 0x10ac, "FSC", ALC880_UNIWILL),
3605         SND_PCI_QUIRK(0x1734, 0x10b0, "Fujitsu", ALC880_FUJITSU),
3606         SND_PCI_QUIRK(0x1854, 0x0018, "LG LW20", ALC880_LG_LW),
3607         SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_LG),
3608         SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_LG),
3609         SND_PCI_QUIRK(0x1854, 0x0077, "LG LW25", ALC880_LG_LW),
3610         SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_TCL_S700),
3611         SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_6ST_DIG), /* broken BIOS */
3612         SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_6ST_DIG),
3613         SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_5ST_DIG),
3614         SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_5ST_DIG),
3615         SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_5ST_DIG),
3616         SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_3ST_DIG),
3617         SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_5ST_DIG),
3618         SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_3ST_DIG),
3619         SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_3ST_DIG),
3620         SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
3621         SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
3622         SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
3623         /* default Intel */
3624         SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_3ST),
3625         SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
3626         SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
3627         {}
3628 };
3629
3630 /*
3631  * ALC880 codec presets
3632  */
3633 static struct alc_config_preset alc880_presets[] = {
3634         [ALC880_3ST] = {
3635                 .mixers = { alc880_three_stack_mixer },
3636                 .init_verbs = { alc880_volume_init_verbs,
3637                                 alc880_pin_3stack_init_verbs },
3638                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3639                 .dac_nids = alc880_dac_nids,
3640                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3641                 .channel_mode = alc880_threestack_modes,
3642                 .need_dac_fix = 1,
3643                 .input_mux = &alc880_capture_source,
3644         },
3645         [ALC880_3ST_DIG] = {
3646                 .mixers = { alc880_three_stack_mixer },
3647                 .init_verbs = { alc880_volume_init_verbs,
3648                                 alc880_pin_3stack_init_verbs },
3649                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3650                 .dac_nids = alc880_dac_nids,
3651                 .dig_out_nid = ALC880_DIGOUT_NID,
3652                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3653                 .channel_mode = alc880_threestack_modes,
3654                 .need_dac_fix = 1,
3655                 .input_mux = &alc880_capture_source,
3656         },
3657         [ALC880_TCL_S700] = {
3658                 .mixers = { alc880_tcl_s700_mixer },
3659                 .init_verbs = { alc880_volume_init_verbs,
3660                                 alc880_pin_tcl_S700_init_verbs,
3661                                 alc880_gpio2_init_verbs },
3662                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3663                 .dac_nids = alc880_dac_nids,
3664                 .adc_nids = alc880_adc_nids_alt, /* FIXME: correct? */
3665                 .num_adc_nids = 1, /* single ADC */
3666                 .hp_nid = 0x03,
3667                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3668                 .channel_mode = alc880_2_jack_modes,
3669                 .input_mux = &alc880_capture_source,
3670         },
3671         [ALC880_5ST] = {
3672                 .mixers = { alc880_three_stack_mixer,
3673                             alc880_five_stack_mixer},
3674                 .init_verbs = { alc880_volume_init_verbs,
3675                                 alc880_pin_5stack_init_verbs },
3676                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3677                 .dac_nids = alc880_dac_nids,
3678                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3679                 .channel_mode = alc880_fivestack_modes,
3680                 .input_mux = &alc880_capture_source,
3681         },
3682         [ALC880_5ST_DIG] = {
3683                 .mixers = { alc880_three_stack_mixer,
3684                             alc880_five_stack_mixer },
3685                 .init_verbs = { alc880_volume_init_verbs,
3686                                 alc880_pin_5stack_init_verbs },
3687                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3688                 .dac_nids = alc880_dac_nids,
3689                 .dig_out_nid = ALC880_DIGOUT_NID,
3690                 .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
3691                 .channel_mode = alc880_fivestack_modes,
3692                 .input_mux = &alc880_capture_source,
3693         },
3694         [ALC880_6ST] = {
3695                 .mixers = { alc880_six_stack_mixer },
3696                 .init_verbs = { alc880_volume_init_verbs,
3697                                 alc880_pin_6stack_init_verbs },
3698                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3699                 .dac_nids = alc880_6st_dac_nids,
3700                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3701                 .channel_mode = alc880_sixstack_modes,
3702                 .input_mux = &alc880_6stack_capture_source,
3703         },
3704         [ALC880_6ST_DIG] = {
3705                 .mixers = { alc880_six_stack_mixer },
3706                 .init_verbs = { alc880_volume_init_verbs,
3707                                 alc880_pin_6stack_init_verbs },
3708                 .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
3709                 .dac_nids = alc880_6st_dac_nids,
3710                 .dig_out_nid = ALC880_DIGOUT_NID,
3711                 .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
3712                 .channel_mode = alc880_sixstack_modes,
3713                 .input_mux = &alc880_6stack_capture_source,
3714         },
3715         [ALC880_W810] = {
3716                 .mixers = { alc880_w810_base_mixer },
3717                 .init_verbs = { alc880_volume_init_verbs,
3718                                 alc880_pin_w810_init_verbs,
3719                                 alc880_gpio2_init_verbs },
3720                 .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
3721                 .dac_nids = alc880_w810_dac_nids,
3722                 .dig_out_nid = ALC880_DIGOUT_NID,
3723                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3724                 .channel_mode = alc880_w810_modes,
3725                 .input_mux = &alc880_capture_source,
3726         },
3727         [ALC880_Z71V] = {
3728                 .mixers = { alc880_z71v_mixer },
3729                 .init_verbs = { alc880_volume_init_verbs,
3730                                 alc880_pin_z71v_init_verbs },
3731                 .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
3732                 .dac_nids = alc880_z71v_dac_nids,
3733                 .dig_out_nid = ALC880_DIGOUT_NID,
3734                 .hp_nid = 0x03,
3735                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3736                 .channel_mode = alc880_2_jack_modes,
3737                 .input_mux = &alc880_capture_source,
3738         },
3739         [ALC880_F1734] = {
3740                 .mixers = { alc880_f1734_mixer },
3741                 .init_verbs = { alc880_volume_init_verbs,
3742                                 alc880_pin_f1734_init_verbs },
3743                 .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
3744                 .dac_nids = alc880_f1734_dac_nids,
3745                 .hp_nid = 0x02,
3746                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3747                 .channel_mode = alc880_2_jack_modes,
3748                 .input_mux = &alc880_f1734_capture_source,
3749                 .unsol_event = alc880_uniwill_p53_unsol_event,
3750                 .init_hook = alc880_uniwill_p53_hp_automute,
3751         },
3752         [ALC880_ASUS] = {
3753                 .mixers = { alc880_asus_mixer },
3754                 .init_verbs = { alc880_volume_init_verbs,
3755                                 alc880_pin_asus_init_verbs,
3756                                 alc880_gpio1_init_verbs },
3757                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3758                 .dac_nids = alc880_asus_dac_nids,
3759                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3760                 .channel_mode = alc880_asus_modes,
3761                 .need_dac_fix = 1,
3762                 .input_mux = &alc880_capture_source,
3763         },
3764         [ALC880_ASUS_DIG] = {
3765                 .mixers = { alc880_asus_mixer },
3766                 .init_verbs = { alc880_volume_init_verbs,
3767                                 alc880_pin_asus_init_verbs,
3768                                 alc880_gpio1_init_verbs },
3769                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3770                 .dac_nids = alc880_asus_dac_nids,
3771                 .dig_out_nid = ALC880_DIGOUT_NID,
3772                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3773                 .channel_mode = alc880_asus_modes,
3774                 .need_dac_fix = 1,
3775                 .input_mux = &alc880_capture_source,
3776         },
3777         [ALC880_ASUS_DIG2] = {
3778                 .mixers = { alc880_asus_mixer },
3779                 .init_verbs = { alc880_volume_init_verbs,
3780                                 alc880_pin_asus_init_verbs,
3781                                 alc880_gpio2_init_verbs }, /* use GPIO2 */
3782                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3783                 .dac_nids = alc880_asus_dac_nids,
3784                 .dig_out_nid = ALC880_DIGOUT_NID,
3785                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3786                 .channel_mode = alc880_asus_modes,
3787                 .need_dac_fix = 1,
3788                 .input_mux = &alc880_capture_source,
3789         },
3790         [ALC880_ASUS_W1V] = {
3791                 .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
3792                 .init_verbs = { alc880_volume_init_verbs,
3793                                 alc880_pin_asus_init_verbs,
3794                                 alc880_gpio1_init_verbs },
3795                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3796                 .dac_nids = alc880_asus_dac_nids,
3797                 .dig_out_nid = ALC880_DIGOUT_NID,
3798                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3799                 .channel_mode = alc880_asus_modes,
3800                 .need_dac_fix = 1,
3801                 .input_mux = &alc880_capture_source,
3802         },
3803         [ALC880_UNIWILL_DIG] = {
3804                 .mixers = { alc880_asus_mixer },
3805                 .init_verbs = { alc880_volume_init_verbs,
3806                                 alc880_pin_asus_init_verbs },
3807                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3808                 .dac_nids = alc880_asus_dac_nids,
3809                 .dig_out_nid = ALC880_DIGOUT_NID,
3810                 .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
3811                 .channel_mode = alc880_asus_modes,
3812                 .need_dac_fix = 1,
3813                 .input_mux = &alc880_capture_source,
3814         },
3815         [ALC880_UNIWILL] = {
3816                 .mixers = { alc880_uniwill_mixer },
3817                 .init_verbs = { alc880_volume_init_verbs,
3818                                 alc880_uniwill_init_verbs },
3819                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3820                 .dac_nids = alc880_asus_dac_nids,
3821                 .dig_out_nid = ALC880_DIGOUT_NID,
3822                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3823                 .channel_mode = alc880_threestack_modes,
3824                 .need_dac_fix = 1,
3825                 .input_mux = &alc880_capture_source,
3826                 .unsol_event = alc880_uniwill_unsol_event,
3827                 .init_hook = alc880_uniwill_automute,
3828         },
3829         [ALC880_UNIWILL_P53] = {
3830                 .mixers = { alc880_uniwill_p53_mixer },
3831                 .init_verbs = { alc880_volume_init_verbs,
3832                                 alc880_uniwill_p53_init_verbs },
3833                 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
3834                 .dac_nids = alc880_asus_dac_nids,
3835                 .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
3836                 .channel_mode = alc880_threestack_modes,
3837                 .input_mux = &alc880_capture_source,
3838                 .unsol_event = alc880_uniwill_p53_unsol_event,
3839                 .init_hook = alc880_uniwill_p53_hp_automute,
3840         },
3841         [ALC880_FUJITSU] = {
3842                 .mixers = { alc880_fujitsu_mixer },
3843                 .init_verbs = { alc880_volume_init_verbs,
3844                                 alc880_uniwill_p53_init_verbs,
3845                                 alc880_beep_init_verbs },
3846                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3847                 .dac_nids = alc880_dac_nids,
3848                 .dig_out_nid = ALC880_DIGOUT_NID,
3849                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3850                 .channel_mode = alc880_2_jack_modes,
3851                 .input_mux = &alc880_capture_source,
3852                 .unsol_event = alc880_uniwill_p53_unsol_event,
3853                 .init_hook = alc880_uniwill_p53_hp_automute,
3854         },
3855         [ALC880_CLEVO] = {
3856                 .mixers = { alc880_three_stack_mixer },
3857                 .init_verbs = { alc880_volume_init_verbs,
3858                                 alc880_pin_clevo_init_verbs },
3859                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3860                 .dac_nids = alc880_dac_nids,
3861                 .hp_nid = 0x03,
3862                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
3863                 .channel_mode = alc880_threestack_modes,
3864                 .need_dac_fix = 1,
3865                 .input_mux = &alc880_capture_source,
3866         },
3867         [ALC880_LG] = {
3868                 .mixers = { alc880_lg_mixer },
3869                 .init_verbs = { alc880_volume_init_verbs,
3870                                 alc880_lg_init_verbs },
3871                 .num_dacs = ARRAY_SIZE(alc880_lg_dac_nids),
3872                 .dac_nids = alc880_lg_dac_nids,
3873                 .dig_out_nid = ALC880_DIGOUT_NID,
3874                 .num_channel_mode = ARRAY_SIZE(alc880_lg_ch_modes),
3875                 .channel_mode = alc880_lg_ch_modes,
3876                 .need_dac_fix = 1,
3877                 .input_mux = &alc880_lg_capture_source,
3878                 .unsol_event = alc880_lg_unsol_event,
3879                 .init_hook = alc880_lg_automute,
3880 #ifdef CONFIG_SND_HDA_POWER_SAVE
3881                 .loopbacks = alc880_lg_loopbacks,
3882 #endif
3883         },
3884         [ALC880_LG_LW] = {
3885                 .mixers = { alc880_lg_lw_mixer },
3886                 .init_verbs = { alc880_volume_init_verbs,
3887                                 alc880_lg_lw_init_verbs },
3888                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3889                 .dac_nids = alc880_dac_nids,
3890                 .dig_out_nid = ALC880_DIGOUT_NID,
3891                 .num_channel_mode = ARRAY_SIZE(alc880_lg_lw_modes),
3892                 .channel_mode = alc880_lg_lw_modes,
3893                 .input_mux = &alc880_lg_lw_capture_source,
3894                 .unsol_event = alc880_lg_lw_unsol_event,
3895                 .init_hook = alc880_lg_lw_automute,
3896         },
3897         [ALC880_MEDION_RIM] = {
3898                 .mixers = { alc880_medion_rim_mixer },
3899                 .init_verbs = { alc880_volume_init_verbs,
3900                                 alc880_medion_rim_init_verbs,
3901                                 alc_gpio2_init_verbs },
3902                 .num_dacs = ARRAY_SIZE(alc880_dac_nids),
3903                 .dac_nids = alc880_dac_nids,
3904                 .dig_out_nid = ALC880_DIGOUT_NID,
3905                 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3906                 .channel_mode = alc880_2_jack_modes,
3907                 .input_mux = &alc880_medion_rim_capture_source,
3908                 .unsol_event = alc880_medion_rim_unsol_event,
3909                 .init_hook = alc880_medion_rim_automute,
3910         },
3911 #ifdef CONFIG_SND_DEBUG
3912         [ALC880_TEST] = {
3913                 .mixers = { alc880_test_mixer },
3914                 .init_verbs = { alc880_test_init_verbs },
3915                 .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
3916                 .dac_nids = alc880_test_dac_nids,
3917                 .dig_out_nid = ALC880_DIGOUT_NID,
3918                 .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
3919                 .channel_mode = alc880_test_modes,
3920                 .input_mux = &alc880_test_capture_source,
3921         },
3922 #endif
3923 };
3924
3925 /*
3926  * Automatic parse of I/O pins from the BIOS configuration
3927  */
3928
3929 enum {
3930         ALC_CTL_WIDGET_VOL,
3931         ALC_CTL_WIDGET_MUTE,
3932         ALC_CTL_BIND_MUTE,
3933 };
3934 static struct snd_kcontrol_new alc880_control_templates[] = {
3935         HDA_CODEC_VOLUME(NULL, 0, 0, 0),
3936         HDA_CODEC_MUTE(NULL, 0, 0, 0),
3937         HDA_BIND_MUTE(NULL, 0, 0, 0),
3938 };
3939
3940 /* add dynamic controls */
3941 static int add_control(struct alc_spec *spec, int type, const char *name,
3942                        unsigned long val)
3943 {
3944         struct snd_kcontrol_new *knew;
3945
3946         snd_array_init(&spec->kctls, sizeof(*knew), 32);
3947         knew = snd_array_new(&spec->kctls);
3948         if (!knew)
3949                 return -ENOMEM;
3950         *knew = alc880_control_templates[type];
3951         knew->name = kstrdup(name, GFP_KERNEL);
3952         if (!knew->name)
3953                 return -ENOMEM;
3954         knew->private_value = val;
3955         return 0;
3956 }
3957
3958 #define alc880_is_fixed_pin(nid)        ((nid) >= 0x14 && (nid) <= 0x17)
3959 #define alc880_fixed_pin_idx(nid)       ((nid) - 0x14)
3960 #define alc880_is_multi_pin(nid)        ((nid) >= 0x18)
3961 #define alc880_multi_pin_idx(nid)       ((nid) - 0x18)
3962 #define alc880_is_input_pin(nid)        ((nid) >= 0x18)
3963 #define alc880_input_pin_idx(nid)       ((nid) - 0x18)
3964 #define alc880_idx_to_dac(nid)          ((nid) + 0x02)
3965 #define alc880_dac_to_idx(nid)          ((nid) - 0x02)
3966 #define alc880_idx_to_mixer(nid)        ((nid) + 0x0c)
3967 #define alc880_idx_to_selector(nid)     ((nid) + 0x10)
3968 #define ALC880_PIN_CD_NID               0x1c
3969
3970 /* fill in the dac_nids table from the parsed pin configuration */
3971 static int alc880_auto_fill_dac_nids(struct alc_spec *spec,
3972                                      const struct auto_pin_cfg *cfg)
3973 {
3974         hda_nid_t nid;
3975         int assigned[4];
3976         int i, j;
3977
3978         memset(assigned, 0, sizeof(assigned));
3979         spec->multiout.dac_nids = spec->private_dac_nids;
3980
3981         /* check the pins hardwired to audio widget */
3982         for (i = 0; i < cfg->line_outs; i++) {
3983                 nid = cfg->line_out_pins[i];
3984                 if (alc880_is_fixed_pin(nid)) {
3985                         int idx = alc880_fixed_pin_idx(nid);
3986                         spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
3987                         assigned[idx] = 1;
3988                 }
3989         }
3990         /* left pins can be connect to any audio widget */
3991         for (i = 0; i < cfg->line_outs; i++) {
3992                 nid = cfg->line_out_pins[i];
3993                 if (alc880_is_fixed_pin(nid))
3994                         continue;
3995                 /* search for an empty channel */
3996                 for (j = 0; j < cfg->line_outs; j++) {
3997                         if (!assigned[j]) {
3998                                 spec->multiout.dac_nids[i] =
3999                                         alc880_idx_to_dac(j);
4000                                 assigned[j] = 1;
4001                                 break;
4002                         }
4003                 }
4004         }
4005         spec->multiout.num_dacs = cfg->line_outs;
4006         return 0;
4007 }
4008
4009 /* add playback controls from the parsed DAC table */
4010 static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
4011                                              const struct auto_pin_cfg *cfg)
4012 {
4013         char name[32];
4014         static const char *chname[4] = {
4015                 "Front", "Surround", NULL /*CLFE*/, "Side"
4016         };
4017         hda_nid_t nid;
4018         int i, err;
4019
4020         for (i = 0; i < cfg->line_outs; i++) {
4021                 if (!spec->multiout.dac_nids[i])
4022                         continue;
4023                 nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
4024                 if (i == 2) {
4025                         /* Center/LFE */
4026                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
4027                                           "Center Playback Volume",
4028                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
4029                                                               HDA_OUTPUT));
4030                         if (err < 0)
4031                                 return err;
4032                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
4033                                           "LFE Playback Volume",
4034                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
4035                                                               HDA_OUTPUT));
4036                         if (err < 0)
4037                                 return err;
4038                         err = add_control(spec, ALC_CTL_BIND_MUTE,
4039                                           "Center Playback Switch",
4040                                           HDA_COMPOSE_AMP_VAL(nid, 1, 2,
4041                                                               HDA_INPUT));
4042                         if (err < 0)
4043                                 return err;
4044                         err = add_control(spec, ALC_CTL_BIND_MUTE,
4045                                           "LFE Playback Switch",
4046                                           HDA_COMPOSE_AMP_VAL(nid, 2, 2,
4047                                                               HDA_INPUT));
4048                         if (err < 0)
4049                                 return err;
4050                 } else {
4051                         sprintf(name, "%s Playback Volume", chname[i]);
4052                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4053                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
4054                                                               HDA_OUTPUT));
4055                         if (err < 0)
4056                                 return err;
4057                         sprintf(name, "%s Playback Switch", chname[i]);
4058                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
4059                                           HDA_COMPOSE_AMP_VAL(nid, 3, 2,
4060                                                               HDA_INPUT));
4061                         if (err < 0)
4062                                 return err;
4063                 }
4064         }
4065         return 0;
4066 }
4067
4068 /* add playback controls for speaker and HP outputs */
4069 static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
4070                                         const char *pfx)
4071 {
4072         hda_nid_t nid;
4073         int err;
4074         char name[32];
4075
4076         if (!pin)
4077                 return 0;
4078
4079         if (alc880_is_fixed_pin(pin)) {
4080                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
4081                 /* specify the DAC as the extra output */
4082                 if (!spec->multiout.hp_nid)
4083                         spec->multiout.hp_nid = nid;
4084                 else
4085                         spec->multiout.extra_out_nid[0] = nid;
4086                 /* control HP volume/switch on the output mixer amp */
4087                 nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
4088                 sprintf(name, "%s Playback Volume", pfx);
4089                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4090                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
4091                 if (err < 0)
4092                         return err;
4093                 sprintf(name, "%s Playback Switch", pfx);
4094                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
4095                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
4096                 if (err < 0)
4097                         return err;
4098         } else if (alc880_is_multi_pin(pin)) {
4099                 /* set manual connection */
4100                 /* we have only a switch on HP-out PIN */
4101                 sprintf(name, "%s Playback Switch", pfx);
4102                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
4103                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
4104                 if (err < 0)
4105                         return err;
4106         }
4107         return 0;
4108 }
4109
4110 /* create input playback/capture controls for the given pin */
4111 static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
4112                             const char *ctlname,
4113                             int idx, hda_nid_t mix_nid)
4114 {
4115         char name[32];
4116         int err;
4117
4118         sprintf(name, "%s Playback Volume", ctlname);
4119         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
4120                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
4121         if (err < 0)
4122                 return err;
4123         sprintf(name, "%s Playback Switch", ctlname);
4124         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
4125                           HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
4126         if (err < 0)
4127                 return err;
4128         return 0;
4129 }
4130
4131 /* create playback/capture controls for input pins */
4132 static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec,
4133                                                 const struct auto_pin_cfg *cfg)
4134 {
4135         struct hda_input_mux *imux = &spec->private_imux[0];
4136         int i, err, idx;
4137
4138         for (i = 0; i < AUTO_PIN_LAST; i++) {
4139                 if (alc880_is_input_pin(cfg->input_pins[i])) {
4140                         idx = alc880_input_pin_idx(cfg->input_pins[i]);
4141                         err = new_analog_input(spec, cfg->input_pins[i],
4142                                                auto_pin_cfg_labels[i],
4143                                                idx, 0x0b);
4144                         if (err < 0)
4145                                 return err;
4146                         imux->items[imux->num_items].label =
4147                                 auto_pin_cfg_labels[i];
4148                         imux->items[imux->num_items].index =
4149                                 alc880_input_pin_idx(cfg->input_pins[i]);
4150                         imux->num_items++;
4151                 }
4152         }
4153         return 0;
4154 }
4155
4156 static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
4157                                unsigned int pin_type)
4158 {
4159         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4160                             pin_type);
4161         /* unmute pin */
4162         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4163                             AMP_OUT_UNMUTE);
4164 }
4165
4166 static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
4167                                               hda_nid_t nid, int pin_type,
4168                                               int dac_idx)
4169 {
4170         alc_set_pin_output(codec, nid, pin_type);
4171         /* need the manual connection? */
4172         if (alc880_is_multi_pin(nid)) {
4173                 struct alc_spec *spec = codec->spec;
4174                 int idx = alc880_multi_pin_idx(nid);
4175                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
4176                                     AC_VERB_SET_CONNECT_SEL,
4177                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
4178         }
4179 }
4180
4181 static int get_pin_type(int line_out_type)
4182 {
4183         if (line_out_type == AUTO_PIN_HP_OUT)
4184                 return PIN_HP;
4185         else
4186                 return PIN_OUT;
4187 }
4188
4189 static void alc880_auto_init_multi_out(struct hda_codec *codec)
4190 {
4191         struct alc_spec *spec = codec->spec;
4192         int i;
4193
4194         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
4195         for (i = 0; i < spec->autocfg.line_outs; i++) {
4196                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
4197                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
4198                 alc880_auto_set_output_and_unmute(codec, nid, pin_type, i);
4199         }
4200 }
4201
4202 static void alc880_auto_init_extra_out(struct hda_codec *codec)
4203 {
4204         struct alc_spec *spec = codec->spec;
4205         hda_nid_t pin;
4206
4207         pin = spec->autocfg.speaker_pins[0];
4208         if (pin) /* connect to front */
4209                 alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
4210         pin = spec->autocfg.hp_pins[0];
4211         if (pin) /* connect to front */
4212                 alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
4213 }
4214
4215 static void alc880_auto_init_analog_input(struct hda_codec *codec)
4216 {
4217         struct alc_spec *spec = codec->spec;
4218         int i;
4219
4220         for (i = 0; i < AUTO_PIN_LAST; i++) {
4221                 hda_nid_t nid = spec->autocfg.input_pins[i];
4222                 if (alc880_is_input_pin(nid)) {
4223                         alc_set_input_pin(codec, nid, i);
4224                         if (nid != ALC880_PIN_CD_NID &&
4225                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
4226                                 snd_hda_codec_write(codec, nid, 0,
4227                                                     AC_VERB_SET_AMP_GAIN_MUTE,
4228                                                     AMP_OUT_MUTE);
4229                 }
4230         }
4231 }
4232
4233 /* parse the BIOS configuration and set up the alc_spec */
4234 /* return 1 if successful, 0 if the proper config is not found,
4235  * or a negative error code
4236  */
4237 static int alc880_parse_auto_config(struct hda_codec *codec)
4238 {
4239         struct alc_spec *spec = codec->spec;
4240         int i, err;
4241         static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4242
4243         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
4244                                            alc880_ignore);
4245         if (err < 0)
4246                 return err;
4247         if (!spec->autocfg.line_outs)
4248                 return 0; /* can't find valid BIOS pin config */
4249
4250         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
4251         if (err < 0)
4252                 return err;
4253         err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
4254         if (err < 0)
4255                 return err;
4256         err = alc880_auto_create_extra_out(spec,
4257                                            spec->autocfg.speaker_pins[0],
4258                                            "Speaker");
4259         if (err < 0)
4260                 return err;
4261         err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
4262                                            "Headphone");
4263         if (err < 0)
4264                 return err;
4265         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
4266         if (err < 0)
4267                 return err;
4268
4269         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4270
4271         /* check multiple SPDIF-out (for recent codecs) */
4272         for (i = 0; i < spec->autocfg.dig_outs; i++) {
4273                 hda_nid_t dig_nid;
4274                 err = snd_hda_get_connections(codec,
4275                                               spec->autocfg.dig_out_pins[i],
4276                                               &dig_nid, 1);
4277                 if (err < 0)
4278                         continue;
4279                 if (!i)
4280                         spec->multiout.dig_out_nid = dig_nid;
4281                 else {
4282                         spec->multiout.slave_dig_outs = spec->slave_dig_outs;
4283                         spec->slave_dig_outs[i - 1] = dig_nid;
4284                         if (i == ARRAY_SIZE(spec->slave_dig_outs) - 1)
4285                                 break;
4286                 }
4287         }
4288         if (spec->autocfg.dig_in_pin)
4289                 spec->dig_in_nid = ALC880_DIGIN_NID;
4290
4291         if (spec->kctls.list)
4292                 add_mixer(spec, spec->kctls.list);
4293
4294         add_verb(spec, alc880_volume_init_verbs);
4295
4296         spec->num_mux_defs = 1;
4297         spec->input_mux = &spec->private_imux[0];
4298
4299         return 1;
4300 }
4301
4302 /* additional initialization for auto-configuration model */
4303 static void alc880_auto_init(struct hda_codec *codec)
4304 {
4305         struct alc_spec *spec = codec->spec;
4306         alc880_auto_init_multi_out(codec);
4307         alc880_auto_init_extra_out(codec);
4308         alc880_auto_init_analog_input(codec);
4309         if (spec->unsol_event)
4310                 alc_inithook(codec);
4311 }
4312
4313 static void set_capture_mixer(struct alc_spec *spec)
4314 {
4315         static struct snd_kcontrol_new *caps[2][3] = {
4316                 { alc_capture_mixer_nosrc1,
4317                   alc_capture_mixer_nosrc2,
4318                   alc_capture_mixer_nosrc3 },
4319                 { alc_capture_mixer1,
4320                   alc_capture_mixer2,
4321                   alc_capture_mixer3 },
4322         };
4323         if (spec->num_adc_nids > 0 && spec->num_adc_nids <= 3) {
4324                 int mux;
4325                 if (spec->input_mux && spec->input_mux->num_items > 1)
4326                         mux = 1;
4327                 else
4328                         mux = 0;
4329                 spec->cap_mixer = caps[mux][spec->num_adc_nids - 1];
4330         }
4331 }
4332
4333 #define set_beep_amp(spec, nid, idx, dir) \
4334         ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4335
4336 /*
4337  * OK, here we have finally the patch for ALC880
4338  */
4339
4340 static int patch_alc880(struct hda_codec *codec)
4341 {
4342         struct alc_spec *spec;
4343         int board_config;
4344         int err;
4345
4346         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4347         if (spec == NULL)
4348                 return -ENOMEM;
4349
4350         codec->spec = spec;
4351
4352         board_config = snd_hda_check_board_config(codec, ALC880_MODEL_LAST,
4353                                                   alc880_models,
4354                                                   alc880_cfg_tbl);
4355         if (board_config < 0) {
4356                 printk(KERN_INFO "hda_codec: Unknown model for ALC880, "
4357                        "trying auto-probe from BIOS...\n");
4358                 board_config = ALC880_AUTO;
4359         }
4360
4361         if (board_config == ALC880_AUTO) {
4362                 /* automatic parse from the BIOS config */
4363                 err = alc880_parse_auto_config(codec);
4364                 if (err < 0) {
4365                         alc_free(codec);
4366                         return err;
4367                 } else if (!err) {
4368                         printk(KERN_INFO
4369                                "hda_codec: Cannot set up configuration "
4370                                "from BIOS.  Using 3-stack mode...\n");
4371                         board_config = ALC880_3ST;
4372                 }
4373         }
4374
4375         err = snd_hda_attach_beep_device(codec, 0x1);
4376         if (err < 0) {
4377                 alc_free(codec);
4378                 return err;
4379         }
4380
4381         if (board_config != ALC880_AUTO)
4382                 setup_preset(spec, &alc880_presets[board_config]);
4383
4384         spec->stream_name_analog = "ALC880 Analog";
4385         spec->stream_analog_playback = &alc880_pcm_analog_playback;
4386         spec->stream_analog_capture = &alc880_pcm_analog_capture;
4387         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
4388
4389         spec->stream_name_digital = "ALC880 Digital";
4390         spec->stream_digital_playback = &alc880_pcm_digital_playback;
4391         spec->stream_digital_capture = &alc880_pcm_digital_capture;
4392
4393         if (!spec->adc_nids && spec->input_mux) {
4394                 /* check whether NID 0x07 is valid */
4395                 unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
4396                 /* get type */
4397                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
4398                 if (wcap != AC_WID_AUD_IN) {
4399                         spec->adc_nids = alc880_adc_nids_alt;
4400                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
4401                 } else {
4402                         spec->adc_nids = alc880_adc_nids;
4403                         spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
4404                 }
4405         }
4406         set_capture_mixer(spec);
4407         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4408
4409         spec->vmaster_nid = 0x0c;
4410
4411         codec->patch_ops = alc_patch_ops;
4412         if (board_config == ALC880_AUTO)
4413                 spec->init_hook = alc880_auto_init;
4414 #ifdef CONFIG_SND_HDA_POWER_SAVE
4415         if (!spec->loopback.amplist)
4416                 spec->loopback.amplist = alc880_loopbacks;
4417 #endif
4418         codec->proc_widget_hook = print_realtek_coef;
4419
4420         return 0;
4421 }
4422
4423
4424 /*
4425  * ALC260 support
4426  */
4427
4428 static hda_nid_t alc260_dac_nids[1] = {
4429         /* front */
4430         0x02,
4431 };
4432
4433 static hda_nid_t alc260_adc_nids[1] = {
4434         /* ADC0 */
4435         0x04,
4436 };
4437
4438 static hda_nid_t alc260_adc_nids_alt[1] = {
4439         /* ADC1 */
4440         0x05,
4441 };
4442
4443 /* NIDs used when simultaneous access to both ADCs makes sense.  Note that
4444  * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
4445  */
4446 static hda_nid_t alc260_dual_adc_nids[2] = {
4447         /* ADC0, ADC1 */
4448         0x04, 0x05
4449 };
4450
4451 #define ALC260_DIGOUT_NID       0x03
4452 #define ALC260_DIGIN_NID        0x06
4453
4454 static struct hda_input_mux alc260_capture_source = {
4455         .num_items = 4,
4456         .items = {
4457                 { "Mic", 0x0 },
4458                 { "Front Mic", 0x1 },
4459                 { "Line", 0x2 },
4460                 { "CD", 0x4 },
4461         },
4462 };
4463
4464 /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
4465  * headphone jack and the internal CD lines since these are the only pins at
4466  * which audio can appear.  For flexibility, also allow the option of
4467  * recording the mixer output on the second ADC (ADC0 doesn't have a
4468  * connection to the mixer output).
4469  */
4470 static struct hda_input_mux alc260_fujitsu_capture_sources[2] = {
4471         {
4472                 .num_items = 3,
4473                 .items = {
4474                         { "Mic/Line", 0x0 },
4475                         { "CD", 0x4 },
4476                         { "Headphone", 0x2 },
4477                 },
4478         },
4479         {
4480                 .num_items = 4,
4481                 .items = {
4482                         { "Mic/Line", 0x0 },
4483                         { "CD", 0x4 },
4484                         { "Headphone", 0x2 },
4485                         { "Mixer", 0x5 },
4486                 },
4487         },
4488
4489 };
4490
4491 /* Acer TravelMate(/Extensa/Aspire) notebooks have similar configuration to
4492  * the Fujitsu S702x, but jacks are marked differently.
4493  */
4494 static struct hda_input_mux alc260_acer_capture_sources[2] = {
4495         {
4496                 .num_items = 4,
4497                 .items = {
4498                         { "Mic", 0x0 },
4499                         { "Line", 0x2 },
4500                         { "CD", 0x4 },
4501                         { "Headphone", 0x5 },
4502                 },
4503         },
4504         {
4505                 .num_items = 5,
4506                 .items = {
4507                         { "Mic", 0x0 },
4508                         { "Line", 0x2 },
4509                         { "CD", 0x4 },
4510                         { "Headphone", 0x6 },
4511                         { "Mixer", 0x5 },
4512                 },
4513         },
4514 };
4515
4516 /* Maxdata Favorit 100XS */
4517 static struct hda_input_mux alc260_favorit100_capture_sources[2] = {
4518         {
4519                 .num_items = 2,
4520                 .items = {
4521                         { "Line/Mic", 0x0 },
4522                         { "CD", 0x4 },
4523                 },
4524         },
4525         {
4526                 .num_items = 3,
4527                 .items = {
4528                         { "Line/Mic", 0x0 },
4529                         { "CD", 0x4 },
4530                         { "Mixer", 0x5 },
4531                 },
4532         },
4533 };
4534
4535 /*
4536  * This is just place-holder, so there's something for alc_build_pcms to look
4537  * at when it calculates the maximum number of channels. ALC260 has no mixer
4538  * element which allows changing the channel mode, so the verb list is
4539  * never used.
4540  */
4541 static struct hda_channel_mode alc260_modes[1] = {
4542         { 2, NULL },
4543 };
4544
4545
4546 /* Mixer combinations
4547  *
4548  * basic: base_output + input + pc_beep + capture
4549  * HP: base_output + input + capture_alt
4550  * HP_3013: hp_3013 + input + capture
4551  * fujitsu: fujitsu + capture
4552  * acer: acer + capture
4553  */
4554
4555 static struct snd_kcontrol_new alc260_base_output_mixer[] = {
4556         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4557         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
4558         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4559         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
4560         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4561         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4562         { } /* end */
4563 };
4564
4565 static struct snd_kcontrol_new alc260_input_mixer[] = {
4566         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4567         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4568         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4569         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4570         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4571         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4572         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
4573         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
4574         { } /* end */
4575 };
4576
4577 /* update HP, line and mono out pins according to the master switch */
4578 static void alc260_hp_master_update(struct hda_codec *codec,
4579                                     hda_nid_t hp, hda_nid_t line,
4580                                     hda_nid_t mono)
4581 {
4582         struct alc_spec *spec = codec->spec;
4583         unsigned int val = spec->master_sw ? PIN_HP : 0;
4584         /* change HP and line-out pins */
4585         snd_hda_codec_write(codec, hp, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4586                             val);
4587         snd_hda_codec_write(codec, line, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4588                             val);
4589         /* mono (speaker) depending on the HP jack sense */
4590         val = (val && !spec->jack_present) ? PIN_OUT : 0;
4591         snd_hda_codec_write(codec, mono, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4592                             val);
4593 }
4594
4595 static int alc260_hp_master_sw_get(struct snd_kcontrol *kcontrol,
4596                                    struct snd_ctl_elem_value *ucontrol)
4597 {
4598         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4599         struct alc_spec *spec = codec->spec;
4600         *ucontrol->value.integer.value = spec->master_sw;
4601         return 0;
4602 }
4603
4604 static int alc260_hp_master_sw_put(struct snd_kcontrol *kcontrol,
4605                                    struct snd_ctl_elem_value *ucontrol)
4606 {
4607         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4608         struct alc_spec *spec = codec->spec;
4609         int val = !!*ucontrol->value.integer.value;
4610         hda_nid_t hp, line, mono;
4611
4612         if (val == spec->master_sw)
4613                 return 0;
4614         spec->master_sw = val;
4615         hp = (kcontrol->private_value >> 16) & 0xff;
4616         line = (kcontrol->private_value >> 8) & 0xff;
4617         mono = kcontrol->private_value & 0xff;
4618         alc260_hp_master_update(codec, hp, line, mono);
4619         return 1;
4620 }
4621
4622 static struct snd_kcontrol_new alc260_hp_output_mixer[] = {
4623         {
4624                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4625                 .name = "Master Playback Switch",
4626                 .info = snd_ctl_boolean_mono_info,
4627                 .get = alc260_hp_master_sw_get,
4628                 .put = alc260_hp_master_sw_put,
4629                 .private_value = (0x0f << 16) | (0x10 << 8) | 0x11
4630         },
4631         HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4632         HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
4633         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4634         HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
4635         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4636                               HDA_OUTPUT),
4637         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2, HDA_INPUT),
4638         { } /* end */
4639 };
4640
4641 static struct hda_verb alc260_hp_unsol_verbs[] = {
4642         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4643         {},
4644 };
4645
4646 static void alc260_hp_automute(struct hda_codec *codec)
4647 {
4648         struct alc_spec *spec = codec->spec;
4649         unsigned int present;
4650
4651         present = snd_hda_codec_read(codec, 0x10, 0,
4652                                      AC_VERB_GET_PIN_SENSE, 0);
4653         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4654         alc260_hp_master_update(codec, 0x0f, 0x10, 0x11);
4655 }
4656
4657 static void alc260_hp_unsol_event(struct hda_codec *codec, unsigned int res)
4658 {
4659         if ((res >> 26) == ALC880_HP_EVENT)
4660                 alc260_hp_automute(codec);
4661 }
4662
4663 static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
4664         {
4665                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4666                 .name = "Master Playback Switch",
4667                 .info = snd_ctl_boolean_mono_info,
4668                 .get = alc260_hp_master_sw_get,
4669                 .put = alc260_hp_master_sw_put,
4670                 .private_value = (0x15 << 16) | (0x10 << 8) | 0x11
4671         },
4672         HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4673         HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
4674         HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
4675         HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
4676         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4677         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
4678         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
4679         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
4680         { } /* end */
4681 };
4682
4683 static struct hda_bind_ctls alc260_dc7600_bind_master_vol = {
4684         .ops = &snd_hda_bind_vol,
4685         .values = {
4686                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_OUTPUT),
4687                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
4688                 HDA_COMPOSE_AMP_VAL(0x0a, 3, 0, HDA_OUTPUT),
4689                 0
4690         },
4691 };
4692
4693 static struct hda_bind_ctls alc260_dc7600_bind_switch = {
4694         .ops = &snd_hda_bind_sw,
4695         .values = {
4696                 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
4697                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
4698                 0
4699         },
4700 };
4701
4702 static struct snd_kcontrol_new alc260_hp_dc7600_mixer[] = {
4703         HDA_BIND_VOL("Master Playback Volume", &alc260_dc7600_bind_master_vol),
4704         HDA_BIND_SW("LineOut Playback Switch", &alc260_dc7600_bind_switch),
4705         HDA_CODEC_MUTE("Speaker Playback Switch", 0x0f, 0x0, HDA_OUTPUT),
4706         HDA_CODEC_MUTE("Headphone Playback Switch", 0x10, 0x0, HDA_OUTPUT),
4707         { } /* end */
4708 };
4709
4710 static struct hda_verb alc260_hp_3013_unsol_verbs[] = {
4711         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
4712         {},
4713 };
4714
4715 static void alc260_hp_3013_automute(struct hda_codec *codec)
4716 {
4717         struct alc_spec *spec = codec->spec;
4718         unsigned int present;
4719
4720         present = snd_hda_codec_read(codec, 0x15, 0,
4721                                      AC_VERB_GET_PIN_SENSE, 0);
4722         spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
4723         alc260_hp_master_update(codec, 0x15, 0x10, 0x11);
4724 }
4725
4726 static void alc260_hp_3013_unsol_event(struct hda_codec *codec,
4727                                        unsigned int res)
4728 {
4729         if ((res >> 26) == ALC880_HP_EVENT)
4730                 alc260_hp_3013_automute(codec);
4731 }
4732
4733 static void alc260_hp_3012_automute(struct hda_codec *codec)
4734 {
4735         unsigned int present, bits;
4736
4737         present = snd_hda_codec_read(codec, 0x10, 0,
4738                         AC_VERB_GET_PIN_SENSE, 0) & AC_PINSENSE_PRESENCE;
4739
4740         bits = present ? 0 : PIN_OUT;
4741         snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4742                             bits);
4743         snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4744                             bits);
4745         snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4746                             bits);
4747 }
4748
4749 static void alc260_hp_3012_unsol_event(struct hda_codec *codec,
4750                                        unsigned int res)
4751 {
4752         if ((res >> 26) == ALC880_HP_EVENT)
4753                 alc260_hp_3012_automute(codec);
4754 }
4755
4756 /* Fujitsu S702x series laptops.  ALC260 pin usage: Mic/Line jack = 0x12,
4757  * HP jack = 0x14, CD audio =  0x16, internal speaker = 0x10.
4758  */
4759 static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
4760         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4761         HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
4762         ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4763         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4764         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4765         HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
4766         HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
4767         ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
4768         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4769         HDA_BIND_MUTE("Speaker Playback Switch", 0x09, 2, HDA_INPUT),
4770         { } /* end */
4771 };
4772
4773 /* Mixer for Acer TravelMate(/Extensa/Aspire) notebooks.  Note that current
4774  * versions of the ALC260 don't act on requests to enable mic bias from NID
4775  * 0x0f (used to drive the headphone jack in these laptops).  The ALC260
4776  * datasheet doesn't mention this restriction.  At this stage it's not clear
4777  * whether this behaviour is intentional or is a hardware bug in chip
4778  * revisions available in early 2006.  Therefore for now allow the
4779  * "Headphone Jack Mode" control to span all choices, but if it turns out
4780  * that the lack of mic bias for this NID is intentional we could change the
4781  * mode from ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
4782  *
4783  * In addition, Acer TravelMate(/Extensa/Aspire) notebooks in early 2006
4784  * don't appear to make the mic bias available from the "line" jack, even
4785  * though the NID used for this jack (0x14) can supply it.  The theory is
4786  * that perhaps Acer have included blocking capacitors between the ALC260
4787  * and the output jack.  If this turns out to be the case for all such
4788  * models the "Line Jack Mode" mode could be changed from ALC_PIN_DIR_INOUT
4789  * to ALC_PIN_DIR_INOUT_NOMICBIAS.
4790  *
4791  * The C20x Tablet series have a mono internal speaker which is controlled
4792  * via the chip's Mono sum widget and pin complex, so include the necessary
4793  * controls for such models.  On models without a "mono speaker" the control
4794  * won't do anything.
4795  */
4796 static struct snd_kcontrol_new alc260_acer_mixer[] = {
4797         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4798         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
4799         ALC_PIN_MODE("Headphone Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
4800         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
4801                               HDA_OUTPUT),
4802         HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2,
4803                            HDA_INPUT),
4804         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4805         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4806         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4807         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4808         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4809         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4810         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4811         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4812         { } /* end */
4813 };
4814
4815 /* Maxdata Favorit 100XS: one output and one input (0x12) jack
4816  */
4817 static struct snd_kcontrol_new alc260_favorit100_mixer[] = {
4818         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4819         HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
4820         ALC_PIN_MODE("Output Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
4821         HDA_CODEC_VOLUME("Line/Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4822         HDA_CODEC_MUTE("Line/Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4823         ALC_PIN_MODE("Line/Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4824         { } /* end */
4825 };
4826
4827 /* Packard bell V7900  ALC260 pin usage: HP = 0x0f, Mic jack = 0x12,
4828  * Line In jack = 0x14, CD audio =  0x16, pc beep = 0x17.
4829  */
4830 static struct snd_kcontrol_new alc260_will_mixer[] = {
4831         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4832         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
4833         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4834         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4835         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4836         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4837         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4838         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4839         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4840         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4841         { } /* end */
4842 };
4843
4844 /* Replacer 672V ALC260 pin usage: Mic jack = 0x12,
4845  * Line In jack = 0x14, ATAPI Mic = 0x13, speaker = 0x0f.
4846  */
4847 static struct snd_kcontrol_new alc260_replacer_672v_mixer[] = {
4848         HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4849         HDA_BIND_MUTE("Master Playback Switch", 0x08, 0x2, HDA_INPUT),
4850         HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4851         HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4852         ALC_PIN_MODE("Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4853         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x07, 0x1, HDA_INPUT),
4854         HDA_CODEC_MUTE("ATATI Mic Playback Switch", 0x07, 0x1, HDA_INPUT),
4855         HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4856         HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4857         ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4858         { } /* end */
4859 };
4860
4861 /*
4862  * initialization verbs
4863  */
4864 static struct hda_verb alc260_init_verbs[] = {
4865         /* Line In pin widget for input */
4866         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4867         /* CD pin widget for input */
4868         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4869         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4870         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4871         /* Mic2 (front panel) pin widget for input and vref at 80% */
4872         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4873         /* LINE-2 is used for line-out in rear */
4874         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4875         /* select line-out */
4876         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
4877         /* LINE-OUT pin */
4878         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4879         /* enable HP */
4880         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4881         /* enable Mono */
4882         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4883         /* mute capture amp left and right */
4884         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4885         /* set connection select to line in (default select for this ADC) */
4886         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4887         /* mute capture amp left and right */
4888         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4889         /* set connection select to line in (default select for this ADC) */
4890         {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
4891         /* set vol=0 Line-Out mixer amp left and right */
4892         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4893         /* unmute pin widget amp left and right (no gain on this amp) */
4894         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4895         /* set vol=0 HP mixer amp left and right */
4896         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4897         /* unmute pin widget amp left and right (no gain on this amp) */
4898         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4899         /* set vol=0 Mono mixer amp left and right */
4900         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4901         /* unmute pin widget amp left and right (no gain on this amp) */
4902         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4903         /* unmute LINE-2 out pin */
4904         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4905         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4906          * Line In 2 = 0x03
4907          */
4908         /* mute analog inputs */
4909         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4910         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4911         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4912         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4913         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4914         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4915         /* mute Front out path */
4916         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4917         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4918         /* mute Headphone out path */
4919         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4920         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4921         /* mute Mono out path */
4922         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4923         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4924         { }
4925 };
4926
4927 #if 0 /* should be identical with alc260_init_verbs? */
4928 static struct hda_verb alc260_hp_init_verbs[] = {
4929         /* Headphone and output */
4930         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4931         /* mono output */
4932         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4933         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4934         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4935         /* Mic2 (front panel) pin widget for input and vref at 80% */
4936         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4937         /* Line In pin widget for input */
4938         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4939         /* Line-2 pin widget for output */
4940         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4941         /* CD pin widget for input */
4942         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4943         /* unmute amp left and right */
4944         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4945         /* set connection select to line in (default select for this ADC) */
4946         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4947         /* unmute Line-Out mixer amp left and right (volume = 0) */
4948         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4949         /* mute pin widget amp left and right (no gain on this amp) */
4950         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4951         /* unmute HP mixer amp left and right (volume = 0) */
4952         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4953         /* mute pin widget amp left and right (no gain on this amp) */
4954         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
4955         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
4956          * Line In 2 = 0x03
4957          */
4958         /* mute analog inputs */
4959         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4960         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4961         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4962         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4963         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4964         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
4965         /* Unmute Front out path */
4966         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4967         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4968         /* Unmute Headphone out path */
4969         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4970         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4971         /* Unmute Mono out path */
4972         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
4973         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
4974         { }
4975 };
4976 #endif
4977
4978 static struct hda_verb alc260_hp_3013_init_verbs[] = {
4979         /* Line out and output */
4980         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4981         /* mono output */
4982         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
4983         /* Mic1 (rear panel) pin widget for input and vref at 80% */
4984         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4985         /* Mic2 (front panel) pin widget for input and vref at 80% */
4986         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
4987         /* Line In pin widget for input */
4988         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4989         /* Headphone pin widget for output */
4990         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
4991         /* CD pin widget for input */
4992         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
4993         /* unmute amp left and right */
4994         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
4995         /* set connection select to line in (default select for this ADC) */
4996         {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
4997         /* unmute Line-Out mixer amp left and right (volume = 0) */
4998         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
4999         /* mute pin widget amp left and right (no gain on this amp) */
5000         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5001         /* unmute HP mixer amp left and right (volume = 0) */
5002         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
5003         /* mute pin widget amp left and right (no gain on this amp) */
5004         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
5005         /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
5006          * Line In 2 = 0x03
5007          */
5008         /* mute analog inputs */
5009         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5010         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5011         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5012         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5013         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5014         /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
5015         /* Unmute Front out path */
5016         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5017         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5018         /* Unmute Headphone out path */
5019         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5020         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5021         /* Unmute Mono out path */
5022         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
5023         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
5024         { }
5025 };
5026
5027 /* Initialisation sequence for ALC260 as configured in Fujitsu S702x
5028  * laptops.  ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
5029  * audio = 0x16, internal speaker = 0x10.
5030  */
5031 static struct hda_verb alc260_fujitsu_init_verbs[] = {
5032         /* Disable all GPIOs */
5033         {0x01, AC_VERB_SET_GPIO_MASK, 0},
5034         /* Internal speaker is connected to headphone pin */
5035         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5036         /* Headphone/Line-out jack connects to Line1 pin; make it an output */
5037         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5038         /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
5039         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5040         /* Ensure all other unused pins are disabled and muted. */
5041         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5042         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5043         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5044         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5045         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5046         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5047         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5048         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5049
5050         /* Disable digital (SPDIF) pins */
5051         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5052         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5053
5054         /* Ensure Line1 pin widget takes its input from the OUT1 sum bus
5055          * when acting as an output.
5056          */
5057         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5058
5059         /* Start with output sum widgets muted and their output gains at min */
5060         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5061         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5062         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5063         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5064         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5065         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5066         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5067         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5068         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5069
5070         /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
5071         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5072         /* Unmute Line1 pin widget output buffer since it starts as an output.
5073          * If the pin mode is changed by the user the pin mode control will
5074          * take care of enabling the pin's input/output buffers as needed.
5075          * Therefore there's no need to enable the input buffer at this
5076          * stage.
5077          */
5078         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5079         /* Unmute input buffer of pin widget used for Line-in (no equiv
5080          * mixer ctrl)
5081          */
5082         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5083
5084         /* Mute capture amp left and right */
5085         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5086         /* Set ADC connection select to match default mixer setting - line
5087          * in (on mic1 pin)
5088          */
5089         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5090
5091         /* Do the same for the second ADC: mute capture input amp and
5092          * set ADC connection to line in (on mic1 pin)
5093          */
5094         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5095         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5096
5097         /* Mute all inputs to mixer widget (even unconnected ones) */
5098         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5099         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5100         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5101         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5102         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5103         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5104         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5105         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5106
5107         { }
5108 };
5109
5110 /* Initialisation sequence for ALC260 as configured in Acer TravelMate and
5111  * similar laptops (adapted from Fujitsu init verbs).
5112  */
5113 static struct hda_verb alc260_acer_init_verbs[] = {
5114         /* On TravelMate laptops, GPIO 0 enables the internal speaker and
5115          * the headphone jack.  Turn this on and rely on the standard mute
5116          * methods whenever the user wants to turn these outputs off.
5117          */
5118         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5119         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5120         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5121         /* Internal speaker/Headphone jack is connected to Line-out pin */
5122         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5123         /* Internal microphone/Mic jack is connected to Mic1 pin */
5124         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
5125         /* Line In jack is connected to Line1 pin */
5126         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
5127         /* Some Acers (eg: C20x Tablets) use Mono pin for internal speaker */
5128         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5129         /* Ensure all other unused pins are disabled and muted. */
5130         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5131         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5132         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5133         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5134         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5135         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5136         /* Disable digital (SPDIF) pins */
5137         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5138         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5139
5140         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
5141          * bus when acting as outputs.
5142          */
5143         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5144         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5145
5146         /* Start with output sum widgets muted and their output gains at min */
5147         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5148         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5149         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5150         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5151         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5152         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5153         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5154         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5155         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5156
5157         /* Unmute Line-out pin widget amp left and right
5158          * (no equiv mixer ctrl)
5159          */
5160         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5161         /* Unmute mono pin widget amp output (no equiv mixer ctrl) */
5162         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5163         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
5164          * inputs. If the pin mode is changed by the user the pin mode control
5165          * will take care of enabling the pin's input/output buffers as needed.
5166          * Therefore there's no need to enable the input buffer at this
5167          * stage.
5168          */
5169         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5170         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5171
5172         /* Mute capture amp left and right */
5173         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5174         /* Set ADC connection select to match default mixer setting - mic
5175          * (on mic1 pin)
5176          */
5177         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5178
5179         /* Do similar with the second ADC: mute capture input amp and
5180          * set ADC connection to mic to match ALSA's default state.
5181          */
5182         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5183         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5184
5185         /* Mute all inputs to mixer widget (even unconnected ones) */
5186         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5187         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5188         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5189         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5190         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5191         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5192         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5193         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5194
5195         { }
5196 };
5197
5198 /* Initialisation sequence for Maxdata Favorit 100XS
5199  * (adapted from Acer init verbs).
5200  */
5201 static struct hda_verb alc260_favorit100_init_verbs[] = {
5202         /* GPIO 0 enables the output jack.
5203          * Turn this on and rely on the standard mute
5204          * methods whenever the user wants to turn these outputs off.
5205          */
5206         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5207         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5208         {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5209         /* Line/Mic input jack is connected to Mic1 pin */
5210         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
5211         /* Ensure all other unused pins are disabled and muted. */
5212         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5213         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5214         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5215         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5216         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5217         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5218         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5219         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5220         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5221         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5222         /* Disable digital (SPDIF) pins */
5223         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5224         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5225
5226         /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
5227          * bus when acting as outputs.
5228          */
5229         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5230         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5231
5232         /* Start with output sum widgets muted and their output gains at min */
5233         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5234         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5235         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5236         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5237         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5238         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5239         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5240         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5241         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5242
5243         /* Unmute Line-out pin widget amp left and right
5244          * (no equiv mixer ctrl)
5245          */
5246         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5247         /* Unmute Mic1 and Line1 pin widget input buffers since they start as
5248          * inputs. If the pin mode is changed by the user the pin mode control
5249          * will take care of enabling the pin's input/output buffers as needed.
5250          * Therefore there's no need to enable the input buffer at this
5251          * stage.
5252          */
5253         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5254
5255         /* Mute capture amp left and right */
5256         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5257         /* Set ADC connection select to match default mixer setting - mic
5258          * (on mic1 pin)
5259          */
5260         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5261
5262         /* Do similar with the second ADC: mute capture input amp and
5263          * set ADC connection to mic to match ALSA's default state.
5264          */
5265         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5266         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5267
5268         /* Mute all inputs to mixer widget (even unconnected ones) */
5269         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5270         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5271         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5272         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5273         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5274         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5275         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5276         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5277
5278         { }
5279 };
5280
5281 static struct hda_verb alc260_will_verbs[] = {
5282         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5283         {0x0b, AC_VERB_SET_CONNECT_SEL, 0x00},
5284         {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
5285         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
5286         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
5287         {0x1a, AC_VERB_SET_PROC_COEF, 0x3040},
5288         {}
5289 };
5290
5291 static struct hda_verb alc260_replacer_672v_verbs[] = {
5292         {0x0f, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
5293         {0x1a, AC_VERB_SET_COEF_INDEX, 0x07},
5294         {0x1a, AC_VERB_SET_PROC_COEF, 0x3050},
5295
5296         {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5297         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5298         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5299
5300         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5301         {}
5302 };
5303
5304 /* toggle speaker-output according to the hp-jack state */
5305 static void alc260_replacer_672v_automute(struct hda_codec *codec)
5306 {
5307         unsigned int present;
5308
5309         /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
5310         present = snd_hda_codec_read(codec, 0x0f, 0,
5311                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5312         if (present) {
5313                 snd_hda_codec_write_cache(codec, 0x01, 0,
5314                                           AC_VERB_SET_GPIO_DATA, 1);
5315                 snd_hda_codec_write_cache(codec, 0x0f, 0,
5316                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
5317                                           PIN_HP);
5318         } else {
5319                 snd_hda_codec_write_cache(codec, 0x01, 0,
5320                                           AC_VERB_SET_GPIO_DATA, 0);
5321                 snd_hda_codec_write_cache(codec, 0x0f, 0,
5322                                           AC_VERB_SET_PIN_WIDGET_CONTROL,
5323                                           PIN_OUT);
5324         }
5325 }
5326
5327 static void alc260_replacer_672v_unsol_event(struct hda_codec *codec,
5328                                        unsigned int res)
5329 {
5330         if ((res >> 26) == ALC880_HP_EVENT)
5331                 alc260_replacer_672v_automute(codec);
5332 }
5333
5334 static struct hda_verb alc260_hp_dc7600_verbs[] = {
5335         {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
5336         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
5337         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5338         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5339         {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5340         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5341         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
5342         {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5343         {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5344         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
5345         {}
5346 };
5347
5348 /* Test configuration for debugging, modelled after the ALC880 test
5349  * configuration.
5350  */
5351 #ifdef CONFIG_SND_DEBUG
5352 static hda_nid_t alc260_test_dac_nids[1] = {
5353         0x02,
5354 };
5355 static hda_nid_t alc260_test_adc_nids[2] = {
5356         0x04, 0x05,
5357 };
5358 /* For testing the ALC260, each input MUX needs its own definition since
5359  * the signal assignments are different.  This assumes that the first ADC
5360  * is NID 0x04.
5361  */
5362 static struct hda_input_mux alc260_test_capture_sources[2] = {
5363         {
5364                 .num_items = 7,
5365                 .items = {
5366                         { "MIC1 pin", 0x0 },
5367                         { "MIC2 pin", 0x1 },
5368                         { "LINE1 pin", 0x2 },
5369                         { "LINE2 pin", 0x3 },
5370                         { "CD pin", 0x4 },
5371                         { "LINE-OUT pin", 0x5 },
5372                         { "HP-OUT pin", 0x6 },
5373                 },
5374         },
5375         {
5376                 .num_items = 8,
5377                 .items = {
5378                         { "MIC1 pin", 0x0 },
5379                         { "MIC2 pin", 0x1 },
5380                         { "LINE1 pin", 0x2 },
5381                         { "LINE2 pin", 0x3 },
5382                         { "CD pin", 0x4 },
5383                         { "Mixer", 0x5 },
5384                         { "LINE-OUT pin", 0x6 },
5385                         { "HP-OUT pin", 0x7 },
5386                 },
5387         },
5388 };
5389 static struct snd_kcontrol_new alc260_test_mixer[] = {
5390         /* Output driver widgets */
5391         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
5392         HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
5393         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
5394         HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
5395         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
5396         HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),
5397
5398         /* Modes for retasking pin widgets
5399          * Note: the ALC260 doesn't seem to act on requests to enable mic
5400          * bias from NIDs 0x0f and 0x10.  The ALC260 datasheet doesn't
5401          * mention this restriction.  At this stage it's not clear whether
5402          * this behaviour is intentional or is a hardware bug in chip
5403          * revisions available at least up until early 2006.  Therefore for
5404          * now allow the "HP-OUT" and "LINE-OUT" Mode controls to span all
5405          * choices, but if it turns out that the lack of mic bias for these
5406          * NIDs is intentional we could change their modes from
5407          * ALC_PIN_DIR_INOUT to ALC_PIN_DIR_INOUT_NOMICBIAS.
5408          */
5409         ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
5410         ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
5411         ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
5412         ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
5413         ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
5414         ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),
5415
5416         /* Loopback mixer controls */
5417         HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
5418         HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
5419         HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
5420         HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
5421         HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
5422         HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
5423         HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
5424         HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
5425         HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5426         HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5427         HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
5428         HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
5429         HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
5430         HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
5431
5432         /* Controls for GPIO pins, assuming they are configured as outputs */
5433         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
5434         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
5435         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
5436         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
5437
5438         /* Switches to allow the digital IO pins to be enabled.  The datasheet
5439          * is ambigious as to which NID is which; testing on laptops which
5440          * make this output available should provide clarification.
5441          */
5442         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x03, 0x01),
5443         ALC_SPDIF_CTRL_SWITCH("SPDIF Capture Switch", 0x06, 0x01),
5444
5445         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
5446          * this output to turn on an external amplifier.
5447          */
5448         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
5449         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
5450
5451         { } /* end */
5452 };
5453 static struct hda_verb alc260_test_init_verbs[] = {
5454         /* Enable all GPIOs as outputs with an initial value of 0 */
5455         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
5456         {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5457         {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
5458
5459         /* Enable retasking pins as output, initially without power amp */
5460         {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5461         {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5462         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5463         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5464         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5465         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
5466
5467         /* Disable digital (SPDIF) pins initially, but users can enable
5468          * them via a mixer switch.  In the case of SPDIF-out, this initverb
5469          * payload also sets the generation to 0, output to be in "consumer"
5470          * PCM format, copyright asserted, no pre-emphasis and no validity
5471          * control.
5472          */
5473         {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5474         {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5475
5476         /* Ensure mic1, mic2, line1 and line2 pin widgets take input from the
5477          * OUT1 sum bus when acting as an output.
5478          */
5479         {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5480         {0x0c, AC_VERB_SET_CONNECT_SEL, 0},
5481         {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5482         {0x0e, AC_VERB_SET_CONNECT_SEL, 0},
5483
5484         /* Start with output sum widgets muted and their output gains at min */
5485         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5486         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5487         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5488         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5489         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5490         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5491         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5492         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5493         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5494
5495         /* Unmute retasking pin widget output buffers since the default
5496          * state appears to be output.  As the pin mode is changed by the
5497          * user the pin mode control will take care of enabling the pin's
5498          * input/output buffers as needed.
5499          */
5500         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5501         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5502         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5503         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5504         {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5505         {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5506         /* Also unmute the mono-out pin widget */
5507         {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5508
5509         /* Mute capture amp left and right */
5510         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5511         /* Set ADC connection select to match default mixer setting (mic1
5512          * pin)
5513          */
5514         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5515
5516         /* Do the same for the second ADC: mute capture input amp and
5517          * set ADC connection to mic1 pin
5518          */
5519         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5520         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5521
5522         /* Mute all inputs to mixer widget (even unconnected ones) */
5523         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5524         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5525         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5526         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5527         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5528         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5529         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5530         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5531
5532         { }
5533 };
5534 #endif
5535
5536 #define alc260_pcm_analog_playback      alc880_pcm_analog_alt_playback
5537 #define alc260_pcm_analog_capture       alc880_pcm_analog_capture
5538
5539 #define alc260_pcm_digital_playback     alc880_pcm_digital_playback
5540 #define alc260_pcm_digital_capture      alc880_pcm_digital_capture
5541
5542 /*
5543  * for BIOS auto-configuration
5544  */
5545
5546 static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
5547                                         const char *pfx, int *vol_bits)
5548 {
5549         hda_nid_t nid_vol;
5550         unsigned long vol_val, sw_val;
5551         char name[32];
5552         int err;
5553
5554         if (nid >= 0x0f && nid < 0x11) {
5555                 nid_vol = nid - 0x7;
5556                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
5557                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
5558         } else if (nid == 0x11) {
5559                 nid_vol = nid - 0x7;
5560                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT);
5561                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
5562         } else if (nid >= 0x12 && nid <= 0x15) {
5563                 nid_vol = 0x08;
5564                 vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
5565                 sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
5566         } else
5567                 return 0; /* N/A */
5568
5569         if (!(*vol_bits & (1 << nid_vol))) {
5570                 /* first control for the volume widget */
5571                 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
5572                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name, vol_val);
5573                 if (err < 0)
5574                         return err;
5575                 *vol_bits |= (1 << nid_vol);
5576         }
5577         snprintf(name, sizeof(name), "%s Playback Switch", pfx);
5578         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, sw_val);
5579         if (err < 0)
5580                 return err;
5581         return 1;
5582 }
5583
5584 /* add playback controls from the parsed DAC table */
5585 static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
5586                                              const struct auto_pin_cfg *cfg)
5587 {
5588         hda_nid_t nid;
5589         int err;
5590         int vols = 0;
5591
5592         spec->multiout.num_dacs = 1;
5593         spec->multiout.dac_nids = spec->private_dac_nids;
5594         spec->multiout.dac_nids[0] = 0x02;
5595
5596         nid = cfg->line_out_pins[0];
5597         if (nid) {
5598                 err = alc260_add_playback_controls(spec, nid, "Front", &vols);
5599                 if (err < 0)
5600                         return err;
5601         }
5602
5603         nid = cfg->speaker_pins[0];
5604         if (nid) {
5605                 err = alc260_add_playback_controls(spec, nid, "Speaker", &vols);
5606                 if (err < 0)
5607                         return err;
5608         }
5609
5610         nid = cfg->hp_pins[0];
5611         if (nid) {
5612                 err = alc260_add_playback_controls(spec, nid, "Headphone",
5613                                                    &vols);
5614                 if (err < 0)
5615                         return err;
5616         }
5617         return 0;
5618 }
5619
5620 /* create playback/capture controls for input pins */
5621 static int alc260_auto_create_analog_input_ctls(struct alc_spec *spec,
5622                                                 const struct auto_pin_cfg *cfg)
5623 {
5624         struct hda_input_mux *imux = &spec->private_imux[0];
5625         int i, err, idx;
5626
5627         for (i = 0; i < AUTO_PIN_LAST; i++) {
5628                 if (cfg->input_pins[i] >= 0x12) {
5629                         idx = cfg->input_pins[i] - 0x12;
5630                         err = new_analog_input(spec, cfg->input_pins[i],
5631                                                auto_pin_cfg_labels[i], idx,
5632                                                0x07);
5633                         if (err < 0)
5634                                 return err;
5635                         imux->items[imux->num_items].label =
5636                                 auto_pin_cfg_labels[i];
5637                         imux->items[imux->num_items].index = idx;
5638                         imux->num_items++;
5639                 }
5640                 if (cfg->input_pins[i] >= 0x0f && cfg->input_pins[i] <= 0x10){
5641                         idx = cfg->input_pins[i] - 0x09;
5642                         err = new_analog_input(spec, cfg->input_pins[i],
5643                                                auto_pin_cfg_labels[i], idx,
5644                                                0x07);
5645                         if (err < 0)
5646                                 return err;
5647                         imux->items[imux->num_items].label =
5648                                 auto_pin_cfg_labels[i];
5649                         imux->items[imux->num_items].index = idx;
5650                         imux->num_items++;
5651                 }
5652         }
5653         return 0;
5654 }
5655
5656 static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
5657                                               hda_nid_t nid, int pin_type,
5658                                               int sel_idx)
5659 {
5660         alc_set_pin_output(codec, nid, pin_type);
5661         /* need the manual connection? */
5662         if (nid >= 0x12) {
5663                 int idx = nid - 0x12;
5664                 snd_hda_codec_write(codec, idx + 0x0b, 0,
5665                                     AC_VERB_SET_CONNECT_SEL, sel_idx);
5666         }
5667 }
5668
5669 static void alc260_auto_init_multi_out(struct hda_codec *codec)
5670 {
5671         struct alc_spec *spec = codec->spec;
5672         hda_nid_t nid;
5673
5674         alc_subsystem_id(codec, 0x10, 0x15, 0x0f);
5675         nid = spec->autocfg.line_out_pins[0];
5676         if (nid) {
5677                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
5678                 alc260_auto_set_output_and_unmute(codec, nid, pin_type, 0);
5679         }
5680
5681         nid = spec->autocfg.speaker_pins[0];
5682         if (nid)
5683                 alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
5684
5685         nid = spec->autocfg.hp_pins[0];
5686         if (nid)
5687                 alc260_auto_set_output_and_unmute(codec, nid, PIN_HP, 0);
5688 }
5689
5690 #define ALC260_PIN_CD_NID               0x16
5691 static void alc260_auto_init_analog_input(struct hda_codec *codec)
5692 {
5693         struct alc_spec *spec = codec->spec;
5694         int i;
5695
5696         for (i = 0; i < AUTO_PIN_LAST; i++) {
5697                 hda_nid_t nid = spec->autocfg.input_pins[i];
5698                 if (nid >= 0x12) {
5699                         alc_set_input_pin(codec, nid, i);
5700                         if (nid != ALC260_PIN_CD_NID &&
5701                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
5702                                 snd_hda_codec_write(codec, nid, 0,
5703                                                     AC_VERB_SET_AMP_GAIN_MUTE,
5704                                                     AMP_OUT_MUTE);
5705                 }
5706         }
5707 }
5708
5709 /*
5710  * generic initialization of ADC, input mixers and output mixers
5711  */
5712 static struct hda_verb alc260_volume_init_verbs[] = {
5713         /*
5714          * Unmute ADC0-1 and set the default input to mic-in
5715          */
5716         {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5717         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5718         {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5719         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5720
5721         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
5722          * mixer widget
5723          * Note: PASD motherboards uses the Line In 2 as the input for
5724          * front panel mic (mic 2)
5725          */
5726         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
5727         /* mute analog inputs */
5728         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5729         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5730         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
5731         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
5732         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
5733
5734         /*
5735          * Set up output mixers (0x08 - 0x0a)
5736          */
5737         /* set vol=0 to output mixers */
5738         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5739         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5740         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5741         /* set up input amps for analog loopback */
5742         /* Amp Indices: DAC = 0, mixer = 1 */
5743         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5744         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5745         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5746         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5747         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5748         {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
5749
5750         { }
5751 };
5752
5753 static int alc260_parse_auto_config(struct hda_codec *codec)
5754 {
5755         struct alc_spec *spec = codec->spec;
5756         int err;
5757         static hda_nid_t alc260_ignore[] = { 0x17, 0 };
5758
5759         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
5760                                            alc260_ignore);
5761         if (err < 0)
5762                 return err;
5763         err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg);
5764         if (err < 0)
5765                 return err;
5766         if (!spec->kctls.list)
5767                 return 0; /* can't find valid BIOS pin config */
5768         err = alc260_auto_create_analog_input_ctls(spec, &spec->autocfg);
5769         if (err < 0)
5770                 return err;
5771
5772         spec->multiout.max_channels = 2;
5773
5774         if (spec->autocfg.dig_outs)
5775                 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
5776         if (spec->kctls.list)
5777                 add_mixer(spec, spec->kctls.list);
5778
5779         add_verb(spec, alc260_volume_init_verbs);
5780
5781         spec->num_mux_defs = 1;
5782         spec->input_mux = &spec->private_imux[0];
5783
5784         return 1;
5785 }
5786
5787 /* additional initialization for auto-configuration model */
5788 static void alc260_auto_init(struct hda_codec *codec)
5789 {
5790         struct alc_spec *spec = codec->spec;
5791         alc260_auto_init_multi_out(codec);
5792         alc260_auto_init_analog_input(codec);
5793         if (spec->unsol_event)
5794                 alc_inithook(codec);
5795 }
5796
5797 #ifdef CONFIG_SND_HDA_POWER_SAVE
5798 static struct hda_amp_list alc260_loopbacks[] = {
5799         { 0x07, HDA_INPUT, 0 },
5800         { 0x07, HDA_INPUT, 1 },
5801         { 0x07, HDA_INPUT, 2 },
5802         { 0x07, HDA_INPUT, 3 },
5803         { 0x07, HDA_INPUT, 4 },
5804         { } /* end */
5805 };
5806 #endif
5807
5808 /*
5809  * ALC260 configurations
5810  */
5811 static const char *alc260_models[ALC260_MODEL_LAST] = {
5812         [ALC260_BASIC]          = "basic",
5813         [ALC260_HP]             = "hp",
5814         [ALC260_HP_3013]        = "hp-3013",
5815         [ALC260_HP_DC7600]      = "hp-dc7600",
5816         [ALC260_FUJITSU_S702X]  = "fujitsu",
5817         [ALC260_ACER]           = "acer",
5818         [ALC260_WILL]           = "will",
5819         [ALC260_REPLACER_672V]  = "replacer",
5820         [ALC260_FAVORIT100]     = "favorit100",
5821 #ifdef CONFIG_SND_DEBUG
5822         [ALC260_TEST]           = "test",
5823 #endif
5824         [ALC260_AUTO]           = "auto",
5825 };
5826
5827 static struct snd_pci_quirk alc260_cfg_tbl[] = {
5828         SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER),
5829         SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
5830         SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FAVORIT100),
5831         SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
5832         SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_HP_3013),
5833         SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
5834         SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP_3013),
5835         SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_DC7600),
5836         SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
5837         SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
5838         SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP),
5839         SND_PCI_QUIRK(0x103c, 0x3016, "HP", ALC260_HP),
5840         SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_BASIC),
5841         SND_PCI_QUIRK(0x104d, 0x81cc, "Sony VAIO", ALC260_BASIC),
5842         SND_PCI_QUIRK(0x104d, 0x81cd, "Sony VAIO", ALC260_BASIC),
5843         SND_PCI_QUIRK(0x10cf, 0x1326, "Fujitsu S702X", ALC260_FUJITSU_S702X),
5844         SND_PCI_QUIRK(0x152d, 0x0729, "CTL U553W", ALC260_BASIC),
5845         SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_REPLACER_672V),
5846         SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_WILL),
5847         {}
5848 };
5849
5850 static struct alc_config_preset alc260_presets[] = {
5851         [ALC260_BASIC] = {
5852                 .mixers = { alc260_base_output_mixer,
5853                             alc260_input_mixer },
5854                 .init_verbs = { alc260_init_verbs },
5855                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5856                 .dac_nids = alc260_dac_nids,
5857                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5858                 .adc_nids = alc260_adc_nids,
5859                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5860                 .channel_mode = alc260_modes,
5861                 .input_mux = &alc260_capture_source,
5862         },
5863         [ALC260_HP] = {
5864                 .mixers = { alc260_hp_output_mixer,
5865                             alc260_input_mixer },
5866                 .init_verbs = { alc260_init_verbs,
5867                                 alc260_hp_unsol_verbs },
5868                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5869                 .dac_nids = alc260_dac_nids,
5870                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
5871                 .adc_nids = alc260_adc_nids_alt,
5872                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5873                 .channel_mode = alc260_modes,
5874                 .input_mux = &alc260_capture_source,
5875                 .unsol_event = alc260_hp_unsol_event,
5876                 .init_hook = alc260_hp_automute,
5877         },
5878         [ALC260_HP_DC7600] = {
5879                 .mixers = { alc260_hp_dc7600_mixer,
5880                             alc260_input_mixer },
5881                 .init_verbs = { alc260_init_verbs,
5882                                 alc260_hp_dc7600_verbs },
5883                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5884                 .dac_nids = alc260_dac_nids,
5885                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
5886                 .adc_nids = alc260_adc_nids_alt,
5887                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5888                 .channel_mode = alc260_modes,
5889                 .input_mux = &alc260_capture_source,
5890                 .unsol_event = alc260_hp_3012_unsol_event,
5891                 .init_hook = alc260_hp_3012_automute,
5892         },
5893         [ALC260_HP_3013] = {
5894                 .mixers = { alc260_hp_3013_mixer,
5895                             alc260_input_mixer },
5896                 .init_verbs = { alc260_hp_3013_init_verbs,
5897                                 alc260_hp_3013_unsol_verbs },
5898                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5899                 .dac_nids = alc260_dac_nids,
5900                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
5901                 .adc_nids = alc260_adc_nids_alt,
5902                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5903                 .channel_mode = alc260_modes,
5904                 .input_mux = &alc260_capture_source,
5905                 .unsol_event = alc260_hp_3013_unsol_event,
5906                 .init_hook = alc260_hp_3013_automute,
5907         },
5908         [ALC260_FUJITSU_S702X] = {
5909                 .mixers = { alc260_fujitsu_mixer },
5910                 .init_verbs = { alc260_fujitsu_init_verbs },
5911                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5912                 .dac_nids = alc260_dac_nids,
5913                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5914                 .adc_nids = alc260_dual_adc_nids,
5915                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5916                 .channel_mode = alc260_modes,
5917                 .num_mux_defs = ARRAY_SIZE(alc260_fujitsu_capture_sources),
5918                 .input_mux = alc260_fujitsu_capture_sources,
5919         },
5920         [ALC260_ACER] = {
5921                 .mixers = { alc260_acer_mixer },
5922                 .init_verbs = { alc260_acer_init_verbs },
5923                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5924                 .dac_nids = alc260_dac_nids,
5925                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5926                 .adc_nids = alc260_dual_adc_nids,
5927                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5928                 .channel_mode = alc260_modes,
5929                 .num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources),
5930                 .input_mux = alc260_acer_capture_sources,
5931         },
5932         [ALC260_FAVORIT100] = {
5933                 .mixers = { alc260_favorit100_mixer },
5934                 .init_verbs = { alc260_favorit100_init_verbs },
5935                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5936                 .dac_nids = alc260_dac_nids,
5937                 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5938                 .adc_nids = alc260_dual_adc_nids,
5939                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5940                 .channel_mode = alc260_modes,
5941                 .num_mux_defs = ARRAY_SIZE(alc260_favorit100_capture_sources),
5942                 .input_mux = alc260_favorit100_capture_sources,
5943         },
5944         [ALC260_WILL] = {
5945                 .mixers = { alc260_will_mixer },
5946                 .init_verbs = { alc260_init_verbs, alc260_will_verbs },
5947                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5948                 .dac_nids = alc260_dac_nids,
5949                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5950                 .adc_nids = alc260_adc_nids,
5951                 .dig_out_nid = ALC260_DIGOUT_NID,
5952                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5953                 .channel_mode = alc260_modes,
5954                 .input_mux = &alc260_capture_source,
5955         },
5956         [ALC260_REPLACER_672V] = {
5957                 .mixers = { alc260_replacer_672v_mixer },
5958                 .init_verbs = { alc260_init_verbs, alc260_replacer_672v_verbs },
5959                 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5960                 .dac_nids = alc260_dac_nids,
5961                 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
5962                 .adc_nids = alc260_adc_nids,
5963                 .dig_out_nid = ALC260_DIGOUT_NID,
5964                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5965                 .channel_mode = alc260_modes,
5966                 .input_mux = &alc260_capture_source,
5967                 .unsol_event = alc260_replacer_672v_unsol_event,
5968                 .init_hook = alc260_replacer_672v_automute,
5969         },
5970 #ifdef CONFIG_SND_DEBUG
5971         [ALC260_TEST] = {
5972                 .mixers = { alc260_test_mixer },
5973                 .init_verbs = { alc260_test_init_verbs },
5974                 .num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
5975                 .dac_nids = alc260_test_dac_nids,
5976                 .num_adc_nids = ARRAY_SIZE(alc260_test_adc_nids),
5977                 .adc_nids = alc260_test_adc_nids,
5978                 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5979                 .channel_mode = alc260_modes,
5980                 .num_mux_defs = ARRAY_SIZE(alc260_test_capture_sources),
5981                 .input_mux = alc260_test_capture_sources,
5982         },
5983 #endif
5984 };
5985
5986 static int patch_alc260(struct hda_codec *codec)
5987 {
5988         struct alc_spec *spec;
5989         int err, board_config;
5990
5991         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5992         if (spec == NULL)
5993                 return -ENOMEM;
5994
5995         codec->spec = spec;
5996
5997         board_config = snd_hda_check_board_config(codec, ALC260_MODEL_LAST,
5998                                                   alc260_models,
5999                                                   alc260_cfg_tbl);
6000         if (board_config < 0) {
6001                 snd_printd(KERN_INFO "hda_codec: Unknown model for ALC260, "
6002                            "trying auto-probe from BIOS...\n");
6003                 board_config = ALC260_AUTO;
6004         }
6005
6006         if (board_config == ALC260_AUTO) {
6007                 /* automatic parse from the BIOS config */
6008                 err = alc260_parse_auto_config(codec);
6009                 if (err < 0) {
6010                         alc_free(codec);
6011                         return err;
6012                 } else if (!err) {
6013                         printk(KERN_INFO
6014                                "hda_codec: Cannot set up configuration "
6015                                "from BIOS.  Using base mode...\n");
6016                         board_config = ALC260_BASIC;
6017                 }
6018         }
6019
6020         err = snd_hda_attach_beep_device(codec, 0x1);
6021         if (err < 0) {
6022                 alc_free(codec);
6023                 return err;
6024         }
6025
6026         if (board_config != ALC260_AUTO)
6027                 setup_preset(spec, &alc260_presets[board_config]);
6028
6029         spec->stream_name_analog = "ALC260 Analog";
6030         spec->stream_analog_playback = &alc260_pcm_analog_playback;
6031         spec->stream_analog_capture = &alc260_pcm_analog_capture;
6032
6033         spec->stream_name_digital = "ALC260 Digital";
6034         spec->stream_digital_playback = &alc260_pcm_digital_playback;
6035         spec->stream_digital_capture = &alc260_pcm_digital_capture;
6036
6037         if (!spec->adc_nids && spec->input_mux) {
6038                 /* check whether NID 0x04 is valid */
6039                 unsigned int wcap = get_wcaps(codec, 0x04);
6040                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
6041                 /* get type */
6042                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
6043                         spec->adc_nids = alc260_adc_nids_alt;
6044                         spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
6045                 } else {
6046                         spec->adc_nids = alc260_adc_nids;
6047                         spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
6048                 }
6049         }
6050         set_capture_mixer(spec);
6051         set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
6052
6053         spec->vmaster_nid = 0x08;
6054
6055         codec->patch_ops = alc_patch_ops;
6056         if (board_config == ALC260_AUTO)
6057                 spec->init_hook = alc260_auto_init;
6058 #ifdef CONFIG_SND_HDA_POWER_SAVE
6059         if (!spec->loopback.amplist)
6060                 spec->loopback.amplist = alc260_loopbacks;
6061 #endif
6062         codec->proc_widget_hook = print_realtek_coef;
6063
6064         return 0;
6065 }
6066
6067
6068 /*
6069  * ALC882 support
6070  *
6071  * ALC882 is almost identical with ALC880 but has cleaner and more flexible
6072  * configuration.  Each pin widget can choose any input DACs and a mixer.
6073  * Each ADC is connected from a mixer of all inputs.  This makes possible
6074  * 6-channel independent captures.
6075  *
6076  * In addition, an independent DAC for the multi-playback (not used in this
6077  * driver yet).
6078  */
6079 #define ALC882_DIGOUT_NID       0x06
6080 #define ALC882_DIGIN_NID        0x0a
6081
6082 static struct hda_channel_mode alc882_ch_modes[1] = {
6083         { 8, NULL }
6084 };
6085
6086 static hda_nid_t alc882_dac_nids[4] = {
6087         /* front, rear, clfe, rear_surr */
6088         0x02, 0x03, 0x04, 0x05
6089 };
6090
6091 /* identical with ALC880 */
6092 #define alc882_adc_nids         alc880_adc_nids
6093 #define alc882_adc_nids_alt     alc880_adc_nids_alt
6094
6095 static hda_nid_t alc882_capsrc_nids[3] = { 0x24, 0x23, 0x22 };
6096 static hda_nid_t alc882_capsrc_nids_alt[2] = { 0x23, 0x22 };
6097
6098 /* input MUX */
6099 /* FIXME: should be a matrix-type input source selection */
6100
6101 static struct hda_input_mux alc882_capture_source = {
6102         .num_items = 4,
6103         .items = {
6104                 { "Mic", 0x0 },
6105                 { "Front Mic", 0x1 },
6106                 { "Line", 0x2 },
6107                 { "CD", 0x4 },
6108         },
6109 };
6110 /*
6111  * 2ch mode
6112  */
6113 static struct hda_verb alc882_3ST_ch2_init[] = {
6114         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
6115         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6116         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6117         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
6118         { } /* end */
6119 };
6120
6121 /*
6122  * 6ch mode
6123  */
6124 static struct hda_verb alc882_3ST_ch6_init[] = {
6125         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6126         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6127         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
6128         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6129         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
6130         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6131         { } /* end */
6132 };
6133
6134 static struct hda_channel_mode alc882_3ST_6ch_modes[2] = {
6135         { 2, alc882_3ST_ch2_init },
6136         { 6, alc882_3ST_ch6_init },
6137 };
6138
6139 /*
6140  * 6ch mode
6141  */
6142 static struct hda_verb alc882_sixstack_ch6_init[] = {
6143         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
6144         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6145         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6146         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6147         { } /* end */
6148 };
6149
6150 /*
6151  * 8ch mode
6152  */
6153 static struct hda_verb alc882_sixstack_ch8_init[] = {
6154         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6155         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6156         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6157         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6158         { } /* end */
6159 };
6160
6161 static struct hda_channel_mode alc882_sixstack_modes[2] = {
6162         { 6, alc882_sixstack_ch6_init },
6163         { 8, alc882_sixstack_ch8_init },
6164 };
6165
6166 /*
6167  * macbook pro ALC885 can switch LineIn to LineOut without loosing Mic
6168  */
6169
6170 /*
6171  * 2ch mode
6172  */
6173 static struct hda_verb alc885_mbp_ch2_init[] = {
6174         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
6175         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6176         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6177         { } /* end */
6178 };
6179
6180 /*
6181  * 6ch mode
6182  */
6183 static struct hda_verb alc885_mbp_ch6_init[] = {
6184         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
6185         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6186         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
6187         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6188         { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6189         { } /* end */
6190 };
6191
6192 static struct hda_channel_mode alc885_mbp_6ch_modes[2] = {
6193         { 2, alc885_mbp_ch2_init },
6194         { 6, alc885_mbp_ch6_init },
6195 };
6196
6197
6198 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
6199  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
6200  */
6201 static struct snd_kcontrol_new alc882_base_mixer[] = {
6202         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6203         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6204         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6205         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
6206         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
6207         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
6208         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
6209         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
6210         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
6211         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
6212         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6213         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6214         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6215         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6216         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6217         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6218         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6219         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6220         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6221         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6222         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6223         { } /* end */
6224 };
6225
6226 static struct snd_kcontrol_new alc885_mbp3_mixer[] = {
6227         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
6228         HDA_BIND_MUTE   ("Front Playback Switch", 0x0c, 0x02, HDA_INPUT),
6229         HDA_CODEC_MUTE  ("Speaker Playback Switch", 0x14, 0x00, HDA_OUTPUT),
6230         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x0d, 0x00, HDA_OUTPUT),
6231         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6232         HDA_CODEC_MUTE  ("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6233         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x00, HDA_INPUT),
6234         HDA_CODEC_MUTE  ("Mic Playback Switch", 0x0b, 0x00, HDA_INPUT),
6235         HDA_CODEC_VOLUME("Line Boost", 0x1a, 0x00, HDA_INPUT),
6236         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x00, HDA_INPUT),
6237         { } /* end */
6238 };
6239 static struct snd_kcontrol_new alc882_w2jc_mixer[] = {
6240         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6241         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6242         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6243         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6244         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6245         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6246         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6247         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6248         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6249         { } /* end */
6250 };
6251
6252 static struct snd_kcontrol_new alc882_targa_mixer[] = {
6253         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6254         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6255         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6256         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6257         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6258         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6259         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6260         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6261         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6262         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6263         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6264         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6265         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6266         { } /* end */
6267 };
6268
6269 /* Pin assignment: Front=0x14, HP = 0x15, Front = 0x16, ???
6270  *                 Front Mic=0x18, Line In = 0x1a, Line In = 0x1b, CD = 0x1c
6271  */
6272 static struct snd_kcontrol_new alc882_asus_a7j_mixer[] = {
6273         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6274         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
6275         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6276         HDA_CODEC_MUTE("Mobile Front Playback Switch", 0x16, 0x0, HDA_OUTPUT),
6277         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6278         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6279         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6280         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6281         HDA_CODEC_VOLUME("Mobile Line Playback Volume", 0x0b, 0x03, HDA_INPUT),
6282         HDA_CODEC_MUTE("Mobile Line Playback Switch", 0x0b, 0x03, HDA_INPUT),
6283         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6284         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6285         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6286         { } /* end */
6287 };
6288
6289 static struct snd_kcontrol_new alc882_asus_a7m_mixer[] = {
6290         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6291         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6292         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
6293         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6294         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6295         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6296         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6297         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6298         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6299         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6300         { } /* end */
6301 };
6302
6303 static struct snd_kcontrol_new alc882_chmode_mixer[] = {
6304         {
6305                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6306                 .name = "Channel Mode",
6307                 .info = alc_ch_mode_info,
6308                 .get = alc_ch_mode_get,
6309                 .put = alc_ch_mode_put,
6310         },
6311         { } /* end */
6312 };
6313
6314 static struct hda_verb alc882_init_verbs[] = {
6315         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6316         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6317         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6318         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6319         /* Rear mixer */
6320         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6321         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6322         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6323         /* CLFE mixer */
6324         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6325         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6326         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6327         /* Side mixer */
6328         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6329         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6330         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6331
6332         /* Front Pin: output 0 (0x0c) */
6333         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6334         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6335         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6336         /* Rear Pin: output 1 (0x0d) */
6337         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6338         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6339         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
6340         /* CLFE Pin: output 2 (0x0e) */
6341         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6342         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6343         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
6344         /* Side Pin: output 3 (0x0f) */
6345         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6346         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6347         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
6348         /* Mic (rear) pin: input vref at 80% */
6349         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6350         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6351         /* Front Mic pin: input vref at 80% */
6352         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6353         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6354         /* Line In pin: input */
6355         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6356         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6357         /* Line-2 In: Headphone output (output 0 - 0x0c) */
6358         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6359         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6360         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
6361         /* CD pin widget for input */
6362         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6363
6364         /* FIXME: use matrix-type input source selection */
6365         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6366         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6367         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6368         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6369         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6370         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6371         /* Input mixer2 */
6372         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6373         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6374         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6375         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6376         /* Input mixer3 */
6377         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6378         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6379         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6380         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6381         /* ADC1: mute amp left and right */
6382         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6383         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6384         /* ADC2: mute amp left and right */
6385         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6386         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6387         /* ADC3: mute amp left and right */
6388         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6389         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6390
6391         { }
6392 };
6393
6394 static struct hda_verb alc882_eapd_verbs[] = {
6395         /* change to EAPD mode */
6396         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
6397         {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
6398         { }
6399 };
6400
6401 /* Mac Pro test */
6402 static struct snd_kcontrol_new alc882_macpro_mixer[] = {
6403         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6404         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6405         HDA_CODEC_MUTE("Headphone Playback Switch", 0x18, 0x0, HDA_OUTPUT),
6406         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
6407         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
6408         /* FIXME: this looks suspicious...
6409         HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x02, HDA_INPUT),
6410         HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x02, HDA_INPUT),
6411         */
6412         { } /* end */
6413 };
6414
6415 static struct hda_verb alc882_macpro_init_verbs[] = {
6416         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6417         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6418         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6419         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6420         /* Front Pin: output 0 (0x0c) */
6421         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6422         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6423         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6424         /* Front Mic pin: input vref at 80% */
6425         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6426         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6427         /* Speaker:  output */
6428         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6429         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6430         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x04},
6431         /* Headphone output (output 0 - 0x0c) */
6432         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6433         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6434         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
6435
6436         /* FIXME: use matrix-type input source selection */
6437         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6438         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6439         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6440         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6441         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6442         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6443         /* Input mixer2 */
6444         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6445         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6446         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6447         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6448         /* Input mixer3 */
6449         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6450         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6451         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6452         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6453         /* ADC1: mute amp left and right */
6454         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6455         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6456         /* ADC2: mute amp left and right */
6457         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6458         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6459         /* ADC3: mute amp left and right */
6460         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6461         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6462
6463         { }
6464 };
6465
6466 /* Macbook Pro rev3 */
6467 static struct hda_verb alc885_mbp3_init_verbs[] = {
6468         /* Front mixer: unmute input/output amp left and right (volume = 0) */
6469         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6470         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6471         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6472         /* Rear mixer */
6473         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6474         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6475         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6476         /* Front Pin: output 0 (0x0c) */
6477         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6478         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6479         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6480         /* HP Pin: output 0 (0x0d) */
6481         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc4},
6482         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6483         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
6484         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6485         /* Mic (rear) pin: input vref at 80% */
6486         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6487         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6488         /* Front Mic pin: input vref at 80% */
6489         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6490         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6491         /* Line In pin: use output 1 when in LineOut mode */
6492         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
6493         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6494         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
6495
6496         /* FIXME: use matrix-type input source selection */
6497         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6498         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6499         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6500         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6501         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6502         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6503         /* Input mixer2 */
6504         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6505         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6506         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6507         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6508         /* Input mixer3 */
6509         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6510         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6511         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6512         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6513         /* ADC1: mute amp left and right */
6514         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6515         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6516         /* ADC2: mute amp left and right */
6517         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6518         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6519         /* ADC3: mute amp left and right */
6520         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6521         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6522
6523         { }
6524 };
6525
6526 /* iMac 24 mixer. */
6527 static struct snd_kcontrol_new alc885_imac24_mixer[] = {
6528         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x00, HDA_OUTPUT),
6529         HDA_CODEC_MUTE("Master Playback Switch", 0x0c, 0x00, HDA_INPUT),
6530         { } /* end */
6531 };
6532
6533 /* iMac 24 init verbs. */
6534 static struct hda_verb alc885_imac24_init_verbs[] = {
6535         /* Internal speakers: output 0 (0x0c) */
6536         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6537         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6538         {0x18, AC_VERB_SET_CONNECT_SEL, 0x00},
6539         /* Internal speakers: output 0 (0x0c) */
6540         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6541         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6542         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
6543         /* Headphone: output 0 (0x0c) */
6544         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6545         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
6546         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
6547         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6548         /* Front Mic: input vref at 80% */
6549         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
6550         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
6551         { }
6552 };
6553
6554 /* Toggle speaker-output according to the hp-jack state */
6555 static void alc885_imac24_automute(struct hda_codec *codec)
6556 {
6557         unsigned int present;
6558
6559         present = snd_hda_codec_read(codec, 0x14, 0,
6560                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6561         snd_hda_codec_amp_stereo(codec, 0x18, HDA_OUTPUT, 0,
6562                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6563         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
6564                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6565 }
6566
6567 /* Processes unsolicited events. */
6568 static void alc885_imac24_unsol_event(struct hda_codec *codec,
6569                                       unsigned int res)
6570 {
6571         /* Headphone insertion or removal. */
6572         if ((res >> 26) == ALC880_HP_EVENT)
6573                 alc885_imac24_automute(codec);
6574 }
6575
6576 static void alc885_mbp3_automute(struct hda_codec *codec)
6577 {
6578         unsigned int present;
6579
6580         present = snd_hda_codec_read(codec, 0x15, 0,
6581                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6582         snd_hda_codec_amp_stereo(codec, 0x14,  HDA_OUTPUT, 0,
6583                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6584         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
6585                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
6586
6587 }
6588 static void alc885_mbp3_unsol_event(struct hda_codec *codec,
6589                                     unsigned int res)
6590 {
6591         /* Headphone insertion or removal. */
6592         if ((res >> 26) == ALC880_HP_EVENT)
6593                 alc885_mbp3_automute(codec);
6594 }
6595
6596
6597 static struct hda_verb alc882_targa_verbs[] = {
6598         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6599         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6600
6601         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6602         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6603
6604         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6605         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6606         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6607
6608         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
6609         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6610         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
6611         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
6612         { } /* end */
6613 };
6614
6615 /* toggle speaker-output according to the hp-jack state */
6616 static void alc882_targa_automute(struct hda_codec *codec)
6617 {
6618         unsigned int present;
6619
6620         present = snd_hda_codec_read(codec, 0x14, 0,
6621                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
6622         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
6623                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
6624         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
6625                                   present ? 1 : 3);
6626 }
6627
6628 static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res)
6629 {
6630         /* Looks like the unsol event is incompatible with the standard
6631          * definition.  4bit tag is placed at 26 bit!
6632          */
6633         if (((res >> 26) == ALC880_HP_EVENT)) {
6634                 alc882_targa_automute(codec);
6635         }
6636 }
6637
6638 static struct hda_verb alc882_asus_a7j_verbs[] = {
6639         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6640         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6641
6642         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6643         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6644         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6645
6646         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6647         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6648         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6649
6650         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6651         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6652         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6653         { } /* end */
6654 };
6655
6656 static struct hda_verb alc882_asus_a7m_verbs[] = {
6657         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6658         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6659
6660         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
6661         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6662         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
6663
6664         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6665         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6666         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front */
6667
6668         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
6669         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
6670         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
6671         { } /* end */
6672 };
6673
6674 static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
6675 {
6676         unsigned int gpiostate, gpiomask, gpiodir;
6677
6678         gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
6679                                        AC_VERB_GET_GPIO_DATA, 0);
6680
6681         if (!muted)
6682                 gpiostate |= (1 << pin);
6683         else
6684                 gpiostate &= ~(1 << pin);
6685
6686         gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
6687                                       AC_VERB_GET_GPIO_MASK, 0);
6688         gpiomask |= (1 << pin);
6689
6690         gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
6691                                      AC_VERB_GET_GPIO_DIRECTION, 0);
6692         gpiodir |= (1 << pin);
6693
6694
6695         snd_hda_codec_write(codec, codec->afg, 0,
6696                             AC_VERB_SET_GPIO_MASK, gpiomask);
6697         snd_hda_codec_write(codec, codec->afg, 0,
6698                             AC_VERB_SET_GPIO_DIRECTION, gpiodir);
6699
6700         msleep(1);
6701
6702         snd_hda_codec_write(codec, codec->afg, 0,
6703                             AC_VERB_SET_GPIO_DATA, gpiostate);
6704 }
6705
6706 /* set up GPIO at initialization */
6707 static void alc885_macpro_init_hook(struct hda_codec *codec)
6708 {
6709         alc882_gpio_mute(codec, 0, 0);
6710         alc882_gpio_mute(codec, 1, 0);
6711 }
6712
6713 /* set up GPIO and update auto-muting at initialization */
6714 static void alc885_imac24_init_hook(struct hda_codec *codec)
6715 {
6716         alc885_macpro_init_hook(codec);
6717         alc885_imac24_automute(codec);
6718 }
6719
6720 /*
6721  * generic initialization of ADC, input mixers and output mixers
6722  */
6723 static struct hda_verb alc882_auto_init_verbs[] = {
6724         /*
6725          * Unmute ADC0-2 and set the default input to mic-in
6726          */
6727         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
6728         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6729         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
6730         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6731         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
6732         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6733
6734         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
6735          * mixer widget
6736          * Note: PASD motherboards uses the Line In 2 as the input for
6737          * front panel mic (mic 2)
6738          */
6739         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
6740         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
6741         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
6742         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
6743         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
6744         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
6745
6746         /*
6747          * Set up output mixers (0x0c - 0x0f)
6748          */
6749         /* set vol=0 to output mixers */
6750         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6751         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6752         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6753         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
6754         /* set up input amps for analog loopback */
6755         /* Amp Indices: DAC = 0, mixer = 1 */
6756         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6757         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6758         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6759         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6760         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6761         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6762         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6763         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6764         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
6765         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
6766
6767         /* FIXME: use matrix-type input source selection */
6768         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
6769         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
6770         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6771         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6772         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6773         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6774         /* Input mixer2 */
6775         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6776         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6777         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6778         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6779         /* Input mixer3 */
6780         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
6781         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
6782         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
6783         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
6784
6785         { }
6786 };
6787
6788 #ifdef CONFIG_SND_HDA_POWER_SAVE
6789 #define alc882_loopbacks        alc880_loopbacks
6790 #endif
6791
6792 /* pcm configuration: identiacal with ALC880 */
6793 #define alc882_pcm_analog_playback      alc880_pcm_analog_playback
6794 #define alc882_pcm_analog_capture       alc880_pcm_analog_capture
6795 #define alc882_pcm_digital_playback     alc880_pcm_digital_playback
6796 #define alc882_pcm_digital_capture      alc880_pcm_digital_capture
6797
6798 /*
6799  * configuration and preset
6800  */
6801 static const char *alc882_models[ALC882_MODEL_LAST] = {
6802         [ALC882_3ST_DIG]        = "3stack-dig",
6803         [ALC882_6ST_DIG]        = "6stack-dig",
6804         [ALC882_ARIMA]          = "arima",
6805         [ALC882_W2JC]           = "w2jc",
6806         [ALC882_TARGA]          = "targa",
6807         [ALC882_ASUS_A7J]       = "asus-a7j",
6808         [ALC882_ASUS_A7M]       = "asus-a7m",
6809         [ALC885_MACPRO]         = "macpro",
6810         [ALC885_MBP3]           = "mbp3",
6811         [ALC885_IMAC24]         = "imac24",
6812         [ALC882_AUTO]           = "auto",
6813 };
6814
6815 static struct snd_pci_quirk alc882_cfg_tbl[] = {
6816         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC882_6ST_DIG),
6817         SND_PCI_QUIRK(0x1043, 0x060d, "Asus A7J", ALC882_ASUS_A7J),
6818         SND_PCI_QUIRK(0x1043, 0x1243, "Asus A7J", ALC882_ASUS_A7J),
6819         SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_ASUS_A7M),
6820         SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_W2JC),
6821         SND_PCI_QUIRK(0x1043, 0x817f, "Asus P5LD2", ALC882_6ST_DIG),
6822         SND_PCI_QUIRK(0x1043, 0x81d8, "Asus P5WD", ALC882_6ST_DIG),
6823         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC882_6ST_DIG),
6824         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte P35 DS3R", ALC882_6ST_DIG),
6825         SND_PCI_QUIRK(0x1462, 0x28fb, "Targa T8", ALC882_TARGA), /* MSI-1049 T8  */
6826         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC882_6ST_DIG),
6827         SND_PCI_QUIRK(0x161f, 0x2054, "Arima W820", ALC882_ARIMA),
6828         {}
6829 };
6830
6831 static struct alc_config_preset alc882_presets[] = {
6832         [ALC882_3ST_DIG] = {
6833                 .mixers = { alc882_base_mixer },
6834                 .init_verbs = { alc882_init_verbs },
6835                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6836                 .dac_nids = alc882_dac_nids,
6837                 .dig_out_nid = ALC882_DIGOUT_NID,
6838                 .dig_in_nid = ALC882_DIGIN_NID,
6839                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6840                 .channel_mode = alc882_ch_modes,
6841                 .need_dac_fix = 1,
6842                 .input_mux = &alc882_capture_source,
6843         },
6844         [ALC882_6ST_DIG] = {
6845                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
6846                 .init_verbs = { alc882_init_verbs },
6847                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6848                 .dac_nids = alc882_dac_nids,
6849                 .dig_out_nid = ALC882_DIGOUT_NID,
6850                 .dig_in_nid = ALC882_DIGIN_NID,
6851                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
6852                 .channel_mode = alc882_sixstack_modes,
6853                 .input_mux = &alc882_capture_source,
6854         },
6855         [ALC882_ARIMA] = {
6856                 .mixers = { alc882_base_mixer, alc882_chmode_mixer },
6857                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs },
6858                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6859                 .dac_nids = alc882_dac_nids,
6860                 .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
6861                 .channel_mode = alc882_sixstack_modes,
6862                 .input_mux = &alc882_capture_source,
6863         },
6864         [ALC882_W2JC] = {
6865                 .mixers = { alc882_w2jc_mixer, alc882_chmode_mixer },
6866                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
6867                                 alc880_gpio1_init_verbs },
6868                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6869                 .dac_nids = alc882_dac_nids,
6870                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
6871                 .channel_mode = alc880_threestack_modes,
6872                 .need_dac_fix = 1,
6873                 .input_mux = &alc882_capture_source,
6874                 .dig_out_nid = ALC882_DIGOUT_NID,
6875         },
6876         [ALC885_MBP3] = {
6877                 .mixers = { alc885_mbp3_mixer, alc882_chmode_mixer },
6878                 .init_verbs = { alc885_mbp3_init_verbs,
6879                                 alc880_gpio1_init_verbs },
6880                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6881                 .dac_nids = alc882_dac_nids,
6882                 .channel_mode = alc885_mbp_6ch_modes,
6883                 .num_channel_mode = ARRAY_SIZE(alc885_mbp_6ch_modes),
6884                 .input_mux = &alc882_capture_source,
6885                 .dig_out_nid = ALC882_DIGOUT_NID,
6886                 .dig_in_nid = ALC882_DIGIN_NID,
6887                 .unsol_event = alc885_mbp3_unsol_event,
6888                 .init_hook = alc885_mbp3_automute,
6889         },
6890         [ALC885_MACPRO] = {
6891                 .mixers = { alc882_macpro_mixer },
6892                 .init_verbs = { alc882_macpro_init_verbs },
6893                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6894                 .dac_nids = alc882_dac_nids,
6895                 .dig_out_nid = ALC882_DIGOUT_NID,
6896                 .dig_in_nid = ALC882_DIGIN_NID,
6897                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6898                 .channel_mode = alc882_ch_modes,
6899                 .input_mux = &alc882_capture_source,
6900                 .init_hook = alc885_macpro_init_hook,
6901         },
6902         [ALC885_IMAC24] = {
6903                 .mixers = { alc885_imac24_mixer },
6904                 .init_verbs = { alc885_imac24_init_verbs },
6905                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6906                 .dac_nids = alc882_dac_nids,
6907                 .dig_out_nid = ALC882_DIGOUT_NID,
6908                 .dig_in_nid = ALC882_DIGIN_NID,
6909                 .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
6910                 .channel_mode = alc882_ch_modes,
6911                 .input_mux = &alc882_capture_source,
6912                 .unsol_event = alc885_imac24_unsol_event,
6913                 .init_hook = alc885_imac24_init_hook,
6914         },
6915         [ALC882_TARGA] = {
6916                 .mixers = { alc882_targa_mixer, alc882_chmode_mixer },
6917                 .init_verbs = { alc882_init_verbs, alc882_targa_verbs},
6918                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6919                 .dac_nids = alc882_dac_nids,
6920                 .dig_out_nid = ALC882_DIGOUT_NID,
6921                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6922                 .adc_nids = alc882_adc_nids,
6923                 .capsrc_nids = alc882_capsrc_nids,
6924                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6925                 .channel_mode = alc882_3ST_6ch_modes,
6926                 .need_dac_fix = 1,
6927                 .input_mux = &alc882_capture_source,
6928                 .unsol_event = alc882_targa_unsol_event,
6929                 .init_hook = alc882_targa_automute,
6930         },
6931         [ALC882_ASUS_A7J] = {
6932                 .mixers = { alc882_asus_a7j_mixer, alc882_chmode_mixer },
6933                 .init_verbs = { alc882_init_verbs, alc882_asus_a7j_verbs},
6934                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6935                 .dac_nids = alc882_dac_nids,
6936                 .dig_out_nid = ALC882_DIGOUT_NID,
6937                 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6938                 .adc_nids = alc882_adc_nids,
6939                 .capsrc_nids = alc882_capsrc_nids,
6940                 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6941                 .channel_mode = alc882_3ST_6ch_modes,
6942                 .need_dac_fix = 1,
6943                 .input_mux = &alc882_capture_source,
6944         },
6945         [ALC882_ASUS_A7M] = {
6946                 .mixers = { alc882_asus_a7m_mixer, alc882_chmode_mixer },
6947                 .init_verbs = { alc882_init_verbs, alc882_eapd_verbs,
6948                                 alc880_gpio1_init_verbs,
6949                                 alc882_asus_a7m_verbs },
6950                 .num_dacs = ARRAY_SIZE(alc882_dac_nids),
6951                 .dac_nids = alc882_dac_nids,
6952                 .dig_out_nid = ALC882_DIGOUT_NID,
6953                 .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
6954                 .channel_mode = alc880_threestack_modes,
6955                 .need_dac_fix = 1,
6956                 .input_mux = &alc882_capture_source,
6957         },
6958 };
6959
6960
6961 /*
6962  * Pin config fixes
6963  */
6964 enum {
6965         PINFIX_ABIT_AW9D_MAX
6966 };
6967
6968 static struct alc_pincfg alc882_abit_aw9d_pinfix[] = {
6969         { 0x15, 0x01080104 }, /* side */
6970         { 0x16, 0x01011012 }, /* rear */
6971         { 0x17, 0x01016011 }, /* clfe */
6972         { }
6973 };
6974
6975 static const struct alc_pincfg *alc882_pin_fixes[] = {
6976         [PINFIX_ABIT_AW9D_MAX] = alc882_abit_aw9d_pinfix,
6977 };
6978
6979 static struct snd_pci_quirk alc882_pinfix_tbl[] = {
6980         SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
6981         {}
6982 };
6983
6984 /*
6985  * BIOS auto configuration
6986  */
6987 static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
6988                                               hda_nid_t nid, int pin_type,
6989                                               int dac_idx)
6990 {
6991         /* set as output */
6992         struct alc_spec *spec = codec->spec;
6993         int idx;
6994
6995         alc_set_pin_output(codec, nid, pin_type);
6996         if (spec->multiout.dac_nids[dac_idx] == 0x25)
6997                 idx = 4;
6998         else
6999                 idx = spec->multiout.dac_nids[dac_idx] - 2;
7000         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
7001
7002 }
7003
7004 static void alc882_auto_init_multi_out(struct hda_codec *codec)
7005 {
7006         struct alc_spec *spec = codec->spec;
7007         int i;
7008
7009         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
7010         for (i = 0; i <= HDA_SIDE; i++) {
7011                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
7012                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
7013                 if (nid)
7014                         alc882_auto_set_output_and_unmute(codec, nid, pin_type,
7015                                                           i);
7016         }
7017 }
7018
7019 static void alc882_auto_init_hp_out(struct hda_codec *codec)
7020 {
7021         struct alc_spec *spec = codec->spec;
7022         hda_nid_t pin;
7023
7024         pin = spec->autocfg.hp_pins[0];
7025         if (pin) /* connect to front */
7026                 /* use dac 0 */
7027                 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
7028         pin = spec->autocfg.speaker_pins[0];
7029         if (pin)
7030                 alc882_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
7031 }
7032
7033 #define alc882_is_input_pin(nid)        alc880_is_input_pin(nid)
7034 #define ALC882_PIN_CD_NID               ALC880_PIN_CD_NID
7035
7036 static void alc882_auto_init_analog_input(struct hda_codec *codec)
7037 {
7038         struct alc_spec *spec = codec->spec;
7039         int i;
7040
7041         for (i = 0; i < AUTO_PIN_LAST; i++) {
7042                 hda_nid_t nid = spec->autocfg.input_pins[i];
7043                 if (!nid)
7044                         continue;
7045                 alc_set_input_pin(codec, nid, AUTO_PIN_FRONT_MIC /*i*/);
7046                 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
7047                         snd_hda_codec_write(codec, nid, 0,
7048                                             AC_VERB_SET_AMP_GAIN_MUTE,
7049                                             AMP_OUT_MUTE);
7050         }
7051 }
7052
7053 static void alc882_auto_init_input_src(struct hda_codec *codec)
7054 {
7055         struct alc_spec *spec = codec->spec;
7056         int c;
7057
7058         for (c = 0; c < spec->num_adc_nids; c++) {
7059                 hda_nid_t conn_list[HDA_MAX_NUM_INPUTS];
7060                 hda_nid_t nid = spec->capsrc_nids[c];
7061                 unsigned int mux_idx;
7062                 const struct hda_input_mux *imux;
7063                 int conns, mute, idx, item;
7064
7065                 conns = snd_hda_get_connections(codec, nid, conn_list,
7066                                                 ARRAY_SIZE(conn_list));
7067                 if (conns < 0)
7068                         continue;
7069                 mux_idx = c >= spec->num_mux_defs ? 0 : c;
7070                 imux = &spec->input_mux[mux_idx];
7071                 for (idx = 0; idx < conns; idx++) {
7072                         /* if the current connection is the selected one,
7073                          * unmute it as default - otherwise mute it
7074                          */
7075                         mute = AMP_IN_MUTE(idx);
7076                         for (item = 0; item < imux->num_items; item++) {
7077                                 if (imux->items[item].index == idx) {
7078                                         if (spec->cur_mux[c] == item)
7079                                                 mute = AMP_IN_UNMUTE(idx);
7080                                         break;
7081                                 }
7082                         }
7083                         /* check if we have a selector or mixer
7084                          * we could check for the widget type instead, but
7085                          * just check for Amp-In presence (in case of mixer
7086                          * without amp-in there is something wrong, this
7087                          * function shouldn't be used or capsrc nid is wrong)
7088                          */
7089                         if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)
7090                                 snd_hda_codec_write(codec, nid, 0,
7091                                                     AC_VERB_SET_AMP_GAIN_MUTE,
7092                                                     mute);
7093                         else if (mute != AMP_IN_MUTE(idx))
7094                                 snd_hda_codec_write(codec, nid, 0,
7095                                                     AC_VERB_SET_CONNECT_SEL,
7096                                                     idx);
7097                 }
7098         }
7099 }
7100
7101 /* add mic boosts if needed */
7102 static int alc_auto_add_mic_boost(struct hda_codec *codec)
7103 {
7104         struct alc_spec *spec = codec->spec;
7105         int err;
7106         hda_nid_t nid;
7107
7108         nid = spec->autocfg.input_pins[AUTO_PIN_MIC];
7109         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
7110                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
7111                                   "Mic Boost",
7112                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
7113                 if (err < 0)
7114                         return err;
7115         }
7116         nid = spec->autocfg.input_pins[AUTO_PIN_FRONT_MIC];
7117         if (nid && (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)) {
7118                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
7119                                   "Front Mic Boost",
7120                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
7121                 if (err < 0)
7122                         return err;
7123         }
7124         return 0;
7125 }
7126
7127 /* almost identical with ALC880 parser... */
7128 static int alc882_parse_auto_config(struct hda_codec *codec)
7129 {
7130         struct alc_spec *spec = codec->spec;
7131         int err = alc880_parse_auto_config(codec);
7132
7133         if (err < 0)
7134                 return err;
7135         else if (!err)
7136                 return 0; /* no config found */
7137
7138         err = alc_auto_add_mic_boost(codec);
7139         if (err < 0)
7140                 return err;
7141
7142         /* hack - override the init verbs */
7143         spec->init_verbs[0] = alc882_auto_init_verbs;
7144
7145         return 1; /* config found */
7146 }
7147
7148 /* additional initialization for auto-configuration model */
7149 static void alc882_auto_init(struct hda_codec *codec)
7150 {
7151         struct alc_spec *spec = codec->spec;
7152         alc882_auto_init_multi_out(codec);
7153         alc882_auto_init_hp_out(codec);
7154         alc882_auto_init_analog_input(codec);
7155         alc882_auto_init_input_src(codec);
7156         if (spec->unsol_event)
7157                 alc_inithook(codec);
7158 }
7159
7160 static int patch_alc883(struct hda_codec *codec); /* called in patch_alc882() */
7161
7162 static int patch_alc882(struct hda_codec *codec)
7163 {
7164         struct alc_spec *spec;
7165         int err, board_config;
7166
7167         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
7168         if (spec == NULL)
7169                 return -ENOMEM;
7170
7171         codec->spec = spec;
7172
7173         board_config = snd_hda_check_board_config(codec, ALC882_MODEL_LAST,
7174                                                   alc882_models,
7175                                                   alc882_cfg_tbl);
7176
7177         if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
7178                 /* Pick up systems that don't supply PCI SSID */
7179                 switch (codec->subsystem_id) {
7180                 case 0x106b0c00: /* Mac Pro */
7181                         board_config = ALC885_MACPRO;
7182                         break;
7183                 case 0x106b1000: /* iMac 24 */
7184                 case 0x106b2800: /* AppleTV */
7185                 case 0x106b3e00: /* iMac 24 Aluminium */
7186                         board_config = ALC885_IMAC24;
7187                         break;
7188                 case 0x106b00a0: /* MacBookPro3,1 - Another revision */
7189                 case 0x106b00a1: /* Macbook (might be wrong - PCI SSID?) */
7190                 case 0x106b00a4: /* MacbookPro4,1 */
7191                 case 0x106b2c00: /* Macbook Pro rev3 */
7192                 case 0x106b3600: /* Macbook 3.1 */
7193                 case 0x106b3800: /* MacbookPro4,1 - latter revision */
7194                         board_config = ALC885_MBP3;
7195                         break;
7196                 default:
7197                         /* ALC889A is handled better as ALC888-compatible */
7198                         if (codec->revision_id == 0x100101 ||
7199                             codec->revision_id == 0x100103) {
7200                                 alc_free(codec);
7201                                 return patch_alc883(codec);
7202                         }
7203                         printk(KERN_INFO "hda_codec: Unknown model for ALC882, "
7204                                          "trying auto-probe from BIOS...\n");
7205                         board_config = ALC882_AUTO;
7206                 }
7207         }
7208
7209         alc_fix_pincfg(codec, alc882_pinfix_tbl, alc882_pin_fixes);
7210
7211         if (board_config == ALC882_AUTO) {
7212                 /* automatic parse from the BIOS config */
7213                 err = alc882_parse_auto_config(codec);
7214                 if (err < 0) {
7215                         alc_free(codec);
7216                         return err;
7217                 } else if (!err) {
7218                         printk(KERN_INFO
7219                                "hda_codec: Cannot set up configuration "
7220                                "from BIOS.  Using base mode...\n");
7221                         board_config = ALC882_3ST_DIG;
7222                 }
7223         }
7224
7225         err = snd_hda_attach_beep_device(codec, 0x1);
7226         if (err < 0) {
7227                 alc_free(codec);
7228                 return err;
7229         }
7230
7231         if (board_config != ALC882_AUTO)
7232                 setup_preset(spec, &alc882_presets[board_config]);
7233
7234         if (codec->vendor_id == 0x10ec0885) {
7235                 spec->stream_name_analog = "ALC885 Analog";
7236                 spec->stream_name_digital = "ALC885 Digital";
7237         } else {
7238                 spec->stream_name_analog = "ALC882 Analog";
7239                 spec->stream_name_digital = "ALC882 Digital";
7240         }
7241
7242         spec->stream_analog_playback = &alc882_pcm_analog_playback;
7243         spec->stream_analog_capture = &alc882_pcm_analog_capture;
7244         /* FIXME: setup DAC5 */
7245         /*spec->stream_analog_alt_playback = &alc880_pcm_analog_alt_playback;*/
7246         spec->stream_analog_alt_capture = &alc880_pcm_analog_alt_capture;
7247
7248         spec->stream_digital_playback = &alc882_pcm_digital_playback;
7249         spec->stream_digital_capture = &alc882_pcm_digital_capture;
7250
7251         spec->capture_style = CAPT_MIX; /* matrix-style capture */
7252         if (!spec->adc_nids && spec->input_mux) {
7253                 /* check whether NID 0x07 is valid */
7254                 unsigned int wcap = get_wcaps(codec, 0x07);
7255                 /* get type */
7256                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
7257                 if (wcap != AC_WID_AUD_IN) {
7258                         spec->adc_nids = alc882_adc_nids_alt;
7259                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt);
7260                         spec->capsrc_nids = alc882_capsrc_nids_alt;
7261                 } else {
7262                         spec->adc_nids = alc882_adc_nids;
7263                         spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
7264                         spec->capsrc_nids = alc882_capsrc_nids;
7265                 }
7266         }
7267         set_capture_mixer(spec);
7268         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
7269
7270         spec->vmaster_nid = 0x0c;
7271
7272         codec->patch_ops = alc_patch_ops;
7273         if (board_config == ALC882_AUTO)
7274                 spec->init_hook = alc882_auto_init;
7275 #ifdef CONFIG_SND_HDA_POWER_SAVE
7276         if (!spec->loopback.amplist)
7277                 spec->loopback.amplist = alc882_loopbacks;
7278 #endif
7279         codec->proc_widget_hook = print_realtek_coef;
7280
7281         return 0;
7282 }
7283
7284 /*
7285  * ALC883 support
7286  *
7287  * ALC883 is almost identical with ALC880 but has cleaner and more flexible
7288  * configuration.  Each pin widget can choose any input DACs and a mixer.
7289  * Each ADC is connected from a mixer of all inputs.  This makes possible
7290  * 6-channel independent captures.
7291  *
7292  * In addition, an independent DAC for the multi-playback (not used in this
7293  * driver yet).
7294  */
7295 #define ALC883_DIGOUT_NID       0x06
7296 #define ALC883_DIGIN_NID        0x0a
7297
7298 #define ALC1200_DIGOUT_NID      0x10
7299
7300 static hda_nid_t alc883_dac_nids[4] = {
7301         /* front, rear, clfe, rear_surr */
7302         0x02, 0x03, 0x04, 0x05
7303 };
7304
7305 static hda_nid_t alc883_adc_nids[2] = {
7306         /* ADC1-2 */
7307         0x08, 0x09,
7308 };
7309
7310 static hda_nid_t alc883_adc_nids_alt[1] = {
7311         /* ADC1 */
7312         0x08,
7313 };
7314
7315 static hda_nid_t alc883_adc_nids_rev[2] = {
7316         /* ADC2-1 */
7317         0x09, 0x08
7318 };
7319
7320 #define alc889_adc_nids         alc880_adc_nids
7321
7322 static hda_nid_t alc883_capsrc_nids[2] = { 0x23, 0x22 };
7323
7324 static hda_nid_t alc883_capsrc_nids_rev[2] = { 0x22, 0x23 };
7325
7326 #define alc889_capsrc_nids      alc882_capsrc_nids
7327
7328 /* input MUX */
7329 /* FIXME: should be a matrix-type input source selection */
7330
7331 static struct hda_input_mux alc883_capture_source = {
7332         .num_items = 4,
7333         .items = {
7334                 { "Mic", 0x0 },
7335                 { "Front Mic", 0x1 },
7336                 { "Line", 0x2 },
7337                 { "CD", 0x4 },
7338         },
7339 };
7340
7341 static struct hda_input_mux alc883_3stack_6ch_intel = {
7342         .num_items = 4,
7343         .items = {
7344                 { "Mic", 0x1 },
7345                 { "Front Mic", 0x0 },
7346                 { "Line", 0x2 },
7347                 { "CD", 0x4 },
7348         },
7349 };
7350
7351 static struct hda_input_mux alc883_lenovo_101e_capture_source = {
7352         .num_items = 2,
7353         .items = {
7354                 { "Mic", 0x1 },
7355                 { "Line", 0x2 },
7356         },
7357 };
7358
7359 static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
7360         .num_items = 4,
7361         .items = {
7362                 { "Mic", 0x0 },
7363                 { "iMic", 0x1 },
7364                 { "Line", 0x2 },
7365                 { "CD", 0x4 },
7366         },
7367 };
7368
7369 static struct hda_input_mux alc883_fujitsu_pi2515_capture_source = {
7370         .num_items = 2,
7371         .items = {
7372                 { "Mic", 0x0 },
7373                 { "Int Mic", 0x1 },
7374         },
7375 };
7376
7377 static struct hda_input_mux alc883_lenovo_sky_capture_source = {
7378         .num_items = 3,
7379         .items = {
7380                 { "Mic", 0x0 },
7381                 { "Front Mic", 0x1 },
7382                 { "Line", 0x4 },
7383         },
7384 };
7385
7386 static struct hda_input_mux alc883_asus_eee1601_capture_source = {
7387         .num_items = 2,
7388         .items = {
7389                 { "Mic", 0x0 },
7390                 { "Line", 0x2 },
7391         },
7392 };
7393
7394 /*
7395  * 2ch mode
7396  */
7397 static struct hda_channel_mode alc883_3ST_2ch_modes[1] = {
7398         { 2, NULL }
7399 };
7400
7401 /*
7402  * 2ch mode
7403  */
7404 static struct hda_verb alc883_3ST_ch2_init[] = {
7405         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7406         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7407         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7408         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7409         { } /* end */
7410 };
7411
7412 /*
7413  * 4ch mode
7414  */
7415 static struct hda_verb alc883_3ST_ch4_init[] = {
7416         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7417         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7418         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7419         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7420         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7421         { } /* end */
7422 };
7423
7424 /*
7425  * 6ch mode
7426  */
7427 static struct hda_verb alc883_3ST_ch6_init[] = {
7428         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7429         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7430         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
7431         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7432         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7433         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7434         { } /* end */
7435 };
7436
7437 static struct hda_channel_mode alc883_3ST_6ch_modes[3] = {
7438         { 2, alc883_3ST_ch2_init },
7439         { 4, alc883_3ST_ch4_init },
7440         { 6, alc883_3ST_ch6_init },
7441 };
7442
7443 /*
7444  * 2ch mode
7445  */
7446 static struct hda_verb alc883_3ST_ch2_intel_init[] = {
7447         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7448         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7449         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7450         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7451         { } /* end */
7452 };
7453
7454 /*
7455  * 4ch mode
7456  */
7457 static struct hda_verb alc883_3ST_ch4_intel_init[] = {
7458         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7459         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7460         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7461         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7462         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7463         { } /* end */
7464 };
7465
7466 /*
7467  * 6ch mode
7468  */
7469 static struct hda_verb alc883_3ST_ch6_intel_init[] = {
7470         { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7471         { 0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7472         { 0x19, AC_VERB_SET_CONNECT_SEL, 0x02 },
7473         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7474         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7475         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
7476         { } /* end */
7477 };
7478
7479 static struct hda_channel_mode alc883_3ST_6ch_intel_modes[3] = {
7480         { 2, alc883_3ST_ch2_intel_init },
7481         { 4, alc883_3ST_ch4_intel_init },
7482         { 6, alc883_3ST_ch6_intel_init },
7483 };
7484
7485 /*
7486  * 6ch mode
7487  */
7488 static struct hda_verb alc883_sixstack_ch6_init[] = {
7489         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
7490         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7491         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7492         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7493         { } /* end */
7494 };
7495
7496 /*
7497  * 8ch mode
7498  */
7499 static struct hda_verb alc883_sixstack_ch8_init[] = {
7500         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7501         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7502         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7503         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7504         { } /* end */
7505 };
7506
7507 static struct hda_channel_mode alc883_sixstack_modes[2] = {
7508         { 6, alc883_sixstack_ch6_init },
7509         { 8, alc883_sixstack_ch8_init },
7510 };
7511
7512 static struct hda_verb alc883_medion_eapd_verbs[] = {
7513         /* eanable EAPD on medion laptop */
7514         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
7515         {0x20, AC_VERB_SET_PROC_COEF, 0x3070},
7516         { }
7517 };
7518
7519 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
7520  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
7521  */
7522
7523 static struct snd_kcontrol_new alc883_base_mixer[] = {
7524         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7525         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7526         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7527         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7528         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7529         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7530         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7531         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7532         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7533         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7534         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7535         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7536         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7537         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7538         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7539         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7540         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7541         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7542         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7543         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7544         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7545         { } /* end */
7546 };
7547
7548 static struct snd_kcontrol_new alc883_mitac_mixer[] = {
7549         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7550         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7551         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7552         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7553         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7554         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7555         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7556         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7557         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7558         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7559         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7560         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7561         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7562         { } /* end */
7563 };
7564
7565 static struct snd_kcontrol_new alc883_clevo_m720_mixer[] = {
7566         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7567         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7568         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7569         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7570         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7571         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7572         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7573         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7574         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7575         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7576         { } /* end */
7577 };
7578
7579 static struct snd_kcontrol_new alc883_2ch_fujitsu_pi2515_mixer[] = {
7580         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7581         HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
7582         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7583         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7584         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7585         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7586         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7587         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7588         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7589         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7590         { } /* end */
7591 };
7592
7593 static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
7594         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7595         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7596         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7597         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7598         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7599         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7600         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7601         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7602         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7603         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7604         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7605         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7606         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7607         { } /* end */
7608 };
7609
7610 static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
7611         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7612         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7613         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7614         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7615         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7616         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7617         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7618         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7619         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7620         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7621         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7622         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7623         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7624         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7625         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7626         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7627         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7628         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7629         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7630         { } /* end */
7631 };
7632
7633 static struct snd_kcontrol_new alc883_3ST_6ch_intel_mixer[] = {
7634         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7635         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7636         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7637         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7638         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0,
7639                               HDA_OUTPUT),
7640         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7641         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7642         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7643         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7644         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7645         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7646         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7647         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7648         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7649         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
7650         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7651         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7652         HDA_CODEC_VOLUME("Front Mic Boost", 0x18, 0, HDA_INPUT),
7653         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7654         { } /* end */
7655 };
7656
7657 static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
7658         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7659         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7660         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7661         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7662         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7663         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7664         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7665         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7666         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7667         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7668         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7669         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7670         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7671         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7672         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7673         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7674         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7675         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7676         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7677         { } /* end */
7678 };
7679
7680 static struct snd_kcontrol_new alc883_tagra_mixer[] = {
7681         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7682         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7683         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7684         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7685         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
7686         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
7687         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
7688         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
7689         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
7690         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7691         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7692         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7693         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7694         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7695         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7696         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7697         { } /* end */
7698 };
7699
7700 static struct snd_kcontrol_new alc883_tagra_2ch_mixer[] = {
7701         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7702         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7703         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7704         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7705         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7706         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7707         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7708         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7709         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7710         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
7711         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7712         { } /* end */
7713 };
7714
7715 static struct snd_kcontrol_new alc883_lenovo_101e_2ch_mixer[] = {
7716         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7717         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7718         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
7719         HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
7720         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7721         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7722         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7723         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7724         { } /* end */
7725 };
7726
7727 static struct snd_kcontrol_new alc883_lenovo_nb0763_mixer[] = {
7728         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7729         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
7730         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7731         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7732         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7733         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7734         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7735         HDA_CODEC_VOLUME("iMic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7736         HDA_CODEC_MUTE("iMic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7737         { } /* end */
7738 };
7739
7740 static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
7741         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7742         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7743         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
7744         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7745         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7746         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7747         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7748         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7749         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7750         { } /* end */
7751 };
7752
7753 static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
7754         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7755         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7756         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7757         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7758         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7759         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7760         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7761         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7762         { } /* end */
7763 };
7764
7765 static struct snd_kcontrol_new alc888_lenovo_sky_mixer[] = {
7766         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7767         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7768         HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
7769         HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
7770         HDA_CODEC_VOLUME_MONO("Center Playback Volume",
7771                                                 0x0d, 1, 0x0, HDA_OUTPUT),
7772         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
7773         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
7774         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
7775         HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
7776         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
7777         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
7778         HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
7779         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
7780         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
7781         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7782         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7783         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7784         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7785         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7786         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7787         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7788         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7789         { } /* end */
7790 };
7791
7792 static struct hda_bind_ctls alc883_bind_cap_vol = {
7793         .ops = &snd_hda_bind_vol,
7794         .values = {
7795                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
7796                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
7797                 0
7798         },
7799 };
7800
7801 static struct hda_bind_ctls alc883_bind_cap_switch = {
7802         .ops = &snd_hda_bind_sw,
7803         .values = {
7804                 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
7805                 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
7806                 0
7807         },
7808 };
7809
7810 static struct snd_kcontrol_new alc883_asus_eee1601_mixer[] = {
7811         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7812         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
7813         HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
7814         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
7815         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
7816         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7817         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
7818         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7819         { } /* end */
7820 };
7821
7822 static struct snd_kcontrol_new alc883_asus_eee1601_cap_mixer[] = {
7823         HDA_BIND_VOL("Capture Volume", &alc883_bind_cap_vol),
7824         HDA_BIND_SW("Capture Switch", &alc883_bind_cap_switch),
7825         {
7826                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7827                 /* .name = "Capture Source", */
7828                 .name = "Input Source",
7829                 .count = 1,
7830                 .info = alc_mux_enum_info,
7831                 .get = alc_mux_enum_get,
7832                 .put = alc_mux_enum_put,
7833         },
7834         { } /* end */
7835 };
7836
7837 static struct snd_kcontrol_new alc883_chmode_mixer[] = {
7838         {
7839                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
7840                 .name = "Channel Mode",
7841                 .info = alc_ch_mode_info,
7842                 .get = alc_ch_mode_get,
7843                 .put = alc_ch_mode_put,
7844         },
7845         { } /* end */
7846 };
7847
7848 static struct hda_verb alc883_init_verbs[] = {
7849         /* ADC1: mute amp left and right */
7850         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7851         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
7852         /* ADC2: mute amp left and right */
7853         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7854         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
7855         /* Front mixer: unmute input/output amp left and right (volume = 0) */
7856         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7857         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7858         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7859         /* Rear mixer */
7860         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7861         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7862         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7863         /* CLFE mixer */
7864         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7865         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7866         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7867         /* Side mixer */
7868         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
7869         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7870         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7871
7872         /* mute analog input loopbacks */
7873         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
7874         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7875         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7876         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
7877         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7878
7879         /* Front Pin: output 0 (0x0c) */
7880         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7881         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7882         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7883         /* Rear Pin: output 1 (0x0d) */
7884         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7885         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7886         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7887         /* CLFE Pin: output 2 (0x0e) */
7888         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7889         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7890         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
7891         /* Side Pin: output 3 (0x0f) */
7892         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7893         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7894         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
7895         /* Mic (rear) pin: input vref at 80% */
7896         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7897         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7898         /* Front Mic pin: input vref at 80% */
7899         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
7900         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7901         /* Line In pin: input */
7902         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7903         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
7904         /* Line-2 In: Headphone output (output 0 - 0x0c) */
7905         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7906         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
7907         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
7908         /* CD pin widget for input */
7909         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
7910
7911         /* FIXME: use matrix-type input source selection */
7912         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
7913         /* Input mixer2 */
7914         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7915         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7916         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7917         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7918         /* Input mixer3 */
7919         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7920         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
7921         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
7922         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
7923         { }
7924 };
7925
7926 /* toggle speaker-output according to the hp-jack state */
7927 static void alc883_mitac_hp_automute(struct hda_codec *codec)
7928 {
7929         unsigned int present;
7930
7931         present = snd_hda_codec_read(codec, 0x15, 0,
7932                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7933         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7934                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7935         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
7936                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7937 }
7938
7939 /* auto-toggle front mic */
7940 /*
7941 static void alc883_mitac_mic_automute(struct hda_codec *codec)
7942 {
7943         unsigned int present;
7944         unsigned char bits;
7945
7946         present = snd_hda_codec_read(codec, 0x18, 0,
7947                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7948         bits = present ? HDA_AMP_MUTE : 0;
7949         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
7950 }
7951 */
7952
7953 static void alc883_mitac_automute(struct hda_codec *codec)
7954 {
7955         alc883_mitac_hp_automute(codec);
7956         /* alc883_mitac_mic_automute(codec); */
7957 }
7958
7959 static void alc883_mitac_unsol_event(struct hda_codec *codec,
7960                                            unsigned int res)
7961 {
7962         switch (res >> 26) {
7963         case ALC880_HP_EVENT:
7964                 alc883_mitac_hp_automute(codec);
7965                 break;
7966         case ALC880_MIC_EVENT:
7967                 /* alc883_mitac_mic_automute(codec); */
7968                 break;
7969         }
7970 }
7971
7972 static struct hda_verb alc883_mitac_verbs[] = {
7973         /* HP */
7974         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7975         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7976         /* Subwoofer */
7977         {0x17, AC_VERB_SET_CONNECT_SEL, 0x02},
7978         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7979
7980         /* enable unsolicited event */
7981         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7982         /* {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN}, */
7983
7984         { } /* end */
7985 };
7986
7987 static struct hda_verb alc883_clevo_m720_verbs[] = {
7988         /* HP */
7989         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7990         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7991         /* Int speaker */
7992         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
7993         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7994
7995         /* enable unsolicited event */
7996         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7997         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
7998
7999         { } /* end */
8000 };
8001
8002 static struct hda_verb alc883_2ch_fujitsu_pi2515_verbs[] = {
8003         /* HP */
8004         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8005         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8006         /* Subwoofer */
8007         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
8008         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8009
8010         /* enable unsolicited event */
8011         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8012
8013         { } /* end */
8014 };
8015
8016 static struct hda_verb alc883_tagra_verbs[] = {
8017         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8018         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8019
8020         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8021         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8022
8023         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
8024         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/surround */
8025         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
8026
8027         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8028         {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
8029         {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
8030         {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
8031
8032         { } /* end */
8033 };
8034
8035 static struct hda_verb alc883_lenovo_101e_verbs[] = {
8036         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8037         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT|AC_USRSP_EN},
8038         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT|AC_USRSP_EN},
8039         { } /* end */
8040 };
8041
8042 static struct hda_verb alc883_lenovo_nb0763_verbs[] = {
8043         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8044         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8045         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8046         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8047         { } /* end */
8048 };
8049
8050 static struct hda_verb alc888_lenovo_ms7195_verbs[] = {
8051         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8052         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8053         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8054         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_FRONT_EVENT | AC_USRSP_EN},
8055         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT    | AC_USRSP_EN},
8056         { } /* end */
8057 };
8058
8059 static struct hda_verb alc883_haier_w66_verbs[] = {
8060         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8061         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8062
8063         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8064
8065         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
8066         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8067         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8068         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8069         { } /* end */
8070 };
8071
8072 static struct hda_verb alc888_lenovo_sky_verbs[] = {
8073         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8074         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8075         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8076         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8077         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8078         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8079         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
8080         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8081         { } /* end */
8082 };
8083
8084 static struct hda_verb alc888_6st_dell_verbs[] = {
8085         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8086         { }
8087 };
8088
8089 static void alc888_3st_hp_front_automute(struct hda_codec *codec)
8090 {
8091         unsigned int present, bits;
8092
8093         present = snd_hda_codec_read(codec, 0x1b, 0,
8094                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8095         bits = present ? HDA_AMP_MUTE : 0;
8096         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8097                                  HDA_AMP_MUTE, bits);
8098         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8099                                  HDA_AMP_MUTE, bits);
8100         snd_hda_codec_amp_stereo(codec, 0x18, HDA_OUTPUT, 0,
8101                                  HDA_AMP_MUTE, bits);
8102 }
8103
8104 static void alc888_3st_hp_unsol_event(struct hda_codec *codec,
8105                                       unsigned int res)
8106 {
8107         switch (res >> 26) {
8108         case ALC880_HP_EVENT:
8109                 alc888_3st_hp_front_automute(codec);
8110                 break;
8111         }
8112 }
8113
8114 static struct hda_verb alc888_3st_hp_verbs[] = {
8115         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Front: output 0 (0x0c) */
8116         {0x16, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Rear : output 1 (0x0d) */
8117         {0x18, AC_VERB_SET_CONNECT_SEL, 0x02},  /* CLFE : output 2 (0x0e) */
8118         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8119         { } /* end */
8120 };
8121
8122 /*
8123  * 2ch mode
8124  */
8125 static struct hda_verb alc888_3st_hp_2ch_init[] = {
8126         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
8127         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8128         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
8129         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8130         { } /* end */
8131 };
8132
8133 /*
8134  * 4ch mode
8135  */
8136 static struct hda_verb alc888_3st_hp_4ch_init[] = {
8137         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
8138         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8139         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8140         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8141         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x01 },
8142         { } /* end */
8143 };
8144
8145 /*
8146  * 6ch mode
8147  */
8148 static struct hda_verb alc888_3st_hp_6ch_init[] = {
8149         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8150         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8151         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
8152         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8153         { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8154         { 0x16, AC_VERB_SET_CONNECT_SEL, 0x01 },
8155         { } /* end */
8156 };
8157
8158 static struct hda_channel_mode alc888_3st_hp_modes[3] = {
8159         { 2, alc888_3st_hp_2ch_init },
8160         { 4, alc888_3st_hp_4ch_init },
8161         { 6, alc888_3st_hp_6ch_init },
8162 };
8163
8164 /* toggle front-jack and RCA according to the hp-jack state */
8165 static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
8166 {
8167         unsigned int present;
8168
8169         present = snd_hda_codec_read(codec, 0x1b, 0,
8170                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8171         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8172                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8173         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8174                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8175 }
8176
8177 /* toggle RCA according to the front-jack state */
8178 static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
8179 {
8180         unsigned int present;
8181
8182         present = snd_hda_codec_read(codec, 0x14, 0,
8183                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8184         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8185                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8186 }
8187
8188 static void alc883_lenovo_ms7195_unsol_event(struct hda_codec *codec,
8189                                              unsigned int res)
8190 {
8191         if ((res >> 26) == ALC880_HP_EVENT)
8192                 alc888_lenovo_ms7195_front_automute(codec);
8193         if ((res >> 26) == ALC880_FRONT_EVENT)
8194                 alc888_lenovo_ms7195_rca_automute(codec);
8195 }
8196
8197 static struct hda_verb alc883_medion_md2_verbs[] = {
8198         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8199         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8200
8201         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8202
8203         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8204         { } /* end */
8205 };
8206
8207 /* toggle speaker-output according to the hp-jack state */
8208 static void alc883_medion_md2_automute(struct hda_codec *codec)
8209 {
8210         unsigned int present;
8211
8212         present = snd_hda_codec_read(codec, 0x14, 0,
8213                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8214         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8215                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8216 }
8217
8218 static void alc883_medion_md2_unsol_event(struct hda_codec *codec,
8219                                           unsigned int res)
8220 {
8221         if ((res >> 26) == ALC880_HP_EVENT)
8222                 alc883_medion_md2_automute(codec);
8223 }
8224
8225 /* toggle speaker-output according to the hp-jack state */
8226 static void alc883_tagra_automute(struct hda_codec *codec)
8227 {
8228         unsigned int present;
8229         unsigned char bits;
8230
8231         present = snd_hda_codec_read(codec, 0x14, 0,
8232                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8233         bits = present ? HDA_AMP_MUTE : 0;
8234         snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
8235                                  HDA_AMP_MUTE, bits);
8236         snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
8237                                   present ? 1 : 3);
8238 }
8239
8240 static void alc883_tagra_unsol_event(struct hda_codec *codec, unsigned int res)
8241 {
8242         if ((res >> 26) == ALC880_HP_EVENT)
8243                 alc883_tagra_automute(codec);
8244 }
8245
8246 /* toggle speaker-output according to the hp-jack state */
8247 static void alc883_clevo_m720_hp_automute(struct hda_codec *codec)
8248 {
8249         unsigned int present;
8250         unsigned char bits;
8251
8252         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
8253                 & AC_PINSENSE_PRESENCE;
8254         bits = present ? HDA_AMP_MUTE : 0;
8255         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8256                                  HDA_AMP_MUTE, bits);
8257 }
8258
8259 static void alc883_clevo_m720_mic_automute(struct hda_codec *codec)
8260 {
8261         unsigned int present;
8262
8263         present = snd_hda_codec_read(codec, 0x18, 0,
8264                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8265         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
8266                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8267 }
8268
8269 static void alc883_clevo_m720_automute(struct hda_codec *codec)
8270 {
8271         alc883_clevo_m720_hp_automute(codec);
8272         alc883_clevo_m720_mic_automute(codec);
8273 }
8274
8275 static void alc883_clevo_m720_unsol_event(struct hda_codec *codec,
8276                                            unsigned int res)
8277 {
8278         switch (res >> 26) {
8279         case ALC880_HP_EVENT:
8280                 alc883_clevo_m720_hp_automute(codec);
8281                 break;
8282         case ALC880_MIC_EVENT:
8283                 alc883_clevo_m720_mic_automute(codec);
8284                 break;
8285         }
8286 }
8287
8288 /* toggle speaker-output according to the hp-jack state */
8289 static void alc883_2ch_fujitsu_pi2515_automute(struct hda_codec *codec)
8290 {
8291         unsigned int present;
8292         unsigned char bits;
8293
8294         present = snd_hda_codec_read(codec, 0x14, 0, AC_VERB_GET_PIN_SENSE, 0)
8295                 & AC_PINSENSE_PRESENCE;
8296         bits = present ? HDA_AMP_MUTE : 0;
8297         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8298                                  HDA_AMP_MUTE, bits);
8299 }
8300
8301 static void alc883_2ch_fujitsu_pi2515_unsol_event(struct hda_codec *codec,
8302                                                   unsigned int res)
8303 {
8304         if ((res >> 26) == ALC880_HP_EVENT)
8305                 alc883_2ch_fujitsu_pi2515_automute(codec);
8306 }
8307
8308 static void alc883_haier_w66_automute(struct hda_codec *codec)
8309 {
8310         unsigned int present;
8311         unsigned char bits;
8312
8313         present = snd_hda_codec_read(codec, 0x1b, 0,
8314                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8315         bits = present ? 0x80 : 0;
8316         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8317                                  0x80, bits);
8318 }
8319
8320 static void alc883_haier_w66_unsol_event(struct hda_codec *codec,
8321                                          unsigned int res)
8322 {
8323         if ((res >> 26) == ALC880_HP_EVENT)
8324                 alc883_haier_w66_automute(codec);
8325 }
8326
8327 static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
8328 {
8329         unsigned int present;
8330         unsigned char bits;
8331
8332         present = snd_hda_codec_read(codec, 0x14, 0,
8333                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8334         bits = present ? HDA_AMP_MUTE : 0;
8335         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8336                                  HDA_AMP_MUTE, bits);
8337 }
8338
8339 static void alc883_lenovo_101e_all_automute(struct hda_codec *codec)
8340 {
8341         unsigned int present;
8342         unsigned char bits;
8343
8344         present = snd_hda_codec_read(codec, 0x1b, 0,
8345                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8346         bits = present ? HDA_AMP_MUTE : 0;
8347         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8348                                  HDA_AMP_MUTE, bits);
8349         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8350                                  HDA_AMP_MUTE, bits);
8351 }
8352
8353 static void alc883_lenovo_101e_unsol_event(struct hda_codec *codec,
8354                                            unsigned int res)
8355 {
8356         if ((res >> 26) == ALC880_HP_EVENT)
8357                 alc883_lenovo_101e_all_automute(codec);
8358         if ((res >> 26) == ALC880_FRONT_EVENT)
8359                 alc883_lenovo_101e_ispeaker_automute(codec);
8360 }
8361
8362 /* toggle speaker-output according to the hp-jack state */
8363 static void alc883_acer_aspire_automute(struct hda_codec *codec)
8364 {
8365         unsigned int present;
8366
8367         present = snd_hda_codec_read(codec, 0x14, 0,
8368                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8369         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8370                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8371         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8372                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8373 }
8374
8375 static void alc883_acer_aspire_unsol_event(struct hda_codec *codec,
8376                                            unsigned int res)
8377 {
8378         if ((res >> 26) == ALC880_HP_EVENT)
8379                 alc883_acer_aspire_automute(codec);
8380 }
8381
8382 static struct hda_verb alc883_acer_eapd_verbs[] = {
8383         /* HP Pin: output 0 (0x0c) */
8384         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8385         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
8386         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8387         /* Front Pin: output 0 (0x0c) */
8388         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8389         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8390         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8391         {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
8392         /* eanable EAPD on medion laptop */
8393         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
8394         {0x20, AC_VERB_SET_PROC_COEF, 0x3050},
8395         /* enable unsolicited event */
8396         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8397         { }
8398 };
8399
8400 static void alc888_6st_dell_front_automute(struct hda_codec *codec)
8401 {
8402         unsigned int present;
8403
8404         present = snd_hda_codec_read(codec, 0x1b, 0,
8405                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8406         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8407                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8408         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8409                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8410         snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8411                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8412         snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
8413                                 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8414 }
8415
8416 static void alc888_6st_dell_unsol_event(struct hda_codec *codec,
8417                                              unsigned int res)
8418 {
8419         switch (res >> 26) {
8420         case ALC880_HP_EVENT:
8421                 /* printk(KERN_DEBUG "hp_event\n"); */
8422                 alc888_6st_dell_front_automute(codec);
8423                 break;
8424         }
8425 }
8426
8427 static void alc888_lenovo_sky_front_automute(struct hda_codec *codec)
8428 {
8429         unsigned int mute;
8430         unsigned int present;
8431
8432         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
8433         present = snd_hda_codec_read(codec, 0x1b, 0,
8434                                      AC_VERB_GET_PIN_SENSE, 0);
8435         present = (present & 0x80000000) != 0;
8436         if (present) {
8437                 /* mute internal speaker */
8438                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8439                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8440                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8441                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8442                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8443                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8444                 snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
8445                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8446                 snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
8447                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
8448         } else {
8449                 /* unmute internal speaker if necessary */
8450                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
8451                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8452                                          HDA_AMP_MUTE, mute);
8453                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8454                                          HDA_AMP_MUTE, mute);
8455                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8456                                          HDA_AMP_MUTE, mute);
8457                 snd_hda_codec_amp_stereo(codec, 0x17, HDA_OUTPUT, 0,
8458                                          HDA_AMP_MUTE, mute);
8459                 snd_hda_codec_amp_stereo(codec, 0x1a, HDA_OUTPUT, 0,
8460                                          HDA_AMP_MUTE, mute);
8461         }
8462 }
8463
8464 static void alc883_lenovo_sky_unsol_event(struct hda_codec *codec,
8465                                              unsigned int res)
8466 {
8467         if ((res >> 26) == ALC880_HP_EVENT)
8468                 alc888_lenovo_sky_front_automute(codec);
8469 }
8470
8471 /*
8472  * generic initialization of ADC, input mixers and output mixers
8473  */
8474 static struct hda_verb alc883_auto_init_verbs[] = {
8475         /*
8476          * Unmute ADC0-2 and set the default input to mic-in
8477          */
8478         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
8479         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8480         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
8481         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8482
8483         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
8484          * mixer widget
8485          * Note: PASD motherboards uses the Line In 2 as the input for
8486          * front panel mic (mic 2)
8487          */
8488         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
8489         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8490         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8491         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8492         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8493         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8494
8495         /*
8496          * Set up output mixers (0x0c - 0x0f)
8497          */
8498         /* set vol=0 to output mixers */
8499         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8500         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8501         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8502         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8503         /* set up input amps for analog loopback */
8504         /* Amp Indices: DAC = 0, mixer = 1 */
8505         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8506         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8507         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8508         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8509         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8510         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8511         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8512         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8513         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8514         {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8515
8516         /* FIXME: use matrix-type input source selection */
8517         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
8518         /* Input mixer1 */
8519         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8520         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8521         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8522         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
8523         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
8524         /* Input mixer2 */
8525         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8526         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8527         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
8528         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, */
8529         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
8530
8531         { }
8532 };
8533
8534 static struct hda_verb alc888_asus_m90v_verbs[] = {
8535         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8536         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8537         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8538         /* enable unsolicited event */
8539         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8540         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
8541         { } /* end */
8542 };
8543
8544 static void alc883_nb_mic_automute(struct hda_codec *codec)
8545 {
8546         unsigned int present;
8547
8548         present = snd_hda_codec_read(codec, 0x18, 0,
8549                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8550         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
8551                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
8552         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
8553                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
8554 }
8555
8556 static void alc883_M90V_speaker_automute(struct hda_codec *codec)
8557 {
8558         unsigned int present;
8559         unsigned char bits;
8560
8561         present = snd_hda_codec_read(codec, 0x1b, 0,
8562                                      AC_VERB_GET_PIN_SENSE, 0)
8563                 & AC_PINSENSE_PRESENCE;
8564         bits = present ? 0 : PIN_OUT;
8565         snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8566                             bits);
8567         snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8568                             bits);
8569         snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8570                             bits);
8571 }
8572
8573 static void alc883_mode2_unsol_event(struct hda_codec *codec,
8574                                            unsigned int res)
8575 {
8576         switch (res >> 26) {
8577         case ALC880_HP_EVENT:
8578                 alc883_M90V_speaker_automute(codec);
8579                 break;
8580         case ALC880_MIC_EVENT:
8581                 alc883_nb_mic_automute(codec);
8582                 break;
8583         }
8584 }
8585
8586 static void alc883_mode2_inithook(struct hda_codec *codec)
8587 {
8588         alc883_M90V_speaker_automute(codec);
8589         alc883_nb_mic_automute(codec);
8590 }
8591
8592 static struct hda_verb alc888_asus_eee1601_verbs[] = {
8593         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8594         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8595         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8596         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8597         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8598         {0x20, AC_VERB_SET_COEF_INDEX, 0x0b},
8599         {0x20, AC_VERB_SET_PROC_COEF,  0x0838},
8600         /* enable unsolicited event */
8601         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8602         { } /* end */
8603 };
8604
8605 static void alc883_eee1601_speaker_automute(struct hda_codec *codec)
8606 {
8607         unsigned int present;
8608         unsigned char bits;
8609
8610         present = snd_hda_codec_read(codec, 0x14, 0,
8611                                      AC_VERB_GET_PIN_SENSE, 0)
8612                 & AC_PINSENSE_PRESENCE;
8613         bits = present ? 0 : PIN_OUT;
8614         snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
8615                             bits);
8616 }
8617
8618 static void alc883_eee1601_unsol_event(struct hda_codec *codec,
8619                                            unsigned int res)
8620 {
8621         switch (res >> 26) {
8622         case ALC880_HP_EVENT:
8623                 alc883_eee1601_speaker_automute(codec);
8624                 break;
8625         }
8626 }
8627
8628 static void alc883_eee1601_inithook(struct hda_codec *codec)
8629 {
8630         alc883_eee1601_speaker_automute(codec);
8631 }
8632
8633 #ifdef CONFIG_SND_HDA_POWER_SAVE
8634 #define alc883_loopbacks        alc880_loopbacks
8635 #endif
8636
8637 /* pcm configuration: identiacal with ALC880 */
8638 #define alc883_pcm_analog_playback      alc880_pcm_analog_playback
8639 #define alc883_pcm_analog_capture       alc880_pcm_analog_capture
8640 #define alc883_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
8641 #define alc883_pcm_digital_playback     alc880_pcm_digital_playback
8642 #define alc883_pcm_digital_capture      alc880_pcm_digital_capture
8643
8644 /*
8645  * configuration and preset
8646  */
8647 static const char *alc883_models[ALC883_MODEL_LAST] = {
8648         [ALC883_3ST_2ch_DIG]    = "3stack-dig",
8649         [ALC883_3ST_6ch_DIG]    = "3stack-6ch-dig",
8650         [ALC883_3ST_6ch]        = "3stack-6ch",
8651         [ALC883_6ST_DIG]        = "6stack-dig",
8652         [ALC883_TARGA_DIG]      = "targa-dig",
8653         [ALC883_TARGA_2ch_DIG]  = "targa-2ch-dig",
8654         [ALC883_ACER]           = "acer",
8655         [ALC883_ACER_ASPIRE]    = "acer-aspire",
8656         [ALC888_ACER_ASPIRE_4930G]      = "acer-aspire-4930g",
8657         [ALC883_MEDION]         = "medion",
8658         [ALC883_MEDION_MD2]     = "medion-md2",
8659         [ALC883_LAPTOP_EAPD]    = "laptop-eapd",
8660         [ALC883_LENOVO_101E_2ch] = "lenovo-101e",
8661         [ALC883_LENOVO_NB0763]  = "lenovo-nb0763",
8662         [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
8663         [ALC888_LENOVO_SKY] = "lenovo-sky",
8664         [ALC883_HAIER_W66]      = "haier-w66",
8665         [ALC888_3ST_HP]         = "3stack-hp",
8666         [ALC888_6ST_DELL]       = "6stack-dell",
8667         [ALC883_MITAC]          = "mitac",
8668         [ALC883_CLEVO_M720]     = "clevo-m720",
8669         [ALC883_FUJITSU_PI2515] = "fujitsu-pi2515",
8670         [ALC888_FUJITSU_XA3530] = "fujitsu-xa3530",
8671         [ALC883_3ST_6ch_INTEL]  = "3stack-6ch-intel",
8672         [ALC1200_ASUS_P5Q]      = "asus-p5q",
8673         [ALC883_AUTO]           = "auto",
8674 };
8675
8676 static struct snd_pci_quirk alc883_cfg_tbl[] = {
8677         SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC883_3ST_6ch_DIG),
8678         SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE),
8679         SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_ACER_ASPIRE),
8680         SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_ACER_ASPIRE),
8681         SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE),
8682         SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE),
8683         SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_ACER_ASPIRE),
8684         SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
8685                 ALC888_ACER_ASPIRE_4930G),
8686         SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
8687                 ALC888_ACER_ASPIRE_4930G),
8688         SND_PCI_QUIRK(0x1025, 0x0157, "Acer X3200", ALC883_AUTO),
8689         SND_PCI_QUIRK(0x1025, 0x0158, "Acer AX1700-U3700A", ALC883_AUTO),
8690         SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
8691                 ALC888_ACER_ASPIRE_4930G),
8692         SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
8693                 ALC888_ACER_ASPIRE_4930G),
8694         /* default Acer */
8695         SND_PCI_QUIRK_VENDOR(0x1025, "Acer laptop", ALC883_ACER),
8696         SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL),
8697         SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
8698         SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
8699         SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
8700         SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG),
8701         SND_PCI_QUIRK(0x103c, 0x2a66, "HP Acacia", ALC888_3ST_HP),
8702         SND_PCI_QUIRK(0x103c, 0x2a72, "HP Educ.ar", ALC888_3ST_HP),
8703         SND_PCI_QUIRK(0x1043, 0x1873, "Asus M90V", ALC888_ASUS_M90V),
8704         SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG),
8705         SND_PCI_QUIRK(0x1043, 0x8284, "Asus Z37E", ALC883_6ST_DIG),
8706         SND_PCI_QUIRK(0x1043, 0x82fe, "Asus P5Q-EM HDMI", ALC1200_ASUS_P5Q),
8707         SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_ASUS_EEE1601),
8708         SND_PCI_QUIRK(0x105b, 0x0ce8, "Foxconn P35AX-S", ALC883_6ST_DIG),
8709         SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG),
8710         SND_PCI_QUIRK(0x1071, 0x8227, "Mitac 82801H", ALC883_MITAC),
8711         SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC),
8712         SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC883_LAPTOP_EAPD),
8713         SND_PCI_QUIRK(0x10f1, 0x2350, "TYAN-S2350", ALC888_6ST_DELL),
8714         SND_PCI_QUIRK(0x108e, 0x534d, NULL, ALC883_3ST_6ch),
8715         SND_PCI_QUIRK(0x1458, 0xa002, "MSI", ALC883_6ST_DIG),
8716         SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
8717         SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG),
8718         SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
8719         SND_PCI_QUIRK(0x1462, 0x2fb3, "MSI", ALC883_TARGA_2ch_DIG),
8720         SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
8721         SND_PCI_QUIRK(0x1462, 0x3783, "NEC S970", ALC883_TARGA_DIG),
8722         SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
8723         SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
8724         SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
8725         SND_PCI_QUIRK(0x1462, 0x3fc3, "MSI", ALC883_TARGA_DIG),
8726         SND_PCI_QUIRK(0x1462, 0x3fcc, "MSI", ALC883_TARGA_DIG),
8727         SND_PCI_QUIRK(0x1462, 0x3fdf, "MSI", ALC883_TARGA_DIG),
8728         SND_PCI_QUIRK(0x1462, 0x4314, "MSI", ALC883_TARGA_DIG),
8729         SND_PCI_QUIRK(0x1462, 0x4319, "MSI", ALC883_TARGA_DIG),
8730         SND_PCI_QUIRK(0x1462, 0x4324, "MSI", ALC883_TARGA_DIG),
8731         SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
8732         SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
8733         SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
8734         SND_PCI_QUIRK(0x1462, 0x7260, "MSI 7260", ALC883_TARGA_DIG),
8735         SND_PCI_QUIRK(0x1462, 0x7267, "MSI", ALC883_3ST_6ch_DIG),
8736         SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
8737         SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
8738         SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
8739         SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG),
8740         SND_PCI_QUIRK(0x1558, 0x0721, "Clevo laptop M720R", ALC883_CLEVO_M720),
8741         SND_PCI_QUIRK(0x1558, 0x0722, "Clevo laptop M720SR", ALC883_CLEVO_M720),
8742         SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC883_LAPTOP_EAPD),
8743         SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
8744         SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
8745         SND_PCI_QUIRK(0x1734, 0x1107, "FSC AMILO Xi2550",
8746                       ALC883_FUJITSU_PI2515),
8747         SND_PCI_QUIRK(0x1734, 0x1108, "Fujitsu AMILO Pi2515", ALC883_FUJITSU_PI2515),
8748         SND_PCI_QUIRK(0x1734, 0x113d, "Fujitsu AMILO Xa3530",
8749                 ALC888_FUJITSU_XA3530),
8750         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
8751         SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8752         SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8753         SND_PCI_QUIRK(0x17aa, 0x3bfd, "Lenovo NB0763", ALC883_LENOVO_NB0763),
8754         SND_PCI_QUIRK(0x17aa, 0x101d, "Lenovo Sky", ALC888_LENOVO_SKY),
8755         SND_PCI_QUIRK(0x17c0, 0x4071, "MEDION MD2", ALC883_MEDION_MD2),
8756         SND_PCI_QUIRK(0x17c0, 0x4085, "MEDION MD96630", ALC888_LENOVO_MS7195_DIG),
8757         SND_PCI_QUIRK(0x17f2, 0x5000, "Albatron KI690-AM2", ALC883_6ST_DIG),
8758         SND_PCI_QUIRK(0x1991, 0x5625, "Haier W66", ALC883_HAIER_W66),
8759         SND_PCI_QUIRK(0x8086, 0x0001, "DG33BUC", ALC883_3ST_6ch_INTEL),
8760         SND_PCI_QUIRK(0x8086, 0x0002, "DG33FBC", ALC883_3ST_6ch_INTEL),
8761         SND_PCI_QUIRK(0x8086, 0x2503, "82801H", ALC883_MITAC),
8762         SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC883_3ST_6ch_INTEL),
8763         SND_PCI_QUIRK(0x8086, 0xd601, "D102GGC", ALC883_3ST_6ch),
8764         {}
8765 };
8766
8767 static hda_nid_t alc883_slave_dig_outs[] = {
8768         ALC1200_DIGOUT_NID, 0,
8769 };
8770
8771 static hda_nid_t alc1200_slave_dig_outs[] = {
8772         ALC883_DIGOUT_NID, 0,
8773 };
8774
8775 static struct alc_config_preset alc883_presets[] = {
8776         [ALC883_3ST_2ch_DIG] = {
8777                 .mixers = { alc883_3ST_2ch_mixer },
8778                 .init_verbs = { alc883_init_verbs },
8779                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8780                 .dac_nids = alc883_dac_nids,
8781                 .dig_out_nid = ALC883_DIGOUT_NID,
8782                 .dig_in_nid = ALC883_DIGIN_NID,
8783                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8784                 .channel_mode = alc883_3ST_2ch_modes,
8785                 .input_mux = &alc883_capture_source,
8786         },
8787         [ALC883_3ST_6ch_DIG] = {
8788                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8789                 .init_verbs = { alc883_init_verbs },
8790                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8791                 .dac_nids = alc883_dac_nids,
8792                 .dig_out_nid = ALC883_DIGOUT_NID,
8793                 .dig_in_nid = ALC883_DIGIN_NID,
8794                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8795                 .channel_mode = alc883_3ST_6ch_modes,
8796                 .need_dac_fix = 1,
8797                 .input_mux = &alc883_capture_source,
8798         },
8799         [ALC883_3ST_6ch] = {
8800                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8801                 .init_verbs = { alc883_init_verbs },
8802                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8803                 .dac_nids = alc883_dac_nids,
8804                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8805                 .channel_mode = alc883_3ST_6ch_modes,
8806                 .need_dac_fix = 1,
8807                 .input_mux = &alc883_capture_source,
8808         },
8809         [ALC883_3ST_6ch_INTEL] = {
8810                 .mixers = { alc883_3ST_6ch_intel_mixer, alc883_chmode_mixer },
8811                 .init_verbs = { alc883_init_verbs },
8812                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8813                 .dac_nids = alc883_dac_nids,
8814                 .dig_out_nid = ALC883_DIGOUT_NID,
8815                 .dig_in_nid = ALC883_DIGIN_NID,
8816                 .slave_dig_outs = alc883_slave_dig_outs,
8817                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_intel_modes),
8818                 .channel_mode = alc883_3ST_6ch_intel_modes,
8819                 .need_dac_fix = 1,
8820                 .input_mux = &alc883_3stack_6ch_intel,
8821         },
8822         [ALC883_6ST_DIG] = {
8823                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
8824                 .init_verbs = { alc883_init_verbs },
8825                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8826                 .dac_nids = alc883_dac_nids,
8827                 .dig_out_nid = ALC883_DIGOUT_NID,
8828                 .dig_in_nid = ALC883_DIGIN_NID,
8829                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8830                 .channel_mode = alc883_sixstack_modes,
8831                 .input_mux = &alc883_capture_source,
8832         },
8833         [ALC883_TARGA_DIG] = {
8834                 .mixers = { alc883_tagra_mixer, alc883_chmode_mixer },
8835                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
8836                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8837                 .dac_nids = alc883_dac_nids,
8838                 .dig_out_nid = ALC883_DIGOUT_NID,
8839                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8840                 .channel_mode = alc883_3ST_6ch_modes,
8841                 .need_dac_fix = 1,
8842                 .input_mux = &alc883_capture_source,
8843                 .unsol_event = alc883_tagra_unsol_event,
8844                 .init_hook = alc883_tagra_automute,
8845         },
8846         [ALC883_TARGA_2ch_DIG] = {
8847                 .mixers = { alc883_tagra_2ch_mixer},
8848                 .init_verbs = { alc883_init_verbs, alc883_tagra_verbs},
8849                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8850                 .dac_nids = alc883_dac_nids,
8851                 .adc_nids = alc883_adc_nids_alt,
8852                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
8853                 .dig_out_nid = ALC883_DIGOUT_NID,
8854                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8855                 .channel_mode = alc883_3ST_2ch_modes,
8856                 .input_mux = &alc883_capture_source,
8857                 .unsol_event = alc883_tagra_unsol_event,
8858                 .init_hook = alc883_tagra_automute,
8859         },
8860         [ALC883_ACER] = {
8861                 .mixers = { alc883_base_mixer },
8862                 /* On TravelMate laptops, GPIO 0 enables the internal speaker
8863                  * and the headphone jack.  Turn this on and rely on the
8864                  * standard mute methods whenever the user wants to turn
8865                  * these outputs off.
8866                  */
8867                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
8868                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8869                 .dac_nids = alc883_dac_nids,
8870                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8871                 .channel_mode = alc883_3ST_2ch_modes,
8872                 .input_mux = &alc883_capture_source,
8873         },
8874         [ALC883_ACER_ASPIRE] = {
8875                 .mixers = { alc883_acer_aspire_mixer },
8876                 .init_verbs = { alc883_init_verbs, alc883_acer_eapd_verbs },
8877                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8878                 .dac_nids = alc883_dac_nids,
8879                 .dig_out_nid = ALC883_DIGOUT_NID,
8880                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8881                 .channel_mode = alc883_3ST_2ch_modes,
8882                 .input_mux = &alc883_capture_source,
8883                 .unsol_event = alc883_acer_aspire_unsol_event,
8884                 .init_hook = alc883_acer_aspire_automute,
8885         },
8886         [ALC888_ACER_ASPIRE_4930G] = {
8887                 .mixers = { alc888_base_mixer,
8888                                 alc883_chmode_mixer },
8889                 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs,
8890                                 alc888_acer_aspire_4930g_verbs },
8891                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8892                 .dac_nids = alc883_dac_nids,
8893                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
8894                 .adc_nids = alc883_adc_nids_rev,
8895                 .capsrc_nids = alc883_capsrc_nids_rev,
8896                 .dig_out_nid = ALC883_DIGOUT_NID,
8897                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8898                 .channel_mode = alc883_3ST_6ch_modes,
8899                 .need_dac_fix = 1,
8900                 .num_mux_defs =
8901                         ARRAY_SIZE(alc888_2_capture_sources),
8902                 .input_mux = alc888_2_capture_sources,
8903                 .unsol_event = alc888_acer_aspire_4930g_unsol_event,
8904                 .init_hook = alc888_acer_aspire_4930g_automute,
8905         },
8906         [ALC883_MEDION] = {
8907                 .mixers = { alc883_fivestack_mixer,
8908                             alc883_chmode_mixer },
8909                 .init_verbs = { alc883_init_verbs,
8910                                 alc883_medion_eapd_verbs },
8911                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8912                 .dac_nids = alc883_dac_nids,
8913                 .adc_nids = alc883_adc_nids_alt,
8914                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
8915                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8916                 .channel_mode = alc883_sixstack_modes,
8917                 .input_mux = &alc883_capture_source,
8918         },
8919         [ALC883_MEDION_MD2] = {
8920                 .mixers = { alc883_medion_md2_mixer},
8921                 .init_verbs = { alc883_init_verbs, alc883_medion_md2_verbs},
8922                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8923                 .dac_nids = alc883_dac_nids,
8924                 .dig_out_nid = ALC883_DIGOUT_NID,
8925                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8926                 .channel_mode = alc883_3ST_2ch_modes,
8927                 .input_mux = &alc883_capture_source,
8928                 .unsol_event = alc883_medion_md2_unsol_event,
8929                 .init_hook = alc883_medion_md2_automute,
8930         },
8931         [ALC883_LAPTOP_EAPD] = {
8932                 .mixers = { alc883_base_mixer },
8933                 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
8934                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8935                 .dac_nids = alc883_dac_nids,
8936                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8937                 .channel_mode = alc883_3ST_2ch_modes,
8938                 .input_mux = &alc883_capture_source,
8939         },
8940         [ALC883_CLEVO_M720] = {
8941                 .mixers = { alc883_clevo_m720_mixer },
8942                 .init_verbs = { alc883_init_verbs, alc883_clevo_m720_verbs },
8943                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8944                 .dac_nids = alc883_dac_nids,
8945                 .dig_out_nid = ALC883_DIGOUT_NID,
8946                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8947                 .channel_mode = alc883_3ST_2ch_modes,
8948                 .input_mux = &alc883_capture_source,
8949                 .unsol_event = alc883_clevo_m720_unsol_event,
8950                 .init_hook = alc883_clevo_m720_automute,
8951         },
8952         [ALC883_LENOVO_101E_2ch] = {
8953                 .mixers = { alc883_lenovo_101e_2ch_mixer},
8954                 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
8955                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8956                 .dac_nids = alc883_dac_nids,
8957                 .adc_nids = alc883_adc_nids_alt,
8958                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_alt),
8959                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8960                 .channel_mode = alc883_3ST_2ch_modes,
8961                 .input_mux = &alc883_lenovo_101e_capture_source,
8962                 .unsol_event = alc883_lenovo_101e_unsol_event,
8963                 .init_hook = alc883_lenovo_101e_all_automute,
8964         },
8965         [ALC883_LENOVO_NB0763] = {
8966                 .mixers = { alc883_lenovo_nb0763_mixer },
8967                 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs},
8968                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8969                 .dac_nids = alc883_dac_nids,
8970                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8971                 .channel_mode = alc883_3ST_2ch_modes,
8972                 .need_dac_fix = 1,
8973                 .input_mux = &alc883_lenovo_nb0763_capture_source,
8974                 .unsol_event = alc883_medion_md2_unsol_event,
8975                 .init_hook = alc883_medion_md2_automute,
8976         },
8977         [ALC888_LENOVO_MS7195_DIG] = {
8978                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
8979                 .init_verbs = { alc883_init_verbs, alc888_lenovo_ms7195_verbs},
8980                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8981                 .dac_nids = alc883_dac_nids,
8982                 .dig_out_nid = ALC883_DIGOUT_NID,
8983                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
8984                 .channel_mode = alc883_3ST_6ch_modes,
8985                 .need_dac_fix = 1,
8986                 .input_mux = &alc883_capture_source,
8987                 .unsol_event = alc883_lenovo_ms7195_unsol_event,
8988                 .init_hook = alc888_lenovo_ms7195_front_automute,
8989         },
8990         [ALC883_HAIER_W66] = {
8991                 .mixers = { alc883_tagra_2ch_mixer},
8992                 .init_verbs = { alc883_init_verbs, alc883_haier_w66_verbs},
8993                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
8994                 .dac_nids = alc883_dac_nids,
8995                 .dig_out_nid = ALC883_DIGOUT_NID,
8996                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
8997                 .channel_mode = alc883_3ST_2ch_modes,
8998                 .input_mux = &alc883_capture_source,
8999                 .unsol_event = alc883_haier_w66_unsol_event,
9000                 .init_hook = alc883_haier_w66_automute,
9001         },
9002         [ALC888_3ST_HP] = {
9003                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9004                 .init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs },
9005                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9006                 .dac_nids = alc883_dac_nids,
9007                 .num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes),
9008                 .channel_mode = alc888_3st_hp_modes,
9009                 .need_dac_fix = 1,
9010                 .input_mux = &alc883_capture_source,
9011                 .unsol_event = alc888_3st_hp_unsol_event,
9012                 .init_hook = alc888_3st_hp_front_automute,
9013         },
9014         [ALC888_6ST_DELL] = {
9015                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
9016                 .init_verbs = { alc883_init_verbs, alc888_6st_dell_verbs },
9017                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9018                 .dac_nids = alc883_dac_nids,
9019                 .dig_out_nid = ALC883_DIGOUT_NID,
9020                 .dig_in_nid = ALC883_DIGIN_NID,
9021                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9022                 .channel_mode = alc883_sixstack_modes,
9023                 .input_mux = &alc883_capture_source,
9024                 .unsol_event = alc888_6st_dell_unsol_event,
9025                 .init_hook = alc888_6st_dell_front_automute,
9026         },
9027         [ALC883_MITAC] = {
9028                 .mixers = { alc883_mitac_mixer },
9029                 .init_verbs = { alc883_init_verbs, alc883_mitac_verbs },
9030                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9031                 .dac_nids = alc883_dac_nids,
9032                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9033                 .channel_mode = alc883_3ST_2ch_modes,
9034                 .input_mux = &alc883_capture_source,
9035                 .unsol_event = alc883_mitac_unsol_event,
9036                 .init_hook = alc883_mitac_automute,
9037         },
9038         [ALC883_FUJITSU_PI2515] = {
9039                 .mixers = { alc883_2ch_fujitsu_pi2515_mixer },
9040                 .init_verbs = { alc883_init_verbs,
9041                                 alc883_2ch_fujitsu_pi2515_verbs},
9042                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9043                 .dac_nids = alc883_dac_nids,
9044                 .dig_out_nid = ALC883_DIGOUT_NID,
9045                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9046                 .channel_mode = alc883_3ST_2ch_modes,
9047                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
9048                 .unsol_event = alc883_2ch_fujitsu_pi2515_unsol_event,
9049                 .init_hook = alc883_2ch_fujitsu_pi2515_automute,
9050         },
9051         [ALC888_FUJITSU_XA3530] = {
9052                 .mixers = { alc888_base_mixer, alc883_chmode_mixer },
9053                 .init_verbs = { alc883_init_verbs,
9054                         alc888_fujitsu_xa3530_verbs },
9055                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9056                 .dac_nids = alc883_dac_nids,
9057                 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids_rev),
9058                 .adc_nids = alc883_adc_nids_rev,
9059                 .capsrc_nids = alc883_capsrc_nids_rev,
9060                 .dig_out_nid = ALC883_DIGOUT_NID,
9061                 .num_channel_mode = ARRAY_SIZE(alc888_4ST_8ch_intel_modes),
9062                 .channel_mode = alc888_4ST_8ch_intel_modes,
9063                 .num_mux_defs =
9064                         ARRAY_SIZE(alc888_2_capture_sources),
9065                 .input_mux = alc888_2_capture_sources,
9066                 .unsol_event = alc888_fujitsu_xa3530_unsol_event,
9067                 .init_hook = alc888_fujitsu_xa3530_automute,
9068         },
9069         [ALC888_LENOVO_SKY] = {
9070                 .mixers = { alc888_lenovo_sky_mixer, alc883_chmode_mixer },
9071                 .init_verbs = { alc883_init_verbs, alc888_lenovo_sky_verbs},
9072                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9073                 .dac_nids = alc883_dac_nids,
9074                 .dig_out_nid = ALC883_DIGOUT_NID,
9075                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9076                 .channel_mode = alc883_sixstack_modes,
9077                 .need_dac_fix = 1,
9078                 .input_mux = &alc883_lenovo_sky_capture_source,
9079                 .unsol_event = alc883_lenovo_sky_unsol_event,
9080                 .init_hook = alc888_lenovo_sky_front_automute,
9081         },
9082         [ALC888_ASUS_M90V] = {
9083                 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
9084                 .init_verbs = { alc883_init_verbs, alc888_asus_m90v_verbs },
9085                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9086                 .dac_nids = alc883_dac_nids,
9087                 .dig_out_nid = ALC883_DIGOUT_NID,
9088                 .dig_in_nid = ALC883_DIGIN_NID,
9089                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
9090                 .channel_mode = alc883_3ST_6ch_modes,
9091                 .need_dac_fix = 1,
9092                 .input_mux = &alc883_fujitsu_pi2515_capture_source,
9093                 .unsol_event = alc883_mode2_unsol_event,
9094                 .init_hook = alc883_mode2_inithook,
9095         },
9096         [ALC888_ASUS_EEE1601] = {
9097                 .mixers = { alc883_asus_eee1601_mixer },
9098                 .cap_mixer = alc883_asus_eee1601_cap_mixer,
9099                 .init_verbs = { alc883_init_verbs, alc888_asus_eee1601_verbs },
9100                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9101                 .dac_nids = alc883_dac_nids,
9102                 .dig_out_nid = ALC883_DIGOUT_NID,
9103                 .dig_in_nid = ALC883_DIGIN_NID,
9104                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
9105                 .channel_mode = alc883_3ST_2ch_modes,
9106                 .need_dac_fix = 1,
9107                 .input_mux = &alc883_asus_eee1601_capture_source,
9108                 .unsol_event = alc883_eee1601_unsol_event,
9109                 .init_hook = alc883_eee1601_inithook,
9110         },
9111         [ALC1200_ASUS_P5Q] = {
9112                 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
9113                 .init_verbs = { alc883_init_verbs },
9114                 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
9115                 .dac_nids = alc883_dac_nids,
9116                 .dig_out_nid = ALC1200_DIGOUT_NID,
9117                 .dig_in_nid = ALC883_DIGIN_NID,
9118                 .slave_dig_outs = alc1200_slave_dig_outs,
9119                 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
9120                 .channel_mode = alc883_sixstack_modes,
9121                 .input_mux = &alc883_capture_source,
9122         },
9123 };
9124
9125
9126 /*
9127  * BIOS auto configuration
9128  */
9129 static void alc883_auto_set_output_and_unmute(struct hda_codec *codec,
9130                                               hda_nid_t nid, int pin_type,
9131                                               int dac_idx)
9132 {
9133         /* set as output */
9134         struct alc_spec *spec = codec->spec;
9135         int idx;
9136
9137         alc_set_pin_output(codec, nid, pin_type);
9138         if (spec->multiout.dac_nids[dac_idx] == 0x25)
9139                 idx = 4;
9140         else
9141                 idx = spec->multiout.dac_nids[dac_idx] - 2;
9142         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
9143
9144 }
9145
9146 static void alc883_auto_init_multi_out(struct hda_codec *codec)
9147 {
9148         struct alc_spec *spec = codec->spec;
9149         int i;
9150
9151         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
9152         for (i = 0; i <= HDA_SIDE; i++) {
9153                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
9154                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
9155                 if (nid)
9156                         alc883_auto_set_output_and_unmute(codec, nid, pin_type,
9157                                                           i);
9158         }
9159 }
9160
9161 static void alc883_auto_init_hp_out(struct hda_codec *codec)
9162 {
9163         struct alc_spec *spec = codec->spec;
9164         hda_nid_t pin;
9165
9166         pin = spec->autocfg.hp_pins[0];
9167         if (pin) /* connect to front */
9168                 /* use dac 0 */
9169                 alc883_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
9170         pin = spec->autocfg.speaker_pins[0];
9171         if (pin)
9172                 alc883_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
9173 }
9174
9175 #define alc883_is_input_pin(nid)        alc880_is_input_pin(nid)
9176 #define ALC883_PIN_CD_NID               ALC880_PIN_CD_NID
9177
9178 static void alc883_auto_init_analog_input(struct hda_codec *codec)
9179 {
9180         struct alc_spec *spec = codec->spec;
9181         int i;
9182
9183         for (i = 0; i < AUTO_PIN_LAST; i++) {
9184                 hda_nid_t nid = spec->autocfg.input_pins[i];
9185                 if (alc883_is_input_pin(nid)) {
9186                         alc_set_input_pin(codec, nid, i);
9187                         if (nid != ALC883_PIN_CD_NID &&
9188                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
9189                                 snd_hda_codec_write(codec, nid, 0,
9190                                                     AC_VERB_SET_AMP_GAIN_MUTE,
9191                                                     AMP_OUT_MUTE);
9192                 }
9193         }
9194 }
9195
9196 #define alc883_auto_init_input_src      alc882_auto_init_input_src
9197
9198 /* almost identical with ALC880 parser... */
9199 static int alc883_parse_auto_config(struct hda_codec *codec)
9200 {
9201         struct alc_spec *spec = codec->spec;
9202         int err = alc880_parse_auto_config(codec);
9203         struct auto_pin_cfg *cfg = &spec->autocfg;
9204         int i;
9205
9206         if (err < 0)
9207                 return err;
9208         else if (!err)
9209                 return 0; /* no config found */
9210
9211         err = alc_auto_add_mic_boost(codec);
9212         if (err < 0)
9213                 return err;
9214
9215         /* hack - override the init verbs */
9216         spec->init_verbs[0] = alc883_auto_init_verbs;
9217
9218         /* setup input_mux for ALC889 */
9219         if (codec->vendor_id == 0x10ec0889) {
9220                 /* digital-mic input pin is excluded in alc880_auto_create..()
9221                  * because it's under 0x18
9222                  */
9223                 if (cfg->input_pins[AUTO_PIN_MIC] == 0x12 ||
9224                     cfg->input_pins[AUTO_PIN_FRONT_MIC] == 0x12) {
9225                         struct hda_input_mux *imux = &spec->private_imux[0];
9226                         for (i = 1; i < 3; i++)
9227                                 memcpy(&spec->private_imux[i],
9228                                        &spec->private_imux[0],
9229                                        sizeof(spec->private_imux[0]));
9230                         imux->items[imux->num_items].label = "Int DMic";
9231                         imux->items[imux->num_items].index = 0x0b;
9232                         imux->num_items++;
9233                         spec->num_mux_defs = 3;
9234                         spec->input_mux = spec->private_imux;
9235                 }
9236         }
9237
9238         return 1; /* config found */
9239 }
9240
9241 /* additional initialization for auto-configuration model */
9242 static void alc883_auto_init(struct hda_codec *codec)
9243 {
9244         struct alc_spec *spec = codec->spec;
9245         alc883_auto_init_multi_out(codec);
9246         alc883_auto_init_hp_out(codec);
9247         alc883_auto_init_analog_input(codec);
9248         alc883_auto_init_input_src(codec);
9249         if (spec->unsol_event)
9250                 alc_inithook(codec);
9251 }
9252
9253 static int patch_alc883(struct hda_codec *codec)
9254 {
9255         struct alc_spec *spec;
9256         int err, board_config;
9257
9258         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
9259         if (spec == NULL)
9260                 return -ENOMEM;
9261
9262         codec->spec = spec;
9263
9264         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
9265
9266         board_config = snd_hda_check_board_config(codec, ALC883_MODEL_LAST,
9267                                                   alc883_models,
9268                                                   alc883_cfg_tbl);
9269         if (board_config < 0) {
9270                 printk(KERN_INFO "hda_codec: Unknown model for ALC883, "
9271                        "trying auto-probe from BIOS...\n");
9272                 board_config = ALC883_AUTO;
9273         }
9274
9275         if (board_config == ALC883_AUTO) {
9276                 /* automatic parse from the BIOS config */
9277                 err = alc883_parse_auto_config(codec);
9278                 if (err < 0) {
9279                         alc_free(codec);
9280                         return err;
9281                 } else if (!err) {
9282                         printk(KERN_INFO
9283                                "hda_codec: Cannot set up configuration "
9284                                "from BIOS.  Using base mode...\n");
9285                         board_config = ALC883_3ST_2ch_DIG;
9286                 }
9287         }
9288
9289         err = snd_hda_attach_beep_device(codec, 0x1);
9290         if (err < 0) {
9291                 alc_free(codec);
9292                 return err;
9293         }
9294
9295         if (board_config != ALC883_AUTO)
9296                 setup_preset(spec, &alc883_presets[board_config]);
9297
9298         switch (codec->vendor_id) {
9299         case 0x10ec0888:
9300                 if (codec->revision_id == 0x100101) {
9301                         spec->stream_name_analog = "ALC1200 Analog";
9302                         spec->stream_name_digital = "ALC1200 Digital";
9303                 } else {
9304                         spec->stream_name_analog = "ALC888 Analog";
9305                         spec->stream_name_digital = "ALC888 Digital";
9306                 }
9307                 if (!spec->num_adc_nids) {
9308                         spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
9309                         spec->adc_nids = alc883_adc_nids;
9310                 }
9311                 if (!spec->capsrc_nids)
9312                         spec->capsrc_nids = alc883_capsrc_nids;
9313                 spec->capture_style = CAPT_MIX; /* matrix-style capture */
9314                 break;
9315         case 0x10ec0889:
9316                 spec->stream_name_analog = "ALC889 Analog";
9317                 spec->stream_name_digital = "ALC889 Digital";
9318                 if (!spec->num_adc_nids) {
9319                         spec->num_adc_nids = ARRAY_SIZE(alc889_adc_nids);
9320                         spec->adc_nids = alc889_adc_nids;
9321                 }
9322                 if (!spec->capsrc_nids)
9323                         spec->capsrc_nids = alc889_capsrc_nids;
9324                 spec->capture_style = CAPT_1MUX_MIX; /* 1mux/Nmix-style
9325                                                         capture */
9326                 break;
9327         default:
9328                 spec->stream_name_analog = "ALC883 Analog";
9329                 spec->stream_name_digital = "ALC883 Digital";
9330                 if (!spec->num_adc_nids) {
9331                         spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
9332                         spec->adc_nids = alc883_adc_nids;
9333                 }
9334                 if (!spec->capsrc_nids)
9335                         spec->capsrc_nids = alc883_capsrc_nids;
9336                 spec->capture_style = CAPT_MIX; /* matrix-style capture */
9337                 break;
9338         }
9339
9340         spec->stream_analog_playback = &alc883_pcm_analog_playback;
9341         spec->stream_analog_capture = &alc883_pcm_analog_capture;
9342         spec->stream_analog_alt_capture = &alc883_pcm_analog_alt_capture;
9343
9344         spec->stream_digital_playback = &alc883_pcm_digital_playback;
9345         spec->stream_digital_capture = &alc883_pcm_digital_capture;
9346
9347         if (!spec->cap_mixer)
9348                 set_capture_mixer(spec);
9349         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
9350
9351         spec->vmaster_nid = 0x0c;
9352
9353         codec->patch_ops = alc_patch_ops;
9354         if (board_config == ALC883_AUTO)
9355                 spec->init_hook = alc883_auto_init;
9356
9357 #ifdef CONFIG_SND_HDA_POWER_SAVE
9358         if (!spec->loopback.amplist)
9359                 spec->loopback.amplist = alc883_loopbacks;
9360 #endif
9361         codec->proc_widget_hook = print_realtek_coef;
9362
9363         return 0;
9364 }
9365
9366 /*
9367  * ALC262 support
9368  */
9369
9370 #define ALC262_DIGOUT_NID       ALC880_DIGOUT_NID
9371 #define ALC262_DIGIN_NID        ALC880_DIGIN_NID
9372
9373 #define alc262_dac_nids         alc260_dac_nids
9374 #define alc262_adc_nids         alc882_adc_nids
9375 #define alc262_adc_nids_alt     alc882_adc_nids_alt
9376 #define alc262_capsrc_nids      alc882_capsrc_nids
9377 #define alc262_capsrc_nids_alt  alc882_capsrc_nids_alt
9378
9379 #define alc262_modes            alc260_modes
9380 #define alc262_capture_source   alc882_capture_source
9381
9382 static hda_nid_t alc262_dmic_adc_nids[1] = {
9383         /* ADC0 */
9384         0x09
9385 };
9386
9387 static hda_nid_t alc262_dmic_capsrc_nids[1] = { 0x22 };
9388
9389 static struct snd_kcontrol_new alc262_base_mixer[] = {
9390         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9391         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9392         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9393         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9394         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9395         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9396         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9397         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9398         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9399         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9400         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9401         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9402         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
9403         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9404         HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
9405         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
9406         { } /* end */
9407 };
9408
9409 static struct snd_kcontrol_new alc262_hippo1_mixer[] = {
9410         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9411         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9412         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9413         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9414         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9415         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9416         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9417         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9418         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9419         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9420         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9421         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9422         /*HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),*/
9423         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9424         { } /* end */
9425 };
9426
9427 /* update HP, line and mono-out pins according to the master switch */
9428 static void alc262_hp_master_update(struct hda_codec *codec)
9429 {
9430         struct alc_spec *spec = codec->spec;
9431         int val = spec->master_sw;
9432
9433         /* HP & line-out */
9434         snd_hda_codec_write_cache(codec, 0x1b, 0,
9435                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9436                                   val ? PIN_HP : 0);
9437         snd_hda_codec_write_cache(codec, 0x15, 0,
9438                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9439                                   val ? PIN_HP : 0);
9440         /* mono (speaker) depending on the HP jack sense */
9441         val = val && !spec->jack_present;
9442         snd_hda_codec_write_cache(codec, 0x16, 0,
9443                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
9444                                   val ? PIN_OUT : 0);
9445 }
9446
9447 static void alc262_hp_bpc_automute(struct hda_codec *codec)
9448 {
9449         struct alc_spec *spec = codec->spec;
9450         unsigned int presence;
9451         presence = snd_hda_codec_read(codec, 0x1b, 0,
9452                                       AC_VERB_GET_PIN_SENSE, 0);
9453         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
9454         alc262_hp_master_update(codec);
9455 }
9456
9457 static void alc262_hp_bpc_unsol_event(struct hda_codec *codec, unsigned int res)
9458 {
9459         if ((res >> 26) != ALC880_HP_EVENT)
9460                 return;
9461         alc262_hp_bpc_automute(codec);
9462 }
9463
9464 static void alc262_hp_wildwest_automute(struct hda_codec *codec)
9465 {
9466         struct alc_spec *spec = codec->spec;
9467         unsigned int presence;
9468         presence = snd_hda_codec_read(codec, 0x15, 0,
9469                                       AC_VERB_GET_PIN_SENSE, 0);
9470         spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
9471         alc262_hp_master_update(codec);
9472 }
9473
9474 static void alc262_hp_wildwest_unsol_event(struct hda_codec *codec,
9475                                            unsigned int res)
9476 {
9477         if ((res >> 26) != ALC880_HP_EVENT)
9478                 return;
9479         alc262_hp_wildwest_automute(codec);
9480 }
9481
9482 static int alc262_hp_master_sw_get(struct snd_kcontrol *kcontrol,
9483                                    struct snd_ctl_elem_value *ucontrol)
9484 {
9485         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9486         struct alc_spec *spec = codec->spec;
9487         *ucontrol->value.integer.value = spec->master_sw;
9488         return 0;
9489 }
9490
9491 static int alc262_hp_master_sw_put(struct snd_kcontrol *kcontrol,
9492                                    struct snd_ctl_elem_value *ucontrol)
9493 {
9494         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9495         struct alc_spec *spec = codec->spec;
9496         int val = !!*ucontrol->value.integer.value;
9497
9498         if (val == spec->master_sw)
9499                 return 0;
9500         spec->master_sw = val;
9501         alc262_hp_master_update(codec);
9502         return 1;
9503 }
9504
9505 static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
9506         {
9507                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9508                 .name = "Master Playback Switch",
9509                 .info = snd_ctl_boolean_mono_info,
9510                 .get = alc262_hp_master_sw_get,
9511                 .put = alc262_hp_master_sw_put,
9512         },
9513         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9514         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9515         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9516         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
9517                               HDA_OUTPUT),
9518         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
9519                             HDA_OUTPUT),
9520         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9521         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9522         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9523         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9524         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9525         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9526         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9527         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9528         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9529         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9530         HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
9531         HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
9532         { } /* end */
9533 };
9534
9535 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
9536         {
9537                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9538                 .name = "Master Playback Switch",
9539                 .info = snd_ctl_boolean_mono_info,
9540                 .get = alc262_hp_master_sw_get,
9541                 .put = alc262_hp_master_sw_put,
9542         },
9543         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9544         HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9545         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9546         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9547         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
9548                               HDA_OUTPUT),
9549         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
9550                             HDA_OUTPUT),
9551         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
9552         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
9553         HDA_CODEC_VOLUME("Front Mic Boost", 0x1a, 0, HDA_INPUT),
9554         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
9555         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
9556         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9557         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9558         { } /* end */
9559 };
9560
9561 static struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
9562         HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9563         HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9564         HDA_CODEC_VOLUME("Rear Mic Boost", 0x18, 0, HDA_INPUT),
9565         { } /* end */
9566 };
9567
9568 /* mute/unmute internal speaker according to the hp jack and mute state */
9569 static void alc262_hp_t5735_automute(struct hda_codec *codec, int force)
9570 {
9571         struct alc_spec *spec = codec->spec;
9572
9573         if (force || !spec->sense_updated) {
9574                 unsigned int present;
9575                 present = snd_hda_codec_read(codec, 0x15, 0,
9576                                              AC_VERB_GET_PIN_SENSE, 0);
9577                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
9578                 spec->sense_updated = 1;
9579         }
9580         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_OUTPUT, 0, HDA_AMP_MUTE,
9581                                  spec->jack_present ? HDA_AMP_MUTE : 0);
9582 }
9583
9584 static void alc262_hp_t5735_unsol_event(struct hda_codec *codec,
9585                                         unsigned int res)
9586 {
9587         if ((res >> 26) != ALC880_HP_EVENT)
9588                 return;
9589         alc262_hp_t5735_automute(codec, 1);
9590 }
9591
9592 static void alc262_hp_t5735_init_hook(struct hda_codec *codec)
9593 {
9594         alc262_hp_t5735_automute(codec, 1);
9595 }
9596
9597 static struct snd_kcontrol_new alc262_hp_t5735_mixer[] = {
9598         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9599         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9600         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
9601         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9602         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9603         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9604         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9605         { } /* end */
9606 };
9607
9608 static struct hda_verb alc262_hp_t5735_verbs[] = {
9609         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9610         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9611
9612         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9613         { }
9614 };
9615
9616 static struct snd_kcontrol_new alc262_hp_rp5700_mixer[] = {
9617         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9618         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9619         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
9620         HDA_CODEC_MUTE("Speaker Playback Switch", 0x16, 0x0, HDA_OUTPUT),
9621         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
9622         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
9623         { } /* end */
9624 };
9625
9626 static struct hda_verb alc262_hp_rp5700_verbs[] = {
9627         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9628         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
9629         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9630         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9631         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9632         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9633         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9634         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
9635         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
9636         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
9637         {}
9638 };
9639
9640 static struct hda_input_mux alc262_hp_rp5700_capture_source = {
9641         .num_items = 1,
9642         .items = {
9643                 { "Line", 0x1 },
9644         },
9645 };
9646
9647 /* bind hp and internal speaker mute (with plug check) */
9648 static int alc262_sony_master_sw_put(struct snd_kcontrol *kcontrol,
9649                                      struct snd_ctl_elem_value *ucontrol)
9650 {
9651         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9652         long *valp = ucontrol->value.integer.value;
9653         int change;
9654
9655         /* change hp mute */
9656         change = snd_hda_codec_amp_update(codec, 0x15, 0, HDA_OUTPUT, 0,
9657                                           HDA_AMP_MUTE,
9658                                           valp[0] ? 0 : HDA_AMP_MUTE);
9659         change |= snd_hda_codec_amp_update(codec, 0x15, 1, HDA_OUTPUT, 0,
9660                                            HDA_AMP_MUTE,
9661                                            valp[1] ? 0 : HDA_AMP_MUTE);
9662         if (change) {
9663                 /* change speaker according to HP jack state */
9664                 struct alc_spec *spec = codec->spec;
9665                 unsigned int mute;
9666                 if (spec->jack_present)
9667                         mute = HDA_AMP_MUTE;
9668                 else
9669                         mute = snd_hda_codec_amp_read(codec, 0x15, 0,
9670                                                       HDA_OUTPUT, 0);
9671                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9672                                          HDA_AMP_MUTE, mute);
9673         }
9674         return change;
9675 }
9676
9677 static struct snd_kcontrol_new alc262_sony_mixer[] = {
9678         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9679         {
9680                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9681                 .name = "Master Playback Switch",
9682                 .info = snd_hda_mixer_amp_switch_info,
9683                 .get = snd_hda_mixer_amp_switch_get,
9684                 .put = alc262_sony_master_sw_put,
9685                 .private_value = HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
9686         },
9687         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9688         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9689         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9690         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9691         { } /* end */
9692 };
9693
9694 static struct snd_kcontrol_new alc262_benq_t31_mixer[] = {
9695         HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9696         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9697         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9698         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9699         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9700         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9701         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9702         { } /* end */
9703 };
9704
9705 static struct snd_kcontrol_new alc262_tyan_mixer[] = {
9706         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9707         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
9708         HDA_CODEC_VOLUME("Aux Playback Volume", 0x0b, 0x06, HDA_INPUT),
9709         HDA_CODEC_MUTE("Aux Playback Switch", 0x0b, 0x06, HDA_INPUT),
9710         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9711         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9712         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9713         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9714         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9715         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9716         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9717         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9718         { } /* end */
9719 };
9720
9721 static struct hda_verb alc262_tyan_verbs[] = {
9722         /* Headphone automute */
9723         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9724         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9725         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9726
9727         /* P11 AUX_IN, white 4-pin connector */
9728         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9729         {0x14, AC_VERB_SET_CONFIG_DEFAULT_BYTES_1, 0xe1},
9730         {0x14, AC_VERB_SET_CONFIG_DEFAULT_BYTES_2, 0x93},
9731         {0x14, AC_VERB_SET_CONFIG_DEFAULT_BYTES_3, 0x19},
9732
9733         {}
9734 };
9735
9736 /* unsolicited event for HP jack sensing */
9737 static void alc262_tyan_automute(struct hda_codec *codec)
9738 {
9739         unsigned int mute;
9740         unsigned int present;
9741
9742         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9743         present = snd_hda_codec_read(codec, 0x1b, 0,
9744                                      AC_VERB_GET_PIN_SENSE, 0);
9745         present = (present & 0x80000000) != 0;
9746         if (present) {
9747                 /* mute line output on ATX panel */
9748                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
9749                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9750         } else {
9751                 /* unmute line output if necessary */
9752                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
9753                 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
9754                                          HDA_AMP_MUTE, mute);
9755         }
9756 }
9757
9758 static void alc262_tyan_unsol_event(struct hda_codec *codec,
9759                                        unsigned int res)
9760 {
9761         if ((res >> 26) != ALC880_HP_EVENT)
9762                 return;
9763         alc262_tyan_automute(codec);
9764 }
9765
9766 #define alc262_capture_mixer            alc882_capture_mixer
9767 #define alc262_capture_alt_mixer        alc882_capture_alt_mixer
9768
9769 /*
9770  * generic initialization of ADC, input mixers and output mixers
9771  */
9772 static struct hda_verb alc262_init_verbs[] = {
9773         /*
9774          * Unmute ADC0-2 and set the default input to mic-in
9775          */
9776         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
9777         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9778         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
9779         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9780         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
9781         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9782
9783         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
9784          * mixer widget
9785          * Note: PASD motherboards uses the Line In 2 as the input for
9786          * front panel mic (mic 2)
9787          */
9788         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
9789         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9790         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9791         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9792         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9793         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9794
9795         /*
9796          * Set up output mixers (0x0c - 0x0e)
9797          */
9798         /* set vol=0 to output mixers */
9799         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9800         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9801         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
9802         /* set up input amps for analog loopback */
9803         /* Amp Indices: DAC = 0, mixer = 1 */
9804         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9805         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9806         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9807         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9808         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
9809         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
9810
9811         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
9812         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9813         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
9814         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9815         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9816         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
9817
9818         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9819         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9820         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9821         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9822         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9823
9824         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
9825         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
9826
9827         /* FIXME: use matrix-type input source selection */
9828         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
9829         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
9830         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9831         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9832         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9833         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9834         /* Input mixer2 */
9835         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9836         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9837         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9838         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9839         /* Input mixer3 */
9840         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
9841         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
9842         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
9843         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
9844
9845         { }
9846 };
9847
9848 static struct hda_verb alc262_eapd_verbs[] = {
9849         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
9850         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
9851         { }
9852 };
9853
9854 static struct hda_verb alc262_hippo_unsol_verbs[] = {
9855         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9856         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9857         {}
9858 };
9859
9860 static struct hda_verb alc262_hippo1_unsol_verbs[] = {
9861         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9862         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
9863         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
9864
9865         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9866         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9867         {}
9868 };
9869
9870 static struct hda_verb alc262_sony_unsol_verbs[] = {
9871         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
9872         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9873         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},   // Front Mic
9874
9875         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9876         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9877         {}
9878 };
9879
9880 static struct hda_input_mux alc262_dmic_capture_source = {
9881         .num_items = 2,
9882         .items = {
9883                 { "Int DMic", 0x9 },
9884                 { "Mic", 0x0 },
9885         },
9886 };
9887
9888 static struct snd_kcontrol_new alc262_toshiba_s06_mixer[] = {
9889         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9890         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9891         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9892         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9893         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9894         { } /* end */
9895 };
9896
9897 static struct hda_verb alc262_toshiba_s06_verbs[] = {
9898         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9899         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9900         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9901         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9902         {0x22, AC_VERB_SET_CONNECT_SEL, 0x09},
9903         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
9904         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
9905         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9906         {}
9907 };
9908
9909 static void alc262_dmic_automute(struct hda_codec *codec)
9910 {
9911         unsigned int present;
9912
9913         present = snd_hda_codec_read(codec, 0x18, 0,
9914                                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
9915         snd_hda_codec_write(codec, 0x22, 0,
9916                                 AC_VERB_SET_CONNECT_SEL, present ? 0x0 : 0x09);
9917 }
9918
9919 /* toggle speaker-output according to the hp-jack state */
9920 static void alc262_toshiba_s06_speaker_automute(struct hda_codec *codec)
9921 {
9922         unsigned int present;
9923         unsigned char bits;
9924
9925         present = snd_hda_codec_read(codec, 0x15, 0,
9926                                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
9927         bits = present ? 0 : PIN_OUT;
9928         snd_hda_codec_write(codec, 0x14, 0,
9929                                         AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
9930 }
9931
9932
9933
9934 /* unsolicited event for HP jack sensing */
9935 static void alc262_toshiba_s06_unsol_event(struct hda_codec *codec,
9936                                        unsigned int res)
9937 {
9938         if ((res >> 26) == ALC880_HP_EVENT)
9939                 alc262_toshiba_s06_speaker_automute(codec);
9940         if ((res >> 26) == ALC880_MIC_EVENT)
9941                 alc262_dmic_automute(codec);
9942
9943 }
9944
9945 static void alc262_toshiba_s06_init_hook(struct hda_codec *codec)
9946 {
9947         alc262_toshiba_s06_speaker_automute(codec);
9948         alc262_dmic_automute(codec);
9949 }
9950
9951 /* mute/unmute internal speaker according to the hp jack and mute state */
9952 static void alc262_hippo_automute(struct hda_codec *codec)
9953 {
9954         struct alc_spec *spec = codec->spec;
9955         unsigned int mute;
9956         unsigned int present;
9957
9958         /* need to execute and sync at first */
9959         snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
9960         present = snd_hda_codec_read(codec, 0x15, 0,
9961                                      AC_VERB_GET_PIN_SENSE, 0);
9962         spec->jack_present = (present & 0x80000000) != 0;
9963         if (spec->jack_present) {
9964                 /* mute internal speaker */
9965                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9966                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9967         } else {
9968                 /* unmute internal speaker if necessary */
9969                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
9970                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9971                                          HDA_AMP_MUTE, mute);
9972         }
9973 }
9974
9975 /* unsolicited event for HP jack sensing */
9976 static void alc262_hippo_unsol_event(struct hda_codec *codec,
9977                                        unsigned int res)
9978 {
9979         if ((res >> 26) != ALC880_HP_EVENT)
9980                 return;
9981         alc262_hippo_automute(codec);
9982 }
9983
9984 static void alc262_hippo1_automute(struct hda_codec *codec)
9985 {
9986         unsigned int mute;
9987         unsigned int present;
9988
9989         snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9990         present = snd_hda_codec_read(codec, 0x1b, 0,
9991                                      AC_VERB_GET_PIN_SENSE, 0);
9992         present = (present & 0x80000000) != 0;
9993         if (present) {
9994                 /* mute internal speaker */
9995                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
9996                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
9997         } else {
9998                 /* unmute internal speaker if necessary */
9999                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
10000                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10001                                          HDA_AMP_MUTE, mute);
10002         }
10003 }
10004
10005 /* unsolicited event for HP jack sensing */
10006 static void alc262_hippo1_unsol_event(struct hda_codec *codec,
10007                                        unsigned int res)
10008 {
10009         if ((res >> 26) != ALC880_HP_EVENT)
10010                 return;
10011         alc262_hippo1_automute(codec);
10012 }
10013
10014 /*
10015  * nec model
10016  *  0x15 = headphone
10017  *  0x16 = internal speaker
10018  *  0x18 = external mic
10019  */
10020
10021 static struct snd_kcontrol_new alc262_nec_mixer[] = {
10022         HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
10023         HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 0, 0x0, HDA_OUTPUT),
10024
10025         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10026         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10027         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10028
10029         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
10030         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
10031         { } /* end */
10032 };
10033
10034 static struct hda_verb alc262_nec_verbs[] = {
10035         /* Unmute Speaker */
10036         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
10037
10038         /* Headphone */
10039         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10040         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10041
10042         /* External mic to headphone */
10043         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10044         /* External mic to speaker */
10045         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10046         {}
10047 };
10048
10049 /*
10050  * fujitsu model
10051  *  0x14 = headphone/spdif-out, 0x15 = internal speaker,
10052  *  0x1b = port replicator headphone out
10053  */
10054
10055 #define ALC_HP_EVENT    0x37
10056
10057 static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
10058         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
10059         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10060         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
10061         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10062         {}
10063 };
10064
10065 static struct hda_verb alc262_lenovo_3000_unsol_verbs[] = {
10066         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
10067         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10068         {}
10069 };
10070
10071 static struct hda_input_mux alc262_fujitsu_capture_source = {
10072         .num_items = 3,
10073         .items = {
10074                 { "Mic", 0x0 },
10075                 { "Int Mic", 0x1 },
10076                 { "CD", 0x4 },
10077         },
10078 };
10079
10080 static struct hda_input_mux alc262_HP_capture_source = {
10081         .num_items = 5,
10082         .items = {
10083                 { "Mic", 0x0 },
10084                 { "Front Mic", 0x1 },
10085                 { "Line", 0x2 },
10086                 { "CD", 0x4 },
10087                 { "AUX IN", 0x6 },
10088         },
10089 };
10090
10091 static struct hda_input_mux alc262_HP_D7000_capture_source = {
10092         .num_items = 4,
10093         .items = {
10094                 { "Mic", 0x0 },
10095                 { "Front Mic", 0x2 },
10096                 { "Line", 0x1 },
10097                 { "CD", 0x4 },
10098         },
10099 };
10100
10101 /* mute/unmute internal speaker according to the hp jacks and mute state */
10102 static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
10103 {
10104         struct alc_spec *spec = codec->spec;
10105         unsigned int mute;
10106
10107         if (force || !spec->sense_updated) {
10108                 unsigned int present;
10109                 /* need to execute and sync at first */
10110                 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
10111                 /* check laptop HP jack */
10112                 present = snd_hda_codec_read(codec, 0x14, 0,
10113                                              AC_VERB_GET_PIN_SENSE, 0);
10114                 /* need to execute and sync at first */
10115                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
10116                 /* check docking HP jack */
10117                 present |= snd_hda_codec_read(codec, 0x1b, 0,
10118                                               AC_VERB_GET_PIN_SENSE, 0);
10119                 if (present & AC_PINSENSE_PRESENCE)
10120                         spec->jack_present = 1;
10121                 else
10122                         spec->jack_present = 0;
10123                 spec->sense_updated = 1;
10124         }
10125         /* unmute internal speaker only if both HPs are unplugged and
10126          * master switch is on
10127          */
10128         if (spec->jack_present)
10129                 mute = HDA_AMP_MUTE;
10130         else
10131                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
10132         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
10133                                  HDA_AMP_MUTE, mute);
10134 }
10135
10136 /* unsolicited event for HP jack sensing */
10137 static void alc262_fujitsu_unsol_event(struct hda_codec *codec,
10138                                        unsigned int res)
10139 {
10140         if ((res >> 26) != ALC_HP_EVENT)
10141                 return;
10142         alc262_fujitsu_automute(codec, 1);
10143 }
10144
10145 static void alc262_fujitsu_init_hook(struct hda_codec *codec)
10146 {
10147         alc262_fujitsu_automute(codec, 1);
10148 }
10149
10150 /* bind volumes of both NID 0x0c and 0x0d */
10151 static struct hda_bind_ctls alc262_fujitsu_bind_master_vol = {
10152         .ops = &snd_hda_bind_vol,
10153         .values = {
10154                 HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT),
10155                 HDA_COMPOSE_AMP_VAL(0x0d, 3, 0, HDA_OUTPUT),
10156                 0
10157         },
10158 };
10159
10160 /* mute/unmute internal speaker according to the hp jack and mute state */
10161 static void alc262_lenovo_3000_automute(struct hda_codec *codec, int force)
10162 {
10163         struct alc_spec *spec = codec->spec;
10164         unsigned int mute;
10165
10166         if (force || !spec->sense_updated) {
10167                 unsigned int present_int_hp;
10168                 /* need to execute and sync at first */
10169                 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
10170                 present_int_hp = snd_hda_codec_read(codec, 0x1b, 0,
10171                                         AC_VERB_GET_PIN_SENSE, 0);
10172                 spec->jack_present = (present_int_hp & 0x80000000) != 0;
10173                 spec->sense_updated = 1;
10174         }
10175         if (spec->jack_present) {
10176                 /* mute internal speaker */
10177                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10178                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
10179                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
10180                                          HDA_AMP_MUTE, HDA_AMP_MUTE);
10181         } else {
10182                 /* unmute internal speaker if necessary */
10183                 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
10184                 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10185                                          HDA_AMP_MUTE, mute);
10186                 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
10187                                          HDA_AMP_MUTE, mute);
10188         }
10189 }
10190
10191 /* unsolicited event for HP jack sensing */
10192 static void alc262_lenovo_3000_unsol_event(struct hda_codec *codec,
10193                                        unsigned int res)
10194 {
10195         if ((res >> 26) != ALC_HP_EVENT)
10196                 return;
10197         alc262_lenovo_3000_automute(codec, 1);
10198 }
10199
10200 /* bind hp and internal speaker mute (with plug check) */
10201 static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
10202                                          struct snd_ctl_elem_value *ucontrol)
10203 {
10204         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10205         long *valp = ucontrol->value.integer.value;
10206         int change;
10207
10208         change = snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10209                                                  HDA_AMP_MUTE,
10210                                                  valp ? 0 : HDA_AMP_MUTE);
10211         change |= snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
10212                                                  HDA_AMP_MUTE,
10213                                                  valp ? 0 : HDA_AMP_MUTE);
10214
10215         if (change)
10216                 alc262_fujitsu_automute(codec, 0);
10217         return change;
10218 }
10219
10220 static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
10221         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
10222         {
10223                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10224                 .name = "Master Playback Switch",
10225                 .info = snd_hda_mixer_amp_switch_info,
10226                 .get = snd_hda_mixer_amp_switch_get,
10227                 .put = alc262_fujitsu_master_sw_put,
10228                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
10229         },
10230         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10231         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10232         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, 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("Int Mic Boost", 0x19, 0, HDA_INPUT),
10236         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
10237         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
10238         { } /* end */
10239 };
10240
10241 /* bind hp and internal speaker mute (with plug check) */
10242 static int alc262_lenovo_3000_master_sw_put(struct snd_kcontrol *kcontrol,
10243                                          struct snd_ctl_elem_value *ucontrol)
10244 {
10245         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10246         long *valp = ucontrol->value.integer.value;
10247         int change;
10248
10249         change = snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
10250                                                  HDA_AMP_MUTE,
10251                                                  valp ? 0 : HDA_AMP_MUTE);
10252
10253         if (change)
10254                 alc262_lenovo_3000_automute(codec, 0);
10255         return change;
10256 }
10257
10258 static struct snd_kcontrol_new alc262_lenovo_3000_mixer[] = {
10259         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
10260         {
10261                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10262                 .name = "Master Playback Switch",
10263                 .info = snd_hda_mixer_amp_switch_info,
10264                 .get = snd_hda_mixer_amp_switch_get,
10265                 .put = alc262_lenovo_3000_master_sw_put,
10266                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
10267         },
10268         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
10269         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
10270         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10271         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10272         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10273         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
10274         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
10275         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
10276         { } /* end */
10277 };
10278
10279 static struct snd_kcontrol_new alc262_toshiba_rx1_mixer[] = {
10280         HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
10281         {
10282                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10283                 .name = "Master Playback Switch",
10284                 .info = snd_hda_mixer_amp_switch_info,
10285                 .get = snd_hda_mixer_amp_switch_get,
10286                 .put = alc262_sony_master_sw_put,
10287                 .private_value = HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
10288         },
10289         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
10290         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
10291         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
10292         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10293         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10294         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
10295         { } /* end */
10296 };
10297
10298 /* additional init verbs for Benq laptops */
10299 static struct hda_verb alc262_EAPD_verbs[] = {
10300         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
10301         {0x20, AC_VERB_SET_PROC_COEF,  0x3070},
10302         {}
10303 };
10304
10305 static struct hda_verb alc262_benq_t31_EAPD_verbs[] = {
10306         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10307         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10308
10309         {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
10310         {0x20, AC_VERB_SET_PROC_COEF,  0x3050},
10311         {}
10312 };
10313
10314 /* Samsung Q1 Ultra Vista model setup */
10315 static struct snd_kcontrol_new alc262_ultra_mixer[] = {
10316         HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
10317         HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
10318         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
10319         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
10320         HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
10321         HDA_CODEC_VOLUME("Headphone Mic Boost", 0x15, 0, HDA_INPUT),
10322         { } /* end */
10323 };
10324
10325 static struct hda_verb alc262_ultra_verbs[] = {
10326         /* output mixer */
10327         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10328         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10329         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10330         /* speaker */
10331         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10332         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10333         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10334         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
10335         /* HP */
10336         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10337         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
10338         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10339         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10340         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10341         /* internal mic */
10342         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
10343         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10344         /* ADC, choose mic */
10345         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10346         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10347         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10348         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10349         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10350         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10351         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10352         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10353         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
10354         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(8)},
10355         {}
10356 };
10357
10358 /* mute/unmute internal speaker according to the hp jack and mute state */
10359 static void alc262_ultra_automute(struct hda_codec *codec)
10360 {
10361         struct alc_spec *spec = codec->spec;
10362         unsigned int mute;
10363
10364         mute = 0;
10365         /* auto-mute only when HP is used as HP */
10366         if (!spec->cur_mux[0]) {
10367                 unsigned int present;
10368                 /* need to execute and sync at first */
10369                 snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
10370                 present = snd_hda_codec_read(codec, 0x15, 0,
10371                                              AC_VERB_GET_PIN_SENSE, 0);
10372                 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
10373                 if (spec->jack_present)
10374                         mute = HDA_AMP_MUTE;
10375         }
10376         /* mute/unmute internal speaker */
10377         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
10378                                  HDA_AMP_MUTE, mute);
10379         /* mute/unmute HP */
10380         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
10381                                  HDA_AMP_MUTE, mute ? 0 : HDA_AMP_MUTE);
10382 }
10383
10384 /* unsolicited event for HP jack sensing */
10385 static void alc262_ultra_unsol_event(struct hda_codec *codec,
10386                                        unsigned int res)
10387 {
10388         if ((res >> 26) != ALC880_HP_EVENT)
10389                 return;
10390         alc262_ultra_automute(codec);
10391 }
10392
10393 static struct hda_input_mux alc262_ultra_capture_source = {
10394         .num_items = 2,
10395         .items = {
10396                 { "Mic", 0x1 },
10397                 { "Headphone", 0x7 },
10398         },
10399 };
10400
10401 static int alc262_ultra_mux_enum_put(struct snd_kcontrol *kcontrol,
10402                                      struct snd_ctl_elem_value *ucontrol)
10403 {
10404         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
10405         struct alc_spec *spec = codec->spec;
10406         int ret;
10407
10408         ret = alc_mux_enum_put(kcontrol, ucontrol);
10409         if (!ret)
10410                 return 0;
10411         /* reprogram the HP pin as mic or HP according to the input source */
10412         snd_hda_codec_write_cache(codec, 0x15, 0,
10413                                   AC_VERB_SET_PIN_WIDGET_CONTROL,
10414                                   spec->cur_mux[0] ? PIN_VREF80 : PIN_HP);
10415         alc262_ultra_automute(codec); /* mute/unmute HP */
10416         return ret;
10417 }
10418
10419 static struct snd_kcontrol_new alc262_ultra_capture_mixer[] = {
10420         HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
10421         HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
10422         {
10423                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
10424                 .name = "Capture Source",
10425                 .info = alc_mux_enum_info,
10426                 .get = alc_mux_enum_get,
10427                 .put = alc262_ultra_mux_enum_put,
10428         },
10429         { } /* end */
10430 };
10431
10432 /* add playback controls from the parsed DAC table */
10433 static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
10434                                              const struct auto_pin_cfg *cfg)
10435 {
10436         hda_nid_t nid;
10437         int err;
10438
10439         spec->multiout.num_dacs = 1;    /* only use one dac */
10440         spec->multiout.dac_nids = spec->private_dac_nids;
10441         spec->multiout.dac_nids[0] = 2;
10442
10443         nid = cfg->line_out_pins[0];
10444         if (nid) {
10445                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
10446                                   "Front Playback Volume",
10447                                   HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT));
10448                 if (err < 0)
10449                         return err;
10450                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10451                                   "Front Playback Switch",
10452                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
10453                 if (err < 0)
10454                         return err;
10455         }
10456
10457         nid = cfg->speaker_pins[0];
10458         if (nid) {
10459                 if (nid == 0x16) {
10460                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
10461                                           "Speaker Playback Volume",
10462                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
10463                                                               HDA_OUTPUT));
10464                         if (err < 0)
10465                                 return err;
10466                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10467                                           "Speaker Playback Switch",
10468                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
10469                                                               HDA_OUTPUT));
10470                         if (err < 0)
10471                                 return err;
10472                 } else {
10473                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10474                                           "Speaker Playback Switch",
10475                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
10476                                                               HDA_OUTPUT));
10477                         if (err < 0)
10478                                 return err;
10479                 }
10480         }
10481         nid = cfg->hp_pins[0];
10482         if (nid) {
10483                 /* spec->multiout.hp_nid = 2; */
10484                 if (nid == 0x16) {
10485                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
10486                                           "Headphone Playback Volume",
10487                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
10488                                                               HDA_OUTPUT));
10489                         if (err < 0)
10490                                 return err;
10491                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10492                                           "Headphone Playback Switch",
10493                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
10494                                                               HDA_OUTPUT));
10495                         if (err < 0)
10496                                 return err;
10497                 } else {
10498                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
10499                                           "Headphone Playback Switch",
10500                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
10501                                                               HDA_OUTPUT));
10502                         if (err < 0)
10503                                 return err;
10504                 }
10505         }
10506         return 0;
10507 }
10508
10509 /* identical with ALC880 */
10510 #define alc262_auto_create_analog_input_ctls \
10511         alc880_auto_create_analog_input_ctls
10512
10513 /*
10514  * generic initialization of ADC, input mixers and output mixers
10515  */
10516 static struct hda_verb alc262_volume_init_verbs[] = {
10517         /*
10518          * Unmute ADC0-2 and set the default input to mic-in
10519          */
10520         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10521         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10522         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10523         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10524         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10525         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10526
10527         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10528          * mixer widget
10529          * Note: PASD motherboards uses the Line In 2 as the input for
10530          * front panel mic (mic 2)
10531          */
10532         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10533         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10534         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10535         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10536         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10537         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10538
10539         /*
10540          * Set up output mixers (0x0c - 0x0f)
10541          */
10542         /* set vol=0 to output mixers */
10543         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10544         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10545         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10546
10547         /* set up input amps for analog loopback */
10548         /* Amp Indices: DAC = 0, mixer = 1 */
10549         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10550         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10551         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10552         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10553         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10554         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10555
10556         /* FIXME: use matrix-type input source selection */
10557         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10558         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10559         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10560         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10561         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10562         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10563         /* Input mixer2 */
10564         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10565         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10566         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10567         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10568         /* Input mixer3 */
10569         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10570         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
10571         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
10572         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
10573
10574         { }
10575 };
10576
10577 static struct hda_verb alc262_HP_BPC_init_verbs[] = {
10578         /*
10579          * Unmute ADC0-2 and set the default input to mic-in
10580          */
10581         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10582         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10583         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10584         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10585         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10586         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10587
10588         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10589          * mixer widget
10590          * Note: PASD motherboards uses the Line In 2 as the input for
10591          * front panel mic (mic 2)
10592          */
10593         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10594         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10595         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10596         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10597         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10598         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10599         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10600         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10601
10602         /*
10603          * Set up output mixers (0x0c - 0x0e)
10604          */
10605         /* set vol=0 to output mixers */
10606         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10607         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10608         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10609
10610         /* set up input amps for analog loopback */
10611         /* Amp Indices: DAC = 0, mixer = 1 */
10612         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10613         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10614         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10615         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10616         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10617         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10618
10619         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
10620         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10621         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
10622
10623         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10624         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10625
10626         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10627         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10628
10629         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10630         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10631         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
10632         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10633         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
10634
10635         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
10636         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10637         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10638         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
10639         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10640         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10641
10642
10643         /* FIXME: use matrix-type input source selection */
10644         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10645         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10646         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10647         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10648         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10649         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10650         /* Input mixer2 */
10651         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10652         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10653         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10654         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10655         /* Input mixer3 */
10656         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10657         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10658         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10659         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10660
10661         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10662
10663         { }
10664 };
10665
10666 static struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
10667         /*
10668          * Unmute ADC0-2 and set the default input to mic-in
10669          */
10670         {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
10671         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10672         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
10673         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10674         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
10675         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10676
10677         /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
10678          * mixer widget
10679          * Note: PASD motherboards uses the Line In 2 as the input for front
10680          * panel mic (mic 2)
10681          */
10682         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
10683         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
10684         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10685         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
10686         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
10687         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
10688         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
10689         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
10690         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
10691         /*
10692          * Set up output mixers (0x0c - 0x0e)
10693          */
10694         /* set vol=0 to output mixers */
10695         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10696         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10697         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
10698
10699         /* set up input amps for analog loopback */
10700         /* Amp Indices: DAC = 0, mixer = 1 */
10701         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10702         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10703         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10704         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10705         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10706         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
10707
10708
10709         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP */
10710         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Mono */
10711         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* rear MIC */
10712         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* Line in */
10713         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
10714         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Line out */
10715         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },        /* CD in */
10716
10717         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10718         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10719
10720         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
10721         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
10722
10723         /* {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 }, */
10724         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10725         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10726         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
10727         {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10728         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
10729
10730         /* FIXME: use matrix-type input source selection */
10731         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
10732         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
10733         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, /*rear MIC*/
10734         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, /*Line in*/
10735         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))}, /*F MIC*/
10736         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))}, /*Front*/
10737         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))}, /*CD*/
10738         /* {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))},  */
10739         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))}, /*HP*/
10740         /* Input mixer2 */
10741         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10742         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10743         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10744         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10745         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10746         /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
10747         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
10748         /* Input mixer3 */
10749         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
10750         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
10751         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
10752         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
10753         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
10754         /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
10755         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
10756
10757         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
10758
10759         { }
10760 };
10761
10762 static struct hda_verb alc262_toshiba_rx1_unsol_verbs[] = {
10763
10764         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },       /* Front Speaker */
10765         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
10766         {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
10767
10768         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* MIC jack */
10769         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },    /* Front MIC */
10770         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
10771         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) },
10772
10773         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },        /* HP  jack */
10774         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
10775         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
10776         {}
10777 };
10778
10779
10780 #ifdef CONFIG_SND_HDA_POWER_SAVE
10781 #define alc262_loopbacks        alc880_loopbacks
10782 #endif
10783
10784 /* pcm configuration: identiacal with ALC880 */
10785 #define alc262_pcm_analog_playback      alc880_pcm_analog_playback
10786 #define alc262_pcm_analog_capture       alc880_pcm_analog_capture
10787 #define alc262_pcm_digital_playback     alc880_pcm_digital_playback
10788 #define alc262_pcm_digital_capture      alc880_pcm_digital_capture
10789
10790 /*
10791  * BIOS auto configuration
10792  */
10793 static int alc262_parse_auto_config(struct hda_codec *codec)
10794 {
10795         struct alc_spec *spec = codec->spec;
10796         int err;
10797         static hda_nid_t alc262_ignore[] = { 0x1d, 0 };
10798
10799         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
10800                                            alc262_ignore);
10801         if (err < 0)
10802                 return err;
10803         if (!spec->autocfg.line_outs) {
10804                 if (spec->autocfg.dig_outs || spec->autocfg.dig_in_pin) {
10805                         spec->multiout.max_channels = 2;
10806                         spec->no_analog = 1;
10807                         goto dig_only;
10808                 }
10809                 return 0; /* can't find valid BIOS pin config */
10810         }
10811         err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
10812         if (err < 0)
10813                 return err;
10814         err = alc262_auto_create_analog_input_ctls(spec, &spec->autocfg);
10815         if (err < 0)
10816                 return err;
10817
10818         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
10819
10820  dig_only:
10821         if (spec->autocfg.dig_outs) {
10822                 spec->multiout.dig_out_nid = ALC262_DIGOUT_NID;
10823                 spec->dig_out_type = spec->autocfg.dig_out_type[0];
10824         }
10825         if (spec->autocfg.dig_in_pin)
10826                 spec->dig_in_nid = ALC262_DIGIN_NID;
10827
10828         if (spec->kctls.list)
10829                 add_mixer(spec, spec->kctls.list);
10830
10831         add_verb(spec, alc262_volume_init_verbs);
10832         spec->num_mux_defs = 1;
10833         spec->input_mux = &spec->private_imux[0];
10834
10835         err = alc_auto_add_mic_boost(codec);
10836         if (err < 0)
10837                 return err;
10838
10839         return 1;
10840 }
10841
10842 #define alc262_auto_init_multi_out      alc882_auto_init_multi_out
10843 #define alc262_auto_init_hp_out         alc882_auto_init_hp_out
10844 #define alc262_auto_init_analog_input   alc882_auto_init_analog_input
10845 #define alc262_auto_init_input_src      alc882_auto_init_input_src
10846
10847
10848 /* init callback for auto-configuration model -- overriding the default init */
10849 static void alc262_auto_init(struct hda_codec *codec)
10850 {
10851         struct alc_spec *spec = codec->spec;
10852         alc262_auto_init_multi_out(codec);
10853         alc262_auto_init_hp_out(codec);
10854         alc262_auto_init_analog_input(codec);
10855         alc262_auto_init_input_src(codec);
10856         if (spec->unsol_event)
10857                 alc_inithook(codec);
10858 }
10859
10860 /*
10861  * configuration and preset
10862  */
10863 static const char *alc262_models[ALC262_MODEL_LAST] = {
10864         [ALC262_BASIC]          = "basic",
10865         [ALC262_HIPPO]          = "hippo",
10866         [ALC262_HIPPO_1]        = "hippo_1",
10867         [ALC262_FUJITSU]        = "fujitsu",
10868         [ALC262_HP_BPC]         = "hp-bpc",
10869         [ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000",
10870         [ALC262_HP_TC_T5735]    = "hp-tc-t5735",
10871         [ALC262_HP_RP5700]      = "hp-rp5700",
10872         [ALC262_BENQ_ED8]       = "benq",
10873         [ALC262_BENQ_T31]       = "benq-t31",
10874         [ALC262_SONY_ASSAMD]    = "sony-assamd",
10875         [ALC262_TOSHIBA_S06]    = "toshiba-s06",
10876         [ALC262_TOSHIBA_RX1]    = "toshiba-rx1",
10877         [ALC262_ULTRA]          = "ultra",
10878         [ALC262_LENOVO_3000]    = "lenovo-3000",
10879         [ALC262_NEC]            = "nec",
10880         [ALC262_TYAN]           = "tyan",
10881         [ALC262_AUTO]           = "auto",
10882 };
10883
10884 static struct snd_pci_quirk alc262_cfg_tbl[] = {
10885         SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
10886         SND_PCI_QUIRK(0x1033, 0x8895, "NEC Versa S9100", ALC262_NEC),
10887         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1200, "HP xw series",
10888                            ALC262_HP_BPC),
10889         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1300, "HP xw series",
10890                            ALC262_HP_BPC),
10891         SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1700, "HP xw series",
10892                            ALC262_HP_BPC),
10893         SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
10894         SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
10895         SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
10896         SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF),
10897         SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL),
10898         SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF),
10899         SND_PCI_QUIRK(0x103c, 0x2806, "HP D7000", ALC262_HP_BPC_D7000_WL),
10900         SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF),
10901         SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC),
10902         SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC),
10903         SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC),
10904         SND_PCI_QUIRK(0x103c, 0x302f, "HP Thin Client T5735",
10905                       ALC262_HP_TC_T5735),
10906         SND_PCI_QUIRK(0x103c, 0x2817, "HP RP5700", ALC262_HP_RP5700),
10907         SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10908         SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
10909         SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10910         SND_PCI_QUIRK(0x104d, 0x9016, "Sony VAIO", ALC262_AUTO), /* dig-only */
10911         SND_PCI_QUIRK_MASK(0x104d, 0xff00, 0x9000, "Sony VAIO",
10912                            ALC262_SONY_ASSAMD),
10913         SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
10914                       ALC262_TOSHIBA_RX1),
10915         SND_PCI_QUIRK(0x1179, 0xff7b, "Toshiba S06", ALC262_TOSHIBA_S06),
10916         SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
10917         SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU),
10918         SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_TYAN),
10919         SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc032, "Samsung Q1",
10920                            ALC262_ULTRA),
10921         SND_PCI_QUIRK(0x144d, 0xc510, "Samsung Q45", ALC262_HIPPO),
10922         SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 y410", ALC262_LENOVO_3000),
10923         SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
10924         SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
10925         SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
10926         {}
10927 };
10928
10929 static struct alc_config_preset alc262_presets[] = {
10930         [ALC262_BASIC] = {
10931                 .mixers = { alc262_base_mixer },
10932                 .init_verbs = { alc262_init_verbs },
10933                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10934                 .dac_nids = alc262_dac_nids,
10935                 .hp_nid = 0x03,
10936                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10937                 .channel_mode = alc262_modes,
10938                 .input_mux = &alc262_capture_source,
10939         },
10940         [ALC262_HIPPO] = {
10941                 .mixers = { alc262_base_mixer },
10942                 .init_verbs = { alc262_init_verbs, alc262_hippo_unsol_verbs},
10943                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10944                 .dac_nids = alc262_dac_nids,
10945                 .hp_nid = 0x03,
10946                 .dig_out_nid = ALC262_DIGOUT_NID,
10947                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10948                 .channel_mode = alc262_modes,
10949                 .input_mux = &alc262_capture_source,
10950                 .unsol_event = alc262_hippo_unsol_event,
10951                 .init_hook = alc262_hippo_automute,
10952         },
10953         [ALC262_HIPPO_1] = {
10954                 .mixers = { alc262_hippo1_mixer },
10955                 .init_verbs = { alc262_init_verbs, alc262_hippo1_unsol_verbs},
10956                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10957                 .dac_nids = alc262_dac_nids,
10958                 .hp_nid = 0x02,
10959                 .dig_out_nid = ALC262_DIGOUT_NID,
10960                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10961                 .channel_mode = alc262_modes,
10962                 .input_mux = &alc262_capture_source,
10963                 .unsol_event = alc262_hippo1_unsol_event,
10964                 .init_hook = alc262_hippo1_automute,
10965         },
10966         [ALC262_FUJITSU] = {
10967                 .mixers = { alc262_fujitsu_mixer },
10968                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
10969                                 alc262_fujitsu_unsol_verbs },
10970                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10971                 .dac_nids = alc262_dac_nids,
10972                 .hp_nid = 0x03,
10973                 .dig_out_nid = ALC262_DIGOUT_NID,
10974                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10975                 .channel_mode = alc262_modes,
10976                 .input_mux = &alc262_fujitsu_capture_source,
10977                 .unsol_event = alc262_fujitsu_unsol_event,
10978                 .init_hook = alc262_fujitsu_init_hook,
10979         },
10980         [ALC262_HP_BPC] = {
10981                 .mixers = { alc262_HP_BPC_mixer },
10982                 .init_verbs = { alc262_HP_BPC_init_verbs },
10983                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10984                 .dac_nids = alc262_dac_nids,
10985                 .hp_nid = 0x03,
10986                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10987                 .channel_mode = alc262_modes,
10988                 .input_mux = &alc262_HP_capture_source,
10989                 .unsol_event = alc262_hp_bpc_unsol_event,
10990                 .init_hook = alc262_hp_bpc_automute,
10991         },
10992         [ALC262_HP_BPC_D7000_WF] = {
10993                 .mixers = { alc262_HP_BPC_WildWest_mixer },
10994                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
10995                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
10996                 .dac_nids = alc262_dac_nids,
10997                 .hp_nid = 0x03,
10998                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
10999                 .channel_mode = alc262_modes,
11000                 .input_mux = &alc262_HP_D7000_capture_source,
11001                 .unsol_event = alc262_hp_wildwest_unsol_event,
11002                 .init_hook = alc262_hp_wildwest_automute,
11003         },
11004         [ALC262_HP_BPC_D7000_WL] = {
11005                 .mixers = { alc262_HP_BPC_WildWest_mixer,
11006                             alc262_HP_BPC_WildWest_option_mixer },
11007                 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
11008                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11009                 .dac_nids = alc262_dac_nids,
11010                 .hp_nid = 0x03,
11011                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11012                 .channel_mode = alc262_modes,
11013                 .input_mux = &alc262_HP_D7000_capture_source,
11014                 .unsol_event = alc262_hp_wildwest_unsol_event,
11015                 .init_hook = alc262_hp_wildwest_automute,
11016         },
11017         [ALC262_HP_TC_T5735] = {
11018                 .mixers = { alc262_hp_t5735_mixer },
11019                 .init_verbs = { alc262_init_verbs, alc262_hp_t5735_verbs },
11020                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11021                 .dac_nids = alc262_dac_nids,
11022                 .hp_nid = 0x03,
11023                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11024                 .channel_mode = alc262_modes,
11025                 .input_mux = &alc262_capture_source,
11026                 .unsol_event = alc262_hp_t5735_unsol_event,
11027                 .init_hook = alc262_hp_t5735_init_hook,
11028         },
11029         [ALC262_HP_RP5700] = {
11030                 .mixers = { alc262_hp_rp5700_mixer },
11031                 .init_verbs = { alc262_init_verbs, alc262_hp_rp5700_verbs },
11032                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11033                 .dac_nids = alc262_dac_nids,
11034                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11035                 .channel_mode = alc262_modes,
11036                 .input_mux = &alc262_hp_rp5700_capture_source,
11037         },
11038         [ALC262_BENQ_ED8] = {
11039                 .mixers = { alc262_base_mixer },
11040                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs },
11041                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11042                 .dac_nids = alc262_dac_nids,
11043                 .hp_nid = 0x03,
11044                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11045                 .channel_mode = alc262_modes,
11046                 .input_mux = &alc262_capture_source,
11047         },
11048         [ALC262_SONY_ASSAMD] = {
11049                 .mixers = { alc262_sony_mixer },
11050                 .init_verbs = { alc262_init_verbs, alc262_sony_unsol_verbs},
11051                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11052                 .dac_nids = alc262_dac_nids,
11053                 .hp_nid = 0x02,
11054                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11055                 .channel_mode = alc262_modes,
11056                 .input_mux = &alc262_capture_source,
11057                 .unsol_event = alc262_hippo_unsol_event,
11058                 .init_hook = alc262_hippo_automute,
11059         },
11060         [ALC262_BENQ_T31] = {
11061                 .mixers = { alc262_benq_t31_mixer },
11062                 .init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs, alc262_hippo_unsol_verbs },
11063                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11064                 .dac_nids = alc262_dac_nids,
11065                 .hp_nid = 0x03,
11066                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11067                 .channel_mode = alc262_modes,
11068                 .input_mux = &alc262_capture_source,
11069                 .unsol_event = alc262_hippo_unsol_event,
11070                 .init_hook = alc262_hippo_automute,
11071         },
11072         [ALC262_ULTRA] = {
11073                 .mixers = { alc262_ultra_mixer },
11074                 .cap_mixer = alc262_ultra_capture_mixer,
11075                 .init_verbs = { alc262_ultra_verbs },
11076                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11077                 .dac_nids = alc262_dac_nids,
11078                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11079                 .channel_mode = alc262_modes,
11080                 .input_mux = &alc262_ultra_capture_source,
11081                 .adc_nids = alc262_adc_nids, /* ADC0 */
11082                 .capsrc_nids = alc262_capsrc_nids,
11083                 .num_adc_nids = 1, /* single ADC */
11084                 .unsol_event = alc262_ultra_unsol_event,
11085                 .init_hook = alc262_ultra_automute,
11086         },
11087         [ALC262_LENOVO_3000] = {
11088                 .mixers = { alc262_lenovo_3000_mixer },
11089                 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
11090                                 alc262_lenovo_3000_unsol_verbs },
11091                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11092                 .dac_nids = alc262_dac_nids,
11093                 .hp_nid = 0x03,
11094                 .dig_out_nid = ALC262_DIGOUT_NID,
11095                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11096                 .channel_mode = alc262_modes,
11097                 .input_mux = &alc262_fujitsu_capture_source,
11098                 .unsol_event = alc262_lenovo_3000_unsol_event,
11099         },
11100         [ALC262_NEC] = {
11101                 .mixers = { alc262_nec_mixer },
11102                 .init_verbs = { alc262_nec_verbs },
11103                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11104                 .dac_nids = alc262_dac_nids,
11105                 .hp_nid = 0x03,
11106                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11107                 .channel_mode = alc262_modes,
11108                 .input_mux = &alc262_capture_source,
11109         },
11110         [ALC262_TOSHIBA_S06] = {
11111                 .mixers = { alc262_toshiba_s06_mixer },
11112                 .init_verbs = { alc262_init_verbs, alc262_toshiba_s06_verbs,
11113                                                         alc262_eapd_verbs },
11114                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11115                 .capsrc_nids = alc262_dmic_capsrc_nids,
11116                 .dac_nids = alc262_dac_nids,
11117                 .adc_nids = alc262_dmic_adc_nids, /* ADC0 */
11118                 .dig_out_nid = ALC262_DIGOUT_NID,
11119                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11120                 .channel_mode = alc262_modes,
11121                 .input_mux = &alc262_dmic_capture_source,
11122                 .unsol_event = alc262_toshiba_s06_unsol_event,
11123                 .init_hook = alc262_toshiba_s06_init_hook,
11124         },
11125         [ALC262_TOSHIBA_RX1] = {
11126                 .mixers = { alc262_toshiba_rx1_mixer },
11127                 .init_verbs = { alc262_init_verbs, alc262_toshiba_rx1_unsol_verbs },
11128                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11129                 .dac_nids = alc262_dac_nids,
11130                 .hp_nid = 0x03,
11131                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11132                 .channel_mode = alc262_modes,
11133                 .input_mux = &alc262_capture_source,
11134                 .unsol_event = alc262_hippo_unsol_event,
11135                 .init_hook = alc262_hippo_automute,
11136         },
11137         [ALC262_TYAN] = {
11138                 .mixers = { alc262_tyan_mixer },
11139                 .init_verbs = { alc262_init_verbs, alc262_tyan_verbs},
11140                 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11141                 .dac_nids = alc262_dac_nids,
11142                 .hp_nid = 0x02,
11143                 .dig_out_nid = ALC262_DIGOUT_NID,
11144                 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11145                 .channel_mode = alc262_modes,
11146                 .input_mux = &alc262_capture_source,
11147                 .unsol_event = alc262_tyan_unsol_event,
11148                 .init_hook = alc262_tyan_automute,
11149         },
11150 };
11151
11152 static int patch_alc262(struct hda_codec *codec)
11153 {
11154         struct alc_spec *spec;
11155         int board_config;
11156         int err;
11157
11158         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
11159         if (spec == NULL)
11160                 return -ENOMEM;
11161
11162         codec->spec = spec;
11163 #if 0
11164         /* pshou 07/11/05  set a zero PCM sample to DAC when FIFO is
11165          * under-run
11166          */
11167         {
11168         int tmp;
11169         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
11170         tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
11171         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
11172         snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
11173         }
11174 #endif
11175
11176         alc_fix_pll_init(codec, 0x20, 0x0a, 10);
11177
11178         board_config = snd_hda_check_board_config(codec, ALC262_MODEL_LAST,
11179                                                   alc262_models,
11180                                                   alc262_cfg_tbl);
11181
11182         if (board_config < 0) {
11183                 printk(KERN_INFO "hda_codec: Unknown model for ALC262, "
11184                        "trying auto-probe from BIOS...\n");
11185                 board_config = ALC262_AUTO;
11186         }
11187
11188         if (board_config == ALC262_AUTO) {
11189                 /* automatic parse from the BIOS config */
11190                 err = alc262_parse_auto_config(codec);
11191                 if (err < 0) {
11192                         alc_free(codec);
11193                         return err;
11194                 } else if (!err) {
11195                         printk(KERN_INFO
11196                                "hda_codec: Cannot set up configuration "
11197                                "from BIOS.  Using base mode...\n");
11198                         board_config = ALC262_BASIC;
11199                 }
11200         }
11201
11202         if (!spec->no_analog) {
11203                 err = snd_hda_attach_beep_device(codec, 0x1);
11204                 if (err < 0) {
11205                         alc_free(codec);
11206                         return err;
11207                 }
11208         }
11209
11210         if (board_config != ALC262_AUTO)
11211                 setup_preset(spec, &alc262_presets[board_config]);
11212
11213         spec->stream_name_analog = "ALC262 Analog";
11214         spec->stream_analog_playback = &alc262_pcm_analog_playback;
11215         spec->stream_analog_capture = &alc262_pcm_analog_capture;
11216
11217         spec->stream_name_digital = "ALC262 Digital";
11218         spec->stream_digital_playback = &alc262_pcm_digital_playback;
11219         spec->stream_digital_capture = &alc262_pcm_digital_capture;
11220
11221         spec->capture_style = CAPT_MIX;
11222         if (!spec->adc_nids && spec->input_mux) {
11223                 /* check whether NID 0x07 is valid */
11224                 unsigned int wcap = get_wcaps(codec, 0x07);
11225
11226                 /* get type */
11227                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
11228                 if (wcap != AC_WID_AUD_IN) {
11229                         spec->adc_nids = alc262_adc_nids_alt;
11230                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids_alt);
11231                         spec->capsrc_nids = alc262_capsrc_nids_alt;
11232                 } else {
11233                         spec->adc_nids = alc262_adc_nids;
11234                         spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids);
11235                         spec->capsrc_nids = alc262_capsrc_nids;
11236                 }
11237         }
11238         if (!spec->cap_mixer && !spec->no_analog)
11239                 set_capture_mixer(spec);
11240         if (!spec->no_analog)
11241                 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
11242
11243         spec->vmaster_nid = 0x0c;
11244
11245         codec->patch_ops = alc_patch_ops;
11246         if (board_config == ALC262_AUTO)
11247                 spec->init_hook = alc262_auto_init;
11248 #ifdef CONFIG_SND_HDA_POWER_SAVE
11249         if (!spec->loopback.amplist)
11250                 spec->loopback.amplist = alc262_loopbacks;
11251 #endif
11252         codec->proc_widget_hook = print_realtek_coef;
11253
11254         return 0;
11255 }
11256
11257 /*
11258  *  ALC268 channel source setting (2 channel)
11259  */
11260 #define ALC268_DIGOUT_NID       ALC880_DIGOUT_NID
11261 #define alc268_modes            alc260_modes
11262
11263 static hda_nid_t alc268_dac_nids[2] = {
11264         /* front, hp */
11265         0x02, 0x03
11266 };
11267
11268 static hda_nid_t alc268_adc_nids[2] = {
11269         /* ADC0-1 */
11270         0x08, 0x07
11271 };
11272
11273 static hda_nid_t alc268_adc_nids_alt[1] = {
11274         /* ADC0 */
11275         0x08
11276 };
11277
11278 static hda_nid_t alc268_capsrc_nids[2] = { 0x23, 0x24 };
11279
11280 static struct snd_kcontrol_new alc268_base_mixer[] = {
11281         /* output mixer control */
11282         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
11283         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11284         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
11285         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11286         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11287         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
11288         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11289         { }
11290 };
11291
11292 /* bind Beep switches of both NID 0x0f and 0x10 */
11293 static struct hda_bind_ctls alc268_bind_beep_sw = {
11294         .ops = &snd_hda_bind_sw,
11295         .values = {
11296                 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
11297                 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
11298                 0
11299         },
11300 };
11301
11302 static struct snd_kcontrol_new alc268_beep_mixer[] = {
11303         HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
11304         HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
11305         { }
11306 };
11307
11308 static struct hda_verb alc268_eapd_verbs[] = {
11309         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
11310         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
11311         { }
11312 };
11313
11314 /* Toshiba specific */
11315 #define alc268_toshiba_automute alc262_hippo_automute
11316
11317 static struct hda_verb alc268_toshiba_verbs[] = {
11318         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11319         { } /* end */
11320 };
11321
11322 static struct hda_input_mux alc268_acer_lc_capture_source = {
11323         .num_items = 2,
11324         .items = {
11325                 { "i-Mic", 0x6 },
11326                 { "E-Mic", 0x0 },
11327         },
11328 };
11329
11330 /* Acer specific */
11331 /* bind volumes of both NID 0x02 and 0x03 */
11332 static struct hda_bind_ctls alc268_acer_bind_master_vol = {
11333         .ops = &snd_hda_bind_vol,
11334         .values = {
11335                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
11336                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
11337                 0
11338         },
11339 };
11340
11341 /* mute/unmute internal speaker according to the hp jack and mute state */
11342 static void alc268_acer_automute(struct hda_codec *codec, int force)
11343 {
11344         struct alc_spec *spec = codec->spec;
11345         unsigned int mute;
11346
11347         if (force || !spec->sense_updated) {
11348                 unsigned int present;
11349                 present = snd_hda_codec_read(codec, 0x14, 0,
11350                                          AC_VERB_GET_PIN_SENSE, 0);
11351                 spec->jack_present = (present & 0x80000000) != 0;
11352                 spec->sense_updated = 1;
11353         }
11354         if (spec->jack_present)
11355                 mute = HDA_AMP_MUTE; /* mute internal speaker */
11356         else /* unmute internal speaker if necessary */
11357                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
11358         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
11359                                  HDA_AMP_MUTE, mute);
11360 }
11361
11362
11363 /* bind hp and internal speaker mute (with plug check) */
11364 static int alc268_acer_master_sw_put(struct snd_kcontrol *kcontrol,
11365                                      struct snd_ctl_elem_value *ucontrol)
11366 {
11367         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
11368         long *valp = ucontrol->value.integer.value;
11369         int change;
11370
11371         change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0,
11372                                           HDA_AMP_MUTE,
11373                                           valp[0] ? 0 : HDA_AMP_MUTE);
11374         change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0,
11375                                            HDA_AMP_MUTE,
11376                                            valp[1] ? 0 : HDA_AMP_MUTE);
11377         if (change)
11378                 alc268_acer_automute(codec, 0);
11379         return change;
11380 }
11381
11382 static struct snd_kcontrol_new alc268_acer_aspire_one_mixer[] = {
11383         /* output mixer control */
11384         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11385         {
11386                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11387                 .name = "Master Playback Switch",
11388                 .info = snd_hda_mixer_amp_switch_info,
11389                 .get = snd_hda_mixer_amp_switch_get,
11390                 .put = alc268_acer_master_sw_put,
11391                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11392         },
11393         HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x18, 0, HDA_INPUT),
11394         { }
11395 };
11396
11397 static struct snd_kcontrol_new alc268_acer_mixer[] = {
11398         /* output mixer control */
11399         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11400         {
11401                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11402                 .name = "Master Playback Switch",
11403                 .info = snd_hda_mixer_amp_switch_info,
11404                 .get = snd_hda_mixer_amp_switch_get,
11405                 .put = alc268_acer_master_sw_put,
11406                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11407         },
11408         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11409         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
11410         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11411         { }
11412 };
11413
11414 static struct snd_kcontrol_new alc268_acer_dmic_mixer[] = {
11415         /* output mixer control */
11416         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
11417         {
11418                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11419                 .name = "Master Playback Switch",
11420                 .info = snd_hda_mixer_amp_switch_info,
11421                 .get = snd_hda_mixer_amp_switch_get,
11422                 .put = alc268_acer_master_sw_put,
11423                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
11424         },
11425         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11426         HDA_CODEC_VOLUME("Line In Boost", 0x1a, 0, HDA_INPUT),
11427         { }
11428 };
11429
11430 static struct hda_verb alc268_acer_aspire_one_verbs[] = {
11431         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11432         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11433         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11434         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
11435         {0x23, AC_VERB_SET_CONNECT_SEL, 0x06},
11436         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, 0xa017},
11437         { }
11438 };
11439
11440 static struct hda_verb alc268_acer_verbs[] = {
11441         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* internal dmic? */
11442         {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
11443         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11444         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
11445         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11446         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
11447         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11448         { }
11449 };
11450
11451 /* unsolicited event for HP jack sensing */
11452 static void alc268_toshiba_unsol_event(struct hda_codec *codec,
11453                                        unsigned int res)
11454 {
11455         if ((res >> 26) != ALC880_HP_EVENT)
11456                 return;
11457         alc268_toshiba_automute(codec);
11458 }
11459
11460 static void alc268_acer_unsol_event(struct hda_codec *codec,
11461                                        unsigned int res)
11462 {
11463         if ((res >> 26) != ALC880_HP_EVENT)
11464                 return;
11465         alc268_acer_automute(codec, 1);
11466 }
11467
11468 static void alc268_acer_init_hook(struct hda_codec *codec)
11469 {
11470         alc268_acer_automute(codec, 1);
11471 }
11472
11473 /* toggle speaker-output according to the hp-jack state */
11474 static void alc268_aspire_one_speaker_automute(struct hda_codec *codec)
11475 {
11476         unsigned int present;
11477         unsigned char bits;
11478
11479         present = snd_hda_codec_read(codec, 0x15, 0,
11480                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11481         bits = present ? AMP_IN_MUTE(0) : 0;
11482         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 0,
11483                                 AMP_IN_MUTE(0), bits);
11484         snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 1,
11485                                 AMP_IN_MUTE(0), bits);
11486 }
11487
11488
11489 static void alc268_acer_mic_automute(struct hda_codec *codec)
11490 {
11491         unsigned int present;
11492
11493         present = snd_hda_codec_read(codec, 0x18, 0,
11494                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11495         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_CONNECT_SEL,
11496                             present ? 0x0 : 0x6);
11497 }
11498
11499 static void alc268_acer_lc_unsol_event(struct hda_codec *codec,
11500                                     unsigned int res)
11501 {
11502         if ((res >> 26) == ALC880_HP_EVENT)
11503                 alc268_aspire_one_speaker_automute(codec);
11504         if ((res >> 26) == ALC880_MIC_EVENT)
11505                 alc268_acer_mic_automute(codec);
11506 }
11507
11508 static void alc268_acer_lc_init_hook(struct hda_codec *codec)
11509 {
11510         alc268_aspire_one_speaker_automute(codec);
11511         alc268_acer_mic_automute(codec);
11512 }
11513
11514 static struct snd_kcontrol_new alc268_dell_mixer[] = {
11515         /* output mixer control */
11516         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11517         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11518         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
11519         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11520         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
11521         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
11522         { }
11523 };
11524
11525 static struct hda_verb alc268_dell_verbs[] = {
11526         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11527         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
11528         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11529         { }
11530 };
11531
11532 /* mute/unmute internal speaker according to the hp jack and mute state */
11533 static void alc268_dell_automute(struct hda_codec *codec)
11534 {
11535         unsigned int present;
11536         unsigned int mute;
11537
11538         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0);
11539         if (present & 0x80000000)
11540                 mute = HDA_AMP_MUTE;
11541         else
11542                 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
11543         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
11544                                  HDA_AMP_MUTE, mute);
11545 }
11546
11547 static void alc268_dell_unsol_event(struct hda_codec *codec,
11548                                     unsigned int res)
11549 {
11550         if ((res >> 26) != ALC880_HP_EVENT)
11551                 return;
11552         alc268_dell_automute(codec);
11553 }
11554
11555 #define alc268_dell_init_hook   alc268_dell_automute
11556
11557 static struct snd_kcontrol_new alc267_quanta_il1_mixer[] = {
11558         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x2, 0x0, HDA_OUTPUT),
11559         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
11560         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
11561         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
11562         HDA_CODEC_VOLUME("Mic Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11563         HDA_BIND_MUTE("Mic Capture Switch", 0x23, 2, HDA_OUTPUT),
11564         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
11565         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
11566         { }
11567 };
11568
11569 static struct hda_verb alc267_quanta_il1_verbs[] = {
11570         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
11571         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
11572         { }
11573 };
11574
11575 static void alc267_quanta_il1_hp_automute(struct hda_codec *codec)
11576 {
11577         unsigned int present;
11578
11579         present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
11580                 & AC_PINSENSE_PRESENCE;
11581         snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
11582                             present ? 0 : PIN_OUT);
11583 }
11584
11585 static void alc267_quanta_il1_mic_automute(struct hda_codec *codec)
11586 {
11587         unsigned int present;
11588
11589         present = snd_hda_codec_read(codec, 0x18, 0,
11590                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
11591         snd_hda_codec_write(codec, 0x23, 0,
11592                             AC_VERB_SET_CONNECT_SEL,
11593                             present ? 0x00 : 0x01);
11594 }
11595
11596 static void alc267_quanta_il1_automute(struct hda_codec *codec)
11597 {
11598         alc267_quanta_il1_hp_automute(codec);
11599         alc267_quanta_il1_mic_automute(codec);
11600 }
11601
11602 static void alc267_quanta_il1_unsol_event(struct hda_codec *codec,
11603                                            unsigned int res)
11604 {
11605         switch (res >> 26) {
11606         case ALC880_HP_EVENT:
11607                 alc267_quanta_il1_hp_automute(codec);
11608                 break;
11609         case ALC880_MIC_EVENT:
11610                 alc267_quanta_il1_mic_automute(codec);
11611                 break;
11612         }
11613 }
11614
11615 /*
11616  * generic initialization of ADC, input mixers and output mixers
11617  */
11618 static struct hda_verb alc268_base_init_verbs[] = {
11619         /* Unmute DAC0-1 and set vol = 0 */
11620         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11621         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11622
11623         /*
11624          * Set up output mixers (0x0c - 0x0e)
11625          */
11626         /* set vol=0 to output mixers */
11627         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11628         {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
11629
11630         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11631         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11632
11633         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
11634         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
11635         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
11636         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11637         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11638         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11639         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11640         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11641
11642         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11643         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11644         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11645         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11646         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11647
11648         /* set PCBEEP vol = 0, mute connections */
11649         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11650         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11651         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11652
11653         /* Unmute Selector 23h,24h and set the default input to mic-in */
11654
11655         {0x23, AC_VERB_SET_CONNECT_SEL, 0x00},
11656         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11657         {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
11658         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
11659
11660         { }
11661 };
11662
11663 /*
11664  * generic initialization of ADC, input mixers and output mixers
11665  */
11666 static struct hda_verb alc268_volume_init_verbs[] = {
11667         /* set output DAC */
11668         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11669         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11670
11671         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11672         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11673         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11674         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11675         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11676
11677         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11678         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11679         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11680
11681         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11682         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11683
11684         /* set PCBEEP vol = 0, mute connections */
11685         {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11686         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11687         {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
11688
11689         { }
11690 };
11691
11692 static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
11693         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11694         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
11695         {
11696                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11697                 /* The multiple "Capture Source" controls confuse alsamixer
11698                  * So call somewhat different..
11699                  */
11700                 /* .name = "Capture Source", */
11701                 .name = "Input Source",
11702                 .count = 1,
11703                 .info = alc_mux_enum_info,
11704                 .get = alc_mux_enum_get,
11705                 .put = alc_mux_enum_put,
11706         },
11707         { } /* end */
11708 };
11709
11710 static struct snd_kcontrol_new alc268_capture_mixer[] = {
11711         HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11712         HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
11713         HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
11714         HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
11715         {
11716                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
11717                 /* The multiple "Capture Source" controls confuse alsamixer
11718                  * So call somewhat different..
11719                  */
11720                 /* .name = "Capture Source", */
11721                 .name = "Input Source",
11722                 .count = 2,
11723                 .info = alc_mux_enum_info,
11724                 .get = alc_mux_enum_get,
11725                 .put = alc_mux_enum_put,
11726         },
11727         { } /* end */
11728 };
11729
11730 static struct hda_input_mux alc268_capture_source = {
11731         .num_items = 4,
11732         .items = {
11733                 { "Mic", 0x0 },
11734                 { "Front Mic", 0x1 },
11735                 { "Line", 0x2 },
11736                 { "CD", 0x3 },
11737         },
11738 };
11739
11740 static struct hda_input_mux alc268_acer_capture_source = {
11741         .num_items = 3,
11742         .items = {
11743                 { "Mic", 0x0 },
11744                 { "Internal Mic", 0x1 },
11745                 { "Line", 0x2 },
11746         },
11747 };
11748
11749 static struct hda_input_mux alc268_acer_dmic_capture_source = {
11750         .num_items = 3,
11751         .items = {
11752                 { "Mic", 0x0 },
11753                 { "Internal Mic", 0x6 },
11754                 { "Line", 0x2 },
11755         },
11756 };
11757
11758 #ifdef CONFIG_SND_DEBUG
11759 static struct snd_kcontrol_new alc268_test_mixer[] = {
11760         /* Volume widgets */
11761         HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x02, 0x0, HDA_OUTPUT),
11762         HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x03, 0x0, HDA_OUTPUT),
11763         HDA_BIND_MUTE_MONO("Mono sum Playback Switch", 0x0e, 1, 2, HDA_INPUT),
11764         HDA_BIND_MUTE("LINE-OUT sum Playback Switch", 0x0f, 2, HDA_INPUT),
11765         HDA_BIND_MUTE("HP-OUT sum Playback Switch", 0x10, 2, HDA_INPUT),
11766         HDA_BIND_MUTE("LINE-OUT Playback Switch", 0x14, 2, HDA_OUTPUT),
11767         HDA_BIND_MUTE("HP-OUT Playback Switch", 0x15, 2, HDA_OUTPUT),
11768         HDA_BIND_MUTE("Mono Playback Switch", 0x16, 2, HDA_OUTPUT),
11769         HDA_CODEC_VOLUME("MIC1 Capture Volume", 0x18, 0x0, HDA_INPUT),
11770         HDA_BIND_MUTE("MIC1 Capture Switch", 0x18, 2, HDA_OUTPUT),
11771         HDA_CODEC_VOLUME("MIC2 Capture Volume", 0x19, 0x0, HDA_INPUT),
11772         HDA_CODEC_VOLUME("LINE1 Capture Volume", 0x1a, 0x0, HDA_INPUT),
11773         HDA_BIND_MUTE("LINE1 Capture Switch", 0x1a, 2, HDA_OUTPUT),
11774         /* The below appears problematic on some hardwares */
11775         /*HDA_CODEC_VOLUME("PCBEEP Playback Volume", 0x1d, 0x0, HDA_INPUT),*/
11776         HDA_CODEC_VOLUME("PCM-IN1 Capture Volume", 0x23, 0x0, HDA_OUTPUT),
11777         HDA_BIND_MUTE("PCM-IN1 Capture Switch", 0x23, 2, HDA_OUTPUT),
11778         HDA_CODEC_VOLUME("PCM-IN2 Capture Volume", 0x24, 0x0, HDA_OUTPUT),
11779         HDA_BIND_MUTE("PCM-IN2 Capture Switch", 0x24, 2, HDA_OUTPUT),
11780
11781         /* Modes for retasking pin widgets */
11782         ALC_PIN_MODE("LINE-OUT pin mode", 0x14, ALC_PIN_DIR_INOUT),
11783         ALC_PIN_MODE("HP-OUT pin mode", 0x15, ALC_PIN_DIR_INOUT),
11784         ALC_PIN_MODE("MIC1 pin mode", 0x18, ALC_PIN_DIR_INOUT),
11785         ALC_PIN_MODE("LINE1 pin mode", 0x1a, ALC_PIN_DIR_INOUT),
11786
11787         /* Controls for GPIO pins, assuming they are configured as outputs */
11788         ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
11789         ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
11790         ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
11791         ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
11792
11793         /* Switches to allow the digital SPDIF output pin to be enabled.
11794          * The ALC268 does not have an SPDIF input.
11795          */
11796         ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x06, 0x01),
11797
11798         /* A switch allowing EAPD to be enabled.  Some laptops seem to use
11799          * this output to turn on an external amplifier.
11800          */
11801         ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
11802         ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
11803
11804         { } /* end */
11805 };
11806 #endif
11807
11808 /* create input playback/capture controls for the given pin */
11809 static int alc268_new_analog_output(struct alc_spec *spec, hda_nid_t nid,
11810                                     const char *ctlname, int idx)
11811 {
11812         char name[32];
11813         int err;
11814
11815         sprintf(name, "%s Playback Volume", ctlname);
11816         if (nid == 0x14) {
11817                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
11818                                   HDA_COMPOSE_AMP_VAL(0x02, 3, idx,
11819                                                       HDA_OUTPUT));
11820                 if (err < 0)
11821                         return err;
11822         } else if (nid == 0x15) {
11823                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
11824                                   HDA_COMPOSE_AMP_VAL(0x03, 3, idx,
11825                                                       HDA_OUTPUT));
11826                 if (err < 0)
11827                         return err;
11828         } else
11829                 return -1;
11830         sprintf(name, "%s Playback Switch", ctlname);
11831         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
11832                           HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_OUTPUT));
11833         if (err < 0)
11834                 return err;
11835         return 0;
11836 }
11837
11838 /* add playback controls from the parsed DAC table */
11839 static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
11840                                              const struct auto_pin_cfg *cfg)
11841 {
11842         hda_nid_t nid;
11843         int err;
11844
11845         spec->multiout.num_dacs = 2;    /* only use one dac */
11846         spec->multiout.dac_nids = spec->private_dac_nids;
11847         spec->multiout.dac_nids[0] = 2;
11848         spec->multiout.dac_nids[1] = 3;
11849
11850         nid = cfg->line_out_pins[0];
11851         if (nid)
11852                 alc268_new_analog_output(spec, nid, "Front", 0);
11853
11854         nid = cfg->speaker_pins[0];
11855         if (nid == 0x1d) {
11856                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
11857                                   "Speaker Playback Volume",
11858                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
11859                 if (err < 0)
11860                         return err;
11861         }
11862         nid = cfg->hp_pins[0];
11863         if (nid)
11864                 alc268_new_analog_output(spec, nid, "Headphone", 0);
11865
11866         nid = cfg->line_out_pins[1] | cfg->line_out_pins[2];
11867         if (nid == 0x16) {
11868                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
11869                                   "Mono Playback Switch",
11870                                   HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_INPUT));
11871                 if (err < 0)
11872                         return err;
11873         }
11874         return 0;
11875 }
11876
11877 /* create playback/capture controls for input pins */
11878 static int alc268_auto_create_analog_input_ctls(struct alc_spec *spec,
11879                                                 const struct auto_pin_cfg *cfg)
11880 {
11881         struct hda_input_mux *imux = &spec->private_imux[0];
11882         int i, idx1;
11883
11884         for (i = 0; i < AUTO_PIN_LAST; i++) {
11885                 switch(cfg->input_pins[i]) {
11886                 case 0x18:
11887                         idx1 = 0;       /* Mic 1 */
11888                         break;
11889                 case 0x19:
11890                         idx1 = 1;       /* Mic 2 */
11891                         break;
11892                 case 0x1a:
11893                         idx1 = 2;       /* Line In */
11894                         break;
11895                 case 0x1c:
11896                         idx1 = 3;       /* CD */
11897                         break;
11898                 case 0x12:
11899                 case 0x13:
11900                         idx1 = 6;       /* digital mics */
11901                         break;
11902                 default:
11903                         continue;
11904                 }
11905                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
11906                 imux->items[imux->num_items].index = idx1;
11907                 imux->num_items++;
11908         }
11909         return 0;
11910 }
11911
11912 static void alc268_auto_init_mono_speaker_out(struct hda_codec *codec)
11913 {
11914         struct alc_spec *spec = codec->spec;
11915         hda_nid_t speaker_nid = spec->autocfg.speaker_pins[0];
11916         hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
11917         hda_nid_t line_nid = spec->autocfg.line_out_pins[0];
11918         unsigned int    dac_vol1, dac_vol2;
11919
11920         if (speaker_nid) {
11921                 snd_hda_codec_write(codec, speaker_nid, 0,
11922                                     AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
11923                 snd_hda_codec_write(codec, 0x0f, 0,
11924                                     AC_VERB_SET_AMP_GAIN_MUTE,
11925                                     AMP_IN_UNMUTE(1));
11926                 snd_hda_codec_write(codec, 0x10, 0,
11927                                     AC_VERB_SET_AMP_GAIN_MUTE,
11928                                     AMP_IN_UNMUTE(1));
11929         } else {
11930                 snd_hda_codec_write(codec, 0x0f, 0,
11931                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
11932                 snd_hda_codec_write(codec, 0x10, 0,
11933                                     AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1));
11934         }
11935
11936         dac_vol1 = dac_vol2 = 0xb000 | 0x40;    /* set max volume  */
11937         if (line_nid == 0x14)
11938                 dac_vol2 = AMP_OUT_ZERO;
11939         else if (line_nid == 0x15)
11940                 dac_vol1 = AMP_OUT_ZERO;
11941         if (hp_nid == 0x14)
11942                 dac_vol2 = AMP_OUT_ZERO;
11943         else if (hp_nid == 0x15)
11944                 dac_vol1 = AMP_OUT_ZERO;
11945         if (line_nid != 0x16 || hp_nid != 0x16 ||
11946             spec->autocfg.line_out_pins[1] != 0x16 ||
11947             spec->autocfg.line_out_pins[2] != 0x16)
11948                 dac_vol1 = dac_vol2 = AMP_OUT_ZERO;
11949
11950         snd_hda_codec_write(codec, 0x02, 0,
11951                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol1);
11952         snd_hda_codec_write(codec, 0x03, 0,
11953                             AC_VERB_SET_AMP_GAIN_MUTE, dac_vol2);
11954 }
11955
11956 /* pcm configuration: identiacal with ALC880 */
11957 #define alc268_pcm_analog_playback      alc880_pcm_analog_playback
11958 #define alc268_pcm_analog_capture       alc880_pcm_analog_capture
11959 #define alc268_pcm_analog_alt_capture   alc880_pcm_analog_alt_capture
11960 #define alc268_pcm_digital_playback     alc880_pcm_digital_playback
11961
11962 /*
11963  * BIOS auto configuration
11964  */
11965 static int alc268_parse_auto_config(struct hda_codec *codec)
11966 {
11967         struct alc_spec *spec = codec->spec;
11968         int err;
11969         static hda_nid_t alc268_ignore[] = { 0 };
11970
11971         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
11972                                            alc268_ignore);
11973         if (err < 0)
11974                 return err;
11975         if (!spec->autocfg.line_outs) {
11976                 if (spec->autocfg.dig_outs || spec->autocfg.dig_in_pin) {
11977                         spec->multiout.max_channels = 2;
11978                         spec->no_analog = 1;
11979                         goto dig_only;
11980                 }
11981                 return 0; /* can't find valid BIOS pin config */
11982         }
11983         err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
11984         if (err < 0)
11985                 return err;
11986         err = alc268_auto_create_analog_input_ctls(spec, &spec->autocfg);
11987         if (err < 0)
11988                 return err;
11989
11990         spec->multiout.max_channels = 2;
11991
11992  dig_only:
11993         /* digital only support output */
11994         if (spec->autocfg.dig_outs) {
11995                 spec->multiout.dig_out_nid = ALC268_DIGOUT_NID;
11996                 spec->dig_out_type = spec->autocfg.dig_out_type[0];
11997         }
11998         if (spec->kctls.list)
11999                 add_mixer(spec, spec->kctls.list);
12000
12001         if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d)
12002                 add_mixer(spec, alc268_beep_mixer);
12003
12004         add_verb(spec, alc268_volume_init_verbs);
12005         spec->num_mux_defs = 1;
12006         spec->input_mux = &spec->private_imux[0];
12007
12008         err = alc_auto_add_mic_boost(codec);
12009         if (err < 0)
12010                 return err;
12011
12012         return 1;
12013 }
12014
12015 #define alc268_auto_init_multi_out      alc882_auto_init_multi_out
12016 #define alc268_auto_init_hp_out         alc882_auto_init_hp_out
12017 #define alc268_auto_init_analog_input   alc882_auto_init_analog_input
12018
12019 /* init callback for auto-configuration model -- overriding the default init */
12020 static void alc268_auto_init(struct hda_codec *codec)
12021 {
12022         struct alc_spec *spec = codec->spec;
12023         alc268_auto_init_multi_out(codec);
12024         alc268_auto_init_hp_out(codec);
12025         alc268_auto_init_mono_speaker_out(codec);
12026         alc268_auto_init_analog_input(codec);
12027         if (spec->unsol_event)
12028                 alc_inithook(codec);
12029 }
12030
12031 /*
12032  * configuration and preset
12033  */
12034 static const char *alc268_models[ALC268_MODEL_LAST] = {
12035         [ALC267_QUANTA_IL1]     = "quanta-il1",
12036         [ALC268_3ST]            = "3stack",
12037         [ALC268_TOSHIBA]        = "toshiba",
12038         [ALC268_ACER]           = "acer",
12039         [ALC268_ACER_DMIC]      = "acer-dmic",
12040         [ALC268_ACER_ASPIRE_ONE]        = "acer-aspire",
12041         [ALC268_DELL]           = "dell",
12042         [ALC268_ZEPTO]          = "zepto",
12043 #ifdef CONFIG_SND_DEBUG
12044         [ALC268_TEST]           = "test",
12045 #endif
12046         [ALC268_AUTO]           = "auto",
12047 };
12048
12049 static struct snd_pci_quirk alc268_cfg_tbl[] = {
12050         SND_PCI_QUIRK(0x1025, 0x011e, "Acer Aspire 5720z", ALC268_ACER),
12051         SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
12052         SND_PCI_QUIRK(0x1025, 0x012e, "Acer Aspire 5310", ALC268_ACER),
12053         SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
12054         SND_PCI_QUIRK(0x1025, 0x0136, "Acer Aspire 5315", ALC268_ACER),
12055         SND_PCI_QUIRK(0x1025, 0x015b, "Acer Aspire One",
12056                                                 ALC268_ACER_ASPIRE_ONE),
12057         SND_PCI_QUIRK(0x1028, 0x0253, "Dell OEM", ALC268_DELL),
12058         SND_PCI_QUIRK(0x1028, 0x02b0, "Dell Inspiron Mini9", ALC268_DELL),
12059         SND_PCI_QUIRK(0x103c, 0x30cc, "TOSHIBA", ALC268_TOSHIBA),
12060         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
12061         SND_PCI_QUIRK(0x1179, 0xff10, "TOSHIBA A205", ALC268_TOSHIBA),
12062         SND_PCI_QUIRK(0x1179, 0xff50, "TOSHIBA A305", ALC268_TOSHIBA),
12063         SND_PCI_QUIRK(0x1179, 0xff64, "TOSHIBA L305", ALC268_TOSHIBA),
12064         SND_PCI_QUIRK(0x14c0, 0x0025, "COMPAL IFL90/JFL-92", ALC268_TOSHIBA),
12065         SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER),
12066         SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1),
12067         SND_PCI_QUIRK(0x1170, 0x0040, "ZEPTO", ALC268_ZEPTO),
12068         {}
12069 };
12070
12071 static struct alc_config_preset alc268_presets[] = {
12072         [ALC267_QUANTA_IL1] = {
12073                 .mixers = { alc267_quanta_il1_mixer, alc268_beep_mixer },
12074                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12075                                 alc267_quanta_il1_verbs },
12076                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12077                 .dac_nids = alc268_dac_nids,
12078                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12079                 .adc_nids = alc268_adc_nids_alt,
12080                 .hp_nid = 0x03,
12081                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12082                 .channel_mode = alc268_modes,
12083                 .input_mux = &alc268_capture_source,
12084                 .unsol_event = alc267_quanta_il1_unsol_event,
12085                 .init_hook = alc267_quanta_il1_automute,
12086         },
12087         [ALC268_3ST] = {
12088                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
12089                             alc268_beep_mixer },
12090                 .init_verbs = { alc268_base_init_verbs },
12091                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12092                 .dac_nids = alc268_dac_nids,
12093                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12094                 .adc_nids = alc268_adc_nids_alt,
12095                 .capsrc_nids = alc268_capsrc_nids,
12096                 .hp_nid = 0x03,
12097                 .dig_out_nid = ALC268_DIGOUT_NID,
12098                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12099                 .channel_mode = alc268_modes,
12100                 .input_mux = &alc268_capture_source,
12101         },
12102         [ALC268_TOSHIBA] = {
12103                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
12104                             alc268_beep_mixer },
12105                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12106                                 alc268_toshiba_verbs },
12107                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12108                 .dac_nids = alc268_dac_nids,
12109                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12110                 .adc_nids = alc268_adc_nids_alt,
12111                 .capsrc_nids = alc268_capsrc_nids,
12112                 .hp_nid = 0x03,
12113                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12114                 .channel_mode = alc268_modes,
12115                 .input_mux = &alc268_capture_source,
12116                 .unsol_event = alc268_toshiba_unsol_event,
12117                 .init_hook = alc268_toshiba_automute,
12118         },
12119         [ALC268_ACER] = {
12120                 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer,
12121                             alc268_beep_mixer },
12122                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12123                                 alc268_acer_verbs },
12124                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12125                 .dac_nids = alc268_dac_nids,
12126                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12127                 .adc_nids = alc268_adc_nids_alt,
12128                 .capsrc_nids = alc268_capsrc_nids,
12129                 .hp_nid = 0x02,
12130                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12131                 .channel_mode = alc268_modes,
12132                 .input_mux = &alc268_acer_capture_source,
12133                 .unsol_event = alc268_acer_unsol_event,
12134                 .init_hook = alc268_acer_init_hook,
12135         },
12136         [ALC268_ACER_DMIC] = {
12137                 .mixers = { alc268_acer_dmic_mixer, alc268_capture_alt_mixer,
12138                             alc268_beep_mixer },
12139                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12140                                 alc268_acer_verbs },
12141                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12142                 .dac_nids = alc268_dac_nids,
12143                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12144                 .adc_nids = alc268_adc_nids_alt,
12145                 .capsrc_nids = alc268_capsrc_nids,
12146                 .hp_nid = 0x02,
12147                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12148                 .channel_mode = alc268_modes,
12149                 .input_mux = &alc268_acer_dmic_capture_source,
12150                 .unsol_event = alc268_acer_unsol_event,
12151                 .init_hook = alc268_acer_init_hook,
12152         },
12153         [ALC268_ACER_ASPIRE_ONE] = {
12154                 .mixers = { alc268_acer_aspire_one_mixer,
12155                             alc268_beep_mixer,
12156                             alc268_capture_alt_mixer },
12157                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12158                                 alc268_acer_aspire_one_verbs },
12159                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12160                 .dac_nids = alc268_dac_nids,
12161                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12162                 .adc_nids = alc268_adc_nids_alt,
12163                 .capsrc_nids = alc268_capsrc_nids,
12164                 .hp_nid = 0x03,
12165                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12166                 .channel_mode = alc268_modes,
12167                 .input_mux = &alc268_acer_lc_capture_source,
12168                 .unsol_event = alc268_acer_lc_unsol_event,
12169                 .init_hook = alc268_acer_lc_init_hook,
12170         },
12171         [ALC268_DELL] = {
12172                 .mixers = { alc268_dell_mixer, alc268_beep_mixer },
12173                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12174                                 alc268_dell_verbs },
12175                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12176                 .dac_nids = alc268_dac_nids,
12177                 .hp_nid = 0x02,
12178                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12179                 .channel_mode = alc268_modes,
12180                 .unsol_event = alc268_dell_unsol_event,
12181                 .init_hook = alc268_dell_init_hook,
12182                 .input_mux = &alc268_capture_source,
12183         },
12184         [ALC268_ZEPTO] = {
12185                 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
12186                             alc268_beep_mixer },
12187                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12188                                 alc268_toshiba_verbs },
12189                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12190                 .dac_nids = alc268_dac_nids,
12191                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12192                 .adc_nids = alc268_adc_nids_alt,
12193                 .capsrc_nids = alc268_capsrc_nids,
12194                 .hp_nid = 0x03,
12195                 .dig_out_nid = ALC268_DIGOUT_NID,
12196                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12197                 .channel_mode = alc268_modes,
12198                 .input_mux = &alc268_capture_source,
12199                 .unsol_event = alc268_toshiba_unsol_event,
12200                 .init_hook = alc268_toshiba_automute
12201         },
12202 #ifdef CONFIG_SND_DEBUG
12203         [ALC268_TEST] = {
12204                 .mixers = { alc268_test_mixer, alc268_capture_mixer },
12205                 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
12206                                 alc268_volume_init_verbs },
12207                 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
12208                 .dac_nids = alc268_dac_nids,
12209                 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
12210                 .adc_nids = alc268_adc_nids_alt,
12211                 .capsrc_nids = alc268_capsrc_nids,
12212                 .hp_nid = 0x03,
12213                 .dig_out_nid = ALC268_DIGOUT_NID,
12214                 .num_channel_mode = ARRAY_SIZE(alc268_modes),
12215                 .channel_mode = alc268_modes,
12216                 .input_mux = &alc268_capture_source,
12217         },
12218 #endif
12219 };
12220
12221 static int patch_alc268(struct hda_codec *codec)
12222 {
12223         struct alc_spec *spec;
12224         int board_config;
12225         int i, has_beep, err;
12226
12227         spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
12228         if (spec == NULL)
12229                 return -ENOMEM;
12230
12231         codec->spec = spec;
12232
12233         board_config = snd_hda_check_board_config(codec, ALC268_MODEL_LAST,
12234                                                   alc268_models,
12235                                                   alc268_cfg_tbl);
12236
12237         if (board_config < 0 || board_config >= ALC268_MODEL_LAST) {
12238                 printk(KERN_INFO "hda_codec: Unknown model for ALC268, "
12239                        "trying auto-probe from BIOS...\n");
12240                 board_config = ALC268_AUTO;
12241         }
12242
12243         if (board_config == ALC268_AUTO) {
12244                 /* automatic parse from the BIOS config */
12245                 err = alc268_parse_auto_config(codec);
12246                 if (err < 0) {
12247                         alc_free(codec);
12248                         return err;
12249                 } else if (!err) {
12250                         printk(KERN_INFO
12251                                "hda_codec: Cannot set up configuration "
12252                                "from BIOS.  Using base mode...\n");
12253                         board_config = ALC268_3ST;
12254                 }
12255         }
12256
12257         if (board_config != ALC268_AUTO)
12258                 setup_preset(spec, &alc268_presets[board_config]);
12259
12260         if (codec->vendor_id == 0x10ec0267) {
12261                 spec->stream_name_analog = "ALC267 Analog";
12262                 spec->stream_name_digital = "ALC267 Digital";
12263         } else {
12264                 spec->stream_name_analog = "ALC268 Analog";
12265                 spec->stream_name_digital = "ALC268 Digital";
12266         }
12267
12268         spec->stream_analog_playback = &alc268_pcm_analog_playback;
12269         spec->stream_analog_capture = &alc268_pcm_analog_capture;
12270         spec->stream_analog_alt_capture = &alc268_pcm_analog_alt_capture;
12271
12272         spec->stream_digital_playback = &alc268_pcm_digital_playback;
12273
12274         has_beep = 0;
12275         for (i = 0; i < spec->num_mixers; i++) {
12276                 if (spec->mixers[i] == alc268_beep_mixer) {
12277                         has_beep = 1;
12278                         break;
12279                 }
12280         }
12281
12282         if (has_beep) {
12283                 err = snd_hda_attach_beep_device(codec, 0x1);
12284                 if (err < 0) {
12285                         alc_free(codec);
12286                         return err;
12287                 }
12288                 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
12289                         /* override the amp caps for beep generator */
12290                         snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
12291                                           (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
12292                                           (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
12293                                           (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
12294                                           (0 << AC_AMPCAP_MUTE_SHIFT));
12295         }
12296
12297         if (!spec->no_analog && !spec->adc_nids && spec->input_mux) {
12298                 /* check whether NID 0x07 is valid */
12299                 unsigned int wcap = get_wcaps(codec, 0x07);
12300                 int i;
12301
12302                 /* get type */
12303                 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
12304                 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
12305                         spec->adc_nids = alc268_adc_nids_alt;
12306                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt);
12307                         add_mixer(spec, alc268_capture_alt_mixer);
12308                 } else {
12309                         spec->adc_nids = alc268_adc_nids;
12310                         spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids);
12311                         add_mixer(spec, alc268_capture_mixer);
12312                 }
12313                 spec->capsrc_nids = alc268_capsrc_nids;
12314                 /* set default input source */
12315                 for (i = 0; i < spec->num_adc_nids; i++)
12316                         snd_hda_codec_write_cache(codec, alc268_capsrc_nids[i],
12317                                 0, AC_VERB_SET_CONNECT_SEL,
12318                                 spec->input_mux->items[0].index);
12319         }
12320
12321         spec->vmaster_nid = 0x02;
12322
12323         codec->patch_ops = alc_patch_ops;
12324         if (board_config == ALC268_AUTO)
12325                 spec->init_hook = alc268_auto_init;
12326
12327         codec->proc_widget_hook = print_realtek_coef;
12328
12329         return 0;
12330 }
12331
12332 /*
12333  *  ALC269 channel source setting (2 channel)
12334  */
12335 #define ALC269_DIGOUT_NID       ALC880_DIGOUT_NID
12336
12337 #define alc269_dac_nids         alc260_dac_nids
12338
12339 static hda_nid_t alc269_adc_nids[1] = {
12340         /* ADC1 */
12341         0x08,
12342 };
12343
12344 static hda_nid_t alc269_capsrc_nids[1] = {
12345         0x23,
12346 };
12347
12348 /* NOTE: ADC2 (0x07) is connected from a recording *MIXER* (0x24),
12349  *       not a mux!
12350  */
12351
12352 static struct hda_input_mux alc269_eeepc_dmic_capture_source = {
12353         .num_items = 2,
12354         .items = {
12355                 { "i-Mic", 0x5 },
12356                 { "e-Mic", 0x0 },
12357         },
12358 };
12359
12360 static struct hda_input_mux alc269_eeepc_amic_capture_source = {
12361         .num_items = 2,
12362         .items = {
12363                 { "i-Mic", 0x1 },
12364                 { "e-Mic", 0x0 },
12365         },
12366 };
12367
12368 #define alc269_modes            alc260_modes
12369 #define alc269_capture_source   alc880_lg_lw_capture_source
12370
12371 static struct snd_kcontrol_new alc269_base_mixer[] = {
12372         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12373         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12374         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
12375         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
12376         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12377         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12378         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12379         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12380         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12381         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
12382         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12383         HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
12384         { } /* end */
12385 };
12386
12387 static struct snd_kcontrol_new alc269_quanta_fl1_mixer[] = {
12388         /* output mixer control */
12389         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
12390         {
12391                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12392                 .name = "Master Playback Switch",
12393                 .info = snd_hda_mixer_amp_switch_info,
12394                 .get = snd_hda_mixer_amp_switch_get,
12395                 .put = alc268_acer_master_sw_put,
12396                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
12397         },
12398         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12399         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12400         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12401         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12402         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12403         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
12404         { }
12405 };
12406
12407 static struct snd_kcontrol_new alc269_lifebook_mixer[] = {
12408         /* output mixer control */
12409         HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
12410         {
12411                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
12412                 .name = "Master Playback Switch",
12413                 .info = snd_hda_mixer_amp_switch_info,
12414                 .get = snd_hda_mixer_amp_switch_get,
12415                 .put = alc268_acer_master_sw_put,
12416                 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
12417         },
12418         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12419         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12420         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12421         HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12422         HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12423         HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
12424         HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x0b, 0x03, HDA_INPUT),
12425         HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x0b, 0x03, HDA_INPUT),
12426         HDA_CODEC_VOLUME("Dock Mic Boost", 0x1b, 0, HDA_INPUT),
12427         { }
12428 };
12429
12430 /* bind volumes of both NID 0x0c and 0x0d */
12431 static struct hda_bind_ctls alc269_epc_bind_vol = {
12432         .ops = &snd_hda_bind_vol,
12433         .values = {
12434                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
12435                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
12436                 0
12437         },
12438 };
12439
12440 static struct snd_kcontrol_new alc269_eeepc_mixer[] = {
12441         HDA_CODEC_MUTE("iSpeaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12442         HDA_BIND_VOL("LineOut Playback Volume", &alc269_epc_bind_vol),
12443         HDA_CODEC_MUTE("LineOut Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12444         { } /* end */
12445 };
12446
12447 /* capture mixer elements */
12448 static struct snd_kcontrol_new alc269_epc_capture_mixer[] = {
12449         HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
12450         HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
12451         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12452         { } /* end */
12453 };
12454
12455 /* FSC amilo */
12456 static struct snd_kcontrol_new alc269_fujitsu_mixer[] = {
12457         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
12458         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
12459         HDA_BIND_VOL("PCM Playback Volume", &alc269_epc_bind_vol),
12460         { } /* end */
12461 };
12462
12463 static struct hda_verb alc269_quanta_fl1_verbs[] = {
12464         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12465         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12466         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12467         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12468         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12469         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12470         { }
12471 };
12472
12473 static struct hda_verb alc269_lifebook_verbs[] = {
12474         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12475         {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
12476         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12477         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12478         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12479         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12480         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12481         {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
12482         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12483         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12484         { }
12485 };
12486
12487 /* toggle speaker-output according to the hp-jack state */
12488 static void alc269_quanta_fl1_speaker_automute(struct hda_codec *codec)
12489 {
12490         unsigned int present;
12491         unsigned char bits;
12492
12493         present = snd_hda_codec_read(codec, 0x15, 0,
12494                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12495         bits = present ? AMP_IN_MUTE(0) : 0;
12496         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
12497                         AMP_IN_MUTE(0), bits);
12498         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
12499                         AMP_IN_MUTE(0), bits);
12500
12501         snd_hda_codec_write(codec, 0x20, 0,
12502                         AC_VERB_SET_COEF_INDEX, 0x0c);
12503         snd_hda_codec_write(codec, 0x20, 0,
12504                         AC_VERB_SET_PROC_COEF, 0x680);
12505
12506         snd_hda_codec_write(codec, 0x20, 0,
12507                         AC_VERB_SET_COEF_INDEX, 0x0c);
12508         snd_hda_codec_write(codec, 0x20, 0,
12509                         AC_VERB_SET_PROC_COEF, 0x480);
12510 }
12511
12512 /* toggle speaker-output according to the hp-jacks state */
12513 static void alc269_lifebook_speaker_automute(struct hda_codec *codec)
12514 {
12515         unsigned int present;
12516         unsigned char bits;
12517
12518         /* Check laptop headphone socket */
12519         present = snd_hda_codec_read(codec, 0x15, 0,
12520                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12521
12522         /* Check port replicator headphone socket */
12523         present |= snd_hda_codec_read(codec, 0x1a, 0,
12524                         AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12525
12526         bits = present ? AMP_IN_MUTE(0) : 0;
12527         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
12528                         AMP_IN_MUTE(0), bits);
12529         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
12530                         AMP_IN_MUTE(0), bits);
12531
12532         snd_hda_codec_write(codec, 0x20, 0,
12533                         AC_VERB_SET_COEF_INDEX, 0x0c);
12534         snd_hda_codec_write(codec, 0x20, 0,
12535                         AC_VERB_SET_PROC_COEF, 0x680);
12536
12537         snd_hda_codec_write(codec, 0x20, 0,
12538                         AC_VERB_SET_COEF_INDEX, 0x0c);
12539         snd_hda_codec_write(codec, 0x20, 0,
12540                         AC_VERB_SET_PROC_COEF, 0x480);
12541 }
12542
12543 static void alc269_quanta_fl1_mic_automute(struct hda_codec *codec)
12544 {
12545         unsigned int present;
12546
12547         present = snd_hda_codec_read(codec, 0x18, 0,
12548                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12549         snd_hda_codec_write(codec, 0x23, 0,
12550                             AC_VERB_SET_CONNECT_SEL, present ? 0x0 : 0x1);
12551 }
12552
12553 static void alc269_lifebook_mic_autoswitch(struct hda_codec *codec)
12554 {
12555         unsigned int present_laptop;
12556         unsigned int present_dock;
12557
12558         present_laptop = snd_hda_codec_read(codec, 0x18, 0,
12559                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12560
12561         present_dock = snd_hda_codec_read(codec, 0x1b, 0,
12562                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12563
12564         /* Laptop mic port overrides dock mic port, design decision */
12565         if (present_dock)
12566                 snd_hda_codec_write(codec, 0x23, 0,
12567                                 AC_VERB_SET_CONNECT_SEL, 0x3);
12568         if (present_laptop)
12569                 snd_hda_codec_write(codec, 0x23, 0,
12570                                 AC_VERB_SET_CONNECT_SEL, 0x0);
12571         if (!present_dock && !present_laptop)
12572                 snd_hda_codec_write(codec, 0x23, 0,
12573                                 AC_VERB_SET_CONNECT_SEL, 0x1);
12574 }
12575
12576 static void alc269_quanta_fl1_unsol_event(struct hda_codec *codec,
12577                                     unsigned int res)
12578 {
12579         if ((res >> 26) == ALC880_HP_EVENT)
12580                 alc269_quanta_fl1_speaker_automute(codec);
12581         if ((res >> 26) == ALC880_MIC_EVENT)
12582                 alc269_quanta_fl1_mic_automute(codec);
12583 }
12584
12585 static void alc269_lifebook_unsol_event(struct hda_codec *codec,
12586                                         unsigned int res)
12587 {
12588         if ((res >> 26) == ALC880_HP_EVENT)
12589                 alc269_lifebook_speaker_automute(codec);
12590         if ((res >> 26) == ALC880_MIC_EVENT)
12591                 alc269_lifebook_mic_autoswitch(codec);
12592 }
12593
12594 static void alc269_quanta_fl1_init_hook(struct hda_codec *codec)
12595 {
12596         alc269_quanta_fl1_speaker_automute(codec);
12597         alc269_quanta_fl1_mic_automute(codec);
12598 }
12599
12600 static void alc269_lifebook_init_hook(struct hda_codec *codec)
12601 {
12602         alc269_lifebook_speaker_automute(codec);
12603         alc269_lifebook_mic_autoswitch(codec);
12604 }
12605
12606 static struct hda_verb alc269_eeepc_dmic_init_verbs[] = {
12607         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12608         {0x23, AC_VERB_SET_CONNECT_SEL, 0x05},
12609         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
12610         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))},
12611         {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12612         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12613         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12614         {}
12615 };
12616
12617 static struct hda_verb alc269_eeepc_amic_init_verbs[] = {
12618         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12619         {0x23, AC_VERB_SET_CONNECT_SEL, 0x01},
12620         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
12621         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x701b | (0x00 << 8))},
12622         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
12623         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
12624         {}
12625 };
12626
12627 /* toggle speaker-output according to the hp-jack state */
12628 static void alc269_speaker_automute(struct hda_codec *codec)
12629 {
12630         unsigned int present;
12631         unsigned char bits;
12632
12633         present = snd_hda_codec_read(codec, 0x15, 0,
12634                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12635         bits = present ? AMP_IN_MUTE(0) : 0;
12636         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
12637                                 AMP_IN_MUTE(0), bits);
12638         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
12639                                 AMP_IN_MUTE(0), bits);
12640 }
12641
12642 static void alc269_eeepc_dmic_automute(struct hda_codec *codec)
12643 {
12644         unsigned int present;
12645
12646         present = snd_hda_codec_read(codec, 0x18, 0,
12647                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12648         snd_hda_codec_write(codec, 0x23, 0,
12649                                 AC_VERB_SET_CONNECT_SEL,  (present ? 0 : 5));
12650 }
12651
12652 static void alc269_eeepc_amic_automute(struct hda_codec *codec)
12653 {
12654         unsigned int present;
12655
12656         present = snd_hda_codec_read(codec, 0x18, 0,
12657                                 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12658         snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
12659                                 0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
12660         snd_hda_codec_write(codec, 0x24, 0, AC_VERB_SET_AMP_GAIN_MUTE,
12661                                 0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
12662 }
12663
12664 /* unsolicited event for HP jack sensing */
12665 static void alc269_eeepc_dmic_unsol_event(struct hda_codec *codec,
12666                                      unsigned int res)
12667 {
12668         if ((res >> 26) == ALC880_HP_EVENT)
12669                 alc269_speaker_automute(codec);
12670
12671         if ((res >> 26) == ALC880_MIC_EVENT)
12672                 alc269_eeepc_dmic_automute(codec);
12673 }
12674
12675 static void alc269_eeepc_dmic_inithook(struct hda_codec *codec)
12676 {
12677         alc269_speaker_automute(codec);
12678         alc269_eeepc_dmic_automute(codec);
12679 }
12680
12681 /* unsolicited event for HP jack sensing */
12682 static void alc269_eeepc_amic_unsol_event(struct hda_codec *codec,
12683                                      unsigned int res)
12684 {
12685         if ((res >> 26) == ALC880_HP_EVENT)
12686                 alc269_speaker_automute(codec);
12687
12688         if ((res >> 26) == ALC880_MIC_EVENT)
12689                 alc269_eeepc_amic_automute(codec);
12690 }
12691
12692 static void alc269_eeepc_amic_inithook(struct hda_codec *codec)
12693 {
12694         alc269_speaker_automute(codec);
12695         alc269_eeepc_amic_automute(codec);
12696 }
12697
12698 /*
12699  * generic initialization of ADC, input mixers and output mixers
12700  */
12701 static struct hda_verb alc269_init_verbs[] = {
12702         /*
12703          * Unmute ADC0 and set the default input to mic-in
12704          */
12705         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12706
12707         /* Mute input amps (PCBeep, Line In, Mic 1 & Mic 2) of the
12708          * analog-loopback mixer widget
12709          * Note: PASD motherboards uses the Line In 2 as the input for
12710          * front panel mic (mic 2)
12711          */
12712         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
12713         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12714         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
12715         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12716         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12717         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
12718
12719         /*
12720          * Set up output mixers (0x0c - 0x0e)
12721          */
12722         /* set vol=0 to output mixers */
12723         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12724         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
12725
12726         /* set up input amps for analog loopback */
12727         /* Amp Indices: DAC = 0, mixer = 1 */
12728         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12729         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12730         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12731         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12732         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
12733         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12734
12735         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12736         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
12737         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
12738         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12739         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
12740         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12741         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
12742
12743         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12744         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
12745         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12746         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12747         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12748         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12749         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12750
12751         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
12752         {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
12753
12754         /* FIXME: use matrix-type input source selection */
12755         /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
12756         /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
12757         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
12758         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
12759         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
12760         {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
12761
12762         /* set EAPD */
12763         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
12764         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
12765         { }
12766 };
12767
12768 /* add playback controls from the parsed DAC table */
12769 static int alc269_auto_create_multi_out_ctls(struct alc_spec *spec,
12770                                              const struct auto_pin_cfg *cfg)
12771 {
12772         hda_nid_t nid;
12773         int err;
12774
12775         spec->multiout.num_dacs = 1;    /* only use one dac */
12776         spec->multiout.dac_nids = spec->private_dac_nids;
12777         spec->multiout.dac_nids[0] = 2;
12778
12779         nid = cfg->line_out_pins[0];
12780         if (nid) {
12781                 err = add_control(spec, ALC_CTL_WIDGET_VOL,
12782                                   "Front Playback Volume",
12783                                   HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT));
12784                 if (err < 0)
12785                         return err;
12786                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12787                                   "Front Playback Switch",
12788                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
12789                 if (err < 0)
12790                         return err;
12791         }
12792
12793         nid = cfg->speaker_pins[0];
12794         if (nid) {
12795                 if (!cfg->line_out_pins[0]) {
12796                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
12797                                           "Speaker Playback Volume",
12798                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
12799                                                               HDA_OUTPUT));
12800                         if (err < 0)
12801                                 return err;
12802                 }
12803                 if (nid == 0x16) {
12804                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12805                                           "Speaker Playback Switch",
12806                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
12807                                                               HDA_OUTPUT));
12808                         if (err < 0)
12809                                 return err;
12810                 } else {
12811                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12812                                           "Speaker Playback Switch",
12813                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
12814                                                               HDA_OUTPUT));
12815                         if (err < 0)
12816                                 return err;
12817                 }
12818         }
12819         nid = cfg->hp_pins[0];
12820         if (nid) {
12821                 /* spec->multiout.hp_nid = 2; */
12822                 if (!cfg->line_out_pins[0] && !cfg->speaker_pins[0]) {
12823                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
12824                                           "Headphone Playback Volume",
12825                                           HDA_COMPOSE_AMP_VAL(0x02, 3, 0,
12826                                                               HDA_OUTPUT));
12827                         if (err < 0)
12828                                 return err;
12829                 }
12830                 if (nid == 0x16) {
12831                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12832                                           "Headphone Playback Switch",
12833                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
12834                                                               HDA_OUTPUT));
12835                         if (err < 0)
12836                                 return err;
12837                 } else {
12838                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
12839                                           "Headphone Playback Switch",
12840                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
12841                                                               HDA_OUTPUT));
12842                         if (err < 0)
12843                                 return err;
12844                 }
12845         }
12846         return 0;
12847 }
12848
12849 static int alc269_auto_create_analog_input_ctls(struct alc_spec *spec,
12850                                                 const struct auto_pin_cfg *cfg)
12851 {
12852         int err;
12853
12854         err = alc880_auto_create_analog_input_ctls(spec, cfg);
12855         if (err < 0)
12856                 return err;
12857         /* digital-mic input pin is excluded in alc880_auto_create..()
12858          * because it's under 0x18
12859          */
12860         if (cfg->input_pins[AUTO_PIN_MIC] == 0x12 ||
12861             cfg->input_pins[AUTO_PIN_FRONT_MIC] == 0x12) {
12862                 struct hda_input_mux *imux = &spec->private_imux[0];
12863                 imux->items[imux->num_items].label = "Int Mic";
12864                 imux->items[imux->num_items].index = 0x05;
12865                 imux->num_items++;
12866         }
12867         return 0;
12868 }
12869
12870 #ifdef CONFIG_SND_HDA_POWER_SAVE
12871 #define alc269_loopbacks        alc880_loopbacks
12872 #endif
12873
12874 /* pcm configuration: identiacal with ALC880 */
12875 #define alc269_pcm_analog_playback      alc880_pcm_analog_playback
12876 #define alc269_pcm_analog_capture       alc880_pcm_analog_capture
12877 #define alc269_pcm_digital_playback     alc880_pcm_digital_playback
12878 #define alc269_pcm_digital_capture      alc880_pcm_digital_capture
12879
12880 static struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
12881         .substreams = 1,
12882         .channels_min = 2,
12883         .channels_max = 8,
12884         .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
12885         /* NID is set in alc_build_pcms */
12886         .ops = {
12887                 .open = alc880_playback_pcm_open,
12888                 .prepare = alc880_playback_pcm_prepare,
12889                 .cleanup = alc880_playback_pcm_cleanup
12890         },
12891 };
12892
12893 static struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
12894         .substreams = 1,
12895         .channels_min = 2,
12896         .channels_max = 2,
12897         .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
12898         /* NID is set in alc_build_pcms */
12899 };
12900
12901 /*
12902  * BIOS auto configuration
12903  */
12904 static int alc269_parse_auto_config(struct hda_codec *codec)
12905 {
12906         struct alc_spec *spec = codec->spec;
12907         int err;
12908         static hda_nid_t alc269_ignore[] = { 0x1d, 0 };
12909
12910         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
12911                                            alc269_ignore);
12912         if (err < 0)
12913                 return err;
12914
12915         err = alc269_auto_create_multi_out_ctls(spec, &spec->autocfg);
12916         if (err < 0)
12917                 return err;
12918         err = alc269_auto_create_analog_input_ctls(spec, &spec->autocfg);
12919         if (err < 0)
12920                 return err;
12921
12922         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
12923
12924         if (spec->autocfg.dig_outs)
12925                 spec->multiout.dig_out_nid = ALC269_DIGOUT_NID;
12926
12927         if (spec->kctls.list)
12928                 add_mixer(spec, spec->kctls.list);
12929
12930         add_verb(spec, alc269_init_verbs);
12931         spec->num_mux_defs = 1;
12932         spec->input_mux = &spec->private_imux[0];
12933         /* set default input source */
12934         snd_hda_codec_write_cache(codec, alc269_capsrc_nids[0],
12935                                   0, AC_VERB_SET_CONNECT_SEL,
12936                                   spec->input_mux->items[0].index);
12937
12938         err = alc_auto_add_mic_boost(codec);
12939         if (err < 0)
12940                 return err;
12941
12942         if (!spec->cap_mixer && !spec->no_analog)
12943                 set_capture_mixer(spec);
12944
12945         return 1;
12946 }
12947
12948 #define alc269_auto_init_multi_out      alc882_auto_init_multi_out
12949 #define alc269_auto_init_hp_out         alc882_auto_init_hp_out
12950 #define alc269_auto_init_analog_input   alc882_auto_init_analog_input
12951
12952
12953 /* init callback for auto-configuration model -- overriding the default init */
12954 static void alc269_auto_init(struct hda_codec *codec)
12955 {
12956         struct alc_spec *spec = codec->spec;
12957         alc269_auto_init_multi_out(codec);
12958         alc269_auto_init_hp_out(codec);
12959         alc269_auto_init_analog_input(codec);
12960         if (spec->unsol_event)
12961                 alc_inithook(codec);
12962 }
12963
12964 /*
12965  * configuration and preset
12966  */
12967 static const char *alc269_models[ALC269_MODEL_LAST] = {
12968         [ALC269_BASIC]                  = "basic",
12969         [ALC269_QUANTA_FL1]             = "quanta",
12970         [ALC269_ASUS_EEEPC_P703]        = "eeepc-p703",
12971         [ALC269_ASUS_EEEPC_P901]        = "eeepc-p901",
12972         [ALC269_FUJITSU]                = "fujitsu",
12973         [ALC269_LIFEBOOK]               = "lifebook"
12974 };
12975
12976 static struct snd_pci_quirk alc269_cfg_tbl[] = {
12977         SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_QUANTA_FL1),
12978         SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
12979                       ALC269_ASUS_EEEPC_P703),
12980         SND_PCI_QUIRK(0x1043, 0x831a, "ASUS Eeepc P901",
12981                       ALC269_ASUS_EEEPC_P901),
12982         SND_PCI_QUIRK(0x1043, 0x834a, "ASUS Eeepc S101",
12983                       ALC269_ASUS_EEEPC_P901),
12984         SND_PCI_QUIRK(0x1734, 0x115d, "FSC Amilo", ALC269_FUJITSU),
12985         SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook ICH9M-based", ALC269_LIFEBOOK),
12986         {}
12987 };
12988
12989 static struct alc_config_preset alc269_presets[] = {
12990         [ALC269_BASIC] = {
12991                 .mixers = { alc269_base_mixer },
12992                 .init_verbs = { alc269_init_verbs },
12993                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
12994                 .dac_nids = alc269_dac_nids,
12995                 .hp_nid = 0x03,
12996                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
12997                 .channel_mode = alc269_modes,
12998                 .input_mux = &alc269_capture_source,
12999         },
13000         [ALC269_QUANTA_FL1] = {
13001                 .mixers = { alc269_quanta_fl1_mixer },
13002                 .init_verbs = { alc269_init_verbs, alc269_quanta_fl1_verbs },
13003                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13004                 .dac_nids = alc269_dac_nids,
13005                 .hp_nid = 0x03,
13006                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13007                 .channel_mode = alc269_modes,
13008                 .input_mux = &alc269_capture_source,
13009                 .unsol_event = alc269_quanta_fl1_unsol_event,
13010                 .init_hook = alc269_quanta_fl1_init_hook,
13011         },
13012         [ALC269_ASUS_EEEPC_P703] = {
13013                 .mixers = { alc269_eeepc_mixer },
13014                 .cap_mixer = alc269_epc_capture_mixer,
13015                 .init_verbs = { alc269_init_verbs,
13016                                 alc269_eeepc_amic_init_verbs },
13017                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13018                 .dac_nids = alc269_dac_nids,
13019                 .hp_nid = 0x03,
13020                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13021                 .channel_mode = alc269_modes,
13022                 .input_mux = &alc269_eeepc_amic_capture_source,
13023                 .unsol_event = alc269_eeepc_amic_unsol_event,
13024                 .init_hook = alc269_eeepc_amic_inithook,
13025         },
13026         [ALC269_ASUS_EEEPC_P901] = {
13027                 .mixers = { alc269_eeepc_mixer },
13028                 .cap_mixer = alc269_epc_capture_mixer,
13029                 .init_verbs = { alc269_init_verbs,
13030                                 alc269_eeepc_dmic_init_verbs },
13031                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13032                 .dac_nids = alc269_dac_nids,
13033                 .hp_nid = 0x03,
13034                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13035                 .channel_mode = alc269_modes,
13036                 .input_mux = &alc269_eeepc_dmic_capture_source,
13037                 .unsol_event = alc269_eeepc_dmic_unsol_event,
13038                 .init_hook = alc269_eeepc_dmic_inithook,
13039         },
13040         [ALC269_FUJITSU] = {
13041                 .mixers = { alc269_fujitsu_mixer },
13042                 .cap_mixer = alc269_epc_capture_mixer,
13043                 .init_verbs = { alc269_init_verbs,
13044                                 alc269_eeepc_dmic_init_verbs },
13045                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13046                 .dac_nids = alc269_dac_nids,
13047                 .hp_nid = 0x03,
13048                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13049                 .channel_mode = alc269_modes,
13050                 .input_mux = &alc269_eeepc_dmic_capture_source,
13051                 .unsol_event = alc269_eeepc_dmic_unsol_event,
13052                 .init_hook = alc269_eeepc_dmic_inithook,
13053         },
13054         [ALC269_LIFEBOOK] = {
13055                 .mixers = { alc269_lifebook_mixer },
13056                 .init_verbs = { alc269_init_verbs, alc269_lifebook_verbs },
13057                 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
13058                 .dac_nids = alc269_dac_nids,
13059                 .hp_nid = 0x03,
13060                 .num_channel_mode = ARRAY_SIZE(alc269_modes),
13061                 .channel_mode = alc269_modes,
13062                 .input_mux = &alc269_capture_source,
13063                 .unsol_event = alc269_lifebook_unsol_event,
13064                 .init_hook = alc269_lifebook_init_hook,
13065         },
13066 };
13067
13068 static int patch_alc269(struct hda_codec *codec)
13069 {
13070         struct alc_spec *spec;
13071         int board_config;
13072         int err;
13073
13074         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
13075         if (spec == NULL)
13076                 return -ENOMEM;
13077
13078         codec->spec = spec;
13079
13080         alc_fix_pll_init(codec, 0x20, 0x04, 15);
13081
13082         board_config = snd_hda_check_board_config(codec, ALC269_MODEL_LAST,
13083                                                   alc269_models,
13084                                                   alc269_cfg_tbl);
13085
13086         if (board_config < 0) {
13087                 printk(KERN_INFO "hda_codec: Unknown model for ALC269, "
13088                        "trying auto-probe from BIOS...\n");
13089                 board_config = ALC269_AUTO;
13090         }
13091
13092         if (board_config == ALC269_AUTO) {
13093                 /* automatic parse from the BIOS config */
13094                 err = alc269_parse_auto_config(codec);
13095                 if (err < 0) {
13096                         alc_free(codec);
13097                         return err;
13098                 } else if (!err) {
13099                         printk(KERN_INFO
13100                                "hda_codec: Cannot set up configuration "
13101                                "from BIOS.  Using base mode...\n");
13102                         board_config = ALC269_BASIC;
13103                 }
13104         }
13105
13106         err = snd_hda_attach_beep_device(codec, 0x1);
13107         if (err < 0) {
13108                 alc_free(codec);
13109                 return err;
13110         }
13111
13112         if (board_config != ALC269_AUTO)
13113                 setup_preset(spec, &alc269_presets[board_config]);
13114
13115         spec->stream_name_analog = "ALC269 Analog";
13116         if (codec->subsystem_id == 0x17aa3bf8) {
13117                 /* Due to a hardware problem on Lenovo Ideadpad, we need to
13118                  * fix the sample rate of analog I/O to 44.1kHz
13119                  */
13120                 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
13121                 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
13122         } else {
13123                 spec->stream_analog_playback = &alc269_pcm_analog_playback;
13124                 spec->stream_analog_capture = &alc269_pcm_analog_capture;
13125         }
13126         spec->stream_name_digital = "ALC269 Digital";
13127         spec->stream_digital_playback = &alc269_pcm_digital_playback;
13128         spec->stream_digital_capture = &alc269_pcm_digital_capture;
13129
13130         spec->adc_nids = alc269_adc_nids;
13131         spec->num_adc_nids = ARRAY_SIZE(alc269_adc_nids);
13132         spec->capsrc_nids = alc269_capsrc_nids;
13133         if (!spec->cap_mixer)
13134                 set_capture_mixer(spec);
13135         set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
13136
13137         codec->patch_ops = alc_patch_ops;
13138         if (board_config == ALC269_AUTO)
13139                 spec->init_hook = alc269_auto_init;
13140 #ifdef CONFIG_SND_HDA_POWER_SAVE
13141         if (!spec->loopback.amplist)
13142                 spec->loopback.amplist = alc269_loopbacks;
13143 #endif
13144         codec->proc_widget_hook = print_realtek_coef;
13145
13146         return 0;
13147 }
13148
13149 /*
13150  *  ALC861 channel source setting (2/6 channel selection for 3-stack)
13151  */
13152
13153 /*
13154  * set the path ways for 2 channel output
13155  * need to set the codec line out and mic 1 pin widgets to inputs
13156  */
13157 static struct hda_verb alc861_threestack_ch2_init[] = {
13158         /* set pin widget 1Ah (line in) for input */
13159         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13160         /* set pin widget 18h (mic1/2) for input, for mic also enable
13161          * the vref
13162          */
13163         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13164
13165         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
13166 #if 0
13167         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
13168         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
13169 #endif
13170         { } /* end */
13171 };
13172 /*
13173  * 6ch mode
13174  * need to set the codec line out and mic 1 pin widgets to outputs
13175  */
13176 static struct hda_verb alc861_threestack_ch6_init[] = {
13177         /* set pin widget 1Ah (line in) for output (Back Surround)*/
13178         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13179         /* set pin widget 18h (mic1) for output (CLFE)*/
13180         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13181
13182         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
13183         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
13184
13185         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
13186 #if 0
13187         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
13188         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
13189 #endif
13190         { } /* end */
13191 };
13192
13193 static struct hda_channel_mode alc861_threestack_modes[2] = {
13194         { 2, alc861_threestack_ch2_init },
13195         { 6, alc861_threestack_ch6_init },
13196 };
13197 /* Set mic1 as input and unmute the mixer */
13198 static struct hda_verb alc861_uniwill_m31_ch2_init[] = {
13199         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13200         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
13201         { } /* end */
13202 };
13203 /* Set mic1 as output and mute mixer */
13204 static struct hda_verb alc861_uniwill_m31_ch4_init[] = {
13205         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13206         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
13207         { } /* end */
13208 };
13209
13210 static struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
13211         { 2, alc861_uniwill_m31_ch2_init },
13212         { 4, alc861_uniwill_m31_ch4_init },
13213 };
13214
13215 /* Set mic1 and line-in as input and unmute the mixer */
13216 static struct hda_verb alc861_asus_ch2_init[] = {
13217         /* set pin widget 1Ah (line in) for input */
13218         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13219         /* set pin widget 18h (mic1/2) for input, for mic also enable
13220          * the vref
13221          */
13222         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13223
13224         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
13225 #if 0
13226         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
13227         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
13228 #endif
13229         { } /* end */
13230 };
13231 /* Set mic1 nad line-in as output and mute mixer */
13232 static struct hda_verb alc861_asus_ch6_init[] = {
13233         /* set pin widget 1Ah (line in) for output (Back Surround)*/
13234         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13235         /* { 0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
13236         /* set pin widget 18h (mic1) for output (CLFE)*/
13237         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13238         /* { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
13239         { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
13240         { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
13241
13242         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
13243 #if 0
13244         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
13245         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
13246 #endif
13247         { } /* end */
13248 };
13249
13250 static struct hda_channel_mode alc861_asus_modes[2] = {
13251         { 2, alc861_asus_ch2_init },
13252         { 6, alc861_asus_ch6_init },
13253 };
13254
13255 /* patch-ALC861 */
13256
13257 static struct snd_kcontrol_new alc861_base_mixer[] = {
13258         /* output mixer control */
13259         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13260         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
13261         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
13262         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13263         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
13264
13265         /*Input mixer control */
13266         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13267            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
13268         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13269         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13270         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13271         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13272         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13273         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13274         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13275         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
13276
13277         { } /* end */
13278 };
13279
13280 static struct snd_kcontrol_new alc861_3ST_mixer[] = {
13281         /* output mixer control */
13282         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13283         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
13284         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
13285         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13286         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
13287
13288         /* Input mixer control */
13289         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13290            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
13291         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13292         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13293         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13294         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13295         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13296         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13297         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13298         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
13299
13300         {
13301                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13302                 .name = "Channel Mode",
13303                 .info = alc_ch_mode_info,
13304                 .get = alc_ch_mode_get,
13305                 .put = alc_ch_mode_put,
13306                 .private_value = ARRAY_SIZE(alc861_threestack_modes),
13307         },
13308         { } /* end */
13309 };
13310
13311 static struct snd_kcontrol_new alc861_toshiba_mixer[] = {
13312         /* output mixer control */
13313         HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13314         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13315         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13316
13317         { } /* end */
13318 };
13319
13320 static struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
13321         /* output mixer control */
13322         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13323         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
13324         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
13325         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13326         /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
13327
13328         /* Input mixer control */
13329         /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13330            HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
13331         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13332         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13333         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13334         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13335         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13336         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13337         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13338         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
13339
13340         {
13341                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13342                 .name = "Channel Mode",
13343                 .info = alc_ch_mode_info,
13344                 .get = alc_ch_mode_get,
13345                 .put = alc_ch_mode_put,
13346                 .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
13347         },
13348         { } /* end */
13349 };
13350
13351 static struct snd_kcontrol_new alc861_asus_mixer[] = {
13352         /* output mixer control */
13353         HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
13354         HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
13355         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
13356         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
13357         HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
13358
13359         /* Input mixer control */
13360         HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
13361         HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT),
13362         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13363         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13364         HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
13365         HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
13366         HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
13367         HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
13368         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
13369         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT),
13370
13371         {
13372                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
13373                 .name = "Channel Mode",
13374                 .info = alc_ch_mode_info,
13375                 .get = alc_ch_mode_get,
13376                 .put = alc_ch_mode_put,
13377                 .private_value = ARRAY_SIZE(alc861_asus_modes),
13378         },
13379         { }
13380 };
13381
13382 /* additional mixer */
13383 static struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
13384         HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13385         HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13386         { }
13387 };
13388
13389 /*
13390  * generic initialization of ADC, input mixers and output mixers
13391  */
13392 static struct hda_verb alc861_base_init_verbs[] = {
13393         /*
13394          * Unmute ADC0 and set the default input to mic-in
13395          */
13396         /* port-A for surround (rear panel) */
13397         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13398         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
13399         /* port-B for mic-in (rear panel) with vref */
13400         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13401         /* port-C for line-in (rear panel) */
13402         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13403         /* port-D for Front */
13404         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13405         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13406         /* port-E for HP out (front panel) */
13407         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
13408         /* route front PCM to HP */
13409         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13410         /* port-F for mic-in (front panel) with vref */
13411         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13412         /* port-G for CLFE (rear panel) */
13413         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13414         { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13415         /* port-H for side (rear panel) */
13416         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13417         { 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
13418         /* CD-in */
13419         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13420         /* route front mic to ADC1*/
13421         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13422         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13423
13424         /* Unmute DAC0~3 & spdif out*/
13425         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13426         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13427         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13428         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13429         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13430
13431         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13432         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13433         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13434         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13435         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13436
13437         /* Unmute Stereo Mixer 15 */
13438         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13439         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13440         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13441         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13442
13443         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13444         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13445         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13446         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13447         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13448         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13449         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13450         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13451         /* hp used DAC 3 (Front) */
13452         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13453         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13454
13455         { }
13456 };
13457
13458 static struct hda_verb alc861_threestack_init_verbs[] = {
13459         /*
13460          * Unmute ADC0 and set the default input to mic-in
13461          */
13462         /* port-A for surround (rear panel) */
13463         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13464         /* port-B for mic-in (rear panel) with vref */
13465         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13466         /* port-C for line-in (rear panel) */
13467         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13468         /* port-D for Front */
13469         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13470         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13471         /* port-E for HP out (front panel) */
13472         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
13473         /* route front PCM to HP */
13474         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13475         /* port-F for mic-in (front panel) with vref */
13476         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13477         /* port-G for CLFE (rear panel) */
13478         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13479         /* port-H for side (rear panel) */
13480         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13481         /* CD-in */
13482         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13483         /* route front mic to ADC1*/
13484         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13485         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13486         /* Unmute DAC0~3 & spdif out*/
13487         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13488         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13489         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13490         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13491         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13492
13493         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13494         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13495         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13496         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13497         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13498
13499         /* Unmute Stereo Mixer 15 */
13500         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13501         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13502         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13503         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13504
13505         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13506         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13507         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13508         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13509         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13510         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13511         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13512         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13513         /* hp used DAC 3 (Front) */
13514         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13515         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13516         { }
13517 };
13518
13519 static struct hda_verb alc861_uniwill_m31_init_verbs[] = {
13520         /*
13521          * Unmute ADC0 and set the default input to mic-in
13522          */
13523         /* port-A for surround (rear panel) */
13524         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13525         /* port-B for mic-in (rear panel) with vref */
13526         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13527         /* port-C for line-in (rear panel) */
13528         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13529         /* port-D for Front */
13530         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13531         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13532         /* port-E for HP out (front panel) */
13533         /* this has to be set to VREF80 */
13534         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13535         /* route front PCM to HP */
13536         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13537         /* port-F for mic-in (front panel) with vref */
13538         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13539         /* port-G for CLFE (rear panel) */
13540         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13541         /* port-H for side (rear panel) */
13542         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
13543         /* CD-in */
13544         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13545         /* route front mic to ADC1*/
13546         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13547         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13548         /* Unmute DAC0~3 & spdif out*/
13549         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13550         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13551         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13552         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13553         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13554
13555         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13556         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13557         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13558         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13559         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13560
13561         /* Unmute Stereo Mixer 15 */
13562         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13563         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13564         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13565         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13566
13567         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13568         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13569         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13570         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13571         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13572         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13573         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13574         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13575         /* hp used DAC 3 (Front) */
13576         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13577         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13578         { }
13579 };
13580
13581 static struct hda_verb alc861_asus_init_verbs[] = {
13582         /*
13583          * Unmute ADC0 and set the default input to mic-in
13584          */
13585         /* port-A for surround (rear panel)
13586          * according to codec#0 this is the HP jack
13587          */
13588         { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, /* was 0x00 */
13589         /* route front PCM to HP */
13590         { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x01 },
13591         /* port-B for mic-in (rear panel) with vref */
13592         { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13593         /* port-C for line-in (rear panel) */
13594         { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13595         /* port-D for Front */
13596         { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13597         { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
13598         /* port-E for HP out (front panel) */
13599         /* this has to be set to VREF80 */
13600         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13601         /* route front PCM to HP */
13602         { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
13603         /* port-F for mic-in (front panel) with vref */
13604         { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
13605         /* port-G for CLFE (rear panel) */
13606         { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13607         /* port-H for side (rear panel) */
13608         { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
13609         /* CD-in */
13610         { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
13611         /* route front mic to ADC1*/
13612         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
13613         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13614         /* Unmute DAC0~3 & spdif out*/
13615         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13616         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13617         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13618         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13619         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13620         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13621         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13622         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13623         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13624         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13625
13626         /* Unmute Stereo Mixer 15 */
13627         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13628         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13629         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13630         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
13631
13632         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13633         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13634         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13635         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13636         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13637         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13638         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13639         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13640         /* hp used DAC 3 (Front) */
13641         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13642         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13643         { }
13644 };
13645
13646 /* additional init verbs for ASUS laptops */
13647 static struct hda_verb alc861_asus_laptop_init_verbs[] = {
13648         { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x45 }, /* HP-out */
13649         { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2) }, /* mute line-in */
13650         { }
13651 };
13652
13653 /*
13654  * generic initialization of ADC, input mixers and output mixers
13655  */
13656 static struct hda_verb alc861_auto_init_verbs[] = {
13657         /*
13658          * Unmute ADC0 and set the default input to mic-in
13659          */
13660         /* {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, */
13661         {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13662
13663         /* Unmute DAC0~3 & spdif out*/
13664         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13665         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13666         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13667         {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13668         {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
13669
13670         /* Unmute Mixer 14 (mic) 1c (Line in)*/
13671         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13672         {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13673         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13674         {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13675
13676         /* Unmute Stereo Mixer 15 */
13677         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13678         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13679         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13680         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c},
13681
13682         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13683         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13684         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13685         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13686         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13687         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13688         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
13689         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
13690
13691         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13692         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13693         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13694         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13695         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
13696         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
13697         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
13698         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
13699
13700         {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},  /* set Mic 1 */
13701
13702         { }
13703 };
13704
13705 static struct hda_verb alc861_toshiba_init_verbs[] = {
13706         {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
13707
13708         { }
13709 };
13710
13711 /* toggle speaker-output according to the hp-jack state */
13712 static void alc861_toshiba_automute(struct hda_codec *codec)
13713 {
13714         unsigned int present;
13715
13716         present = snd_hda_codec_read(codec, 0x0f, 0,
13717                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13718         snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
13719                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
13720         snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
13721                                  HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
13722 }
13723
13724 static void alc861_toshiba_unsol_event(struct hda_codec *codec,
13725                                        unsigned int res)
13726 {
13727         if ((res >> 26) == ALC880_HP_EVENT)
13728                 alc861_toshiba_automute(codec);
13729 }
13730
13731 /* pcm configuration: identiacal with ALC880 */
13732 #define alc861_pcm_analog_playback      alc880_pcm_analog_playback
13733 #define alc861_pcm_analog_capture       alc880_pcm_analog_capture
13734 #define alc861_pcm_digital_playback     alc880_pcm_digital_playback
13735 #define alc861_pcm_digital_capture      alc880_pcm_digital_capture
13736
13737
13738 #define ALC861_DIGOUT_NID       0x07
13739
13740 static struct hda_channel_mode alc861_8ch_modes[1] = {
13741         { 8, NULL }
13742 };
13743
13744 static hda_nid_t alc861_dac_nids[4] = {
13745         /* front, surround, clfe, side */
13746         0x03, 0x06, 0x05, 0x04
13747 };
13748
13749 static hda_nid_t alc660_dac_nids[3] = {
13750         /* front, clfe, surround */
13751         0x03, 0x05, 0x06
13752 };
13753
13754 static hda_nid_t alc861_adc_nids[1] = {
13755         /* ADC0-2 */
13756         0x08,
13757 };
13758
13759 static struct hda_input_mux alc861_capture_source = {
13760         .num_items = 5,
13761         .items = {
13762                 { "Mic", 0x0 },
13763                 { "Front Mic", 0x3 },
13764                 { "Line", 0x1 },
13765                 { "CD", 0x4 },
13766                 { "Mixer", 0x5 },
13767         },
13768 };
13769
13770 /* fill in the dac_nids table from the parsed pin configuration */
13771 static int alc861_auto_fill_dac_nids(struct alc_spec *spec,
13772                                      const struct auto_pin_cfg *cfg)
13773 {
13774         int i;
13775         hda_nid_t nid;
13776
13777         spec->multiout.dac_nids = spec->private_dac_nids;
13778         for (i = 0; i < cfg->line_outs; i++) {
13779                 nid = cfg->line_out_pins[i];
13780                 if (nid) {
13781                         if (i >= ARRAY_SIZE(alc861_dac_nids))
13782                                 continue;
13783                         spec->multiout.dac_nids[i] = alc861_dac_nids[i];
13784                 }
13785         }
13786         spec->multiout.num_dacs = cfg->line_outs;
13787         return 0;
13788 }
13789
13790 /* add playback controls from the parsed DAC table */
13791 static int alc861_auto_create_multi_out_ctls(struct alc_spec *spec,
13792                                              const struct auto_pin_cfg *cfg)
13793 {
13794         char name[32];
13795         static const char *chname[4] = {
13796                 "Front", "Surround", NULL /*CLFE*/, "Side"
13797         };
13798         hda_nid_t nid;
13799         int i, idx, err;
13800
13801         for (i = 0; i < cfg->line_outs; i++) {
13802                 nid = spec->multiout.dac_nids[i];
13803                 if (!nid)
13804                         continue;
13805                 if (nid == 0x05) {
13806                         /* Center/LFE */
13807                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13808                                           "Center Playback Switch",
13809                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
13810                                                               HDA_OUTPUT));
13811                         if (err < 0)
13812                                 return err;
13813                         err = add_control(spec, ALC_CTL_BIND_MUTE,
13814                                           "LFE Playback Switch",
13815                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
13816                                                               HDA_OUTPUT));
13817                         if (err < 0)
13818                                 return err;
13819                 } else {
13820                         for (idx = 0; idx < ARRAY_SIZE(alc861_dac_nids) - 1;
13821                              idx++)
13822                                 if (nid == alc861_dac_nids[idx])
13823                                         break;
13824                         sprintf(name, "%s Playback Switch", chname[idx]);
13825                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
13826                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
13827                                                               HDA_OUTPUT));
13828                         if (err < 0)
13829                                 return err;
13830                 }
13831         }
13832         return 0;
13833 }
13834
13835 static int alc861_auto_create_hp_ctls(struct alc_spec *spec, hda_nid_t pin)
13836 {
13837         int err;
13838         hda_nid_t nid;
13839
13840         if (!pin)
13841                 return 0;
13842
13843         if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
13844                 nid = 0x03;
13845                 err = add_control(spec, ALC_CTL_WIDGET_MUTE,
13846                                   "Headphone Playback Switch",
13847                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
13848                 if (err < 0)
13849                         return err;
13850                 spec->multiout.hp_nid = nid;
13851         }
13852         return 0;
13853 }
13854
13855 /* create playback/capture controls for input pins */
13856 static int alc861_auto_create_analog_input_ctls(struct alc_spec *spec,
13857                                                 const struct auto_pin_cfg *cfg)
13858 {
13859         struct hda_input_mux *imux = &spec->private_imux[0];
13860         int i, err, idx, idx1;
13861
13862         for (i = 0; i < AUTO_PIN_LAST; i++) {
13863                 switch (cfg->input_pins[i]) {
13864                 case 0x0c:
13865                         idx1 = 1;
13866                         idx = 2;        /* Line In */
13867                         break;
13868                 case 0x0f:
13869                         idx1 = 2;
13870                         idx = 2;        /* Line In */
13871                         break;
13872                 case 0x0d:
13873                         idx1 = 0;
13874                         idx = 1;        /* Mic In */
13875                         break;
13876                 case 0x10:
13877                         idx1 = 3;
13878                         idx = 1;        /* Mic In */
13879                         break;
13880                 case 0x11:
13881                         idx1 = 4;
13882                         idx = 0;        /* CD */
13883                         break;
13884                 default:
13885                         continue;
13886                 }
13887
13888                 err = new_analog_input(spec, cfg->input_pins[i],
13889                                        auto_pin_cfg_labels[i], idx, 0x15);
13890                 if (err < 0)
13891                         return err;
13892
13893                 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
13894                 imux->items[imux->num_items].index = idx1;
13895                 imux->num_items++;
13896         }
13897         return 0;
13898 }
13899
13900 static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
13901                                               hda_nid_t nid,
13902                                               int pin_type, int dac_idx)
13903 {
13904         snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
13905                             pin_type);
13906         snd_hda_codec_write(codec, dac_idx, 0, AC_VERB_SET_AMP_GAIN_MUTE,
13907                             AMP_OUT_UNMUTE);
13908 }
13909
13910 static void alc861_auto_init_multi_out(struct hda_codec *codec)
13911 {
13912         struct alc_spec *spec = codec->spec;
13913         int i;
13914
13915         alc_subsystem_id(codec, 0x0e, 0x0f, 0x0b);
13916         for (i = 0; i < spec->autocfg.line_outs; i++) {
13917                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
13918                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
13919                 if (nid)
13920                         alc861_auto_set_output_and_unmute(codec, nid, pin_type,
13921                                                           spec->multiout.dac_nids[i]);
13922         }
13923 }
13924
13925 static void alc861_auto_init_hp_out(struct hda_codec *codec)
13926 {
13927         struct alc_spec *spec = codec->spec;
13928         hda_nid_t pin;
13929
13930         pin = spec->autocfg.hp_pins[0];
13931         if (pin) /* connect to front */
13932                 alc861_auto_set_output_and_unmute(codec, pin, PIN_HP,
13933                                                   spec->multiout.dac_nids[0]);
13934         pin = spec->autocfg.speaker_pins[0];
13935         if (pin)
13936                 alc861_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
13937 }
13938
13939 static void alc861_auto_init_analog_input(struct hda_codec *codec)
13940 {
13941         struct alc_spec *spec = codec->spec;
13942         int i;
13943
13944         for (i = 0; i < AUTO_PIN_LAST; i++) {
13945                 hda_nid_t nid = spec->autocfg.input_pins[i];
13946                 if (nid >= 0x0c && nid <= 0x11)
13947                         alc_set_input_pin(codec, nid, i);
13948         }
13949 }
13950
13951 /* parse the BIOS configuration and set up the alc_spec */
13952 /* return 1 if successful, 0 if the proper config is not found,
13953  * or a negative error code
13954  */
13955 static int alc861_parse_auto_config(struct hda_codec *codec)
13956 {
13957         struct alc_spec *spec = codec->spec;
13958         int err;
13959         static hda_nid_t alc861_ignore[] = { 0x1d, 0 };
13960
13961         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
13962                                            alc861_ignore);
13963         if (err < 0)
13964                 return err;
13965         if (!spec->autocfg.line_outs)
13966                 return 0; /* can't find valid BIOS pin config */
13967
13968         err = alc861_auto_fill_dac_nids(spec, &spec->autocfg);
13969         if (err < 0)
13970                 return err;
13971         err = alc861_auto_create_multi_out_ctls(spec, &spec->autocfg);
13972         if (err < 0)
13973                 return err;
13974         err = alc861_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
13975         if (err < 0)
13976                 return err;
13977         err = alc861_auto_create_analog_input_ctls(spec, &spec->autocfg);
13978         if (err < 0)
13979                 return err;
13980
13981         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
13982
13983         if (spec->autocfg.dig_outs)
13984                 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;
13985
13986         if (spec->kctls.list)
13987                 add_mixer(spec, spec->kctls.list);
13988
13989         add_verb(spec, alc861_auto_init_verbs);
13990
13991         spec->num_mux_defs = 1;
13992         spec->input_mux = &spec->private_imux[0];
13993
13994         spec->adc_nids = alc861_adc_nids;
13995         spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
13996         set_capture_mixer(spec);
13997
13998         return 1;
13999 }
14000
14001 /* additional initialization for auto-configuration model */
14002 static void alc861_auto_init(struct hda_codec *codec)
14003 {
14004         struct alc_spec *spec = codec->spec;
14005         alc861_auto_init_multi_out(codec);
14006         alc861_auto_init_hp_out(codec);
14007         alc861_auto_init_analog_input(codec);
14008         if (spec->unsol_event)
14009                 alc_inithook(codec);
14010 }
14011
14012 #ifdef CONFIG_SND_HDA_POWER_SAVE
14013 static struct hda_amp_list alc861_loopbacks[] = {
14014         { 0x15, HDA_INPUT, 0 },
14015         { 0x15, HDA_INPUT, 1 },
14016         { 0x15, HDA_INPUT, 2 },
14017         { 0x15, HDA_INPUT, 3 },
14018         { } /* end */
14019 };
14020 #endif
14021
14022
14023 /*
14024  * configuration and preset
14025  */
14026 static const char *alc861_models[ALC861_MODEL_LAST] = {
14027         [ALC861_3ST]            = "3stack",
14028         [ALC660_3ST]            = "3stack-660",
14029         [ALC861_3ST_DIG]        = "3stack-dig",
14030         [ALC861_6ST_DIG]        = "6stack-dig",
14031         [ALC861_UNIWILL_M31]    = "uniwill-m31",
14032         [ALC861_TOSHIBA]        = "toshiba",
14033         [ALC861_ASUS]           = "asus",
14034         [ALC861_ASUS_LAPTOP]    = "asus-laptop",
14035         [ALC861_AUTO]           = "auto",
14036 };
14037
14038 static struct snd_pci_quirk alc861_cfg_tbl[] = {
14039         SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC861_3ST),
14040         SND_PCI_QUIRK(0x1043, 0x1335, "ASUS F2/3", ALC861_ASUS_LAPTOP),
14041         SND_PCI_QUIRK(0x1043, 0x1338, "ASUS F2/3", ALC861_ASUS_LAPTOP),
14042         SND_PCI_QUIRK(0x1043, 0x1393, "ASUS", ALC861_ASUS),
14043         SND_PCI_QUIRK(0x1043, 0x13d7, "ASUS A9rp", ALC861_ASUS_LAPTOP),
14044         SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS P1-AH2", ALC861_3ST_DIG),
14045         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba", ALC861_TOSHIBA),
14046         /* FIXME: the entry below breaks Toshiba A100 (model=auto works!)
14047          *        Any other models that need this preset?
14048          */
14049         /* SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba", ALC861_TOSHIBA), */
14050         SND_PCI_QUIRK(0x1462, 0x7254, "HP dx2200 (MSI MS-7254)", ALC861_3ST),
14051         SND_PCI_QUIRK(0x1462, 0x7297, "HP dx2250 (MSI MS-7297)", ALC861_3ST),
14052         SND_PCI_QUIRK(0x1584, 0x2b01, "Uniwill X40AIx", ALC861_UNIWILL_M31),
14053         SND_PCI_QUIRK(0x1584, 0x9072, "Uniwill m31", ALC861_UNIWILL_M31),
14054         SND_PCI_QUIRK(0x1584, 0x9075, "Airis Praxis N1212", ALC861_ASUS_LAPTOP),
14055         /* FIXME: the below seems conflict */
14056         /* SND_PCI_QUIRK(0x1584, 0x9075, "Uniwill", ALC861_UNIWILL_M31), */
14057         SND_PCI_QUIRK(0x1849, 0x0660, "Asrock 939SLI32", ALC660_3ST),
14058         SND_PCI_QUIRK(0x8086, 0xd600, "Intel", ALC861_3ST),
14059         {}
14060 };
14061
14062 static struct alc_config_preset alc861_presets[] = {
14063         [ALC861_3ST] = {
14064                 .mixers = { alc861_3ST_mixer },
14065                 .init_verbs = { alc861_threestack_init_verbs },
14066                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14067                 .dac_nids = alc861_dac_nids,
14068                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
14069                 .channel_mode = alc861_threestack_modes,
14070                 .need_dac_fix = 1,
14071                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14072                 .adc_nids = alc861_adc_nids,
14073                 .input_mux = &alc861_capture_source,
14074         },
14075         [ALC861_3ST_DIG] = {
14076                 .mixers = { alc861_base_mixer },
14077                 .init_verbs = { alc861_threestack_init_verbs },
14078                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14079                 .dac_nids = alc861_dac_nids,
14080                 .dig_out_nid = ALC861_DIGOUT_NID,
14081                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
14082                 .channel_mode = alc861_threestack_modes,
14083                 .need_dac_fix = 1,
14084                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14085                 .adc_nids = alc861_adc_nids,
14086                 .input_mux = &alc861_capture_source,
14087         },
14088         [ALC861_6ST_DIG] = {
14089                 .mixers = { alc861_base_mixer },
14090                 .init_verbs = { alc861_base_init_verbs },
14091                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14092                 .dac_nids = alc861_dac_nids,
14093                 .dig_out_nid = ALC861_DIGOUT_NID,
14094                 .num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
14095                 .channel_mode = alc861_8ch_modes,
14096                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14097                 .adc_nids = alc861_adc_nids,
14098                 .input_mux = &alc861_capture_source,
14099         },
14100         [ALC660_3ST] = {
14101                 .mixers = { alc861_3ST_mixer },
14102                 .init_verbs = { alc861_threestack_init_verbs },
14103                 .num_dacs = ARRAY_SIZE(alc660_dac_nids),
14104                 .dac_nids = alc660_dac_nids,
14105                 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
14106                 .channel_mode = alc861_threestack_modes,
14107                 .need_dac_fix = 1,
14108                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14109                 .adc_nids = alc861_adc_nids,
14110                 .input_mux = &alc861_capture_source,
14111         },
14112         [ALC861_UNIWILL_M31] = {
14113                 .mixers = { alc861_uniwill_m31_mixer },
14114                 .init_verbs = { alc861_uniwill_m31_init_verbs },
14115                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14116                 .dac_nids = alc861_dac_nids,
14117                 .dig_out_nid = ALC861_DIGOUT_NID,
14118                 .num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
14119                 .channel_mode = alc861_uniwill_m31_modes,
14120                 .need_dac_fix = 1,
14121                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14122                 .adc_nids = alc861_adc_nids,
14123                 .input_mux = &alc861_capture_source,
14124         },
14125         [ALC861_TOSHIBA] = {
14126                 .mixers = { alc861_toshiba_mixer },
14127                 .init_verbs = { alc861_base_init_verbs,
14128                                 alc861_toshiba_init_verbs },
14129                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14130                 .dac_nids = alc861_dac_nids,
14131                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
14132                 .channel_mode = alc883_3ST_2ch_modes,
14133                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14134                 .adc_nids = alc861_adc_nids,
14135                 .input_mux = &alc861_capture_source,
14136                 .unsol_event = alc861_toshiba_unsol_event,
14137                 .init_hook = alc861_toshiba_automute,
14138         },
14139         [ALC861_ASUS] = {
14140                 .mixers = { alc861_asus_mixer },
14141                 .init_verbs = { alc861_asus_init_verbs },
14142                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14143                 .dac_nids = alc861_dac_nids,
14144                 .dig_out_nid = ALC861_DIGOUT_NID,
14145                 .num_channel_mode = ARRAY_SIZE(alc861_asus_modes),
14146                 .channel_mode = alc861_asus_modes,
14147                 .need_dac_fix = 1,
14148                 .hp_nid = 0x06,
14149                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14150                 .adc_nids = alc861_adc_nids,
14151                 .input_mux = &alc861_capture_source,
14152         },
14153         [ALC861_ASUS_LAPTOP] = {
14154                 .mixers = { alc861_toshiba_mixer, alc861_asus_laptop_mixer },
14155                 .init_verbs = { alc861_asus_init_verbs,
14156                                 alc861_asus_laptop_init_verbs },
14157                 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
14158                 .dac_nids = alc861_dac_nids,
14159                 .dig_out_nid = ALC861_DIGOUT_NID,
14160                 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
14161                 .channel_mode = alc883_3ST_2ch_modes,
14162                 .need_dac_fix = 1,
14163                 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
14164                 .adc_nids = alc861_adc_nids,
14165                 .input_mux = &alc861_capture_source,
14166         },
14167 };
14168
14169
14170 static int patch_alc861(struct hda_codec *codec)
14171 {
14172         struct alc_spec *spec;
14173         int board_config;
14174         int err;
14175
14176         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
14177         if (spec == NULL)
14178                 return -ENOMEM;
14179
14180         codec->spec = spec;
14181
14182         board_config = snd_hda_check_board_config(codec, ALC861_MODEL_LAST,
14183                                                   alc861_models,
14184                                                   alc861_cfg_tbl);
14185
14186         if (board_config < 0) {
14187                 printk(KERN_INFO "hda_codec: Unknown model for ALC861, "
14188                        "trying auto-probe from BIOS...\n");
14189                 board_config = ALC861_AUTO;
14190         }
14191
14192         if (board_config == ALC861_AUTO) {
14193                 /* automatic parse from the BIOS config */
14194                 err = alc861_parse_auto_config(codec);
14195                 if (err < 0) {
14196                         alc_free(codec);
14197                         return err;
14198                 } else if (!err) {
14199                         printk(KERN_INFO
14200                                "hda_codec: Cannot set up configuration "
14201                                "from BIOS.  Using base mode...\n");
14202                    board_config = ALC861_3ST_DIG;
14203                 }
14204         }
14205
14206         err = snd_hda_attach_beep_device(codec, 0x23);
14207         if (err < 0) {
14208                 alc_free(codec);
14209                 return err;
14210         }
14211
14212         if (board_config != ALC861_AUTO)
14213                 setup_preset(spec, &alc861_presets[board_config]);
14214
14215         spec->stream_name_analog = "ALC861 Analog";
14216         spec->stream_analog_playback = &alc861_pcm_analog_playback;
14217         spec->stream_analog_capture = &alc861_pcm_analog_capture;
14218
14219         spec->stream_name_digital = "ALC861 Digital";
14220         spec->stream_digital_playback = &alc861_pcm_digital_playback;
14221         spec->stream_digital_capture = &alc861_pcm_digital_capture;
14222
14223         set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
14224
14225         spec->vmaster_nid = 0x03;
14226
14227         codec->patch_ops = alc_patch_ops;
14228         if (board_config == ALC861_AUTO)
14229                 spec->init_hook = alc861_auto_init;
14230 #ifdef CONFIG_SND_HDA_POWER_SAVE
14231         if (!spec->loopback.amplist)
14232                 spec->loopback.amplist = alc861_loopbacks;
14233 #endif
14234         codec->proc_widget_hook = print_realtek_coef;
14235
14236         return 0;
14237 }
14238
14239 /*
14240  * ALC861-VD support
14241  *
14242  * Based on ALC882
14243  *
14244  * In addition, an independent DAC
14245  */
14246 #define ALC861VD_DIGOUT_NID     0x06
14247
14248 static hda_nid_t alc861vd_dac_nids[4] = {
14249         /* front, surr, clfe, side surr */
14250         0x02, 0x03, 0x04, 0x05
14251 };
14252
14253 /* dac_nids for ALC660vd are in a different order - according to
14254  * Realtek's driver.
14255  * This should probably tesult in a different mixer for 6stack models
14256  * of ALC660vd codecs, but for now there is only 3stack mixer
14257  * - and it is the same as in 861vd.
14258  * adc_nids in ALC660vd are (is) the same as in 861vd
14259  */
14260 static hda_nid_t alc660vd_dac_nids[3] = {
14261         /* front, rear, clfe, rear_surr */
14262         0x02, 0x04, 0x03
14263 };
14264
14265 static hda_nid_t alc861vd_adc_nids[1] = {
14266         /* ADC0 */
14267         0x09,
14268 };
14269
14270 static hda_nid_t alc861vd_capsrc_nids[1] = { 0x22 };
14271
14272 /* input MUX */
14273 /* FIXME: should be a matrix-type input source selection */
14274 static struct hda_input_mux alc861vd_capture_source = {
14275         .num_items = 4,
14276         .items = {
14277                 { "Mic", 0x0 },
14278                 { "Front Mic", 0x1 },
14279                 { "Line", 0x2 },
14280                 { "CD", 0x4 },
14281         },
14282 };
14283
14284 static struct hda_input_mux alc861vd_dallas_capture_source = {
14285         .num_items = 2,
14286         .items = {
14287                 { "Ext Mic", 0x0 },
14288                 { "Int Mic", 0x1 },
14289         },
14290 };
14291
14292 static struct hda_input_mux alc861vd_hp_capture_source = {
14293         .num_items = 2,
14294         .items = {
14295                 { "Front Mic", 0x0 },
14296                 { "ATAPI Mic", 0x1 },
14297         },
14298 };
14299
14300 /*
14301  * 2ch mode
14302  */
14303 static struct hda_channel_mode alc861vd_3stack_2ch_modes[1] = {
14304         { 2, NULL }
14305 };
14306
14307 /*
14308  * 6ch mode
14309  */
14310 static struct hda_verb alc861vd_6stack_ch6_init[] = {
14311         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
14312         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14313         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14314         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14315         { } /* end */
14316 };
14317
14318 /*
14319  * 8ch mode
14320  */
14321 static struct hda_verb alc861vd_6stack_ch8_init[] = {
14322         { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14323         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14324         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14325         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
14326         { } /* end */
14327 };
14328
14329 static struct hda_channel_mode alc861vd_6stack_modes[2] = {
14330         { 6, alc861vd_6stack_ch6_init },
14331         { 8, alc861vd_6stack_ch8_init },
14332 };
14333
14334 static struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
14335         {
14336                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
14337                 .name = "Channel Mode",
14338                 .info = alc_ch_mode_info,
14339                 .get = alc_ch_mode_get,
14340                 .put = alc_ch_mode_put,
14341         },
14342         { } /* end */
14343 };
14344
14345 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
14346  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
14347  */
14348 static struct snd_kcontrol_new alc861vd_6st_mixer[] = {
14349         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14350         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14351
14352         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14353         HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
14354
14355         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0,
14356                                 HDA_OUTPUT),
14357         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0,
14358                                 HDA_OUTPUT),
14359         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
14360         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
14361
14362         HDA_CODEC_VOLUME("Side Playback Volume", 0x05, 0x0, HDA_OUTPUT),
14363         HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
14364
14365         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14366
14367         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
14368         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14369         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14370
14371         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
14372         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14373         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14374
14375         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14376         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14377
14378         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14379         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14380
14381         { } /* end */
14382 };
14383
14384 static struct snd_kcontrol_new alc861vd_3st_mixer[] = {
14385         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14386         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14387
14388         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14389
14390         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
14391         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14392         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14393
14394         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
14395         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14396         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14397
14398         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
14399         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
14400
14401         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14402         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14403
14404         { } /* end */
14405 };
14406
14407 static struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
14408         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14409         /*HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),*/
14410         HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
14411
14412         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
14413
14414         HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
14415         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14416         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14417
14418         HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
14419         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14420         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14421
14422         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14423         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14424
14425         { } /* end */
14426 };
14427
14428 /* Pin assignment: Speaker=0x14, HP = 0x15,
14429  *                 Ext Mic=0x18, Int Mic = 0x19, CD = 0x1c, PC Beep = 0x1d
14430  */
14431 static struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
14432         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14433         HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
14434         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14435         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
14436         HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
14437         HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14438         HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14439         HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
14440         HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14441         HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14442         { } /* end */
14443 };
14444
14445 /* Pin assignment: Speaker=0x14, Line-out = 0x15,
14446  *                 Front Mic=0x18, ATAPI Mic = 0x19,
14447  */
14448 static struct snd_kcontrol_new alc861vd_hp_mixer[] = {
14449         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
14450         HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
14451         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
14452         HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
14453         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
14454         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14455         HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14456         HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14457
14458         { } /* end */
14459 };
14460
14461 /*
14462  * generic initialization of ADC, input mixers and output mixers
14463  */
14464 static struct hda_verb alc861vd_volume_init_verbs[] = {
14465         /*
14466          * Unmute ADC0 and set the default input to mic-in
14467          */
14468         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
14469         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14470
14471         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of
14472          * the analog-loopback mixer widget
14473          */
14474         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
14475         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14476         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14477         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14478         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14479         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14480
14481         /* Capture mixer: unmute Mic, F-Mic, Line, CD inputs */
14482         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14483         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14484         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
14485         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
14486
14487         /*
14488          * Set up output mixers (0x02 - 0x05)
14489          */
14490         /* set vol=0 to output mixers */
14491         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14492         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14493         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14494         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14495
14496         /* set up input amps for analog loopback */
14497         /* Amp Indices: DAC = 0, mixer = 1 */
14498         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14499         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14500         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14501         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14502         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14503         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14504         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14505         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14506
14507         { }
14508 };
14509
14510 /*
14511  * 3-stack pin configuration:
14512  * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
14513  */
14514 static struct hda_verb alc861vd_3stack_init_verbs[] = {
14515         /*
14516          * Set pin mode and muting
14517          */
14518         /* set front pin widgets 0x14 for output */
14519         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14520         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14521         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
14522
14523         /* Mic (rear) pin: input vref at 80% */
14524         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14525         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14526         /* Front Mic pin: input vref at 80% */
14527         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14528         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14529         /* Line In pin: input */
14530         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14531         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14532         /* Line-2 In: Headphone output (output 0 - 0x0c) */
14533         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14534         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14535         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
14536         /* CD pin widget for input */
14537         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14538
14539         { }
14540 };
14541
14542 /*
14543  * 6-stack pin configuration:
14544  */
14545 static struct hda_verb alc861vd_6stack_init_verbs[] = {
14546         /*
14547          * Set pin mode and muting
14548          */
14549         /* set front pin widgets 0x14 for output */
14550         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14551         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14552         {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
14553
14554         /* Rear Pin: output 1 (0x0d) */
14555         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14556         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14557         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
14558         /* CLFE Pin: output 2 (0x0e) */
14559         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14560         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14561         {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
14562         /* Side Pin: output 3 (0x0f) */
14563         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14564         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14565         {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
14566
14567         /* Mic (rear) pin: input vref at 80% */
14568         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14569         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14570         /* Front Mic pin: input vref at 80% */
14571         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
14572         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14573         /* Line In pin: input */
14574         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14575         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14576         /* Line-2 In: Headphone output (output 0 - 0x0c) */
14577         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
14578         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14579         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
14580         /* CD pin widget for input */
14581         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14582
14583         { }
14584 };
14585
14586 static struct hda_verb alc861vd_eapd_verbs[] = {
14587         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
14588         { }
14589 };
14590
14591 static struct hda_verb alc660vd_eapd_verbs[] = {
14592         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
14593         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
14594         { }
14595 };
14596
14597 static struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
14598         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14599         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14600         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
14601         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14602         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
14603         {}
14604 };
14605
14606 /* toggle speaker-output according to the hp-jack state */
14607 static void alc861vd_lenovo_hp_automute(struct hda_codec *codec)
14608 {
14609         unsigned int present;
14610         unsigned char bits;
14611
14612         present = snd_hda_codec_read(codec, 0x1b, 0,
14613                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14614         bits = present ? HDA_AMP_MUTE : 0;
14615         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
14616                                  HDA_AMP_MUTE, bits);
14617 }
14618
14619 static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
14620 {
14621         unsigned int present;
14622         unsigned char bits;
14623
14624         present = snd_hda_codec_read(codec, 0x18, 0,
14625                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14626         bits = present ? HDA_AMP_MUTE : 0;
14627         snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
14628                                  HDA_AMP_MUTE, bits);
14629 }
14630
14631 static void alc861vd_lenovo_automute(struct hda_codec *codec)
14632 {
14633         alc861vd_lenovo_hp_automute(codec);
14634         alc861vd_lenovo_mic_automute(codec);
14635 }
14636
14637 static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
14638                                         unsigned int res)
14639 {
14640         switch (res >> 26) {
14641         case ALC880_HP_EVENT:
14642                 alc861vd_lenovo_hp_automute(codec);
14643                 break;
14644         case ALC880_MIC_EVENT:
14645                 alc861vd_lenovo_mic_automute(codec);
14646                 break;
14647         }
14648 }
14649
14650 static struct hda_verb alc861vd_dallas_verbs[] = {
14651         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14652         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14653         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14654         {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
14655
14656         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14657         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
14658         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14659         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14660         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14661         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14662         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14663         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
14664
14665         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14666         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14667         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14668         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14669         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14670         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14671         {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
14672         {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
14673
14674         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
14675         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14676         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
14677         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
14678         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14679         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14680         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14681         {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
14682
14683         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
14684         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
14685         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
14686         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
14687
14688         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
14689         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
14690         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
14691
14692         { } /* end */
14693 };
14694
14695 /* toggle speaker-output according to the hp-jack state */
14696 static void alc861vd_dallas_automute(struct hda_codec *codec)
14697 {
14698         unsigned int present;
14699
14700         present = snd_hda_codec_read(codec, 0x15, 0,
14701                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14702         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
14703                                  HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
14704 }
14705
14706 static void alc861vd_dallas_unsol_event(struct hda_codec *codec, unsigned int res)
14707 {
14708         if ((res >> 26) == ALC880_HP_EVENT)
14709                 alc861vd_dallas_automute(codec);
14710 }
14711
14712 #ifdef CONFIG_SND_HDA_POWER_SAVE
14713 #define alc861vd_loopbacks      alc880_loopbacks
14714 #endif
14715
14716 /* pcm configuration: identiacal with ALC880 */
14717 #define alc861vd_pcm_analog_playback    alc880_pcm_analog_playback
14718 #define alc861vd_pcm_analog_capture     alc880_pcm_analog_capture
14719 #define alc861vd_pcm_digital_playback   alc880_pcm_digital_playback
14720 #define alc861vd_pcm_digital_capture    alc880_pcm_digital_capture
14721
14722 /*
14723  * configuration and preset
14724  */
14725 static const char *alc861vd_models[ALC861VD_MODEL_LAST] = {
14726         [ALC660VD_3ST]          = "3stack-660",
14727         [ALC660VD_3ST_DIG]      = "3stack-660-digout",
14728         [ALC660VD_ASUS_V1S]     = "asus-v1s",
14729         [ALC861VD_3ST]          = "3stack",
14730         [ALC861VD_3ST_DIG]      = "3stack-digout",
14731         [ALC861VD_6ST_DIG]      = "6stack-digout",
14732         [ALC861VD_LENOVO]       = "lenovo",
14733         [ALC861VD_DALLAS]       = "dallas",
14734         [ALC861VD_HP]           = "hp",
14735         [ALC861VD_AUTO]         = "auto",
14736 };
14737
14738 static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
14739         SND_PCI_QUIRK(0x1019, 0xa88d, "Realtek ALC660 demo", ALC660VD_3ST),
14740         SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_HP),
14741         SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST),
14742         SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),
14743         SND_PCI_QUIRK(0x1043, 0x1633, "Asus V1Sn", ALC660VD_ASUS_V1S),
14744         SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG),
14745         SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
14746         SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
14747         /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
14748         SND_PCI_QUIRK(0x1179, 0xff01, "DALLAS", ALC861VD_DALLAS),
14749         SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
14750         SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_DALLAS),
14751         SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
14752         SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", ALC861VD_LENOVO),
14753         SND_PCI_QUIRK(0x1849, 0x0862, "ASRock K8NF6G-VSTA", ALC861VD_6ST_DIG),
14754         {}
14755 };
14756
14757 static struct alc_config_preset alc861vd_presets[] = {
14758         [ALC660VD_3ST] = {
14759                 .mixers = { alc861vd_3st_mixer },
14760                 .init_verbs = { alc861vd_volume_init_verbs,
14761                                  alc861vd_3stack_init_verbs },
14762                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14763                 .dac_nids = alc660vd_dac_nids,
14764                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14765                 .channel_mode = alc861vd_3stack_2ch_modes,
14766                 .input_mux = &alc861vd_capture_source,
14767         },
14768         [ALC660VD_3ST_DIG] = {
14769                 .mixers = { alc861vd_3st_mixer },
14770                 .init_verbs = { alc861vd_volume_init_verbs,
14771                                  alc861vd_3stack_init_verbs },
14772                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14773                 .dac_nids = alc660vd_dac_nids,
14774                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14775                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14776                 .channel_mode = alc861vd_3stack_2ch_modes,
14777                 .input_mux = &alc861vd_capture_source,
14778         },
14779         [ALC861VD_3ST] = {
14780                 .mixers = { alc861vd_3st_mixer },
14781                 .init_verbs = { alc861vd_volume_init_verbs,
14782                                  alc861vd_3stack_init_verbs },
14783                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14784                 .dac_nids = alc861vd_dac_nids,
14785                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14786                 .channel_mode = alc861vd_3stack_2ch_modes,
14787                 .input_mux = &alc861vd_capture_source,
14788         },
14789         [ALC861VD_3ST_DIG] = {
14790                 .mixers = { alc861vd_3st_mixer },
14791                 .init_verbs = { alc861vd_volume_init_verbs,
14792                                  alc861vd_3stack_init_verbs },
14793                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14794                 .dac_nids = alc861vd_dac_nids,
14795                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14796                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14797                 .channel_mode = alc861vd_3stack_2ch_modes,
14798                 .input_mux = &alc861vd_capture_source,
14799         },
14800         [ALC861VD_6ST_DIG] = {
14801                 .mixers = { alc861vd_6st_mixer, alc861vd_chmode_mixer },
14802                 .init_verbs = { alc861vd_volume_init_verbs,
14803                                 alc861vd_6stack_init_verbs },
14804                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14805                 .dac_nids = alc861vd_dac_nids,
14806                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14807                 .num_channel_mode = ARRAY_SIZE(alc861vd_6stack_modes),
14808                 .channel_mode = alc861vd_6stack_modes,
14809                 .input_mux = &alc861vd_capture_source,
14810         },
14811         [ALC861VD_LENOVO] = {
14812                 .mixers = { alc861vd_lenovo_mixer },
14813                 .init_verbs = { alc861vd_volume_init_verbs,
14814                                 alc861vd_3stack_init_verbs,
14815                                 alc861vd_eapd_verbs,
14816                                 alc861vd_lenovo_unsol_verbs },
14817                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14818                 .dac_nids = alc660vd_dac_nids,
14819                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14820                 .channel_mode = alc861vd_3stack_2ch_modes,
14821                 .input_mux = &alc861vd_capture_source,
14822                 .unsol_event = alc861vd_lenovo_unsol_event,
14823                 .init_hook = alc861vd_lenovo_automute,
14824         },
14825         [ALC861VD_DALLAS] = {
14826                 .mixers = { alc861vd_dallas_mixer },
14827                 .init_verbs = { alc861vd_dallas_verbs },
14828                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14829                 .dac_nids = alc861vd_dac_nids,
14830                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14831                 .channel_mode = alc861vd_3stack_2ch_modes,
14832                 .input_mux = &alc861vd_dallas_capture_source,
14833                 .unsol_event = alc861vd_dallas_unsol_event,
14834                 .init_hook = alc861vd_dallas_automute,
14835         },
14836         [ALC861VD_HP] = {
14837                 .mixers = { alc861vd_hp_mixer },
14838                 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs },
14839                 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
14840                 .dac_nids = alc861vd_dac_nids,
14841                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14842                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14843                 .channel_mode = alc861vd_3stack_2ch_modes,
14844                 .input_mux = &alc861vd_hp_capture_source,
14845                 .unsol_event = alc861vd_dallas_unsol_event,
14846                 .init_hook = alc861vd_dallas_automute,
14847         },
14848         [ALC660VD_ASUS_V1S] = {
14849                 .mixers = { alc861vd_lenovo_mixer },
14850                 .init_verbs = { alc861vd_volume_init_verbs,
14851                                 alc861vd_3stack_init_verbs,
14852                                 alc861vd_eapd_verbs,
14853                                 alc861vd_lenovo_unsol_verbs },
14854                 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
14855                 .dac_nids = alc660vd_dac_nids,
14856                 .dig_out_nid = ALC861VD_DIGOUT_NID,
14857                 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
14858                 .channel_mode = alc861vd_3stack_2ch_modes,
14859                 .input_mux = &alc861vd_capture_source,
14860                 .unsol_event = alc861vd_lenovo_unsol_event,
14861                 .init_hook = alc861vd_lenovo_automute,
14862         },
14863 };
14864
14865 /*
14866  * BIOS auto configuration
14867  */
14868 static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
14869                                 hda_nid_t nid, int pin_type, int dac_idx)
14870 {
14871         alc_set_pin_output(codec, nid, pin_type);
14872 }
14873
14874 static void alc861vd_auto_init_multi_out(struct hda_codec *codec)
14875 {
14876         struct alc_spec *spec = codec->spec;
14877         int i;
14878
14879         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
14880         for (i = 0; i <= HDA_SIDE; i++) {
14881                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
14882                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
14883                 if (nid)
14884                         alc861vd_auto_set_output_and_unmute(codec, nid,
14885                                                             pin_type, i);
14886         }
14887 }
14888
14889
14890 static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
14891 {
14892         struct alc_spec *spec = codec->spec;
14893         hda_nid_t pin;
14894
14895         pin = spec->autocfg.hp_pins[0];
14896         if (pin) /* connect to front and  use dac 0 */
14897                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
14898         pin = spec->autocfg.speaker_pins[0];
14899         if (pin)
14900                 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
14901 }
14902
14903 #define alc861vd_is_input_pin(nid)      alc880_is_input_pin(nid)
14904 #define ALC861VD_PIN_CD_NID             ALC880_PIN_CD_NID
14905
14906 static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
14907 {
14908         struct alc_spec *spec = codec->spec;
14909         int i;
14910
14911         for (i = 0; i < AUTO_PIN_LAST; i++) {
14912                 hda_nid_t nid = spec->autocfg.input_pins[i];
14913                 if (alc861vd_is_input_pin(nid)) {
14914                         alc_set_input_pin(codec, nid, i);
14915                         if (nid != ALC861VD_PIN_CD_NID &&
14916                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
14917                                 snd_hda_codec_write(codec, nid, 0,
14918                                                 AC_VERB_SET_AMP_GAIN_MUTE,
14919                                                 AMP_OUT_MUTE);
14920                 }
14921         }
14922 }
14923
14924 #define alc861vd_auto_init_input_src    alc882_auto_init_input_src
14925
14926 #define alc861vd_idx_to_mixer_vol(nid)          ((nid) + 0x02)
14927 #define alc861vd_idx_to_mixer_switch(nid)       ((nid) + 0x0c)
14928
14929 /* add playback controls from the parsed DAC table */
14930 /* Based on ALC880 version. But ALC861VD has separate,
14931  * different NIDs for mute/unmute switch and volume control */
14932 static int alc861vd_auto_create_multi_out_ctls(struct alc_spec *spec,
14933                                              const struct auto_pin_cfg *cfg)
14934 {
14935         char name[32];
14936         static const char *chname[4] = {"Front", "Surround", "CLFE", "Side"};
14937         hda_nid_t nid_v, nid_s;
14938         int i, err;
14939
14940         for (i = 0; i < cfg->line_outs; i++) {
14941                 if (!spec->multiout.dac_nids[i])
14942                         continue;
14943                 nid_v = alc861vd_idx_to_mixer_vol(
14944                                 alc880_dac_to_idx(
14945                                         spec->multiout.dac_nids[i]));
14946                 nid_s = alc861vd_idx_to_mixer_switch(
14947                                 alc880_dac_to_idx(
14948                                         spec->multiout.dac_nids[i]));
14949
14950                 if (i == 2) {
14951                         /* Center/LFE */
14952                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
14953                                           "Center Playback Volume",
14954                                           HDA_COMPOSE_AMP_VAL(nid_v, 1, 0,
14955                                                               HDA_OUTPUT));
14956                         if (err < 0)
14957                                 return err;
14958                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
14959                                           "LFE Playback Volume",
14960                                           HDA_COMPOSE_AMP_VAL(nid_v, 2, 0,
14961                                                               HDA_OUTPUT));
14962                         if (err < 0)
14963                                 return err;
14964                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14965                                           "Center Playback Switch",
14966                                           HDA_COMPOSE_AMP_VAL(nid_s, 1, 2,
14967                                                               HDA_INPUT));
14968                         if (err < 0)
14969                                 return err;
14970                         err = add_control(spec, ALC_CTL_BIND_MUTE,
14971                                           "LFE Playback Switch",
14972                                           HDA_COMPOSE_AMP_VAL(nid_s, 2, 2,
14973                                                               HDA_INPUT));
14974                         if (err < 0)
14975                                 return err;
14976                 } else {
14977                         sprintf(name, "%s Playback Volume", chname[i]);
14978                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
14979                                           HDA_COMPOSE_AMP_VAL(nid_v, 3, 0,
14980                                                               HDA_OUTPUT));
14981                         if (err < 0)
14982                                 return err;
14983                         sprintf(name, "%s Playback Switch", chname[i]);
14984                         err = add_control(spec, ALC_CTL_BIND_MUTE, name,
14985                                           HDA_COMPOSE_AMP_VAL(nid_s, 3, 2,
14986                                                               HDA_INPUT));
14987                         if (err < 0)
14988                                 return err;
14989                 }
14990         }
14991         return 0;
14992 }
14993
14994 /* add playback controls for speaker and HP outputs */
14995 /* Based on ALC880 version. But ALC861VD has separate,
14996  * different NIDs for mute/unmute switch and volume control */
14997 static int alc861vd_auto_create_extra_out(struct alc_spec *spec,
14998                                         hda_nid_t pin, const char *pfx)
14999 {
15000         hda_nid_t nid_v, nid_s;
15001         int err;
15002         char name[32];
15003
15004         if (!pin)
15005                 return 0;
15006
15007         if (alc880_is_fixed_pin(pin)) {
15008                 nid_v = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
15009                 /* specify the DAC as the extra output */
15010                 if (!spec->multiout.hp_nid)
15011                         spec->multiout.hp_nid = nid_v;
15012                 else
15013                         spec->multiout.extra_out_nid[0] = nid_v;
15014                 /* control HP volume/switch on the output mixer amp */
15015                 nid_v = alc861vd_idx_to_mixer_vol(
15016                                 alc880_fixed_pin_idx(pin));
15017                 nid_s = alc861vd_idx_to_mixer_switch(
15018                                 alc880_fixed_pin_idx(pin));
15019
15020                 sprintf(name, "%s Playback Volume", pfx);
15021                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
15022                                   HDA_COMPOSE_AMP_VAL(nid_v, 3, 0, HDA_OUTPUT));
15023                 if (err < 0)
15024                         return err;
15025                 sprintf(name, "%s Playback Switch", pfx);
15026                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
15027                                   HDA_COMPOSE_AMP_VAL(nid_s, 3, 2, HDA_INPUT));
15028                 if (err < 0)
15029                         return err;
15030         } else if (alc880_is_multi_pin(pin)) {
15031                 /* set manual connection */
15032                 /* we have only a switch on HP-out PIN */
15033                 sprintf(name, "%s Playback Switch", pfx);
15034                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
15035                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
15036                 if (err < 0)
15037                         return err;
15038         }
15039         return 0;
15040 }
15041
15042 /* parse the BIOS configuration and set up the alc_spec
15043  * return 1 if successful, 0 if the proper config is not found,
15044  * or a negative error code
15045  * Based on ALC880 version - had to change it to override
15046  * alc880_auto_create_extra_out and alc880_auto_create_multi_out_ctls */
15047 static int alc861vd_parse_auto_config(struct hda_codec *codec)
15048 {
15049         struct alc_spec *spec = codec->spec;
15050         int err;
15051         static hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
15052
15053         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
15054                                            alc861vd_ignore);
15055         if (err < 0)
15056                 return err;
15057         if (!spec->autocfg.line_outs)
15058                 return 0; /* can't find valid BIOS pin config */
15059
15060         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
15061         if (err < 0)
15062                 return err;
15063         err = alc861vd_auto_create_multi_out_ctls(spec, &spec->autocfg);
15064         if (err < 0)
15065                 return err;
15066         err = alc861vd_auto_create_extra_out(spec,
15067                                              spec->autocfg.speaker_pins[0],
15068                                              "Speaker");
15069         if (err < 0)
15070                 return err;
15071         err = alc861vd_auto_create_extra_out(spec,
15072                                              spec->autocfg.hp_pins[0],
15073                                              "Headphone");
15074         if (err < 0)
15075                 return err;
15076         err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg);
15077         if (err < 0)
15078                 return err;
15079
15080         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
15081
15082         if (spec->autocfg.dig_outs)
15083                 spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID;
15084
15085         if (spec->kctls.list)
15086                 add_mixer(spec, spec->kctls.list);
15087
15088         add_verb(spec, alc861vd_volume_init_verbs);
15089
15090         spec->num_mux_defs = 1;
15091         spec->input_mux = &spec->private_imux[0];
15092
15093         err = alc_auto_add_mic_boost(codec);
15094         if (err < 0)
15095                 return err;
15096
15097         return 1;
15098 }
15099
15100 /* additional initialization for auto-configuration model */
15101 static void alc861vd_auto_init(struct hda_codec *codec)
15102 {
15103         struct alc_spec *spec = codec->spec;
15104         alc861vd_auto_init_multi_out(codec);
15105         alc861vd_auto_init_hp_out(codec);
15106         alc861vd_auto_init_analog_input(codec);
15107         alc861vd_auto_init_input_src(codec);
15108         if (spec->unsol_event)
15109                 alc_inithook(codec);
15110 }
15111
15112 static int patch_alc861vd(struct hda_codec *codec)
15113 {
15114         struct alc_spec *spec;
15115         int err, board_config;
15116
15117         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
15118         if (spec == NULL)
15119                 return -ENOMEM;
15120
15121         codec->spec = spec;
15122
15123         board_config = snd_hda_check_board_config(codec, ALC861VD_MODEL_LAST,
15124                                                   alc861vd_models,
15125                                                   alc861vd_cfg_tbl);
15126
15127         if (board_config < 0 || board_config >= ALC861VD_MODEL_LAST) {
15128                 printk(KERN_INFO "hda_codec: Unknown model for ALC660VD/"
15129                         "ALC861VD, trying auto-probe from BIOS...\n");
15130                 board_config = ALC861VD_AUTO;
15131         }
15132
15133         if (board_config == ALC861VD_AUTO) {
15134                 /* automatic parse from the BIOS config */
15135                 err = alc861vd_parse_auto_config(codec);
15136                 if (err < 0) {
15137                         alc_free(codec);
15138                         return err;
15139                 } else if (!err) {
15140                         printk(KERN_INFO
15141                                "hda_codec: Cannot set up configuration "
15142                                "from BIOS.  Using base mode...\n");
15143                         board_config = ALC861VD_3ST;
15144                 }
15145         }
15146
15147         err = snd_hda_attach_beep_device(codec, 0x23);
15148         if (err < 0) {
15149                 alc_free(codec);
15150                 return err;
15151         }
15152
15153         if (board_config != ALC861VD_AUTO)
15154                 setup_preset(spec, &alc861vd_presets[board_config]);
15155
15156         if (codec->vendor_id == 0x10ec0660) {
15157                 spec->stream_name_analog = "ALC660-VD Analog";
15158                 spec->stream_name_digital = "ALC660-VD Digital";
15159                 /* always turn on EAPD */
15160                 add_verb(spec, alc660vd_eapd_verbs);
15161         } else {
15162                 spec->stream_name_analog = "ALC861VD Analog";
15163                 spec->stream_name_digital = "ALC861VD Digital";
15164         }
15165
15166         spec->stream_analog_playback = &alc861vd_pcm_analog_playback;
15167         spec->stream_analog_capture = &alc861vd_pcm_analog_capture;
15168
15169         spec->stream_digital_playback = &alc861vd_pcm_digital_playback;
15170         spec->stream_digital_capture = &alc861vd_pcm_digital_capture;
15171
15172         spec->adc_nids = alc861vd_adc_nids;
15173         spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
15174         spec->capsrc_nids = alc861vd_capsrc_nids;
15175         spec->capture_style = CAPT_MIX;
15176
15177         set_capture_mixer(spec);
15178         set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
15179
15180         spec->vmaster_nid = 0x02;
15181
15182         codec->patch_ops = alc_patch_ops;
15183
15184         if (board_config == ALC861VD_AUTO)
15185                 spec->init_hook = alc861vd_auto_init;
15186 #ifdef CONFIG_SND_HDA_POWER_SAVE
15187         if (!spec->loopback.amplist)
15188                 spec->loopback.amplist = alc861vd_loopbacks;
15189 #endif
15190         codec->proc_widget_hook = print_realtek_coef;
15191
15192         return 0;
15193 }
15194
15195 /*
15196  * ALC662 support
15197  *
15198  * ALC662 is almost identical with ALC880 but has cleaner and more flexible
15199  * configuration.  Each pin widget can choose any input DACs and a mixer.
15200  * Each ADC is connected from a mixer of all inputs.  This makes possible
15201  * 6-channel independent captures.
15202  *
15203  * In addition, an independent DAC for the multi-playback (not used in this
15204  * driver yet).
15205  */
15206 #define ALC662_DIGOUT_NID       0x06
15207 #define ALC662_DIGIN_NID        0x0a
15208
15209 static hda_nid_t alc662_dac_nids[4] = {
15210         /* front, rear, clfe, rear_surr */
15211         0x02, 0x03, 0x04
15212 };
15213
15214 static hda_nid_t alc662_adc_nids[1] = {
15215         /* ADC1-2 */
15216         0x09,
15217 };
15218
15219 static hda_nid_t alc662_capsrc_nids[1] = { 0x22 };
15220
15221 /* input MUX */
15222 /* FIXME: should be a matrix-type input source selection */
15223 static struct hda_input_mux alc662_capture_source = {
15224         .num_items = 4,
15225         .items = {
15226                 { "Mic", 0x0 },
15227                 { "Front Mic", 0x1 },
15228                 { "Line", 0x2 },
15229                 { "CD", 0x4 },
15230         },
15231 };
15232
15233 static struct hda_input_mux alc662_lenovo_101e_capture_source = {
15234         .num_items = 2,
15235         .items = {
15236                 { "Mic", 0x1 },
15237                 { "Line", 0x2 },
15238         },
15239 };
15240
15241 static struct hda_input_mux alc662_eeepc_capture_source = {
15242         .num_items = 2,
15243         .items = {
15244                 { "i-Mic", 0x1 },
15245                 { "e-Mic", 0x0 },
15246         },
15247 };
15248
15249 static struct hda_input_mux alc663_capture_source = {
15250         .num_items = 3,
15251         .items = {
15252                 { "Mic", 0x0 },
15253                 { "Front Mic", 0x1 },
15254                 { "Line", 0x2 },
15255         },
15256 };
15257
15258 static struct hda_input_mux alc663_m51va_capture_source = {
15259         .num_items = 2,
15260         .items = {
15261                 { "Ext-Mic", 0x0 },
15262                 { "D-Mic", 0x9 },
15263         },
15264 };
15265
15266 /*
15267  * 2ch mode
15268  */
15269 static struct hda_channel_mode alc662_3ST_2ch_modes[1] = {
15270         { 2, NULL }
15271 };
15272
15273 /*
15274  * 2ch mode
15275  */
15276 static struct hda_verb alc662_3ST_ch2_init[] = {
15277         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
15278         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
15279         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
15280         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
15281         { } /* end */
15282 };
15283
15284 /*
15285  * 6ch mode
15286  */
15287 static struct hda_verb alc662_3ST_ch6_init[] = {
15288         { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15289         { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
15290         { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
15291         { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15292         { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
15293         { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
15294         { } /* end */
15295 };
15296
15297 static struct hda_channel_mode alc662_3ST_6ch_modes[2] = {
15298         { 2, alc662_3ST_ch2_init },
15299         { 6, alc662_3ST_ch6_init },
15300 };
15301
15302 /*
15303  * 2ch mode
15304  */
15305 static struct hda_verb alc662_sixstack_ch6_init[] = {
15306         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
15307         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
15308         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15309         { } /* end */
15310 };
15311
15312 /*
15313  * 6ch mode
15314  */
15315 static struct hda_verb alc662_sixstack_ch8_init[] = {
15316         { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15317         { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15318         { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
15319         { } /* end */
15320 };
15321
15322 static struct hda_channel_mode alc662_5stack_modes[2] = {
15323         { 2, alc662_sixstack_ch6_init },
15324         { 6, alc662_sixstack_ch8_init },
15325 };
15326
15327 /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
15328  *                 Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
15329  */
15330
15331 static struct snd_kcontrol_new alc662_base_mixer[] = {
15332         /* output mixer control */
15333         HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
15334         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
15335         HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
15336         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
15337         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15338         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15339         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
15340         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
15341         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15342
15343         /*Input mixer control */
15344         HDA_CODEC_VOLUME("CD Playback Volume", 0xb, 0x4, HDA_INPUT),
15345         HDA_CODEC_MUTE("CD Playback Switch", 0xb, 0x4, HDA_INPUT),
15346         HDA_CODEC_VOLUME("Line Playback Volume", 0xb, 0x02, HDA_INPUT),
15347         HDA_CODEC_MUTE("Line Playback Switch", 0xb, 0x02, HDA_INPUT),
15348         HDA_CODEC_VOLUME("Mic Playback Volume", 0xb, 0x0, HDA_INPUT),
15349         HDA_CODEC_MUTE("Mic Playback Switch", 0xb, 0x0, HDA_INPUT),
15350         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0xb, 0x01, HDA_INPUT),
15351         HDA_CODEC_MUTE("Front Mic Playback Switch", 0xb, 0x01, HDA_INPUT),
15352         { } /* end */
15353 };
15354
15355 static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
15356         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15357         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
15358         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15359         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
15360         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
15361         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15362         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15363         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15364         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15365         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15366         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15367         { } /* end */
15368 };
15369
15370 static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
15371         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15372         HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
15373         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15374         HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
15375         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15376         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15377         HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
15378         HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
15379         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15380         HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
15381         HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
15382         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15383         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15384         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15385         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15386         HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15387         HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15388         { } /* end */
15389 };
15390
15391 static struct snd_kcontrol_new alc662_lenovo_101e_mixer[] = {
15392         HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15393         HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
15394         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15395         HDA_BIND_MUTE("Speaker Playback Switch", 0x03, 2, HDA_INPUT),
15396         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15397         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15398         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15399         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15400         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15401         { } /* end */
15402 };
15403
15404 static struct snd_kcontrol_new alc662_eeepc_p701_mixer[] = {
15405         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15406
15407         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15408         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15409
15410         HDA_CODEC_VOLUME("e-Mic Boost", 0x18, 0, HDA_INPUT),
15411         HDA_CODEC_VOLUME("e-Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15412         HDA_CODEC_MUTE("e-Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15413
15414         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
15415         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15416         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15417         { } /* end */
15418 };
15419
15420 static struct snd_kcontrol_new alc662_eeepc_ep20_mixer[] = {
15421         HDA_CODEC_VOLUME("Line-Out Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15422         HDA_CODEC_MUTE("Line-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15423         HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15424         HDA_BIND_MUTE("Surround Playback Switch", 0x03, 2, HDA_INPUT),
15425         HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
15426         HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
15427         HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT),
15428         HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT),
15429         HDA_CODEC_MUTE("Speaker Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15430         HDA_BIND_MUTE("MuteCtrl Playback Switch", 0x0c, 2, HDA_INPUT),
15431         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15432         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15433         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15434         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15435         { } /* end */
15436 };
15437
15438 static struct hda_bind_ctls alc663_asus_bind_master_vol = {
15439         .ops = &snd_hda_bind_vol,
15440         .values = {
15441                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
15442                 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
15443                 0
15444         },
15445 };
15446
15447 static struct hda_bind_ctls alc663_asus_one_bind_switch = {
15448         .ops = &snd_hda_bind_sw,
15449         .values = {
15450                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15451                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
15452                 0
15453         },
15454 };
15455
15456 static struct snd_kcontrol_new alc663_m51va_mixer[] = {
15457         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15458         HDA_BIND_SW("Master Playback Switch", &alc663_asus_one_bind_switch),
15459         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15460         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15461         { } /* end */
15462 };
15463
15464 static struct hda_bind_ctls alc663_asus_tree_bind_switch = {
15465         .ops = &snd_hda_bind_sw,
15466         .values = {
15467                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15468                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
15469                 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
15470                 0
15471         },
15472 };
15473
15474 static struct snd_kcontrol_new alc663_two_hp_m1_mixer[] = {
15475         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15476         HDA_BIND_SW("Master Playback Switch", &alc663_asus_tree_bind_switch),
15477         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15478         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15479         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15480         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15481
15482         { } /* end */
15483 };
15484
15485 static struct hda_bind_ctls alc663_asus_four_bind_switch = {
15486         .ops = &snd_hda_bind_sw,
15487         .values = {
15488                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15489                 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
15490                 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
15491                 0
15492         },
15493 };
15494
15495 static struct snd_kcontrol_new alc663_two_hp_m2_mixer[] = {
15496         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15497         HDA_BIND_SW("Master Playback Switch", &alc663_asus_four_bind_switch),
15498         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15499         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15500         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15501         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15502         { } /* end */
15503 };
15504
15505 static struct snd_kcontrol_new alc662_1bjd_mixer[] = {
15506         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15507         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15508         HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
15509         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15510         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15511         HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15512         HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15513         { } /* end */
15514 };
15515
15516 static struct hda_bind_ctls alc663_asus_two_bind_master_vol = {
15517         .ops = &snd_hda_bind_vol,
15518         .values = {
15519                 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
15520                 HDA_COMPOSE_AMP_VAL(0x04, 3, 0, HDA_OUTPUT),
15521                 0
15522         },
15523 };
15524
15525 static struct hda_bind_ctls alc663_asus_two_bind_switch = {
15526         .ops = &snd_hda_bind_sw,
15527         .values = {
15528                 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
15529                 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT),
15530                 0
15531         },
15532 };
15533
15534 static struct snd_kcontrol_new alc663_asus_21jd_clfe_mixer[] = {
15535         HDA_BIND_VOL("Master Playback Volume",
15536                                 &alc663_asus_two_bind_master_vol),
15537         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
15538         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15539         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
15540         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15541         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15542         { } /* end */
15543 };
15544
15545 static struct snd_kcontrol_new alc663_asus_15jd_clfe_mixer[] = {
15546         HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
15547         HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
15548         HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15549         HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
15550         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15551         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15552         { } /* end */
15553 };
15554
15555 static struct snd_kcontrol_new alc663_g71v_mixer[] = {
15556         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15557         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15558         HDA_CODEC_VOLUME("Front Playback Volume", 0x03, 0x0, HDA_OUTPUT),
15559         HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
15560         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
15561
15562         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15563         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15564         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15565         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15566         { } /* end */
15567 };
15568
15569 static struct snd_kcontrol_new alc663_g50v_mixer[] = {
15570         HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
15571         HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
15572         HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
15573
15574         HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
15575         HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15576         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15577         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15578         HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
15579         HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
15580         { } /* end */
15581 };
15582
15583 static struct snd_kcontrol_new alc662_chmode_mixer[] = {
15584         {
15585                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
15586                 .name = "Channel Mode",
15587                 .info = alc_ch_mode_info,
15588                 .get = alc_ch_mode_get,
15589                 .put = alc_ch_mode_put,
15590         },
15591         { } /* end */
15592 };
15593
15594 static struct hda_verb alc662_init_verbs[] = {
15595         /* ADC: mute amp left and right */
15596         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15597         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
15598         /* Front mixer: unmute input/output amp left and right (volume = 0) */
15599
15600         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15601         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15602         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
15603         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
15604         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
15605
15606         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15607         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15608         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15609         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15610         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15611         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15612
15613         /* Front Pin: output 0 (0x0c) */
15614         {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15615         {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15616
15617         /* Rear Pin: output 1 (0x0d) */
15618         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15619         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15620
15621         /* CLFE Pin: output 2 (0x0e) */
15622         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15623         {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15624
15625         /* Mic (rear) pin: input vref at 80% */
15626         {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
15627         {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15628         /* Front Mic pin: input vref at 80% */
15629         {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
15630         {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15631         /* Line In pin: input */
15632         {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15633         {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
15634         /* Line-2 In: Headphone output (output 0 - 0x0c) */
15635         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15636         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15637         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
15638         /* CD pin widget for input */
15639         {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15640
15641         /* FIXME: use matrix-type input source selection */
15642         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
15643         /* Input mixer */
15644         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15645         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15646         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
15647         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
15648
15649         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15650         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15651         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
15652         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
15653
15654         /* always trun on EAPD */
15655         {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
15656         {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
15657
15658         { }
15659 };
15660
15661 static struct hda_verb alc662_sue_init_verbs[] = {
15662         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
15663         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
15664         {}
15665 };
15666
15667 static struct hda_verb alc662_eeepc_sue_init_verbs[] = {
15668         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15669         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15670         {}
15671 };
15672
15673 /* Set Unsolicited Event*/
15674 static struct hda_verb alc662_eeepc_ep20_sue_init_verbs[] = {
15675         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
15676         {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15677         {}
15678 };
15679
15680 /*
15681  * generic initialization of ADC, input mixers and output mixers
15682  */
15683 static struct hda_verb alc662_auto_init_verbs[] = {
15684         /*
15685          * Unmute ADC and set the default input to mic-in
15686          */
15687         {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
15688         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15689
15690         /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
15691          * mixer widget
15692          * Note: PASD motherboards uses the Line In 2 as the input for front
15693          * panel mic (mic 2)
15694          */
15695         /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
15696         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15697         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
15698         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
15699         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
15700         {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
15701
15702         /*
15703          * Set up output mixers (0x0c - 0x0f)
15704          */
15705         /* set vol=0 to output mixers */
15706         {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15707         {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15708         {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
15709
15710         /* set up input amps for analog loopback */
15711         /* Amp Indices: DAC = 0, mixer = 1 */
15712         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15713         {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15714         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15715         {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15716         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15717         {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15718
15719
15720         /* FIXME: use matrix-type input source selection */
15721         /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
15722         /* Input mixer */
15723         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15724         {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15725         { }
15726 };
15727
15728 /* additional verbs for ALC663 */
15729 static struct hda_verb alc663_auto_init_verbs[] = {
15730         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
15731         {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15732         { }
15733 };
15734
15735 static struct hda_verb alc663_m51va_init_verbs[] = {
15736         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15737         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15738         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15739         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15740         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15741         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15742         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
15743         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15744         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15745         {}
15746 };
15747
15748 static struct hda_verb alc663_21jd_amic_init_verbs[] = {
15749         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15750         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15751         {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15752         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15753         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15754         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15755         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15756         {}
15757 };
15758
15759 static struct hda_verb alc662_1bjd_amic_init_verbs[] = {
15760         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15761         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15762         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15763         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
15764         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15765         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15766         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15767         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15768         {}
15769 };
15770
15771 static struct hda_verb alc663_15jd_amic_init_verbs[] = {
15772         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15773         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15774         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15775         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15776         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15777         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15778         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15779         {}
15780 };
15781
15782 static struct hda_verb alc663_two_hp_amic_m1_init_verbs[] = {
15783         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15784         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15785         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15786         {0x21, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
15787         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15788         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15789         {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},   /* Headphone */
15790         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15791         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15792         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15793         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15794         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15795         {}
15796 };
15797
15798 static struct hda_verb alc663_two_hp_amic_m2_init_verbs[] = {
15799         {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
15800         {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15801         {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15802         {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15803         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15804         {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15805         {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},  /* Headphone */
15806         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15807         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
15808         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15809         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15810         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15811         {}
15812 };
15813
15814 static struct hda_verb alc663_g71v_init_verbs[] = {
15815         {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15816         /* {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
15817         /* {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, */ /* Headphone */
15818
15819         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15820         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15821         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
15822
15823         {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_FRONT_EVENT},
15824         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_MIC_EVENT},
15825         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
15826         {}
15827 };
15828
15829 static struct hda_verb alc663_g50v_init_verbs[] = {
15830         {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
15831         {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
15832         {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},  /* Headphone */
15833
15834         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15835         {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15836         {}
15837 };
15838
15839 static struct hda_verb alc662_ecs_init_verbs[] = {
15840         {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0x701f},
15841         {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
15842         {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_MIC_EVENT},
15843         {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
15844         {}
15845 };
15846
15847 static struct snd_kcontrol_new alc662_auto_capture_mixer[] = {
15848         HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
15849         HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
15850         { } /* end */
15851 };
15852
15853 static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
15854 {
15855         unsigned int present;
15856         unsigned char bits;
15857
15858         present = snd_hda_codec_read(codec, 0x14, 0,
15859                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15860         bits = present ? HDA_AMP_MUTE : 0;
15861         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
15862                                  HDA_AMP_MUTE, bits);
15863 }
15864
15865 static void alc662_lenovo_101e_all_automute(struct hda_codec *codec)
15866 {
15867         unsigned int present;
15868         unsigned char bits;
15869
15870         present = snd_hda_codec_read(codec, 0x1b, 0,
15871                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15872         bits = present ? HDA_AMP_MUTE : 0;
15873         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
15874                                  HDA_AMP_MUTE, bits);
15875         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
15876                                  HDA_AMP_MUTE, bits);
15877 }
15878
15879 static void alc662_lenovo_101e_unsol_event(struct hda_codec *codec,
15880                                            unsigned int res)
15881 {
15882         if ((res >> 26) == ALC880_HP_EVENT)
15883                 alc662_lenovo_101e_all_automute(codec);
15884         if ((res >> 26) == ALC880_FRONT_EVENT)
15885                 alc662_lenovo_101e_ispeaker_automute(codec);
15886 }
15887
15888 static void alc662_eeepc_mic_automute(struct hda_codec *codec)
15889 {
15890         unsigned int present;
15891
15892         present = snd_hda_codec_read(codec, 0x18, 0,
15893                                      AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15894         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15895                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15896         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15897                             0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
15898         snd_hda_codec_write(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15899                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
15900         snd_hda_codec_write(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
15901                             0x7000 | (0x01 << 8) | (present ? 0x80 : 0));
15902 }
15903
15904 /* unsolicited event for HP jack sensing */
15905 static void alc662_eeepc_unsol_event(struct hda_codec *codec,
15906                                      unsigned int res)
15907 {
15908         if ((res >> 26) == ALC880_HP_EVENT)
15909                 alc262_hippo1_automute( codec );
15910
15911         if ((res >> 26) == ALC880_MIC_EVENT)
15912                 alc662_eeepc_mic_automute(codec);
15913 }
15914
15915 static void alc662_eeepc_inithook(struct hda_codec *codec)
15916 {
15917         alc262_hippo1_automute( codec );
15918         alc662_eeepc_mic_automute(codec);
15919 }
15920
15921 static void alc662_eeepc_ep20_automute(struct hda_codec *codec)
15922 {
15923         unsigned int mute;
15924         unsigned int present;
15925
15926         snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
15927         present = snd_hda_codec_read(codec, 0x14, 0,
15928                                      AC_VERB_GET_PIN_SENSE, 0);
15929         present = (present & 0x80000000) != 0;
15930         if (present) {
15931                 /* mute internal speaker */
15932                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
15933                                         HDA_AMP_MUTE, HDA_AMP_MUTE);
15934         } else {
15935                 /* unmute internal speaker if necessary */
15936                 mute = snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0);
15937                 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
15938                                         HDA_AMP_MUTE, mute);
15939         }
15940 }
15941
15942 /* unsolicited event for HP jack sensing */
15943 static void alc662_eeepc_ep20_unsol_event(struct hda_codec *codec,
15944                                           unsigned int res)
15945 {
15946         if ((res >> 26) == ALC880_HP_EVENT)
15947                 alc662_eeepc_ep20_automute(codec);
15948 }
15949
15950 static void alc662_eeepc_ep20_inithook(struct hda_codec *codec)
15951 {
15952         alc662_eeepc_ep20_automute(codec);
15953 }
15954
15955 static void alc663_m51va_speaker_automute(struct hda_codec *codec)
15956 {
15957         unsigned int present;
15958         unsigned char bits;
15959
15960         present = snd_hda_codec_read(codec, 0x21, 0,
15961                         AC_VERB_GET_PIN_SENSE, 0)
15962                         & AC_PINSENSE_PRESENCE;
15963         bits = present ? HDA_AMP_MUTE : 0;
15964         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15965                                 AMP_IN_MUTE(0), bits);
15966         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15967                                 AMP_IN_MUTE(0), bits);
15968 }
15969
15970 static void alc663_21jd_two_speaker_automute(struct hda_codec *codec)
15971 {
15972         unsigned int present;
15973         unsigned char bits;
15974
15975         present = snd_hda_codec_read(codec, 0x21, 0,
15976                         AC_VERB_GET_PIN_SENSE, 0)
15977                         & AC_PINSENSE_PRESENCE;
15978         bits = present ? HDA_AMP_MUTE : 0;
15979         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15980                                 AMP_IN_MUTE(0), bits);
15981         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
15982                                 AMP_IN_MUTE(0), bits);
15983         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
15984                                 AMP_IN_MUTE(0), bits);
15985         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
15986                                 AMP_IN_MUTE(0), bits);
15987 }
15988
15989 static void alc663_15jd_two_speaker_automute(struct hda_codec *codec)
15990 {
15991         unsigned int present;
15992         unsigned char bits;
15993
15994         present = snd_hda_codec_read(codec, 0x15, 0,
15995                         AC_VERB_GET_PIN_SENSE, 0)
15996                         & AC_PINSENSE_PRESENCE;
15997         bits = present ? HDA_AMP_MUTE : 0;
15998         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
15999                                 AMP_IN_MUTE(0), bits);
16000         snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16001                                 AMP_IN_MUTE(0), bits);
16002         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 0,
16003                                 AMP_IN_MUTE(0), bits);
16004         snd_hda_codec_amp_stereo(codec, 0x0e, HDA_INPUT, 1,
16005                                 AMP_IN_MUTE(0), bits);
16006 }
16007
16008 static void alc662_f5z_speaker_automute(struct hda_codec *codec)
16009 {
16010         unsigned int present;
16011         unsigned char bits;
16012
16013         present = snd_hda_codec_read(codec, 0x1b, 0,
16014                         AC_VERB_GET_PIN_SENSE, 0)
16015                         & AC_PINSENSE_PRESENCE;
16016         bits = present ? 0 : PIN_OUT;
16017         snd_hda_codec_write(codec, 0x14, 0,
16018                          AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
16019 }
16020
16021 static void alc663_two_hp_m1_speaker_automute(struct hda_codec *codec)
16022 {
16023         unsigned int present1, present2;
16024
16025         present1 = snd_hda_codec_read(codec, 0x21, 0,
16026                         AC_VERB_GET_PIN_SENSE, 0)
16027                         & AC_PINSENSE_PRESENCE;
16028         present2 = snd_hda_codec_read(codec, 0x15, 0,
16029                         AC_VERB_GET_PIN_SENSE, 0)
16030                         & AC_PINSENSE_PRESENCE;
16031
16032         if (present1 || present2) {
16033                 snd_hda_codec_write_cache(codec, 0x14, 0,
16034                         AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
16035         } else {
16036                 snd_hda_codec_write_cache(codec, 0x14, 0,
16037                         AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
16038         }
16039 }
16040
16041 static void alc663_two_hp_m2_speaker_automute(struct hda_codec *codec)
16042 {
16043         unsigned int present1, present2;
16044
16045         present1 = snd_hda_codec_read(codec, 0x1b, 0,
16046                                 AC_VERB_GET_PIN_SENSE, 0)
16047                                 & AC_PINSENSE_PRESENCE;
16048         present2 = snd_hda_codec_read(codec, 0x15, 0,
16049                                 AC_VERB_GET_PIN_SENSE, 0)
16050                                 & AC_PINSENSE_PRESENCE;
16051
16052         if (present1 || present2) {
16053                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16054                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
16055                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16056                                 AMP_IN_MUTE(0), AMP_IN_MUTE(0));
16057         } else {
16058                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16059                                 AMP_IN_MUTE(0), 0);
16060                 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
16061                                 AMP_IN_MUTE(0), 0);
16062         }
16063 }
16064
16065 static void alc663_m51va_mic_automute(struct hda_codec *codec)
16066 {
16067         unsigned int present;
16068
16069         present = snd_hda_codec_read(codec, 0x18, 0,
16070                         AC_VERB_GET_PIN_SENSE, 0)
16071                         & AC_PINSENSE_PRESENCE;
16072         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16073                         0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
16074         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16075                         0x7000 | (0x00 << 8) | (present ? 0 : 0x80));
16076         snd_hda_codec_write_cache(codec, 0x22, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16077                         0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
16078         snd_hda_codec_write_cache(codec, 0x23, 0, AC_VERB_SET_AMP_GAIN_MUTE,
16079                         0x7000 | (0x09 << 8) | (present ? 0x80 : 0));
16080 }
16081
16082 static void alc663_m51va_unsol_event(struct hda_codec *codec,
16083                                            unsigned int res)
16084 {
16085         switch (res >> 26) {
16086         case ALC880_HP_EVENT:
16087                 alc663_m51va_speaker_automute(codec);
16088                 break;
16089         case ALC880_MIC_EVENT:
16090                 alc663_m51va_mic_automute(codec);
16091                 break;
16092         }
16093 }
16094
16095 static void alc663_m51va_inithook(struct hda_codec *codec)
16096 {
16097         alc663_m51va_speaker_automute(codec);
16098         alc663_m51va_mic_automute(codec);
16099 }
16100
16101 /* ***************** Mode1 ******************************/
16102 static void alc663_mode1_unsol_event(struct hda_codec *codec,
16103                                            unsigned int res)
16104 {
16105         switch (res >> 26) {
16106         case ALC880_HP_EVENT:
16107                 alc663_m51va_speaker_automute(codec);
16108                 break;
16109         case ALC880_MIC_EVENT:
16110                 alc662_eeepc_mic_automute(codec);
16111                 break;
16112         }
16113 }
16114
16115 static void alc663_mode1_inithook(struct hda_codec *codec)
16116 {
16117         alc663_m51va_speaker_automute(codec);
16118         alc662_eeepc_mic_automute(codec);
16119 }
16120 /* ***************** Mode2 ******************************/
16121 static void alc662_mode2_unsol_event(struct hda_codec *codec,
16122                                            unsigned int res)
16123 {
16124         switch (res >> 26) {
16125         case ALC880_HP_EVENT:
16126                 alc662_f5z_speaker_automute(codec);
16127                 break;
16128         case ALC880_MIC_EVENT:
16129                 alc662_eeepc_mic_automute(codec);
16130                 break;
16131         }
16132 }
16133
16134 static void alc662_mode2_inithook(struct hda_codec *codec)
16135 {
16136         alc662_f5z_speaker_automute(codec);
16137         alc662_eeepc_mic_automute(codec);
16138 }
16139 /* ***************** Mode3 ******************************/
16140 static void alc663_mode3_unsol_event(struct hda_codec *codec,
16141                                            unsigned int res)
16142 {
16143         switch (res >> 26) {
16144         case ALC880_HP_EVENT:
16145                 alc663_two_hp_m1_speaker_automute(codec);
16146                 break;
16147         case ALC880_MIC_EVENT:
16148                 alc662_eeepc_mic_automute(codec);
16149                 break;
16150         }
16151 }
16152
16153 static void alc663_mode3_inithook(struct hda_codec *codec)
16154 {
16155         alc663_two_hp_m1_speaker_automute(codec);
16156         alc662_eeepc_mic_automute(codec);
16157 }
16158 /* ***************** Mode4 ******************************/
16159 static void alc663_mode4_unsol_event(struct hda_codec *codec,
16160                                            unsigned int res)
16161 {
16162         switch (res >> 26) {
16163         case ALC880_HP_EVENT:
16164                 alc663_21jd_two_speaker_automute(codec);
16165                 break;
16166         case ALC880_MIC_EVENT:
16167                 alc662_eeepc_mic_automute(codec);
16168                 break;
16169         }
16170 }
16171
16172 static void alc663_mode4_inithook(struct hda_codec *codec)
16173 {
16174         alc663_21jd_two_speaker_automute(codec);
16175         alc662_eeepc_mic_automute(codec);
16176 }
16177 /* ***************** Mode5 ******************************/
16178 static void alc663_mode5_unsol_event(struct hda_codec *codec,
16179                                            unsigned int res)
16180 {
16181         switch (res >> 26) {
16182         case ALC880_HP_EVENT:
16183                 alc663_15jd_two_speaker_automute(codec);
16184                 break;
16185         case ALC880_MIC_EVENT:
16186                 alc662_eeepc_mic_automute(codec);
16187                 break;
16188         }
16189 }
16190
16191 static void alc663_mode5_inithook(struct hda_codec *codec)
16192 {
16193         alc663_15jd_two_speaker_automute(codec);
16194         alc662_eeepc_mic_automute(codec);
16195 }
16196 /* ***************** Mode6 ******************************/
16197 static void alc663_mode6_unsol_event(struct hda_codec *codec,
16198                                            unsigned int res)
16199 {
16200         switch (res >> 26) {
16201         case ALC880_HP_EVENT:
16202                 alc663_two_hp_m2_speaker_automute(codec);
16203                 break;
16204         case ALC880_MIC_EVENT:
16205                 alc662_eeepc_mic_automute(codec);
16206                 break;
16207         }
16208 }
16209
16210 static void alc663_mode6_inithook(struct hda_codec *codec)
16211 {
16212         alc663_two_hp_m2_speaker_automute(codec);
16213         alc662_eeepc_mic_automute(codec);
16214 }
16215
16216 static void alc663_g71v_hp_automute(struct hda_codec *codec)
16217 {
16218         unsigned int present;
16219         unsigned char bits;
16220
16221         present = snd_hda_codec_read(codec, 0x21, 0,
16222                                      AC_VERB_GET_PIN_SENSE, 0)
16223                 & AC_PINSENSE_PRESENCE;
16224         bits = present ? HDA_AMP_MUTE : 0;
16225         snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
16226                                  HDA_AMP_MUTE, bits);
16227         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
16228                                  HDA_AMP_MUTE, bits);
16229 }
16230
16231 static void alc663_g71v_front_automute(struct hda_codec *codec)
16232 {
16233         unsigned int present;
16234         unsigned char bits;
16235
16236         present = snd_hda_codec_read(codec, 0x15, 0,
16237                                      AC_VERB_GET_PIN_SENSE, 0)
16238                 & AC_PINSENSE_PRESENCE;
16239         bits = present ? HDA_AMP_MUTE : 0;
16240         snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
16241                                  HDA_AMP_MUTE, bits);
16242 }
16243
16244 static void alc663_g71v_unsol_event(struct hda_codec *codec,
16245                                            unsigned int res)
16246 {
16247         switch (res >> 26) {
16248         case ALC880_HP_EVENT:
16249                 alc663_g71v_hp_automute(codec);
16250                 break;
16251         case ALC880_FRONT_EVENT:
16252                 alc663_g71v_front_automute(codec);
16253                 break;
16254         case ALC880_MIC_EVENT:
16255                 alc662_eeepc_mic_automute(codec);
16256                 break;
16257         }
16258 }
16259
16260 static void alc663_g71v_inithook(struct hda_codec *codec)
16261 {
16262         alc663_g71v_front_automute(codec);
16263         alc663_g71v_hp_automute(codec);
16264         alc662_eeepc_mic_automute(codec);
16265 }
16266
16267 static void alc663_g50v_unsol_event(struct hda_codec *codec,
16268                                            unsigned int res)
16269 {
16270         switch (res >> 26) {
16271         case ALC880_HP_EVENT:
16272                 alc663_m51va_speaker_automute(codec);
16273                 break;
16274         case ALC880_MIC_EVENT:
16275                 alc662_eeepc_mic_automute(codec);
16276                 break;
16277         }
16278 }
16279
16280 static void alc663_g50v_inithook(struct hda_codec *codec)
16281 {
16282         alc663_m51va_speaker_automute(codec);
16283         alc662_eeepc_mic_automute(codec);
16284 }
16285
16286 /* bind hp and internal speaker mute (with plug check) */
16287 static int alc662_ecs_master_sw_put(struct snd_kcontrol *kcontrol,
16288                                      struct snd_ctl_elem_value *ucontrol)
16289 {
16290         struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
16291         long *valp = ucontrol->value.integer.value;
16292         int change;
16293
16294         change = snd_hda_codec_amp_update(codec, 0x1b, 0, HDA_OUTPUT, 0,
16295                                           HDA_AMP_MUTE,
16296                                           valp[0] ? 0 : HDA_AMP_MUTE);
16297         change |= snd_hda_codec_amp_update(codec, 0x1b, 1, HDA_OUTPUT, 0,
16298                                            HDA_AMP_MUTE,
16299                                            valp[1] ? 0 : HDA_AMP_MUTE);
16300         if (change)
16301                 alc262_hippo1_automute(codec);
16302         return change;
16303 }
16304
16305 static struct snd_kcontrol_new alc662_ecs_mixer[] = {
16306         HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
16307         {
16308                 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
16309                 .name = "Master Playback Switch",
16310                 .info = snd_hda_mixer_amp_switch_info,
16311                 .get = snd_hda_mixer_amp_switch_get,
16312                 .put = alc662_ecs_master_sw_put,
16313                 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
16314         },
16315
16316         HDA_CODEC_VOLUME("e-Mic/LineIn Boost", 0x18, 0, HDA_INPUT),
16317         HDA_CODEC_VOLUME("e-Mic/LineIn Playback Volume", 0x0b, 0x0, HDA_INPUT),
16318         HDA_CODEC_MUTE("e-Mic/LineIn Playback Switch", 0x0b, 0x0, HDA_INPUT),
16319
16320         HDA_CODEC_VOLUME("i-Mic Boost", 0x19, 0, HDA_INPUT),
16321         HDA_CODEC_VOLUME("i-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
16322         HDA_CODEC_MUTE("i-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
16323         { } /* end */
16324 };
16325
16326 #ifdef CONFIG_SND_HDA_POWER_SAVE
16327 #define alc662_loopbacks        alc880_loopbacks
16328 #endif
16329
16330
16331 /* pcm configuration: identiacal with ALC880 */
16332 #define alc662_pcm_analog_playback      alc880_pcm_analog_playback
16333 #define alc662_pcm_analog_capture       alc880_pcm_analog_capture
16334 #define alc662_pcm_digital_playback     alc880_pcm_digital_playback
16335 #define alc662_pcm_digital_capture      alc880_pcm_digital_capture
16336
16337 /*
16338  * configuration and preset
16339  */
16340 static const char *alc662_models[ALC662_MODEL_LAST] = {
16341         [ALC662_3ST_2ch_DIG]    = "3stack-dig",
16342         [ALC662_3ST_6ch_DIG]    = "3stack-6ch-dig",
16343         [ALC662_3ST_6ch]        = "3stack-6ch",
16344         [ALC662_5ST_DIG]        = "6stack-dig",
16345         [ALC662_LENOVO_101E]    = "lenovo-101e",
16346         [ALC662_ASUS_EEEPC_P701] = "eeepc-p701",
16347         [ALC662_ASUS_EEEPC_EP20] = "eeepc-ep20",
16348         [ALC662_ECS] = "ecs",
16349         [ALC663_ASUS_M51VA] = "m51va",
16350         [ALC663_ASUS_G71V] = "g71v",
16351         [ALC663_ASUS_H13] = "h13",
16352         [ALC663_ASUS_G50V] = "g50v",
16353         [ALC663_ASUS_MODE1] = "asus-mode1",
16354         [ALC662_ASUS_MODE2] = "asus-mode2",
16355         [ALC663_ASUS_MODE3] = "asus-mode3",
16356         [ALC663_ASUS_MODE4] = "asus-mode4",
16357         [ALC663_ASUS_MODE5] = "asus-mode5",
16358         [ALC663_ASUS_MODE6] = "asus-mode6",
16359         [ALC662_AUTO]           = "auto",
16360 };
16361
16362 static struct snd_pci_quirk alc662_cfg_tbl[] = {
16363         SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_ECS),
16364         SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC663_ASUS_MODE1),
16365         SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC663_ASUS_MODE3),
16366         SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC663_ASUS_MODE3),
16367         SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC663_ASUS_MODE1),
16368         SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_ASUS_MODE2),
16369         SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC663_ASUS_MODE1),
16370         SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_ASUS_MODE2),
16371         SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_ASUS_MODE2),
16372         SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_ASUS_MODE2),
16373         SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC663_ASUS_MODE6),
16374         SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC663_ASUS_MODE6),
16375         SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_ASUS_MODE2),
16376         SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_ASUS_MODE2),
16377         SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC663_ASUS_MODE5),
16378         SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC663_ASUS_MODE6),
16379         SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_ASUS_MODE2),
16380         SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_ASUS_MODE2),
16381         SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_ASUS_MODE2),
16382         SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M51VA", ALC663_ASUS_M51VA),
16383         /*SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M50Vr", ALC663_ASUS_MODE1),*/
16384         SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC663_ASUS_MODE3),
16385         SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC663_ASUS_MODE3),
16386         SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC663_ASUS_MODE1),
16387         SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_ASUS_MODE2),
16388         SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_ASUS_MODE2),
16389         SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC663_ASUS_MODE1),
16390         SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC663_ASUS_MODE3),
16391         SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC663_ASUS_MODE1),
16392         SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS G50V", ALC663_ASUS_G50V),
16393         /*SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS NB", ALC663_ASUS_MODE1),*/
16394         SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC663_ASUS_MODE1),
16395         SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_ASUS_MODE2),
16396         SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC663_ASUS_MODE1),
16397         SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC663_ASUS_MODE4),
16398         SND_PCI_QUIRK(0x1043, 0x8290, "ASUS P5GC-MX", ALC662_3ST_6ch_DIG),
16399         SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
16400         SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20),
16401         SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_ECS),
16402         SND_PCI_QUIRK(0x105b, 0x0d47, "Foxconn 45CMX/45GMX/45CMX-K",
16403                       ALC662_3ST_6ch_DIG),
16404         SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte 945GCM-S2L",
16405                       ALC662_3ST_6ch_DIG),
16406         SND_PCI_QUIRK(0x1565, 0x820f, "Biostar TA780G M2+", ALC662_3ST_6ch_DIG),
16407         SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
16408         SND_PCI_QUIRK(0x1849, 0x3662, "ASROCK K10N78FullHD-hSLI R3.0",
16409                                         ALC662_3ST_6ch_DIG),
16410         SND_PCI_QUIRK_MASK(0x1854, 0xf000, 0x2000, "ASUS H13-200x",
16411                            ALC663_ASUS_H13),
16412         {}
16413 };
16414
16415 static struct alc_config_preset alc662_presets[] = {
16416         [ALC662_3ST_2ch_DIG] = {
16417                 .mixers = { alc662_3ST_2ch_mixer },
16418                 .init_verbs = { alc662_init_verbs },
16419                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16420                 .dac_nids = alc662_dac_nids,
16421                 .dig_out_nid = ALC662_DIGOUT_NID,
16422                 .dig_in_nid = ALC662_DIGIN_NID,
16423                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16424                 .channel_mode = alc662_3ST_2ch_modes,
16425                 .input_mux = &alc662_capture_source,
16426         },
16427         [ALC662_3ST_6ch_DIG] = {
16428                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
16429                 .init_verbs = { alc662_init_verbs },
16430                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16431                 .dac_nids = alc662_dac_nids,
16432                 .dig_out_nid = ALC662_DIGOUT_NID,
16433                 .dig_in_nid = ALC662_DIGIN_NID,
16434                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16435                 .channel_mode = alc662_3ST_6ch_modes,
16436                 .need_dac_fix = 1,
16437                 .input_mux = &alc662_capture_source,
16438         },
16439         [ALC662_3ST_6ch] = {
16440                 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
16441                 .init_verbs = { alc662_init_verbs },
16442                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16443                 .dac_nids = alc662_dac_nids,
16444                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16445                 .channel_mode = alc662_3ST_6ch_modes,
16446                 .need_dac_fix = 1,
16447                 .input_mux = &alc662_capture_source,
16448         },
16449         [ALC662_5ST_DIG] = {
16450                 .mixers = { alc662_base_mixer, alc662_chmode_mixer },
16451                 .init_verbs = { alc662_init_verbs },
16452                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16453                 .dac_nids = alc662_dac_nids,
16454                 .dig_out_nid = ALC662_DIGOUT_NID,
16455                 .dig_in_nid = ALC662_DIGIN_NID,
16456                 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
16457                 .channel_mode = alc662_5stack_modes,
16458                 .input_mux = &alc662_capture_source,
16459         },
16460         [ALC662_LENOVO_101E] = {
16461                 .mixers = { alc662_lenovo_101e_mixer },
16462                 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs },
16463                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16464                 .dac_nids = alc662_dac_nids,
16465                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16466                 .channel_mode = alc662_3ST_2ch_modes,
16467                 .input_mux = &alc662_lenovo_101e_capture_source,
16468                 .unsol_event = alc662_lenovo_101e_unsol_event,
16469                 .init_hook = alc662_lenovo_101e_all_automute,
16470         },
16471         [ALC662_ASUS_EEEPC_P701] = {
16472                 .mixers = { alc662_eeepc_p701_mixer },
16473                 .init_verbs = { alc662_init_verbs,
16474                                 alc662_eeepc_sue_init_verbs },
16475                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16476                 .dac_nids = alc662_dac_nids,
16477                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16478                 .channel_mode = alc662_3ST_2ch_modes,
16479                 .input_mux = &alc662_eeepc_capture_source,
16480                 .unsol_event = alc662_eeepc_unsol_event,
16481                 .init_hook = alc662_eeepc_inithook,
16482         },
16483         [ALC662_ASUS_EEEPC_EP20] = {
16484                 .mixers = { alc662_eeepc_ep20_mixer,
16485                             alc662_chmode_mixer },
16486                 .init_verbs = { alc662_init_verbs,
16487                                 alc662_eeepc_ep20_sue_init_verbs },
16488                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16489                 .dac_nids = alc662_dac_nids,
16490                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16491                 .channel_mode = alc662_3ST_6ch_modes,
16492                 .input_mux = &alc662_lenovo_101e_capture_source,
16493                 .unsol_event = alc662_eeepc_ep20_unsol_event,
16494                 .init_hook = alc662_eeepc_ep20_inithook,
16495         },
16496         [ALC662_ECS] = {
16497                 .mixers = { alc662_ecs_mixer },
16498                 .init_verbs = { alc662_init_verbs,
16499                                 alc662_ecs_init_verbs },
16500                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16501                 .dac_nids = alc662_dac_nids,
16502                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16503                 .channel_mode = alc662_3ST_2ch_modes,
16504                 .input_mux = &alc662_eeepc_capture_source,
16505                 .unsol_event = alc662_eeepc_unsol_event,
16506                 .init_hook = alc662_eeepc_inithook,
16507         },
16508         [ALC663_ASUS_M51VA] = {
16509                 .mixers = { alc663_m51va_mixer },
16510                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
16511                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16512                 .dac_nids = alc662_dac_nids,
16513                 .dig_out_nid = ALC662_DIGOUT_NID,
16514                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16515                 .channel_mode = alc662_3ST_2ch_modes,
16516                 .input_mux = &alc663_m51va_capture_source,
16517                 .unsol_event = alc663_m51va_unsol_event,
16518                 .init_hook = alc663_m51va_inithook,
16519         },
16520         [ALC663_ASUS_G71V] = {
16521                 .mixers = { alc663_g71v_mixer },
16522                 .init_verbs = { alc662_init_verbs, alc663_g71v_init_verbs },
16523                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16524                 .dac_nids = alc662_dac_nids,
16525                 .dig_out_nid = ALC662_DIGOUT_NID,
16526                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16527                 .channel_mode = alc662_3ST_2ch_modes,
16528                 .input_mux = &alc662_eeepc_capture_source,
16529                 .unsol_event = alc663_g71v_unsol_event,
16530                 .init_hook = alc663_g71v_inithook,
16531         },
16532         [ALC663_ASUS_H13] = {
16533                 .mixers = { alc663_m51va_mixer },
16534                 .init_verbs = { alc662_init_verbs, alc663_m51va_init_verbs },
16535                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16536                 .dac_nids = alc662_dac_nids,
16537                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16538                 .channel_mode = alc662_3ST_2ch_modes,
16539                 .input_mux = &alc663_m51va_capture_source,
16540                 .unsol_event = alc663_m51va_unsol_event,
16541                 .init_hook = alc663_m51va_inithook,
16542         },
16543         [ALC663_ASUS_G50V] = {
16544                 .mixers = { alc663_g50v_mixer },
16545                 .init_verbs = { alc662_init_verbs, alc663_g50v_init_verbs },
16546                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16547                 .dac_nids = alc662_dac_nids,
16548                 .dig_out_nid = ALC662_DIGOUT_NID,
16549                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
16550                 .channel_mode = alc662_3ST_6ch_modes,
16551                 .input_mux = &alc663_capture_source,
16552                 .unsol_event = alc663_g50v_unsol_event,
16553                 .init_hook = alc663_g50v_inithook,
16554         },
16555         [ALC663_ASUS_MODE1] = {
16556                 .mixers = { alc663_m51va_mixer },
16557                 .cap_mixer = alc662_auto_capture_mixer,
16558                 .init_verbs = { alc662_init_verbs,
16559                                 alc663_21jd_amic_init_verbs },
16560                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16561                 .hp_nid = 0x03,
16562                 .dac_nids = alc662_dac_nids,
16563                 .dig_out_nid = ALC662_DIGOUT_NID,
16564                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16565                 .channel_mode = alc662_3ST_2ch_modes,
16566                 .input_mux = &alc662_eeepc_capture_source,
16567                 .unsol_event = alc663_mode1_unsol_event,
16568                 .init_hook = alc663_mode1_inithook,
16569         },
16570         [ALC662_ASUS_MODE2] = {
16571                 .mixers = { alc662_1bjd_mixer },
16572                 .cap_mixer = alc662_auto_capture_mixer,
16573                 .init_verbs = { alc662_init_verbs,
16574                                 alc662_1bjd_amic_init_verbs },
16575                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16576                 .dac_nids = alc662_dac_nids,
16577                 .dig_out_nid = ALC662_DIGOUT_NID,
16578                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16579                 .channel_mode = alc662_3ST_2ch_modes,
16580                 .input_mux = &alc662_eeepc_capture_source,
16581                 .unsol_event = alc662_mode2_unsol_event,
16582                 .init_hook = alc662_mode2_inithook,
16583         },
16584         [ALC663_ASUS_MODE3] = {
16585                 .mixers = { alc663_two_hp_m1_mixer },
16586                 .cap_mixer = alc662_auto_capture_mixer,
16587                 .init_verbs = { alc662_init_verbs,
16588                                 alc663_two_hp_amic_m1_init_verbs },
16589                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16590                 .hp_nid = 0x03,
16591                 .dac_nids = alc662_dac_nids,
16592                 .dig_out_nid = ALC662_DIGOUT_NID,
16593                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16594                 .channel_mode = alc662_3ST_2ch_modes,
16595                 .input_mux = &alc662_eeepc_capture_source,
16596                 .unsol_event = alc663_mode3_unsol_event,
16597                 .init_hook = alc663_mode3_inithook,
16598         },
16599         [ALC663_ASUS_MODE4] = {
16600                 .mixers = { alc663_asus_21jd_clfe_mixer },
16601                 .cap_mixer = alc662_auto_capture_mixer,
16602                 .init_verbs = { alc662_init_verbs,
16603                                 alc663_21jd_amic_init_verbs},
16604                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16605                 .hp_nid = 0x03,
16606                 .dac_nids = alc662_dac_nids,
16607                 .dig_out_nid = ALC662_DIGOUT_NID,
16608                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16609                 .channel_mode = alc662_3ST_2ch_modes,
16610                 .input_mux = &alc662_eeepc_capture_source,
16611                 .unsol_event = alc663_mode4_unsol_event,
16612                 .init_hook = alc663_mode4_inithook,
16613         },
16614         [ALC663_ASUS_MODE5] = {
16615                 .mixers = { alc663_asus_15jd_clfe_mixer },
16616                 .cap_mixer = alc662_auto_capture_mixer,
16617                 .init_verbs = { alc662_init_verbs,
16618                                 alc663_15jd_amic_init_verbs },
16619                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16620                 .hp_nid = 0x03,
16621                 .dac_nids = alc662_dac_nids,
16622                 .dig_out_nid = ALC662_DIGOUT_NID,
16623                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16624                 .channel_mode = alc662_3ST_2ch_modes,
16625                 .input_mux = &alc662_eeepc_capture_source,
16626                 .unsol_event = alc663_mode5_unsol_event,
16627                 .init_hook = alc663_mode5_inithook,
16628         },
16629         [ALC663_ASUS_MODE6] = {
16630                 .mixers = { alc663_two_hp_m2_mixer },
16631                 .cap_mixer = alc662_auto_capture_mixer,
16632                 .init_verbs = { alc662_init_verbs,
16633                                 alc663_two_hp_amic_m2_init_verbs },
16634                 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
16635                 .hp_nid = 0x03,
16636                 .dac_nids = alc662_dac_nids,
16637                 .dig_out_nid = ALC662_DIGOUT_NID,
16638                 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
16639                 .channel_mode = alc662_3ST_2ch_modes,
16640                 .input_mux = &alc662_eeepc_capture_source,
16641                 .unsol_event = alc663_mode6_unsol_event,
16642                 .init_hook = alc663_mode6_inithook,
16643         },
16644 };
16645
16646
16647 /*
16648  * BIOS auto configuration
16649  */
16650
16651 /* add playback controls from the parsed DAC table */
16652 static int alc662_auto_create_multi_out_ctls(struct alc_spec *spec,
16653                                              const struct auto_pin_cfg *cfg)
16654 {
16655         char name[32];
16656         static const char *chname[4] = {
16657                 "Front", "Surround", NULL /*CLFE*/, "Side"
16658         };
16659         hda_nid_t nid;
16660         int i, err;
16661
16662         for (i = 0; i < cfg->line_outs; i++) {
16663                 if (!spec->multiout.dac_nids[i])
16664                         continue;
16665                 nid = alc880_idx_to_dac(i);
16666                 if (i == 2) {
16667                         /* Center/LFE */
16668                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
16669                                           "Center Playback Volume",
16670                                           HDA_COMPOSE_AMP_VAL(nid, 1, 0,
16671                                                               HDA_OUTPUT));
16672                         if (err < 0)
16673                                 return err;
16674                         err = add_control(spec, ALC_CTL_WIDGET_VOL,
16675                                           "LFE Playback Volume",
16676                                           HDA_COMPOSE_AMP_VAL(nid, 2, 0,
16677                                                               HDA_OUTPUT));
16678                         if (err < 0)
16679                                 return err;
16680                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
16681                                           "Center Playback Switch",
16682                                           HDA_COMPOSE_AMP_VAL(0x0e, 1, 0,
16683                                                               HDA_INPUT));
16684                         if (err < 0)
16685                                 return err;
16686                         err = add_control(spec, ALC_CTL_WIDGET_MUTE,
16687                                           "LFE Playback Switch",
16688                                           HDA_COMPOSE_AMP_VAL(0x0e, 2, 0,
16689                                                               HDA_INPUT));
16690                         if (err < 0)
16691                                 return err;
16692                 } else {
16693                         sprintf(name, "%s Playback Volume", chname[i]);
16694                         err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
16695                                           HDA_COMPOSE_AMP_VAL(nid, 3, 0,
16696                                                               HDA_OUTPUT));
16697                         if (err < 0)
16698                                 return err;
16699                         sprintf(name, "%s Playback Switch", chname[i]);
16700                         err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
16701                                 HDA_COMPOSE_AMP_VAL(alc880_idx_to_mixer(i),
16702                                                     3, 0, HDA_INPUT));
16703                         if (err < 0)
16704                                 return err;
16705                 }
16706         }
16707         return 0;
16708 }
16709
16710 /* add playback controls for speaker and HP outputs */
16711 static int alc662_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
16712                                         const char *pfx)
16713 {
16714         hda_nid_t nid;
16715         int err;
16716         char name[32];
16717
16718         if (!pin)
16719                 return 0;
16720
16721         if (pin == 0x17) {
16722                 /* ALC663 has a mono output pin on 0x17 */
16723                 sprintf(name, "%s Playback Switch", pfx);
16724                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
16725                                   HDA_COMPOSE_AMP_VAL(pin, 2, 0, HDA_OUTPUT));
16726                 return err;
16727         }
16728
16729         if (alc880_is_fixed_pin(pin)) {
16730                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
16731                 /* printk(KERN_DEBUG "DAC nid=%x\n",nid); */
16732                 /* specify the DAC as the extra output */
16733                 if (!spec->multiout.hp_nid)
16734                         spec->multiout.hp_nid = nid;
16735                 else
16736                         spec->multiout.extra_out_nid[0] = nid;
16737                 /* control HP volume/switch on the output mixer amp */
16738                 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
16739                 sprintf(name, "%s Playback Volume", pfx);
16740                 err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
16741                                   HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
16742                 if (err < 0)
16743                         return err;
16744                 sprintf(name, "%s Playback Switch", pfx);
16745                 err = add_control(spec, ALC_CTL_BIND_MUTE, name,
16746                                   HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
16747                 if (err < 0)
16748                         return err;
16749         } else if (alc880_is_multi_pin(pin)) {
16750                 /* set manual connection */
16751                 /* we have only a switch on HP-out PIN */
16752                 sprintf(name, "%s Playback Switch", pfx);
16753                 err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
16754                                   HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
16755                 if (err < 0)
16756                         return err;
16757         }
16758         return 0;
16759 }
16760
16761 /* return the index of the src widget from the connection list of the nid.
16762  * return -1 if not found
16763  */
16764 static int alc662_input_pin_idx(struct hda_codec *codec, hda_nid_t nid,
16765                                 hda_nid_t src)
16766 {
16767         hda_nid_t conn_list[HDA_MAX_CONNECTIONS];
16768         int i, conns;
16769
16770         conns = snd_hda_get_connections(codec, nid, conn_list,
16771                                         ARRAY_SIZE(conn_list));
16772         if (conns < 0)
16773                 return -1;
16774         for (i = 0; i < conns; i++)
16775                 if (conn_list[i] == src)
16776                         return i;
16777         return -1;
16778 }
16779
16780 static int alc662_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
16781 {
16782         unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
16783         return (pincap & AC_PINCAP_IN) != 0;
16784 }
16785
16786 /* create playback/capture controls for input pins */
16787 static int alc662_auto_create_analog_input_ctls(struct hda_codec *codec,
16788                                                 const struct auto_pin_cfg *cfg)
16789 {
16790         struct alc_spec *spec = codec->spec;
16791         struct hda_input_mux *imux = &spec->private_imux[0];
16792         int i, err, idx;
16793
16794         for (i = 0; i < AUTO_PIN_LAST; i++) {
16795                 if (alc662_is_input_pin(codec, cfg->input_pins[i])) {
16796                         idx = alc662_input_pin_idx(codec, 0x0b,
16797                                                    cfg->input_pins[i]);
16798                         if (idx >= 0) {
16799                                 err = new_analog_input(spec, cfg->input_pins[i],
16800                                                        auto_pin_cfg_labels[i],
16801                                                        idx, 0x0b);
16802                                 if (err < 0)
16803                                         return err;
16804                         }
16805                         idx = alc662_input_pin_idx(codec, 0x22,
16806                                                    cfg->input_pins[i]);
16807                         if (idx >= 0) {
16808                                 imux->items[imux->num_items].label =
16809                                         auto_pin_cfg_labels[i];
16810                                 imux->items[imux->num_items].index = idx;
16811                                 imux->num_items++;
16812                         }
16813                 }
16814         }
16815         return 0;
16816 }
16817
16818 static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
16819                                               hda_nid_t nid, int pin_type,
16820                                               int dac_idx)
16821 {
16822         alc_set_pin_output(codec, nid, pin_type);
16823         /* need the manual connection? */
16824         if (alc880_is_multi_pin(nid)) {
16825                 struct alc_spec *spec = codec->spec;
16826                 int idx = alc880_multi_pin_idx(nid);
16827                 snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
16828                                     AC_VERB_SET_CONNECT_SEL,
16829                                     alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
16830         }
16831 }
16832
16833 static void alc662_auto_init_multi_out(struct hda_codec *codec)
16834 {
16835         struct alc_spec *spec = codec->spec;
16836         int i;
16837
16838         alc_subsystem_id(codec, 0x15, 0x1b, 0x14);
16839         for (i = 0; i <= HDA_SIDE; i++) {
16840                 hda_nid_t nid = spec->autocfg.line_out_pins[i];
16841                 int pin_type = get_pin_type(spec->autocfg.line_out_type);
16842                 if (nid)
16843                         alc662_auto_set_output_and_unmute(codec, nid, pin_type,
16844                                                           i);
16845         }
16846 }
16847
16848 static void alc662_auto_init_hp_out(struct hda_codec *codec)
16849 {
16850         struct alc_spec *spec = codec->spec;
16851         hda_nid_t pin;
16852
16853         pin = spec->autocfg.hp_pins[0];
16854         if (pin) /* connect to front */
16855                 /* use dac 0 */
16856                 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
16857         pin = spec->autocfg.speaker_pins[0];
16858         if (pin)
16859                 alc662_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
16860 }
16861
16862 #define ALC662_PIN_CD_NID               ALC880_PIN_CD_NID
16863
16864 static void alc662_auto_init_analog_input(struct hda_codec *codec)
16865 {
16866         struct alc_spec *spec = codec->spec;
16867         int i;
16868
16869         for (i = 0; i < AUTO_PIN_LAST; i++) {
16870                 hda_nid_t nid = spec->autocfg.input_pins[i];
16871                 if (alc662_is_input_pin(codec, nid)) {
16872                         alc_set_input_pin(codec, nid, i);
16873                         if (nid != ALC662_PIN_CD_NID &&
16874                             (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
16875                                 snd_hda_codec_write(codec, nid, 0,
16876                                                     AC_VERB_SET_AMP_GAIN_MUTE,
16877                                                     AMP_OUT_MUTE);
16878                 }
16879         }
16880 }
16881
16882 #define alc662_auto_init_input_src      alc882_auto_init_input_src
16883
16884 static int alc662_parse_auto_config(struct hda_codec *codec)
16885 {
16886         struct alc_spec *spec = codec->spec;
16887         int err;
16888         static hda_nid_t alc662_ignore[] = { 0x1d, 0 };
16889
16890         err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
16891                                            alc662_ignore);
16892         if (err < 0)
16893                 return err;
16894         if (!spec->autocfg.line_outs)
16895                 return 0; /* can't find valid BIOS pin config */
16896
16897         err = alc880_auto_fill_dac_nids(spec, &spec->autocfg);
16898         if (err < 0)
16899                 return err;
16900         err = alc662_auto_create_multi_out_ctls(spec, &spec->autocfg);
16901         if (err < 0)
16902                 return err;
16903         err = alc662_auto_create_extra_out(spec,
16904                                            spec->autocfg.speaker_pins[0],
16905                                            "Speaker");
16906         if (err < 0)
16907                 return err;
16908         err = alc662_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
16909                                            "Headphone");
16910         if (err < 0)
16911                 return err;
16912         err = alc662_auto_create_analog_input_ctls(codec, &spec->autocfg);
16913         if (err < 0)
16914                 return err;
16915
16916         spec->multiout.max_channels = spec->multiout.num_dacs * 2;
16917
16918         if (spec->autocfg.dig_outs)
16919                 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
16920
16921         if (spec->kctls.list)
16922                 add_mixer(spec, spec->kctls.list);
16923
16924         spec->num_mux_defs = 1;
16925         spec->input_mux = &spec->private_imux[0];
16926
16927         add_verb(spec, alc662_auto_init_verbs);
16928         if (codec->vendor_id == 0x10ec0663)
16929                 add_verb(spec, alc663_auto_init_verbs);
16930
16931         err = alc_auto_add_mic_boost(codec);
16932         if (err < 0)
16933                 return err;
16934
16935         return 1;
16936 }
16937
16938 /* additional initialization for auto-configuration model */
16939 static void alc662_auto_init(struct hda_codec *codec)
16940 {
16941         struct alc_spec *spec = codec->spec;
16942         alc662_auto_init_multi_out(codec);
16943         alc662_auto_init_hp_out(codec);
16944         alc662_auto_init_analog_input(codec);
16945         alc662_auto_init_input_src(codec);
16946         if (spec->unsol_event)
16947                 alc_inithook(codec);
16948 }
16949
16950 static int patch_alc662(struct hda_codec *codec)
16951 {
16952         struct alc_spec *spec;
16953         int err, board_config;
16954
16955         spec = kzalloc(sizeof(*spec), GFP_KERNEL);
16956         if (!spec)
16957                 return -ENOMEM;
16958
16959         codec->spec = spec;
16960
16961         alc_fix_pll_init(codec, 0x20, 0x04, 15);
16962
16963         board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
16964                                                   alc662_models,
16965                                                   alc662_cfg_tbl);
16966         if (board_config < 0) {
16967                 printk(KERN_INFO "hda_codec: Unknown model for ALC662, "
16968                        "trying auto-probe from BIOS...\n");
16969                 board_config = ALC662_AUTO;
16970         }
16971
16972         if (board_config == ALC662_AUTO) {
16973                 /* automatic parse from the BIOS config */
16974                 err = alc662_parse_auto_config(codec);
16975                 if (err < 0) {
16976                         alc_free(codec);
16977                         return err;
16978                 } else if (!err) {
16979                         printk(KERN_INFO
16980                                "hda_codec: Cannot set up configuration "
16981                                "from BIOS.  Using base mode...\n");
16982                         board_config = ALC662_3ST_2ch_DIG;
16983                 }
16984         }
16985
16986         err = snd_hda_attach_beep_device(codec, 0x1);
16987         if (err < 0) {
16988                 alc_free(codec);
16989                 return err;
16990         }
16991
16992         if (board_config != ALC662_AUTO)
16993                 setup_preset(spec, &alc662_presets[board_config]);
16994
16995         if (codec->vendor_id == 0x10ec0663) {
16996                 spec->stream_name_analog = "ALC663 Analog";
16997                 spec->stream_name_digital = "ALC663 Digital";
16998         } else if (codec->vendor_id == 0x10ec0272) {
16999                 spec->stream_name_analog = "ALC272 Analog";
17000                 spec->stream_name_digital = "ALC272 Digital";
17001         } else {
17002                 spec->stream_name_analog = "ALC662 Analog";
17003                 spec->stream_name_digital = "ALC662 Digital";
17004         }
17005
17006         spec->stream_analog_playback = &alc662_pcm_analog_playback;
17007         spec->stream_analog_capture = &alc662_pcm_analog_capture;
17008
17009         spec->stream_digital_playback = &alc662_pcm_digital_playback;
17010         spec->stream_digital_capture = &alc662_pcm_digital_capture;
17011
17012         spec->adc_nids = alc662_adc_nids;
17013         spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
17014         spec->capsrc_nids = alc662_capsrc_nids;
17015         spec->capture_style = CAPT_MIX;
17016
17017         if (!spec->cap_mixer)
17018                 set_capture_mixer(spec);
17019         if (codec->vendor_id == 0x10ec0662)
17020                 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
17021         else
17022                 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
17023
17024         spec->vmaster_nid = 0x02;
17025
17026         codec->patch_ops = alc_patch_ops;
17027         if (board_config == ALC662_AUTO)
17028                 spec->init_hook = alc662_auto_init;
17029 #ifdef CONFIG_SND_HDA_POWER_SAVE
17030         if (!spec->loopback.amplist)
17031                 spec->loopback.amplist = alc662_loopbacks;
17032 #endif
17033         codec->proc_widget_hook = print_realtek_coef;
17034
17035         return 0;
17036 }
17037
17038 /*
17039  * patch entries
17040  */
17041 static struct hda_codec_preset snd_hda_preset_realtek[] = {
17042         { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
17043         { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
17044         { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
17045         { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
17046         { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
17047         { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
17048         { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
17049           .patch = patch_alc861 },
17050         { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
17051         { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
17052         { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
17053         { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
17054           .patch = patch_alc883 },
17055         { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
17056           .patch = patch_alc662 },
17057         { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
17058         { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
17059         { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
17060         { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 },
17061         { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
17062           .patch = patch_alc882 }, /* should be patch_alc883() in future */
17063         { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
17064           .patch = patch_alc882 }, /* should be patch_alc883() in future */
17065         { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
17066         { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc883 },
17067         { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
17068           .patch = patch_alc883 },
17069         { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc883 },
17070         { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc883 },
17071         {} /* terminator */
17072 };
17073
17074 MODULE_ALIAS("snd-hda-codec-id:10ec*");
17075
17076 MODULE_LICENSE("GPL");
17077 MODULE_DESCRIPTION("Realtek HD-audio codec");
17078
17079 static struct hda_codec_preset_list realtek_list = {
17080         .preset = snd_hda_preset_realtek,
17081         .owner = THIS_MODULE,
17082 };
17083
17084 static int __init patch_realtek_init(void)
17085 {
17086         return snd_hda_add_codec_preset(&realtek_list);
17087 }
17088
17089 static void __exit patch_realtek_exit(void)
17090 {
17091         snd_hda_delete_codec_preset(&realtek_list);
17092 }
17093
17094 module_init(patch_realtek_init)
17095 module_exit(patch_realtek_exit)